use of BasicCommonClasses.ProductPackage 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 BasicCommonClasses.ProductPackage 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 BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class PlaceProductPackageOnShelvesTest method placeProductPackageOnShelvesIllegalCatalogProductTest.
@Test
public void placeProductPackageOnShelvesIllegalCatalogProductTest() {
assertEquals(ResultDescriptor.SM_ERR, (new CommandExecuter(new CommandWrapper(1, CommandDescriptor.PLACE_PRODUCT_PACKAGE_ON_SHELVES, new Gson().toJson("", String.class)).serialize())).execute(sqlDatabaseConnection).getResultDescriptor());
assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, (new CommandExecuter(new CommandWrapper(1, CommandDescriptor.PLACE_PRODUCT_PACKAGE_ON_SHELVES, 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 Customer method returnProductToShelf.
@Override
public void returnProductToShelf(SmartCode c, int amount) throws AmountBiggerThanAvailable, ProductPackageDoesNotExist, CriticalError, CustomerNotConnected {
String serverResponse;
log.info("Creating REMOVE_PRODUCT_FROM_GROCERY_LIST command wrapper to customer with id: " + id);
establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
try {
serverResponse = sendRequestWithRespondToServer(new CommandWrapper(id, CommandDescriptor.REMOVE_PRODUCT_FROM_GROCERY_LIST, Serialization.serialize(new ProductPackage(c, amount, null))).serialize());
} catch (SocketTimeoutException e) {
log.fatal("Critical bug: failed to get respond from server");
throw new CriticalError();
}
terminateCommunication();
try {
resultDescriptorHandler(getCommandWrapper(serverResponse).getResultDescriptor());
} catch (InvalidCommandDescriptor | InvalidParameter | ProductCatalogDoesNotExist | GroceryListIsEmpty | AuthenticationError | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
/* update customer data: groceryList, cartProductCache, totalSum */
if (groceryList == null)
throw new CriticalError();
try {
groceryList.removeProduct(new ProductPackage(c, amount, null));
} catch (ProductNotInList | AmountIsBiggerThanAvailable ¢) {
throw new CriticalError();
}
long barcode = c.getBarcode();
CartProduct cartProduct = cartProductCache.get(barcode);
ProductPackage productPackage = new ProductPackage(c, amount, null);
cartProduct.removeProductPackage(productPackage);
if (cartProduct.getTotalAmount() <= 0)
cartProductCache.remove(barcode);
else
cartProductCache.put(barcode, cartProduct);
totalProductsAmount -= amount;
totalSum -= amount * cartProduct.getCatalogProduct().getPrice();
log.info("REMOVE_PRODUCT_FROM_GROCERY_LIST command succeed.");
}
use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class ManagePackagesTab method smartcodeEntered.
private void smartcodeEntered(SmartCode c) throws SMException {
log.info("===============================smartcodeEntered======================================");
getProductCatalog(barcodeTextField.getText());
int amountInStore = worker.getProductPackageAmount(new ProductPackage(c, 1, new Location(0, 0, PlaceInMarket.STORE))), amountInWarehouse = worker.getProductPackageAmount(new ProductPackage(c, 1, new Location(0, 0, PlaceInMarket.WAREHOUSE)));
this.amountInStore = amountInStore;
this.amountInWarehouse = amountInWarehouse;
showScanCodePane(false);
showSmartCodeOperationsPane(true);
addProductParametersToQuickView(catalogProduct.getName(), barcodeTextField.getText(), c.getExpirationDate() + "", Integer.toString(amountInStore), Integer.toString(amountInWarehouse));
log.info("amount in store: " + amountInStore);
log.info("amount in werehouse: " + amountInWarehouse);
log.info("===============================smartcodeEntered======================================");
}
Aggregations