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());
}
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");
}
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());
}
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());
}
Aggregations