Search in sources :

Example 6 with GroceryListIsEmpty

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");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CommandWrapper(ClientServerApi.CommandWrapper) GroceryListIsEmpty(SQLDatabase.SQLDatabaseException.GroceryListIsEmpty)

Example 7 with GroceryListIsEmpty

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());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CommandWrapper(ClientServerApi.CommandWrapper) GroceryListIsEmpty(SQLDatabase.SQLDatabaseException.GroceryListIsEmpty) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 8 with GroceryListIsEmpty

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());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CommandWrapper(ClientServerApi.CommandWrapper) GroceryListIsEmpty(SQLDatabase.SQLDatabaseException.GroceryListIsEmpty) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Aggregations

ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)8 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)8 GroceryListIsEmpty (SQLDatabase.SQLDatabaseException.GroceryListIsEmpty)8 Test (org.junit.Test)7 CommandWrapper (ClientServerApi.CommandWrapper)5 CommandExecuter (CommandHandler.CommandExecuter)4 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)3 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)3 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)3 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)3 ProductPackage (BasicCommonClasses.ProductPackage)2 SmartCode (BasicCommonClasses.SmartCode)2 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)2 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)2 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)2