use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class RemoveProductPackageFromGroceryListTest method removeProductPackageFromGroceryListClientNotConnectedTest.
@Test
public void removeProductPackageFromGroceryListClientNotConnectedTest() {
int cartID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(cartID, CommandDescriptor.REMOVE_PRODUCT_FROM_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).removeProductFromGroceryList(cartID, productPackage);
} catch (CriticalError | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
} catch (ClientNotConnected __) {
/* Successful */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class AddNewIngredientTest method addNewIngredientClientNotConnectedTest.
@Test
public void addNewIngredientClientNotConnectedTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.addIngredient(senderID, ingredient.getName())).thenThrow(new ClientNotConnected());
} catch (CriticalError e) {
fail();
} catch (ClientNotConnected e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class AddNewIngredientTest method addNewIngredientSuccessfulTest.
@Test
public void addNewIngredientSuccessfulTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.addIngredient(senderID, ingredient.getName())).thenReturn("0");
} catch (CriticalError | ClientNotConnected e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class AddNewIngredientTest method addNewIngredientCriticalErrorTest.
@Test
public void addNewIngredientCriticalErrorTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.addIngredient(senderID, ingredient.getName())).thenThrow(new CriticalError());
} catch (ClientNotConnected e) {
fail();
} catch (CriticalError e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class AddProductToCatalogTest method addCatalogProductCriticalErrorTest.
@Test
public void addCatalogProductCriticalErrorTest() {
int senderID = 1;
CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 4, null, null);
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_PRODUCT_TO_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).addProductToCatalog(senderID, catalogProduct);
} catch (ProductAlreadyExistInCatalog | IngredientNotExist | ManufacturerNotExist | ClientNotConnected e) {
fail();
} catch (CriticalError __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Aggregations