use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method logoutAsCart.
/**
* logout cart from system. (remove cartID entry and it grocery list)
*
* @param cartID
* @throws CriticalError
*/
private void logoutAsCart(int cartID) throws CriticalError {
// READ part of transaction
int listID = getCartListId(cartID);
PreparedStatement deleteGroceryList = null, deleteCart = null;
try {
// WRITE part of transaction
// get grocery list and returns each product to shelf
ResultSet groceryListResultSet = getGroceryListResultSetByCartID(cartID);
groceryListResultSet.first();
GroceryList groceryList = SQLJsonGenerator.resultSetToGroceryList(groceryListResultSet);
if (groceryList.getList() != null)
for (ProductPackage p : groceryList.getList().values()) moveProductPackage(cartID, LOCATIONS_TYPES.CART, LOCATIONS_TYPES.STORE, p, p.getAmount());
// delete grocery list and cart
deleteGroceryList = getParameterizedQuery(generateDeleteQuery(GroceriesListsTable.table, BinaryCondition.equalTo(GroceriesListsTable.listIDCol, PARAM_MARK)), listID);
deleteCart = getParameterizedQuery(generateDeleteQuery(CartsListTable.table, BinaryCondition.equalTo(CartsListTable.listIDCol, PARAM_MARK)), listID);
log.debug("logoutAsCart: delete groceryList " + listID + ".\n by run query: " + deleteGroceryList);
deleteGroceryList.executeUpdate();
log.debug("logoutAsCart: disconnect cart " + cartID + ".\n by run query: " + deleteCart);
deleteCart.executeUpdate();
} catch (SQLException e) {
throw new CriticalError();
} catch (ProductPackageAmountNotMatch e) {
log.error("logoutAsCart: trying to return product to shelf but amount not matched to what in the grocery list");
throw new CriticalError();
} catch (ProductPackageNotExist e) {
log.error("logoutAsCart: trying to return product to shelf but product package not exist in grocery list");
throw new CriticalError();
} finally {
closeResources(deleteGroceryList, deleteCart);
}
}
use of BasicCommonClasses.ProductPackage 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 BasicCommonClasses.ProductPackage 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 BasicCommonClasses.ProductPackage 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 BasicCommonClasses.ProductPackage 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