use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class EditProductFromCatalogTest method editCatalogProductNotExistInCatalogTest.
@Test
public void editCatalogProductNotExistInCatalogTest() {
int senderID = 1;
CatalogProduct catalogProduct = new CatalogProduct(0, "Shoko", null, null, null, 4, null, null);
String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_PRODUCT_FROM_CATALOG, new Gson().toJson(catalogProduct, CatalogProduct.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ProductNotExistInCatalog()).when(sqlDatabaseConnection).editProductInCatalog(senderID, catalogProduct);
} catch (CriticalError | ClientNotConnected | IngredientNotExist | ManufacturerNotExist e1) {
fail();
} catch (ProductNotExistInCatalog __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class GetAllManufacturerTest method getAllManufacturersSuccessfulTest.
@Test
public void getAllManufacturersSuccessfulTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.GET_ALL_MANUFACTURERS).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.getManufacturersList(senderID)).thenReturn("");
} 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 GetAllManufacturerTest method getAllManufacturersClientNotConnectedTest.
@Test
public void getAllManufacturersClientNotConnectedTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.GET_ALL_MANUFACTURERS).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.getManufacturersList(senderID)).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 RemoveProductPackageFromGroceryListTest method removeProductPackageFromGroceryListSuccessfulTest.
@Test
public void removeProductPackageFromGroceryListSuccessfulTest() {
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.doNothing().when(sqlDatabaseConnection).removeProductFromGroceryList(cartID, productPackage);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class RemoveProductPackageFromGroceryListTest method removeProductToGroceryListIllegalCatalogProductTest.
@Test
public void removeProductToGroceryListIllegalCatalogProductTest() {
assertEquals(ResultDescriptor.SM_ERR, (new CommandExecuter(new CommandWrapper(1, CommandDescriptor.REMOVE_PRODUCT_FROM_GROCERY_LIST, new Gson().toJson("", String.class)).serialize())).execute(sqlDatabaseConnection).getResultDescriptor());
assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, (new CommandExecuter(new CommandWrapper(1, CommandDescriptor.REMOVE_PRODUCT_FROM_GROCERY_LIST, new Gson().toJson(new ProductPackage(new SmartCode(1, null), -1, new Location(0, 0, PlaceInMarket.WAREHOUSE)), ProductPackage.class)).serialize())).execute(sqlDatabaseConnection).getResultDescriptor());
}
Aggregations