use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCartCheckoutDoLogout.
/**
* [[SuppressWarningsSpartan]]
*/
@Test
public void testCartCheckoutDoLogout() {
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);
assertTrue(sqlConnection.isClientLoggedIn(session));
sqlConnection.addProductPackageToWarehouse(null, productPackage);
sqlConnection.placeProductPackageOnShelves(null, productPackage);
sqlConnection.addProductToGroceryList(session, productPackage);
} catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
try {
sqlConnection.cartCheckout(session);
assertFalse(sqlConnection.isClientLoggedIn(session));
} catch (CriticalError | ClientNotConnected | GroceryListIsEmpty e) {
fail();
}
try {
sqlConnection.logout(session, ClientServerDefs.anonymousCustomerUsername);
fail();
} catch (ClientNotConnected e) {
} catch (CriticalError e) {
fail();
}
try {
sqlConnection.clearGroceryListsHistory();
} catch (CriticalError e) {
fail();
}
}
use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCartLogoutReturnsProductsToShelves.
@Test
public void testCartLogoutReturnsProductsToShelves() {
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);
sqlConnection.addProductPackageToWarehouse(null, productPackage);
sqlConnection.placeProductPackageOnShelves(null, productPackage);
assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.addProductToGroceryList(session, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
try {
sqlConnection.logout(session, ClientServerDefs.anonymousCustomerUsername);
assert !sqlConnection.isClientLoggedIn(session);
assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
sqlConnection.removeProductPackageFromShelves(null, productPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
}
}
use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class AddProductToGroceryListTest method addProductToGroceryListCriticalErrorTest.
@Test
public void addProductToGroceryListCriticalErrorTest() {
int cartID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(cartID, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).addProductToGroceryList(cartID, productPackage);
} catch (ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
fail();
} catch (CriticalError __) {
/* Successful */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of BasicCommonClasses.ProductPackage in project SmartCity-Market by TechnionYP5777.
the class AddProductToGroceryListTest method addProductToGroceryListIllegalCatalogProductTest.
@Test
public void addProductToGroceryListIllegalCatalogProductTest() {
assertEquals(ResultDescriptor.SM_ERR, (new CommandExecuter(new CommandWrapper(1, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, new Gson().toJson("", String.class)).serialize())).execute(sqlDatabaseConnection).getResultDescriptor());
assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, (new CommandExecuter(new CommandWrapper(1, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, 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 AddProductToGroceryListTest method addProductToGroceryListProductPackageAmountNotMatchTest.
@Test
public void addProductToGroceryListProductPackageAmountNotMatchTest() {
int cartID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(cartID, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ProductPackageAmountNotMatch()).when(sqlDatabaseConnection).addProductToGroceryList(cartID, productPackage);
} catch (ClientNotConnected | CriticalError | ProductNotExistInCatalog | ProductPackageNotExist e) {
fail();
} catch (ProductPackageAmountNotMatch __) {
/* Successful */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_PRODUCT_PACKAGE_AMOUNT_BIGGER_THEN_AVAILABLE, out.getResultDescriptor());
}
Aggregations