use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class EditIngredientTest method editIngredientIngredientNotExistTest.
@Test
public void editIngredientIngredientNotExistTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.EDIT_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new IngredientNotExist()).when(sqlDatabaseConnection).editIngredient(senderID, ingredient);
} catch (CriticalError | ClientNotConnected e1) {
fail();
} catch (IngredientNotExist e) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.PARAM_ID_IS_NOT_EXIST, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class RegisterNewCustomerTest method registerNewCustomerProfileIngredientNotExistTest.
@Test
public void registerNewCustomerProfileIngredientNotExistTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_CUSTOMER, new Gson().toJson(customerProfile, CustomerProfile.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).registerCustomer(customerProfile.getUserName(), customerProfile.getPassword());
} catch (CriticalError | ClientAlreadyExist e) {
fail();
}
try {
Mockito.doThrow(new IngredientNotExist()).when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
} catch (CriticalError | ClientNotExist e1) {
fail();
} catch (IngredientNotExist e) {
/* success */
}
try {
Mockito.doNothing().when(sqlDatabaseConnection).setSecurityQACustomer(customerProfile.getUserName(), customerProfile.getForgetPassword());
} catch (CriticalError | ClientNotExist e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class RegisterNewCustomerTest method registerNewCustomerProfileSuccessfulTest.
@Test
public void registerNewCustomerProfileSuccessfulTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_CUSTOMER, new Gson().toJson(customerProfile, CustomerProfile.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).registerCustomer(customerProfile.getUserName(), customerProfile.getPassword());
} catch (CriticalError | ClientAlreadyExist e) {
fail();
}
try {
Mockito.doNothing().when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
} catch (CriticalError | ClientNotExist | IngredientNotExist e1) {
fail();
}
try {
Mockito.doNothing().when(sqlDatabaseConnection).setSecurityQACustomer(customerProfile.getUserName(), customerProfile.getForgetPassword());
} catch (CriticalError | ClientNotExist e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class RegisterNewCustomerTest method registerNewCustomerProfileCriticalErrorTest1.
@Test
public void registerNewCustomerProfileCriticalErrorTest1() {
String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_CUSTOMER, new Gson().toJson(customerProfile, CustomerProfile.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).registerCustomer(customerProfile.getUserName(), customerProfile.getPassword());
} catch (ClientAlreadyExist e) {
fail();
} catch (CriticalError e) {
/* success */
}
try {
Mockito.doNothing().when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
} catch (CriticalError | ClientNotExist | IngredientNotExist e1) {
fail();
}
try {
Mockito.doNothing().when(sqlDatabaseConnection).setSecurityQACustomer(customerProfile.getUserName(), customerProfile.getForgetPassword());
} catch (CriticalError | ClientNotExist e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
use of CommandHandler.CommandExecuter in project SmartCity-Market by TechnionYP5777.
the class RegisterNewWorkerTest method registerNewWorkerCriticalErrorTest.
@Test
public void registerNewWorkerCriticalErrorTest() {
int senderID = 1;
String command = new CommandWrapper(senderID, CommandDescriptor.REGISTER_NEW_WORKER, new Gson().toJson(worker, Login.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).addWorker(senderID, worker, worker.getForgetPassword());
} catch (ClientAlreadyExist | ClientNotConnected e) {
fail();
} catch (CriticalError __) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Aggregations