use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class ManagePackagesTab method runTheOperationButtonPressed.
@FXML
private void runTheOperationButtonPressed(ActionEvent __) {
SmartCode smartcode = new SmartCode(Long.parseLong(barcodeTextField.getText()), datePicker.getValue());
int amountVal = editPackagesAmountSpinner.getValue();
log.info("===============================runTheOperationButtonPressed======================================");
log.info("amount in spinner: " + amountVal);
try {
if (barcodeOperationsPane.isVisible()) {
log.info("barcode pane is visible");
if (addPakageToWarhouseRadioButton.isSelected()) {
log.info("addPakageToWarhouseRadioButton");
// init
Location loc = new Location(0, 0, PlaceInMarket.WAREHOUSE);
ProductPackage pp = new ProductPackage(smartcode, amountVal, loc);
// exec
worker.addProductToWarehouse(pp);
printToSuccessLog("Added (" + amountVal + ") " + "product packages (" + pp + ") to warehouse");
this.expirationDate = datePicker.getValue();
searchCodeButtonPressed(null);
}
} else if (addPackageToStoreRadioButton.isSelected()) {
log.info("addPackageToStoreRadioButton");
Location loc = new Location(0, 0, PlaceInMarket.STORE);
ProductPackage pp = new ProductPackage(smartcode, amountVal, loc);
worker.placeProductPackageOnShelves(pp);
printToSuccessLog("Added (" + amountVal + ") " + "product packages (" + pp + ") to store");
searchCodeButtonPressed(null);
} else if (removePackageFromStoreRadioButton.isSelected()) {
log.info("removePackageFromStoreRadioButton");
Location loc = new Location(0, 0, PlaceInMarket.STORE);
ProductPackage pp = new ProductPackage(smartcode, amountVal, loc);
worker.removeProductPackageFromStore(pp);
printToSuccessLog("Removed (" + amountVal + ") " + "product packages (" + pp + ") from store");
searchCodeButtonPressed(null);
} else if (!removePackageFromWarhouseRadioButton.isSelected()) {
if (printSmartCodeRadioButton.isSelected())
new SmartcodePrint(smartcode, amountVal).print();
} else {
log.info("removePackageFromWarhouseRadioButton");
Location loc = new Location(0, 0, PlaceInMarket.WAREHOUSE);
ProductPackage pp = new ProductPackage(smartcode, amountVal, loc);
worker.removeProductPackageFromStore(pp);
printToSuccessLog("Removed (" + amountVal + ") " + "product packages (" + pp + ") from warehouse");
searchCodeButtonPressed(null);
}
} catch (SMException e) {
log.fatal(e);
log.debug(StackTraceUtil.getStackTrace(e));
e.showInfoToUser();
}
log.info("===============================runTheOperationButtonPressed======================================");
}
use of BasicCommonClasses.ProductPackage 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 BasicCommonClasses.ProductPackage 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();
}
}
use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testSplitPackageToCartPakage.
@Test
public void testSplitPackageToCartPakage() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse), productPackageCart = new ProductPackage(new SmartCode(barcodeDebug, date112000), 2, locationWarehouse);
int cartSession = 0;
try {
cartSession = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
sqlConnection.addProductPackageToWarehouse(null, productPackage);
sqlConnection.placeProductPackageOnShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackageCart));
sqlConnection.addProductToGroceryList(cartSession, productPackageCart);
assertEquals(productPackage.getAmount() - productPackageCart.getAmount() + "", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded e) {
fail();
}
productPackage.setAmount(3);
try {
sqlConnection.removeProductPackageFromShelves(null, productPackage);
sqlConnection.removeProductFromGroceryList(cartSession, productPackageCart);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("2", sqlConnection.getProductPackageAmonutOnShelves(null, productPackageCart));
sqlConnection.removeProductPackageFromShelves(null, productPackageCart);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackageCart));
sqlConnection.logout(cartSession, ClientServerDefs.anonymousCustomerUsername);
} catch (ProductPackageNotExist | CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
}
}
use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testRemoveMoreThanHaveFromCart.
// TODO: test manufacturers methods
@Test
public void testRemoveMoreThanHaveFromCart() {
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);
sqlConnection.addProductPackageToWarehouse(null, productPackage);
assertEquals("10", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
sqlConnection.placeProductPackageOnShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("10", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.addProductToGroceryList(sessionCart, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
productPackage.setAmount(11);
try {
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
fail();
} catch (ProductPackageAmountNotMatch e) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageNotExist e) {
fail();
}
productPackage.setAmount(10);
try {
sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
sqlConnection.removeProductPackageFromShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.logout(sessionCart, ClientServerDefs.anonymousCustomerUsername);
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
}
Aggregations