Added Integration Tests for services table
This commit is contained in:
parent
4c6b7686af
commit
48ac26f804
2 changed files with 94 additions and 1 deletions
|
@ -309,6 +309,17 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
new String[]{name}) > 0;
|
new String[]{name}) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Looks in database for a service, and deletes the corresponding
|
||||||
|
* entry. Returns true if a user was deleted, false otherwise.
|
||||||
|
*
|
||||||
|
* @param service service of entry to delete
|
||||||
|
* @return whether the service was deleted
|
||||||
|
*/
|
||||||
|
public boolean deleteService(String service) {
|
||||||
|
return writeDB.delete(TABLE_SERVICES, COLUMN_SERVICE+" = ?",
|
||||||
|
new String[]{service}) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of String arrays containing the service categories,
|
* Returns a list of String arrays containing the service categories,
|
||||||
|
|
|
@ -20,7 +20,7 @@ import static org.junit.Assert.*;
|
||||||
public class DBIntegrationTest {
|
public class DBIntegrationTest {
|
||||||
private DBHelper dbHelper = new DBHelper(RuntimeEnvironment.application);
|
private DBHelper dbHelper = new DBHelper(RuntimeEnvironment.application);
|
||||||
|
|
||||||
|
//testing user login table
|
||||||
@Test
|
@Test
|
||||||
public void testAdminExists(){
|
public void testAdminExists(){
|
||||||
UserType dbUser = dbHelper.findUserByUsername("admin");
|
UserType dbUser = dbHelper.findUserByUsername("admin");
|
||||||
|
@ -128,5 +128,87 @@ public class DBIntegrationTest {
|
||||||
dbHelper.deleteUser("jbO4aBF4dC");
|
dbHelper.deleteUser("jbO4aBF4dC");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Testing services table
|
||||||
|
@Test
|
||||||
|
public void testAddAndDeleteServices(){
|
||||||
|
Service originalService, dbService;
|
||||||
|
boolean deleted, addedOne, addedTwo;
|
||||||
|
|
||||||
|
|
||||||
|
originalService = new Service("Exterminating flatworms", 20.00);
|
||||||
|
addedOne = dbHelper.addService(originalService);
|
||||||
|
dbService = dbHelper.findService("Exterminating flatworms");
|
||||||
|
|
||||||
|
assertEquals("Exterminating flatworms", dbService.getName());
|
||||||
|
assertEquals(20.00, dbService.getRate(), 0.001);
|
||||||
|
|
||||||
|
|
||||||
|
originalService = new Service("Cleaning shoes", 15.00);
|
||||||
|
addedTwo = dbHelper.addService(originalService);
|
||||||
|
dbService = dbHelper.findService("Cleaning shoes");
|
||||||
|
|
||||||
|
assertEquals("Cleaning shoes", dbService.getName());
|
||||||
|
assertEquals(15.00, dbService.getRate(), 0.001);
|
||||||
|
|
||||||
|
if (addedOne) {
|
||||||
|
deleted = dbHelper.deleteService("Exterminating flatworms");
|
||||||
|
assertTrue(deleted);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addedTwo) {
|
||||||
|
deleted = dbHelper.deleteService("Cleaning shoes");
|
||||||
|
assertTrue(deleted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddDuplicateService(){
|
||||||
|
boolean added;
|
||||||
|
|
||||||
|
added = dbHelper.addService(new Service("Exterminating flatworms", 20.00));
|
||||||
|
assertTrue(added);
|
||||||
|
added = dbHelper.addService(new Service("Exterminating flatworms", 25.00));
|
||||||
|
assertTrue(!added);
|
||||||
|
|
||||||
|
dbHelper.deleteService("Exterminating flatworms");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateService(){
|
||||||
|
boolean updated;
|
||||||
|
Service service;
|
||||||
|
|
||||||
|
dbHelper.addService(new Service("Exterminating flatworms", 20.00));
|
||||||
|
updated = dbHelper.updateService("Exterminating flatworms", 25.00);
|
||||||
|
assertTrue(updated);
|
||||||
|
|
||||||
|
service = dbHelper.findService("Exterminating flatworms");
|
||||||
|
|
||||||
|
assertEquals("Exterminating flatworms", service.getName());
|
||||||
|
assertEquals(25.00, service.getRate(), 0.001);
|
||||||
|
|
||||||
|
dbHelper.deleteService("Exterminating flatworms");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllServices(){
|
||||||
|
dbHelper.addService(new Service("Exterminating flatworms", 20.00));
|
||||||
|
|
||||||
|
List<String[]> allServices = dbHelper.getAllServices();
|
||||||
|
|
||||||
|
for (String[] service : allServices){
|
||||||
|
/* for (String s : user){
|
||||||
|
System.out.print(s + " ");
|
||||||
|
}
|
||||||
|
System.out.println();*/
|
||||||
|
Service dbService = dbHelper.findService(service[0]);
|
||||||
|
assertEquals(dbService.getRate(), Double.parseDouble(service[1]), 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
dbHelper.deleteUser("jbO4aBF4dC");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue