use of SQLDatabase.SQLDatabaseException.IngredientNotExist in project SmartCity-Market by TechnionYP5777.
the class RegisterNewCustomerTest method registerNewCustomerProfileCriticalErrorTest2.
@Test
public void registerNewCustomerProfileCriticalErrorTest2() {
String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_CUSTOMER, new Gson().toJson(customerProfile, CustomerProfile.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).registerCustomer(customerProfile.getUserName(), customerProfile.getPassword());
} catch (CriticalError | ClientAlreadyExist e) {
fail();
}
try {
Mockito.doThrow(new ClientNotExist()).when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
} catch (CriticalError | IngredientNotExist e1) {
fail();
} catch (ClientNotExist e) {
/* success */
}
try {
Mockito.doNothing().when(sqlDatabaseConnection).setSecurityQACustomer(customerProfile.getUserName(), customerProfile.getForgetPassword());
} catch (CriticalError | ClientNotExist e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.IngredientNotExist in project SmartCity-Market by TechnionYP5777.
the class RegisterNewCustomerTest method registerNewCustomerProfileClientAlreadyExistTest.
@Test
public void registerNewCustomerProfileClientAlreadyExistTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_CUSTOMER, new Gson().toJson(customerProfile, CustomerProfile.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ClientAlreadyExist()).when(sqlDatabaseConnection).registerCustomer(customerProfile.getUserName(), customerProfile.getPassword());
} catch (CriticalError e) {
fail();
} catch (ClientAlreadyExist e) {
/* success */
}
try {
Mockito.doNothing().when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
} catch (CriticalError | ClientNotExist | IngredientNotExist e1) {
fail();
}
try {
Mockito.doNothing().when(sqlDatabaseConnection).setSecurityQACustomer(customerProfile.getUserName(), customerProfile.getForgetPassword());
} catch (CriticalError | ClientNotExist e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_USERNAME_ALREADY_EXISTS, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.IngredientNotExist in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCantEditNotExistedIngredient.
@Test
public void testCantEditNotExistedIngredient() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
final String ingredientName = "glotendebug";
Ingredient ingredient = new Ingredient(999, ingredientName);
try {
sqlConnection.editIngredient(null, ingredient);
fail();
} catch (CriticalError | ClientNotConnected e) {
fail();
} catch (IngredientNotExist e) {
}
}
use of SQLDatabase.SQLDatabaseException.IngredientNotExist in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testAddRemoveIngredient.
@Test
public void testAddRemoveIngredient() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
final String ingredientName = "glotendebug";
String result = null;
Ingredient ingredient = null;
//test add ingredient
try {
String tempID = sqlConnection.addIngredient(null, ingredientName);
ingredient = Serialization.deserialize(tempID, Ingredient.class);
result = sqlConnection.getIngredientsList();
} catch (CriticalError | ClientNotConnected e) {
fail();
}
assert result != null;
HashSet<Ingredient> set = Serialization.deserializeIngredientHashSet(result);
assert set != null;
assert set.contains(ingredient);
//test remove ingredient
try {
sqlConnection.removeIngredient(null, ingredient);
result = sqlConnection.getIngredientsList();
} catch (CriticalError | ClientNotConnected | IngredientNotExist | IngredientStillUsed e) {
fail();
}
assert result != null;
set = Serialization.deserializeIngredientHashSet(result);
assert set != null;
assert !set.contains(ingredient);
}
use of SQLDatabase.SQLDatabaseException.IngredientNotExist in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCantRemoveNotExistedIngredient.
@Test
public void testCantRemoveNotExistedIngredient() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
final String ingredientName = "glotendebug";
Ingredient ingredient = new Ingredient(999, ingredientName);
try {
sqlConnection.removeIngredient(null, ingredient);
fail();
} catch (CriticalError | ClientNotConnected | IngredientStillUsed e) {
fail();
} catch (IngredientNotExist e) {
}
}
Aggregations