use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class PlaceProductPackageOnShelvesTest method placeProductPackageOnShelvesProductNotExistInCatalogTest.
@Test
public void placeProductPackageOnShelvesProductNotExistInCatalogTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(senderID, CommandDescriptor.PLACE_PRODUCT_PACKAGE_ON_SHELVES, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ProductNotExistInCatalog()).when(sqlDatabaseConnection).placeProductPackageOnShelves(senderID, productPackage);
} catch (CriticalError | ClientNotConnected | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
} catch (ProductNotExistInCatalog __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST, out.getResultDescriptor());
}
use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class PlaceProductPackageOnShelvesTest method placeProductPackageOnShelvesSuccessfulTest.
@Test
public void placeProductPackageOnShelvesSuccessfulTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(senderID, CommandDescriptor.PLACE_PRODUCT_PACKAGE_ON_SHELVES, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).placeProductPackageOnShelves(senderID, productPackage);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class GetProductPackageAmountTest method getProductPackageAmountSuccessfulTest.
@Test
public void getProductPackageAmountSuccessfulTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(senderID, CommandDescriptor.GET_PRODUCT_PACKAGE_AMOUNT, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(!productPackage.getLocation().equals(PlaceInMarket.WAREHOUSE) ? sqlDatabaseConnection.getProductPackageAmonutOnShelves(senderID, productPackage) : sqlDatabaseConnection.getProductPackageAmonutInWarehouse(senderID, productPackage)).thenReturn("");
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e1) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class GetProductPackageAmountTest method getProductPackageAmountClientNotConnectedTest.
@Test
public void getProductPackageAmountClientNotConnectedTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(senderID, CommandDescriptor.GET_PRODUCT_PACKAGE_AMOUNT, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.getProductPackageAmonutOnShelves(senderID, productPackage)).thenThrow(new ClientNotConnected());
Mockito.when(sqlDatabaseConnection.getProductPackageAmonutInWarehouse(senderID, productPackage)).thenThrow(new ClientNotConnected());
} catch (CriticalError | ProductNotExistInCatalog e1) {
fail();
} catch (ClientNotConnected __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testAddTwicePakageToWarehouse.
@Test
public void testAddTwicePakageToWarehouse() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse);
try {
sqlConnection.addProductPackageToWarehouse(null, productPackage);
assertEquals("5", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
sqlConnection.addProductPackageToWarehouse(null, productPackage);
assertEquals("10", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
productPackage.setAmount(10);
sqlConnection.removeProductPackageFromWarehouse(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
}
Aggregations