use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class ViewCatalogProductTest method viewCatalogProductWorkerNotConnectedTest.
@Test
public void viewCatalogProductWorkerNotConnectedTest() {
int senderID = 1;
SmartCode smartCode = new SmartCode(0, null);
String command = new CommandWrapper(senderID, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.getProductFromCatalog(senderID, smartCode.getBarcode())).thenThrow(new ClientNotConnected());
} catch (ProductNotExistInCatalog | ClientNotConnected | CriticalError e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class AddNewManufacturerTest method addNewManufacturerClientNotConnectedrTest.
@Test
public void addNewManufacturerClientNotConnectedrTest() {
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 ClientNotConnected());
} catch (CriticalError e) {
fail();
} catch (ClientNotConnected e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class AddNewManufacturerTest method addNewManufacturerSuccessfulTest.
@Test
public void addNewManufacturerSuccessfulTest() {
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())).thenReturn("0");
} catch (CriticalError | ClientNotConnected e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class AddProductPackageToWarehouseTest method addProductPackageToWarehouseCriticalErrorTest.
@Test
public void addProductPackageToWarehouseCriticalErrorTest() {
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 CriticalError()).when(sqlDatabaseConnection).addProductPackageToWarehouse(senderID, productPackage);
} catch (ClientNotConnected | ProductNotExistInCatalog e) {
fail();
} catch (CriticalError __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.
the class AddProductToCatalogTest method addCatalogProductClientNotConnectedTest.
@Test
public void addCatalogProductClientNotConnectedTest() {
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 ClientNotConnected()).when(sqlDatabaseConnection).addProductToCatalog(senderID, catalogProduct);
} catch (ProductAlreadyExistInCatalog | IngredientNotExist | ManufacturerNotExist | CriticalError e) {
fail();
} catch (ClientNotConnected __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
Aggregations