diff --git a/OlympusServices/.idea/codeStyles/Project.xml b/OlympusServices/.idea/codeStyles/Project.xml index 30aa626..d5ec3da 100644 --- a/OlympusServices/.idea/codeStyles/Project.xml +++ b/OlympusServices/.idea/codeStyles/Project.xml @@ -1,5 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file 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 d4d1f92..f85b3b1 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 @@ -256,8 +256,8 @@ public class DBHelper extends SQLiteOpenHelper { values.put(COLUMN_COMPANY, company); } - boolean licensed = serviceProvider.isLicensed(); - values.put(COLUMN_LICENSED, Boolean.toString(licensed)); + String licensed = String.valueOf(serviceProvider.isLicensed()); + values.put(COLUMN_LICENSED, licensed); } @@ -338,7 +338,7 @@ public class DBHelper extends SQLiteOpenHelper { if (address != null && !address.equals(""))values.put(COLUMN_ADDRESS, address); if (phonenumber != null && !phonenumber.equals(""))values.put(COLUMN_PHONE, phonenumber); if (companyname != null && !companyname.equals(""))values.put(COLUMN_COMPANY, companyname); - if (licensed != null)values.put(COLUMN_LICENSED, Boolean.toString(licensed)); + if (licensed != null)values.put(COLUMN_LICENSED, String.valueOf(licensed)); return writeDB.update(TABLE_LOGIN, values, COLUMN_USERNAME+" = ?", @@ -543,7 +543,7 @@ public class DBHelper extends SQLiteOpenHelper { new String[]{serviceProviderUsername, serviceName}, null, null, null, "1"); - //If cursor has 1+ elements in it, username already exists in table + //If cursor has 1+ elements in it, username/service combination already exists in table if (cursor != null && cursor.getCount() > 0){ cursor.close(); return false; @@ -629,6 +629,7 @@ public class DBHelper extends SQLiteOpenHelper { addAvailabilityToContentValues(contentValues, COLUMN_FRISTART, COLUMN_FRIEND, availabilities[4]); addAvailabilityToContentValues(contentValues, COLUMN_SATSTART, COLUMN_SATEND, availabilities[5]); addAvailabilityToContentValues(contentValues, COLUMN_SUNSTART, COLUMN_SUNEND, availabilities[6]); + if (!cursor.moveToFirst()){ contentValues.put(COLUMN_AVAILABILITYNAME, serviceProvider.getUsername()); writeDB.insert(TABLE_AVAILABILITY, null, contentValues); @@ -648,7 +649,7 @@ public class DBHelper extends SQLiteOpenHelper { } else { int startTime = startAndEndTimes[0]*60+startAndEndTimes[1]; int endTime = startAndEndTimes[2]*60+startAndEndTimes[3]; - if (endTime - startTime <=0 || startTime > 1439 || startTime <= 0 + if (endTime - startTime <=0 || startTime > 1439 || startTime < 0 || endTime > 1439 || endTime <= 0) { contentValues.put(startColumn, 0); contentValues.put(endColumn, 0); 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 7a38f8a..d936dd9 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 @@ -173,6 +173,8 @@ public class DBIntegrationTest { assertTrue(added); added = dbHelper.addService(new Service("Exterminating flatworms", 25.00)); assertTrue(!added); + added = dbHelper.addService(new Service("extermiNating fLatworms", 25.00)); + assertTrue(!added); dbHelper.deleteService("Exterminating flatworms"); } @@ -227,16 +229,19 @@ public class DBIntegrationTest { @Test public void testGetAllServicesProvidedByUserAndDeleteService(){ - dbHelper.addUser(new ServiceProvider("jbO4aBF4dC", null, null, null, - "testaddress", "8888888888", "companydotcom", true)); + ServiceProvider serviceProvider = new ServiceProvider("jbO4aBF4dC", null, null, null, + "testaddress", "8888888888", "companydotcom", true); + dbHelper.addUser(serviceProvider); - dbHelper.addService(new Service("Hitman", 12358)); - dbHelper.addService(new Service("Exterminating flatworms", 392.457)); + Service service1 = new Service("Hitman", 12358); + Service service2 = new Service("Exterminating flatworms", 392.457); + dbHelper.addService(service1); + dbHelper.addService(service2); - dbHelper.addServiceProvidedByUser("jbO4aBF4dC", "hitman"); - dbHelper.addServiceProvidedByUser("jbO4aBF4dC", "exterminating flatworms"); + dbHelper.addServiceProvidedByUser(serviceProvider, service1); + dbHelper.addServiceProvidedByUser(serviceProvider, service2); - List servicesProvidedByUser = dbHelper.getAllServicesProvidedByUser("jbO4aBF4dC"); + List servicesProvidedByUser = dbHelper.getAllServicesProvidedByUser(serviceProvider); assertEquals(2, servicesProvidedByUser.size()); assertEquals("hitman", servicesProvidedByUser.get(0)[0]); assertEquals(12358, Double.parseDouble(servicesProvidedByUser.get(0)[1]), 0.00001); @@ -281,13 +286,17 @@ public class DBIntegrationTest { ServiceProvider serviceProvider = new ServiceProvider("jbO4aBF4dC", null, null, null, "testaddress", "8888888888", "companydotcom", true); serviceProvider.setAvailabilities(0, 4, 18, 19, 30); - serviceProvider.setAvailabilities(3, 8, 12, 15, 14); + serviceProvider.setAvailabilities(1, 5, 20, 21, 11); + serviceProvider.setAvailabilities(3, 7, 12, 15, 14); + serviceProvider.setAvailabilities(4, 0, 0, 23, 29); //TODO:Perhaps implement a deep clone function for UserType? ServiceProvider serviceProvider2 = new ServiceProvider("jbO4aBF4dC", null, null, null, "testaddress", "8888888888", "companydotcom", true); serviceProvider2.setAvailabilities(0, 4, 18, 19, 30); - serviceProvider2.setAvailabilities(3, 8, 12, 15, 14); + serviceProvider2.setAvailabilities(1, 5, 20, 21, 11); + serviceProvider2.setAvailabilities(3, 7, 12, 15, 14); + serviceProvider2.setAvailabilities(4, 0, 0, 23, 29); dbHelper.addUser(serviceProvider2); @@ -307,5 +316,57 @@ public class DBIntegrationTest { } } + @Test + public void testAddServiceProvider(){ + ServiceProvider serviceProvider = new ServiceProvider("7MuF1c59XP", null, null, null, + "testaddress", "8888888888", "companydotcom", true); + dbHelper.addUser(serviceProvider); + + UserType userType = dbHelper.findUserByUsername("7MuF1c59XP"); + assertTrue(userType instanceof ServiceProvider); + ServiceProvider dbServiceProvider = (ServiceProvider) userType; + assertEquals(serviceProvider.getAddress(), dbServiceProvider.getAddress()); + assertEquals(serviceProvider.getPhonenumber(), dbServiceProvider.getPhonenumber()); + assertEquals(serviceProvider.getCompanyname(), dbServiceProvider.getCompanyname()); + assertEquals(serviceProvider.isLicensed(), dbServiceProvider.isLicensed()); + + } +// +// @Test +// public void testDeleteServiceProvidedByUser(){ +// +// } + +// @Test +// public void testInvalidAvailability(){ +// ServiceProvider serviceProvider = new ServiceProvider("jbO4aBF4dC", null, null, null, +// "testaddress", "8888888888", "companydotcom", true); +// serviceProvider.setAvailabilities(0, 4, 18, 19, 30); +// serviceProvider.setAvailabilities(3, 8, 12, 15, 14); +// +// //TODO:Perhaps implement a deep clone function for UserType? +// ServiceProvider serviceProvider2 = new ServiceProvider("jbO4aBF4dC", null, null, null, +// "testaddress", "8888888888", "companydotcom", true); +// serviceProvider2.setAvailabilities(0, 4, 18, 19, 30); +// serviceProvider2.setAvailabilities(3, 8, 12, 15, 14); +// +// dbHelper.addUser(serviceProvider2); +// +// boolean updated = dbHelper.updateAvailability(serviceProvider2); +// assertTrue(updated); +// +// serviceProvider2.setAvailabilities(3, 8, 12, 15, 10); +// int[][] dbAvailabilities = dbHelper.getAvailabilities(serviceProvider2); +// int[][] availabilities = serviceProvider.getAvailabilities(); +// +// assertEquals(14, serviceProvider2.getAvailabilities()[3][3]); +// +// for (int i = 0; i < 7; i++){ +// for (int j = 0; j < 4; j++){ +// assertEquals(availabilities[i][j], dbAvailabilities[i][j]); +// } +// } +// } + }