commit
4c2c67be68
3 changed files with 224 additions and 32 deletions
|
@ -1,5 +1,29 @@
|
||||||
<component name="ProjectCodeStyleConfiguration">
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
<code_scheme name="Project" version="173">
|
<code_scheme name="Project" version="173">
|
||||||
|
<DBN-PSQL>
|
||||||
|
<case-options enabled="false">
|
||||||
|
<option name="KEYWORD_CASE" value="lower" />
|
||||||
|
<option name="FUNCTION_CASE" value="lower" />
|
||||||
|
<option name="PARAMETER_CASE" value="lower" />
|
||||||
|
<option name="DATATYPE_CASE" value="lower" />
|
||||||
|
<option name="OBJECT_CASE" value="preserve" />
|
||||||
|
</case-options>
|
||||||
|
<formatting-settings enabled="false" />
|
||||||
|
</DBN-PSQL>
|
||||||
|
<DBN-SQL>
|
||||||
|
<case-options enabled="false">
|
||||||
|
<option name="KEYWORD_CASE" value="lower" />
|
||||||
|
<option name="FUNCTION_CASE" value="lower" />
|
||||||
|
<option name="PARAMETER_CASE" value="lower" />
|
||||||
|
<option name="DATATYPE_CASE" value="lower" />
|
||||||
|
<option name="OBJECT_CASE" value="preserve" />
|
||||||
|
</case-options>
|
||||||
|
<formatting-settings enabled="false">
|
||||||
|
<option name="STATEMENT_SPACING" value="one_line" />
|
||||||
|
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
|
||||||
|
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
|
||||||
|
</formatting-settings>
|
||||||
|
</DBN-SQL>
|
||||||
<Objective-C-extensions>
|
<Objective-C-extensions>
|
||||||
<file>
|
<file>
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
|
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
|
||||||
|
@ -25,5 +49,29 @@
|
||||||
<pair source="c" header="h" fileNamingConvention="NONE" />
|
<pair source="c" header="h" fileNamingConvention="NONE" />
|
||||||
</extensions>
|
</extensions>
|
||||||
</Objective-C-extensions>
|
</Objective-C-extensions>
|
||||||
|
<DBN-PSQL>
|
||||||
|
<case-options enabled="false">
|
||||||
|
<option name="KEYWORD_CASE" value="lower" />
|
||||||
|
<option name="FUNCTION_CASE" value="lower" />
|
||||||
|
<option name="PARAMETER_CASE" value="lower" />
|
||||||
|
<option name="DATATYPE_CASE" value="lower" />
|
||||||
|
<option name="OBJECT_CASE" value="preserve" />
|
||||||
|
</case-options>
|
||||||
|
<formatting-settings enabled="false" />
|
||||||
|
</DBN-PSQL>
|
||||||
|
<DBN-SQL>
|
||||||
|
<case-options enabled="false">
|
||||||
|
<option name="KEYWORD_CASE" value="lower" />
|
||||||
|
<option name="FUNCTION_CASE" value="lower" />
|
||||||
|
<option name="PARAMETER_CASE" value="lower" />
|
||||||
|
<option name="DATATYPE_CASE" value="lower" />
|
||||||
|
<option name="OBJECT_CASE" value="preserve" />
|
||||||
|
</case-options>
|
||||||
|
<formatting-settings enabled="false">
|
||||||
|
<option name="STATEMENT_SPACING" value="one_line" />
|
||||||
|
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
|
||||||
|
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
|
||||||
|
</formatting-settings>
|
||||||
|
</DBN-SQL>
|
||||||
</code_scheme>
|
</code_scheme>
|
||||||
</component>
|
</component>
|
|
@ -256,8 +256,8 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
values.put(COLUMN_COMPANY, company);
|
values.put(COLUMN_COMPANY, company);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean licensed = serviceProvider.isLicensed();
|
String licensed = String.valueOf(serviceProvider.isLicensed());
|
||||||
values.put(COLUMN_LICENSED, Boolean.toString(licensed));
|
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 (address != null && !address.equals(""))values.put(COLUMN_ADDRESS, address);
|
||||||
if (phonenumber != null && !phonenumber.equals(""))values.put(COLUMN_PHONE, phonenumber);
|
if (phonenumber != null && !phonenumber.equals(""))values.put(COLUMN_PHONE, phonenumber);
|
||||||
if (companyname != null && !companyname.equals(""))values.put(COLUMN_COMPANY, companyname);
|
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+" = ?",
|
return writeDB.update(TABLE_LOGIN, values, COLUMN_USERNAME+" = ?",
|
||||||
|
@ -353,8 +353,32 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
* @return whether a user was deleted
|
* @return whether a user was deleted
|
||||||
*/
|
*/
|
||||||
public boolean deleteUser(String username) {
|
public boolean deleteUser(String username) {
|
||||||
return writeDB.delete(TABLE_LOGIN, COLUMN_USERNAME+" = ?",
|
if (username == null) return false;
|
||||||
new String[]{username}) > 0;
|
|
||||||
|
Cursor cursor = readDB.rawQuery("SELECT * FROM " + TABLE_LOGIN
|
||||||
|
+ " WHERE " + COLUMN_USERNAME + " = ?",
|
||||||
|
new String[]{username});
|
||||||
|
|
||||||
|
if (!cursor.moveToFirst()) return false;
|
||||||
|
|
||||||
|
boolean deleted;
|
||||||
|
if (cursor.getString(4).equals("ServiceProvider")) {
|
||||||
|
deleted = writeDB.delete(TABLE_LOGIN, COLUMN_USERNAME+" = ?",
|
||||||
|
new String[]{username}) > 0;
|
||||||
|
|
||||||
|
if (deleted) {
|
||||||
|
writeDB.delete(TABLE_SERVICEPROVIDERS, COLUMN_SERVICEPROVIDERNAME + " = ?",
|
||||||
|
new String[]{username});
|
||||||
|
writeDB.delete(TABLE_AVAILABILITY, COLUMN_AVAILABILITYNAME + " = ?",
|
||||||
|
new String[]{username});
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
return deleted;
|
||||||
|
} else {
|
||||||
|
cursor.close();
|
||||||
|
return writeDB.delete(TABLE_LOGIN, COLUMN_USERNAME+" = ?",
|
||||||
|
new String[]{username}) > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -487,22 +511,13 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
boolean deleted;
|
boolean deleted;
|
||||||
String nullify = null;
|
String nullify = null;
|
||||||
service = service.toLowerCase().trim();
|
service = service.toLowerCase().trim();
|
||||||
ContentValues contentValues = new ContentValues();
|
|
||||||
contentValues.put(COLUMN_SERVICEPROVIDERSERVICE, nullify);
|
|
||||||
writeDB.update(TABLE_SERVICEPROVIDERS, contentValues, COLUMN_SERVICEPROVIDERSERVICE+" = ?",
|
|
||||||
new String[]{service});
|
|
||||||
|
|
||||||
deleted = writeDB.delete(TABLE_SERVICES, COLUMN_SERVICE+" = ?",
|
deleted = writeDB.delete(TABLE_SERVICES, COLUMN_SERVICE+" = ?",
|
||||||
new String[]{service}) > 0;
|
new String[]{service}) > 0;
|
||||||
|
|
||||||
if (deleted) {
|
if (deleted) {
|
||||||
writeDB.delete(TABLE_SERVICEPROVIDERS, COLUMN_SERVICEPROVIDERSERVICE+" = ?",
|
writeDB.delete(TABLE_SERVICEPROVIDERS, COLUMN_SERVICEPROVIDERSERVICE + " = ?",
|
||||||
new String[]{service});
|
new String[]{service});
|
||||||
} else {
|
|
||||||
ContentValues restoreContentValues = new ContentValues();
|
|
||||||
restoreContentValues.put(COLUMN_SERVICEPROVIDERSERVICE, service);
|
|
||||||
writeDB.update(TABLE_SERVICEPROVIDERS, restoreContentValues, COLUMN_SERVICEPROVIDERSERVICE+" = ?",
|
|
||||||
null);
|
|
||||||
}
|
}
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
@ -543,7 +558,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
new String[]{serviceProviderUsername, serviceName},
|
new String[]{serviceProviderUsername, serviceName},
|
||||||
null, null, null,
|
null, null, null,
|
||||||
"1");
|
"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){
|
if (cursor != null && cursor.getCount() > 0){
|
||||||
cursor.close();
|
cursor.close();
|
||||||
return false;
|
return false;
|
||||||
|
@ -629,6 +644,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
addAvailabilityToContentValues(contentValues, COLUMN_FRISTART, COLUMN_FRIEND, availabilities[4]);
|
addAvailabilityToContentValues(contentValues, COLUMN_FRISTART, COLUMN_FRIEND, availabilities[4]);
|
||||||
addAvailabilityToContentValues(contentValues, COLUMN_SATSTART, COLUMN_SATEND, availabilities[5]);
|
addAvailabilityToContentValues(contentValues, COLUMN_SATSTART, COLUMN_SATEND, availabilities[5]);
|
||||||
addAvailabilityToContentValues(contentValues, COLUMN_SUNSTART, COLUMN_SUNEND, availabilities[6]);
|
addAvailabilityToContentValues(contentValues, COLUMN_SUNSTART, COLUMN_SUNEND, availabilities[6]);
|
||||||
|
|
||||||
if (!cursor.moveToFirst()){
|
if (!cursor.moveToFirst()){
|
||||||
contentValues.put(COLUMN_AVAILABILITYNAME, serviceProvider.getUsername());
|
contentValues.put(COLUMN_AVAILABILITYNAME, serviceProvider.getUsername());
|
||||||
writeDB.insert(TABLE_AVAILABILITY, null, contentValues);
|
writeDB.insert(TABLE_AVAILABILITY, null, contentValues);
|
||||||
|
@ -648,7 +664,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
} else {
|
} else {
|
||||||
int startTime = startAndEndTimes[0]*60+startAndEndTimes[1];
|
int startTime = startAndEndTimes[0]*60+startAndEndTimes[1];
|
||||||
int endTime = startAndEndTimes[2]*60+startAndEndTimes[3];
|
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) {
|
|| endTime > 1439 || endTime <= 0) {
|
||||||
contentValues.put(startColumn, 0);
|
contentValues.put(startColumn, 0);
|
||||||
contentValues.put(endColumn, 0);
|
contentValues.put(endColumn, 0);
|
||||||
|
@ -674,6 +690,8 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
serviceProvider.setAvailabilities(i, start/60, start%60,
|
serviceProvider.setAvailabilities(i, start/60, start%60,
|
||||||
end/60, end%60);
|
end/60, end%60);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return new int[7][4];
|
||||||
}
|
}
|
||||||
return serviceProvider.getAvailabilities();
|
return serviceProvider.getAvailabilities();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ public class DBIntegrationTest {
|
||||||
//testing user login table
|
//testing user login table
|
||||||
@Test
|
@Test
|
||||||
public void testAdminExists(){
|
public void testAdminExists(){
|
||||||
|
//Admin is automatically created when DB starts up, if admin does not already exist.
|
||||||
|
//so findUserByUsername("admin") should always return an Admin object
|
||||||
UserType dbUser = dbHelper.findUserByUsername("admin");
|
UserType dbUser = dbHelper.findUserByUsername("admin");
|
||||||
assertEquals("Admin", dbUser.getClass().getSimpleName());
|
assertEquals("Admin", dbUser.getClass().getSimpleName());
|
||||||
assertEquals("admin", dbUser.getUsername());
|
assertEquals("admin", dbUser.getUsername());
|
||||||
|
@ -36,29 +38,32 @@ public class DBIntegrationTest {
|
||||||
UserType originalUser, dbUser;
|
UserType originalUser, dbUser;
|
||||||
boolean deleted, addedOne, addedTwo;
|
boolean deleted, addedOne, addedTwo;
|
||||||
|
|
||||||
|
//add a HomeOwner to database
|
||||||
originalUser = new HomeOwner("mgarzon", "soccer", "Miguel", "Garzon");
|
originalUser = new HomeOwner("mgarzon", "soccer", "Miguel", "Garzon");
|
||||||
addedOne = dbHelper.addUser(originalUser);
|
addedOne = dbHelper.addUser(originalUser);
|
||||||
dbUser = dbHelper.findUserByUsername("mgarzon");
|
|
||||||
|
|
||||||
|
//test retrieving HomeOwner, and confirm that user info is the same as that in object passed
|
||||||
|
dbUser = dbHelper.findUserByUsername("mgarzon");
|
||||||
assertEquals("HomeOwner", dbUser.getClass().getSimpleName());
|
assertEquals("HomeOwner", dbUser.getClass().getSimpleName());
|
||||||
assertEquals("mgarzon", dbUser.getUsername());
|
assertEquals("mgarzon", dbUser.getUsername());
|
||||||
assertEquals("soccer", dbUser.getPassword());
|
assertEquals("soccer", dbUser.getPassword());
|
||||||
assertEquals("Miguel", dbUser.getFirstname());
|
assertEquals("Miguel", dbUser.getFirstname());
|
||||||
assertEquals("Garzon", dbUser.getLastname());
|
assertEquals("Garzon", dbUser.getLastname());
|
||||||
|
|
||||||
|
//add a ServiceProvider to database
|
||||||
originalUser = new ServiceProvider("jbO4aBF4dC", "seg2105", "Juan", "Guzman",
|
originalUser = new ServiceProvider("jbO4aBF4dC", "seg2105", "Juan", "Guzman",
|
||||||
"testaddress", "8888888888", "companydotcom", true);
|
"testaddress", "8888888888", "companydotcom", true);
|
||||||
addedTwo = dbHelper.addUser(originalUser);
|
addedTwo = dbHelper.addUser(originalUser);
|
||||||
dbUser = dbHelper.findUserByUsername("jbO4aBF4dC");
|
|
||||||
|
|
||||||
|
//test retrieving ServiceProvider, and confirm that user info is the same as that in object passed
|
||||||
|
dbUser = dbHelper.findUserByUsername("jbO4aBF4dC");
|
||||||
assertEquals("ServiceProvider", dbUser.getClass().getSimpleName());
|
assertEquals("ServiceProvider", dbUser.getClass().getSimpleName());
|
||||||
assertEquals("jbO4aBF4dC", dbUser.getUsername());
|
assertEquals("jbO4aBF4dC", dbUser.getUsername());
|
||||||
assertEquals("seg2105", dbUser.getPassword());
|
assertEquals("seg2105", dbUser.getPassword());
|
||||||
assertEquals("Juan", dbUser.getFirstname());
|
assertEquals("Juan", dbUser.getFirstname());
|
||||||
assertEquals("Guzman", dbUser.getLastname());
|
assertEquals("Guzman", dbUser.getLastname());
|
||||||
|
|
||||||
|
//if user exsists in database, delete and test that user has been deleted
|
||||||
if (addedOne) {
|
if (addedOne) {
|
||||||
deleted = dbHelper.deleteUser("mgarzon");
|
deleted = dbHelper.deleteUser("mgarzon");
|
||||||
assertTrue(deleted);
|
assertTrue(deleted);
|
||||||
|
@ -68,16 +73,72 @@ public class DBIntegrationTest {
|
||||||
deleted = dbHelper.deleteUser("jbO4aBF4dC");
|
deleted = dbHelper.deleteUser("jbO4aBF4dC");
|
||||||
assertTrue(deleted);
|
assertTrue(deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAddAndGetServiceProvider(){
|
||||||
|
//ServiceProviders have extra fields that can be added to the DB
|
||||||
|
ServiceProvider serviceProvider = new ServiceProvider("7MuF1c59XP", null, null, null,
|
||||||
|
"testaddress", "8888888888", "companydotcom", true);
|
||||||
|
dbHelper.addUser(serviceProvider);
|
||||||
|
|
||||||
|
//retrieve ServiceProvider and test the newly added fields
|
||||||
|
UserType userType = dbHelper.findUserByUsername("7MuF1c59XP");
|
||||||
|
//UserType returned should be an instance of ServiceProvider.
|
||||||
|
//Also serves as check before casting
|
||||||
|
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());
|
||||||
|
|
||||||
|
dbHelper.deleteUser("7MuF1c59XP");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteServiceProvider(){
|
||||||
|
//make sure all the rows related to ServiceProvider in all tables are deleted
|
||||||
|
ServiceProvider serviceProvider = new ServiceProvider("jbO4aBF4dC", null, null, null,
|
||||||
|
"testaddress", "8888888888", "companydotcom", true);
|
||||||
|
dbHelper.addUser(serviceProvider);
|
||||||
|
|
||||||
|
Service service1 = new Service("Hitman", 12358);
|
||||||
|
Service service2 = new Service("Exterminating flatworms", 392.457);
|
||||||
|
dbHelper.addService(service1);
|
||||||
|
dbHelper.addService(service2);
|
||||||
|
|
||||||
|
dbHelper.addServiceProvidedByUser(serviceProvider, service1);
|
||||||
|
dbHelper.addServiceProvidedByUser(serviceProvider, service2);
|
||||||
|
|
||||||
|
serviceProvider.setAvailabilities(0, 4, 18, 19, 30);
|
||||||
|
serviceProvider.setAvailabilities(1, 5, 20, 21, 11);
|
||||||
|
serviceProvider.setAvailabilities(3, 7, 12, 15, 14);
|
||||||
|
serviceProvider.setAvailabilities(4, 0, 0, 23, 29);
|
||||||
|
dbHelper.updateAvailability(serviceProvider);
|
||||||
|
|
||||||
|
dbHelper.deleteUser("jbO4aBF4dC");
|
||||||
|
|
||||||
|
List<String[]> providersList = dbHelper.getAllProvidersByService("hitman");
|
||||||
|
assertEquals(0, providersList.size());
|
||||||
|
providersList = dbHelper.getAllProvidersByService("hitman");
|
||||||
|
assertEquals(0, providersList.size());
|
||||||
|
|
||||||
|
int[][] availabilities = dbHelper.getAvailabilities(serviceProvider);
|
||||||
|
for (int i = 0; i<7; i++) {
|
||||||
|
for (int j = 0; j < 4; j++) {
|
||||||
|
assertEquals(0, availabilities[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddDuplicateUsers(){
|
public void testAddDuplicateUsers(){
|
||||||
boolean added;
|
boolean added;
|
||||||
|
|
||||||
added = dbHelper.addUser(new HomeOwner("jbO4aBF4dC", "soccer", "Miguel", "Garzon"));
|
added = dbHelper.addUser(new HomeOwner("jbO4aBF4dC", "soccer", "Miguel", "Garzon"));
|
||||||
assertTrue(added);
|
assertTrue(added);
|
||||||
|
//should not be able to add user of same username, regardless of user type
|
||||||
added = dbHelper.addUser(new HomeOwner("jbO4aBF4dC", "seg2105", "Miguel", "Garzon"));
|
added = dbHelper.addUser(new HomeOwner("jbO4aBF4dC", "seg2105", "Miguel", "Garzon"));
|
||||||
assertTrue(!added);
|
assertTrue(!added);
|
||||||
added = dbHelper.addUser(new ServiceProvider("jbO4aBF4dC", "seg2105", "Juan", "Guzman",
|
added = dbHelper.addUser(new ServiceProvider("jbO4aBF4dC", "seg2105", "Juan", "Guzman",
|
||||||
|
@ -173,6 +234,8 @@ public class DBIntegrationTest {
|
||||||
assertTrue(added);
|
assertTrue(added);
|
||||||
added = dbHelper.addService(new Service("Exterminating flatworms", 25.00));
|
added = dbHelper.addService(new Service("Exterminating flatworms", 25.00));
|
||||||
assertTrue(!added);
|
assertTrue(!added);
|
||||||
|
added = dbHelper.addService(new Service("extermiNating fLatworms", 25.00));
|
||||||
|
assertTrue(!added);
|
||||||
|
|
||||||
dbHelper.deleteService("Exterminating flatworms");
|
dbHelper.deleteService("Exterminating flatworms");
|
||||||
}
|
}
|
||||||
|
@ -227,16 +290,19 @@ public class DBIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAllServicesProvidedByUserAndDeleteService(){
|
public void testGetAllServicesProvidedByUserAndDeleteService(){
|
||||||
dbHelper.addUser(new ServiceProvider("jbO4aBF4dC", null, null, null,
|
ServiceProvider serviceProvider = new ServiceProvider("jbO4aBF4dC", null, null, null,
|
||||||
"testaddress", "8888888888", "companydotcom", true));
|
"testaddress", "8888888888", "companydotcom", true);
|
||||||
|
dbHelper.addUser(serviceProvider);
|
||||||
|
|
||||||
dbHelper.addService(new Service("Hitman", 12358));
|
Service service1 = new Service("Hitman", 12358);
|
||||||
dbHelper.addService(new Service("Exterminating flatworms", 392.457));
|
Service service2 = new Service("Exterminating flatworms", 392.457);
|
||||||
|
dbHelper.addService(service1);
|
||||||
|
dbHelper.addService(service2);
|
||||||
|
|
||||||
dbHelper.addServiceProvidedByUser("jbO4aBF4dC", "hitman");
|
dbHelper.addServiceProvidedByUser(serviceProvider, service1);
|
||||||
dbHelper.addServiceProvidedByUser("jbO4aBF4dC", "exterminating flatworms");
|
dbHelper.addServiceProvidedByUser(serviceProvider, service2);
|
||||||
|
|
||||||
List<String[]> servicesProvidedByUser = dbHelper.getAllServicesProvidedByUser("jbO4aBF4dC");
|
List<String[]> servicesProvidedByUser = dbHelper.getAllServicesProvidedByUser(serviceProvider);
|
||||||
assertEquals(2, servicesProvidedByUser.size());
|
assertEquals(2, servicesProvidedByUser.size());
|
||||||
assertEquals("hitman", servicesProvidedByUser.get(0)[0]);
|
assertEquals("hitman", servicesProvidedByUser.get(0)[0]);
|
||||||
assertEquals(12358, Double.parseDouble(servicesProvidedByUser.get(0)[1]), 0.00001);
|
assertEquals(12358, Double.parseDouble(servicesProvidedByUser.get(0)[1]), 0.00001);
|
||||||
|
@ -276,18 +342,53 @@ public class DBIntegrationTest {
|
||||||
dbHelper.deleteUser("7MuF1c59XP");
|
dbHelper.deleteUser("7MuF1c59XP");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteServiceProvidedByUser(){
|
||||||
|
ServiceProvider serviceProvider = new ServiceProvider("jbO4aBF4dC", null, null, null,
|
||||||
|
"testaddress", "8888888888", "companydotcom", true);
|
||||||
|
dbHelper.addUser(serviceProvider);
|
||||||
|
|
||||||
|
Service service1 = new Service("Hitman", 12358);
|
||||||
|
Service service2 = new Service("Exterminating flatworms", 392.457);
|
||||||
|
dbHelper.addService(service1);
|
||||||
|
dbHelper.addService(service2);
|
||||||
|
|
||||||
|
dbHelper.addServiceProvidedByUser(serviceProvider, service1);
|
||||||
|
dbHelper.addServiceProvidedByUser(serviceProvider, service2);
|
||||||
|
|
||||||
|
List<String[]> servicesProvidedByUser = dbHelper.getAllServicesProvidedByUser(serviceProvider);
|
||||||
|
assertEquals(2, servicesProvidedByUser.size());
|
||||||
|
|
||||||
|
dbHelper.deleteServiceProvidedByUser("jbO4aBF4dC","hitman");
|
||||||
|
servicesProvidedByUser = dbHelper.getAllServicesProvidedByUser("jbO4aBF4dC");
|
||||||
|
assertEquals(1, servicesProvidedByUser.size());
|
||||||
|
|
||||||
|
dbHelper.deleteServiceProvidedByUser("jbO4aBF4dC", "exterminating flatworms");
|
||||||
|
servicesProvidedByUser = dbHelper.getAllServicesProvidedByUser("jbO4aBF4dC");
|
||||||
|
assertEquals(0, servicesProvidedByUser.size());
|
||||||
|
|
||||||
|
dbHelper.deleteUser("jbO4aBF4dC");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateAndGetAvailability(){
|
public void testUpdateAndGetAvailability(){
|
||||||
ServiceProvider serviceProvider = new ServiceProvider("jbO4aBF4dC", null, null, null,
|
ServiceProvider serviceProvider = new ServiceProvider("jbO4aBF4dC", null, null, null,
|
||||||
"testaddress", "8888888888", "companydotcom", true);
|
"testaddress", "8888888888", "companydotcom", true);
|
||||||
serviceProvider.setAvailabilities(0, 4, 18, 19, 30);
|
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?
|
//TODO:Perhaps implement a deep clone function for UserType?
|
||||||
ServiceProvider serviceProvider2 = new ServiceProvider("jbO4aBF4dC", null, null, null,
|
ServiceProvider serviceProvider2 = new ServiceProvider("jbO4aBF4dC", null, null, null,
|
||||||
"testaddress", "8888888888", "companydotcom", true);
|
"testaddress", "8888888888", "companydotcom", true);
|
||||||
serviceProvider2.setAvailabilities(0, 4, 18, 19, 30);
|
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);
|
dbHelper.addUser(serviceProvider2);
|
||||||
|
|
||||||
|
@ -305,7 +406,32 @@ public class DBIntegrationTest {
|
||||||
assertEquals(availabilities[i][j], dbAvailabilities[i][j]);
|
assertEquals(availabilities[i][j], dbAvailabilities[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dbHelper.deleteUser("jbO4aBF4dC");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInvalidAvailability(){
|
||||||
|
ServiceProvider serviceProvider = new ServiceProvider("jbO4aBF4dC", null, null, null,
|
||||||
|
"testaddress", "8888888888", "companydotcom", true);
|
||||||
|
serviceProvider.setAvailabilities(2, 8, 14, 8, 14);
|
||||||
|
serviceProvider.setAvailabilities(3, 15, 12, 8, 14);
|
||||||
|
|
||||||
|
|
||||||
|
dbHelper.addUser(serviceProvider);
|
||||||
|
|
||||||
|
boolean updated = dbHelper.updateAvailability(serviceProvider);
|
||||||
|
assertTrue(updated);
|
||||||
|
int[][] dbAvailabilities = dbHelper.getAvailabilities(serviceProvider);
|
||||||
|
int[][] availabilities = serviceProvider.getAvailabilities();
|
||||||
|
|
||||||
|
for (int i = 0; i<7; i++) {
|
||||||
|
for (int j = 0; j < 4; j++) {
|
||||||
|
assertEquals(0, availabilities[i][j]);
|
||||||
|
assertEquals(0, dbAvailabilities[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dbHelper.deleteUser("jbO4aBF4dC");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue