Search in sources :

Example 1 with NoGroceryListToRestore

use of SQLDatabase.SQLDatabaseException.NoGroceryListToRestore in project SmartCity-Market by TechnionYP5777.

the class LoadGroceryListTest method loadGroceryListNoGroceryListToRestoreTest.

@Test
public void loadGroceryListNoGroceryListToRestoreTest() {
    int senderID = 1;
    String command = new CommandWrapper(senderID, CommandDescriptor.LOAD_GROCERY_LIST).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.cartRestoreGroceryList(senderID)).thenThrow(new NoGroceryListToRestore());
    } catch (NoGroceryListToRestore __) {
    /* Success */
    } catch (CriticalError e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
Also used : NoGroceryListToRestore(SQLDatabase.SQLDatabaseException.NoGroceryListToRestore) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 2 with NoGroceryListToRestore

use of SQLDatabase.SQLDatabaseException.NoGroceryListToRestore in project SmartCity-Market by TechnionYP5777.

the class CommandExecuter method loadGroceryList.

private void loadGroceryList(SQLDatabaseConnection c) {
    log.info("Load Grocery List from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, c.cartRestoreGroceryList(inCommandWrapper.getSenderID()));
    } catch (CriticalError e) {
        log.fatal("Load Grocery List command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (NoGroceryListToRestore e) {
        log.info("Load Grocery List command failed, no grocery list for senderID " + inCommandWrapper.getSenderID() + " to restore");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
    }
    log.info("Load Grocery List from serderID " + inCommandWrapper.getSenderID() + " command finished");
}
Also used : NoGroceryListToRestore(SQLDatabase.SQLDatabaseException.NoGroceryListToRestore) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper)

Example 3 with NoGroceryListToRestore

use of SQLDatabase.SQLDatabaseException.NoGroceryListToRestore in project SmartCity-Market by TechnionYP5777.

the class LoadGroceryListTest method loadGroceryListSuccessfulTest.

@Test
public void loadGroceryListSuccessfulTest() {
    int senderID = 1;
    String command = new CommandWrapper(senderID, CommandDescriptor.LOAD_GROCERY_LIST).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.cartRestoreGroceryList(senderID)).thenReturn("");
    } catch (CriticalError | NoGroceryListToRestore e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : NoGroceryListToRestore(SQLDatabase.SQLDatabaseException.NoGroceryListToRestore) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 4 with NoGroceryListToRestore

use of SQLDatabase.SQLDatabaseException.NoGroceryListToRestore in project SmartCity-Market by TechnionYP5777.

the class LoadGroceryListTest method loadGroceryListCriticalErrorTest.

@Test
public void loadGroceryListCriticalErrorTest() {
    int senderID = 1;
    String command = new CommandWrapper(senderID, CommandDescriptor.LOAD_GROCERY_LIST).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.cartRestoreGroceryList(senderID)).thenThrow(new CriticalError());
    } catch (CriticalError __) {
    /* Success */
    } catch (NoGroceryListToRestore e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Also used : NoGroceryListToRestore(SQLDatabase.SQLDatabaseException.NoGroceryListToRestore) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Aggregations

CommandWrapper (ClientServerApi.CommandWrapper)4 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)4 NoGroceryListToRestore (SQLDatabase.SQLDatabaseException.NoGroceryListToRestore)4 CommandExecuter (CommandHandler.CommandExecuter)3 Test (org.junit.Test)3