use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class AddNewManufacturerTest method addNewManufacturerCriticalErrorTest.
@Test
public void addNewManufacturerCriticalErrorTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.addManufacturer(senderID, manufacturer.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 AddProductPackageToWarehouseTest method addProductPackageToWarehouseSuccessfulTest.
@Test
public void addProductPackageToWarehouseSuccessfulTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_PRODUCT_PACKAGE_TO_WAREHOUSE, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).addProductPackageToWarehouse(senderID, productPackage);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class AddProductPackageToWarehouseTest method addProductPackageToWarehouseIllegalProductPackageTest.
@Test
public void addProductPackageToWarehouseIllegalProductPackageTest() {
assertEquals(ResultDescriptor.SM_ERR, (new CommandExecuter(new CommandWrapper(1, CommandDescriptor.ADD_PRODUCT_PACKAGE_TO_WAREHOUSE, new Gson().toJson("", String.class)).serialize())).execute(sqlDatabaseConnection).getResultDescriptor());
assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, (new CommandExecuter(new CommandWrapper(1, CommandDescriptor.ADD_PRODUCT_PACKAGE_TO_WAREHOUSE, new Gson().toJson(new ProductPackage(new SmartCode(1, null), -1, new Location(0, 0, PlaceInMarket.WAREHOUSE)), ProductPackage.class)).serialize())).execute(sqlDatabaseConnection).getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class AddProductPackageToWarehouseTest method addProductPackageToWarehouseClientNotConnectedTest.
@Test
public void addProductPackageToWarehouseClientNotConnectedTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_PRODUCT_PACKAGE_TO_WAREHOUSE, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).addProductPackageToWarehouse(senderID, productPackage);
} catch (CriticalError | ProductNotExistInCatalog e) {
fail();
} catch (ClientNotConnected __) {
/* 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 AddProductPackageToWarehouseTest method addProductPackageToWarehouseProductNotExistInCatalogTest.
@Test
public void addProductPackageToWarehouseProductNotExistInCatalogTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_PRODUCT_PACKAGE_TO_WAREHOUSE, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ProductNotExistInCatalog()).when(sqlDatabaseConnection).addProductPackageToWarehouse(senderID, productPackage);
} catch (CriticalError | ClientNotConnected e) {
fail();
} catch (ProductNotExistInCatalog __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST, out.getResultDescriptor());
}
Aggregations