use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class UpdateCustomerProfileTest method updateCustomerProfileSuccessfulTest.
@Test
public void updateCustomerProfileSuccessfulTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.UPDATE_CUSTOMER_PROFILE, new Gson().toJson(customerProfile, CustomerProfile.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
} catch (CriticalError | ClientNotExist | IngredientNotExist e1) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class ViewCatalogProductTest method viewCatalogProductCriticalErrorTest.
@Test
public void viewCatalogProductCriticalErrorTest() {
int senderID = 1;
SmartCode smartCode = new SmartCode(0, null);
String command = new CommandWrapper(senderID, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.getProductFromCatalog(senderID, smartCode.getBarcode())).thenThrow(new CriticalError());
} catch (ClientNotConnected | ProductNotExistInCatalog | CriticalError e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class ViewCatalogProductTest method viewCatalogProductWorkerNotConnectedTest.
@Test
public void viewCatalogProductWorkerNotConnectedTest() {
int senderID = 1;
SmartCode smartCode = new SmartCode(0, null);
String command = new CommandWrapper(senderID, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.getProductFromCatalog(senderID, smartCode.getBarcode())).thenThrow(new ClientNotConnected());
} catch (ProductNotExistInCatalog | ClientNotConnected | CriticalError e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class AddNewManufacturerTest method addNewManufacturerClientNotConnectedrTest.
@Test
public void addNewManufacturerClientNotConnectedrTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.addManufacturer(senderID, manufacturer.getName())).thenThrow(new ClientNotConnected());
} catch (CriticalError e) {
fail();
} catch (ClientNotConnected e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class AddNewManufacturerTest method addNewManufacturerSuccessfulTest.
@Test
public void addNewManufacturerSuccessfulTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.ADD_MANUFACTURER, new Gson().toJson(manufacturer, Manufacturer.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.when(sqlDatabaseConnection.addManufacturer(senderID, manufacturer.getName())).thenReturn("0");
} catch (CriticalError | ClientNotConnected e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Aggregations