From 97148737de991793f1c612978c0a4661d9e72801 Mon Sep 17 00:00:00 2001 From: Mary Tran Date: Thu, 25 Oct 2018 16:43:08 -0400 Subject: [PATCH] Added Integration Tests for services table --- .../olympus/olympusservices/DBHelper.java | 11 +++ .../olympusservices/DBIntegrationTest.java | 84 ++++++++++++++++++- 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java index 7d34209..cd9346e 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/DBHelper.java @@ -309,6 +309,17 @@ public class DBHelper extends SQLiteOpenHelper { 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, diff --git a/OlympusServices/app/src/test/java/com/uottawa/olympus/olympusservices/DBIntegrationTest.java b/OlympusServices/app/src/test/java/com/uottawa/olympus/olympusservices/DBIntegrationTest.java index 397c1c8..073ee17 100644 --- a/OlympusServices/app/src/test/java/com/uottawa/olympus/olympusservices/DBIntegrationTest.java +++ b/OlympusServices/app/src/test/java/com/uottawa/olympus/olympusservices/DBIntegrationTest.java @@ -20,7 +20,7 @@ import static org.junit.Assert.*; public class DBIntegrationTest { private DBHelper dbHelper = new DBHelper(RuntimeEnvironment.application); - + //testing user login table @Test public void testAdminExists(){ UserType dbUser = dbHelper.findUserByUsername("admin"); @@ -128,5 +128,87 @@ public class DBIntegrationTest { 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 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"); + } + }