use of SQLDatabase.SQLDatabaseException.GroceryListIsEmpty 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 SQLDatabase.SQLDatabaseException.GroceryListIsEmpty in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCartCantCheckoutWithEmptyList.
@Test
public void testCartCantCheckoutWithEmptyList() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
int session = 0;
try {
session = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
assert sqlConnection.isClientLoggedIn(session);
} catch (AuthenticationError | CriticalError | ClientAlreadyConnected | NumberOfConnectionsExceeded e) {
fail();
}
try {
sqlConnection.cartCheckout(session);
fail();
} catch (CriticalError | ClientNotConnected e) {
fail();
} catch (GroceryListIsEmpty e) {
}
try {
sqlConnection.logout(session, ClientServerDefs.anonymousCustomerUsername);
} catch (CriticalError | ClientNotConnected e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseException.GroceryListIsEmpty in project SmartCity-Market by TechnionYP5777.
the class CheckoutGroceryListTest method checkoutGroceryListSuccessfulTest.
@Test
public void checkoutGroceryListSuccessfulTest() {
int cartID = 1;
String command = new CommandWrapper(cartID, CommandDescriptor.CHECKOUT_GROCERY_LIST).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).cartCheckout(cartID);
} catch (CriticalError | ClientNotConnected | GroceryListIsEmpty e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.GroceryListIsEmpty in project SmartCity-Market by TechnionYP5777.
the class CheckoutGroceryListTest method checkoutGroceryListCriticalErrorTest.
@Test
public void checkoutGroceryListCriticalErrorTest() {
int cartID = 1;
String command = new CommandWrapper(cartID, CommandDescriptor.CHECKOUT_GROCERY_LIST).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).cartCheckout(cartID);
} catch (ClientNotConnected | GroceryListIsEmpty e) {
fail();
} catch (CriticalError __) {
/* Successful */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.GroceryListIsEmpty 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