use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.
the class RemoveProductPackageFromStoreTest method removeProductPackageFromStoreClientNotConnectedTest.
@Test
public void removeProductPackageFromStoreClientNotConnectedTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_PACKAGE_FROM_STORE, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
if (productPackage.getLocation().equals(PlaceInMarket.STORE))
Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).removeProductPackageFromShelves(senderID, productPackage);
else
Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).removeProductPackageFromWarehouse(senderID, productPackage);
} catch (CriticalError | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
} catch (ClientNotConnected __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method teardown.
@After
public void teardown() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse), productPackage2 = new ProductPackage(new SmartCode(barcodeDebug, date232015), 5, locationWarehouse);
try {
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage2));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage2));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testRemoveMoreThanHaveFromWarehouse.
@Test
public void testRemoveMoreThanHaveFromWarehouse() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 10, locationWarehouse);
try {
sqlConnection.addProductPackageToWarehouse(null, productPackage);
assertEquals("10", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e) {
fail();
}
productPackage.setAmount(11);
try {
sqlConnection.removeProductPackageFromWarehouse(null, productPackage);
fail();
} catch (ProductPackageAmountNotMatch e) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageNotExist e) {
fail();
}
productPackage.setAmount(10);
try {
sqlConnection.removeProductPackageFromWarehouse(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testSimpleGetProductFromCatalog.
@Test
public void testSimpleGetProductFromCatalog() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
HashSet<Ingredient> ingredients = new HashSet<Ingredient>();
ingredients.add(new Ingredient(1, "חלב"));
HashSet<Location> locations = new HashSet<Location>();
// locations.add(new Location(1, 1, PlaceInMarket.STORE));
String milkImage = "";
try {
assertEquals(sqlConnection.getProductFromCatalog(null, 1234567890), new Gson().toJson(new CatalogProduct(1234567890L, "חלב", ingredients, new Manufacturer(1, "תנובה"), "", 10.5, milkImage, locations)));
} catch (ProductNotExistInCatalog | ClientNotConnected | CriticalError e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testRemovePakageFromWarehouseTwice.
@Test
public void testRemovePakageFromWarehouseTwice() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 10, locationWarehouse);
try {
sqlConnection.addProductPackageToWarehouse(null, productPackage);
assertEquals("10", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
productPackage.setAmount(5);
sqlConnection.removeProductPackageFromWarehouse(null, productPackage);
assertEquals("5", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
sqlConnection.removeProductPackageFromWarehouse(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
}
Aggregations