use of SQLDatabase.SQLDatabaseException.IngredientStillUsed in project SmartCity-Market by TechnionYP5777.
the class RemoveIngredientTest method removeIngredientClientNotConnectedTest.
@Test
public void removeIngredientClientNotConnectedTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).removeIngredient(senderID, ingredient);
} catch (CriticalError | IngredientNotExist | IngredientStillUsed e1) {
fail();
} catch (ClientNotConnected e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.IngredientStillUsed 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.IngredientStillUsed 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) {
}
}
use of SQLDatabase.SQLDatabaseException.IngredientStillUsed 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.IngredientStillUsed in project SmartCity-Market by TechnionYP5777.
the class RemoveIngredientTest method removeIngredientIngredientNotExistTest.
@Test
public void removeIngredientIngredientNotExistTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new IngredientNotExist()).when(sqlDatabaseConnection).removeIngredient(senderID, ingredient);
} catch (CriticalError | ClientNotConnected | IngredientStillUsed e1) {
fail();
} catch (IngredientNotExist e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.PARAM_ID_IS_NOT_EXIST, out.getResultDescriptor());
}
Aggregations