use of SQLDatabase.SQLDatabaseException.GroceryListIsEmpty in project SmartCity-Market by TechnionYP5777.
the class CommandExecuter method checkoutGroceryList.
private void checkoutGroceryList(SQLDatabaseConnection c) {
log.info("Checkout Grocery List from serderID " + inCommandWrapper.getSenderID() + " command called");
try {
c.cartCheckout(inCommandWrapper.getSenderID());
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
} catch (CriticalError e) {
log.fatal("Checkout Grocery List command failed, critical error occured from SQL Database connection");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} catch (ClientNotConnected e) {
log.info("Checkout Grocery List command failed, client is not connected");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
} catch (GroceryListIsEmpty e) {
log.info("Checkout Grocery List command failed, grocery list is empty");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_GROCERY_LIST_IS_EMPTY);
}
log.info("Checkout Grocery List from serderID " + inCommandWrapper.getSenderID() + " finished");
}
use of SQLDatabase.SQLDatabaseException.GroceryListIsEmpty in project SmartCity-Market by TechnionYP5777.
the class CheckoutGroceryListTest method checkoutGroceryListClientNotConnectedTest.
@Test
public void checkoutGroceryListClientNotConnectedTest() {
int cartID = 1;
String command = new CommandWrapper(cartID, CommandDescriptor.CHECKOUT_GROCERY_LIST).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ClientNotConnected()).when(sqlDatabaseConnection).cartCheckout(cartID);
} catch (CriticalError | GroceryListIsEmpty e) {
fail();
} catch (ClientNotConnected __) {
/* Successful */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.GroceryListIsEmpty in project SmartCity-Market by TechnionYP5777.
the class CheckoutGroceryListTest method checkoutGroceryListEmptyTest.
@Test
public void checkoutGroceryListEmptyTest() {
int cartID = 1;
String command = new CommandWrapper(cartID, CommandDescriptor.CHECKOUT_GROCERY_LIST).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new GroceryListIsEmpty()).when(sqlDatabaseConnection).cartCheckout(cartID);
} catch (CriticalError | ClientNotConnected e) {
fail();
} catch (GroceryListIsEmpty __) {
/* Successful */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_GROCERY_LIST_IS_EMPTY, out.getResultDescriptor());
}
Aggregations