use of SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch in project SmartCity-Market by TechnionYP5777.
the class RemoveProductPackageFromStoreTest method removeProductPackageFromStoreSuccessfulTest.
@Test
public void removeProductPackageFromStoreSuccessfulTest() {
int senderID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.STORE));
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.doNothing().when(sqlDatabaseConnection).removeProductPackageFromShelves(senderID, productPackage);
else
Mockito.doNothing().when(sqlDatabaseConnection).removeProductPackageFromWarehouse(senderID, productPackage);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch in project SmartCity-Market by TechnionYP5777.
the class PlaceProductPackageOnShelvesTest method placeProductPackageOnShelvesProductPackageAmountNotMatchTest.
@Test
public void placeProductPackageOnShelvesProductPackageAmountNotMatchTest() {
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 ProductPackageAmountNotMatch()).when(sqlDatabaseConnection).placeProductPackageOnShelves(senderID, productPackage);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageNotExist e) {
fail();
} catch (ProductPackageAmountNotMatch __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_PRODUCT_PACKAGE_AMOUNT_BIGGER_THEN_AVAILABLE, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch in project SmartCity-Market by TechnionYP5777.
the class PlaceProductPackageOnShelvesTest method placeProductPackageOnShelvesProductPackageNotExistTest.
@Test
public void placeProductPackageOnShelvesProductPackageNotExistTest() {
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 ProductPackageNotExist()).when(sqlDatabaseConnection).placeProductPackageOnShelves(senderID, productPackage);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
} catch (ProductPackageNotExist __) {
/* Success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_PRODUCT_PACKAGE_DOES_NOT_EXIST, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testRemoveNotExistedPakageFromCart.
@Test
public void testRemoveNotExistedPakageFromCart() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 10, locationWarehouse);
int sessionCart = 0;
try {
sessionCart = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
} catch (AuthenticationError | ClientAlreadyConnected | CriticalError | NumberOfConnectionsExceeded e1) {
fail();
}
try {
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
fail();
} catch (ProductPackageNotExist e) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
}
try {
sqlConnection.addProductPackageToWarehouse(null, productPackage);
assertEquals("10", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e1) {
fail();
}
try {
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
fail();
} catch (ProductPackageNotExist e) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
}
try {
sqlConnection.placeProductPackageOnShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("10", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e1) {
fail();
}
try {
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
fail();
} catch (ProductPackageNotExist e) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
}
try {
sqlConnection.addProductToGroceryList(sessionCart, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("10", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e1) {
fail();
}
try {
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
fail();
} catch (ProductPackageNotExist e) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
}
try {
sqlConnection.removeProductPackageFromShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e1) {
fail();
}
try {
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
fail();
} catch (ProductPackageNotExist e) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
}
try {
sqlConnection.logout(sessionCart, ClientServerDefs.anonymousCustomerUsername);
} catch (ClientNotConnected | CriticalError e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testWhenCartCheckoutItProductsNotReturnToStore.
@Test
public void testWhenCartCheckoutItProductsNotReturnToStore() {
ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse);
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
int session = 0;
try {
session = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
assert sqlConnection.isClientLoggedIn(session);
sqlConnection.addProductPackageToWarehouse(null, productPackage);
sqlConnection.placeProductPackageOnShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.addProductToGroceryList(session, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
try {
sqlConnection.cartCheckout(session);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
assert !sqlConnection.isClientLoggedIn(session);
} catch (CriticalError | ClientNotConnected | GroceryListIsEmpty | ProductNotExistInCatalog e) {
fail();
}
try {
sqlConnection.clearGroceryListsHistory();
} catch (CriticalError e) {
fail();
}
}
Aggregations