use of SQLDatabase.SQLDatabaseException.IngredientNotExist in project SmartCity-Market by TechnionYP5777.
the class EditIngredientTest method editIngredientSuccessfulTest.
@Test
public void editIngredientSuccessfulTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).editIngredient(senderID, ingredient);
} catch (CriticalError | ClientNotConnected | IngredientNotExist e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.IngredientNotExist in project SmartCity-Market by TechnionYP5777.
the class EditIngredientTest method editIngredientCriticalErrorTest.
@Test
public void editIngredientCriticalErrorTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).editIngredient(senderID, ingredient);
} catch (ClientNotConnected | IngredientNotExist e1) {
fail();
} catch (CriticalError e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.IngredientNotExist in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCustomerCanSetProfile.
@Test
public void testCustomerCanSetProfile() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
CustomerProfile p = new CustomerProfile(customerName, customerName, "name", "last", "number", "email", "city", "street", date112000, new HashSet<>(), new ForgotPasswordData("question", "answer"));
CustomerProfile result = null;
try {
sqlConnection.registerCustomer(customerName, customerName);
} catch (CriticalError | ClientAlreadyExist e) {
fail();
}
try {
sqlConnection.setCustomerProfile(customerName, p);
result = Serialization.deserialize(sqlConnection.getCustomerProfile(customerName), CustomerProfile.class);
} catch (CriticalError | ClientNotExist | IngredientNotExist e1) {
fail();
} finally {
try {
sqlConnection.removeCustomer(customerName);
} catch (CriticalError | ClientNotExist e) {
e.printStackTrace();
}
}
assertEquals(p.getBirthdate(), result.getBirthdate());
assertEquals(p.getCity(), result.getCity());
assertEquals(p.getEmailAddress(), result.getEmailAddress());
assertEquals(p.getFirstName(), result.getFirstName());
assertEquals(p.getLastName(), result.getLastName());
assertEquals(p.getPhoneNumber(), result.getPhoneNumber());
assertEquals(p.getStreet(), result.getStreet());
assertEquals(p.getUserName(), result.getUserName());
}
use of SQLDatabase.SQLDatabaseException.IngredientNotExist in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testEditIngredient.
@Test
public void testEditIngredient() {
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);
ingredient.setName("newIngredient");
sqlConnection.editIngredient(null, ingredient);
result = sqlConnection.getIngredientsList();
} catch (CriticalError | ClientNotConnected | IngredientNotExist e) {
fail();
}
assert result != null;
HashSet<Ingredient> set = Serialization.deserializeIngredientHashSet(result);
assert set != null;
assert set.contains(ingredient);
//remove ingredient
try {
sqlConnection.removeIngredient(null, ingredient);
} catch (CriticalError | ClientNotConnected | IngredientNotExist | IngredientStillUsed e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseException.IngredientNotExist in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCantSetProfileToNotExistedCustomer.
@Test
public void testCantSetProfileToNotExistedCustomer() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
CustomerProfile p = new CustomerProfile(customerName, customerName, "name", "last", "number", "email", "city", "street", date112000, new HashSet<>(), new ForgotPasswordData("question", "answer"));
try {
sqlConnection.setCustomerProfile(customerName, p);
fail();
} catch (CriticalError | IngredientNotExist e1) {
fail();
} catch (ClientNotExist e2) {
}
}
Aggregations