use of SQLDatabase.SQLDatabaseException.ClientAlreadyExist 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 SQLDatabase.SQLDatabaseException.ClientAlreadyExist 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());
}
use of SQLDatabase.SQLDatabaseException.ClientAlreadyExist in project SmartCity-Market by TechnionYP5777.
the class RegisterNewWorkerTest method registerNewWorkerClientNotConnectedTest.
@Test
public void registerNewWorkerClientNotConnectedTest() {
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 ClientNotConnected()).when(sqlDatabaseConnection).addWorker(senderID, worker, worker.getForgetPassword());
} catch (CriticalError | ClientAlreadyExist e) {
fail();
} catch (ClientNotConnected __) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ClientAlreadyExist in project SmartCity-Market by TechnionYP5777.
the class RegisterNewWorkerTest method registerNewWorkerClientAlreadyExistTest.
@Test
public void registerNewWorkerClientAlreadyExistTest() {
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 ClientAlreadyExist()).when(sqlDatabaseConnection).addWorker(senderID, worker, worker.getForgetPassword());
} catch (CriticalError | ClientNotConnected e) {
fail();
} catch (ClientAlreadyExist __) {
/* success */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_USERNAME_ALREADY_EXISTS, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ClientAlreadyExist in project SmartCity-Market by TechnionYP5777.
the class RegisterNewWorkerTest method registerNewWorkerSuccessfulTest.
@Test
public void registerNewWorkerSuccessfulTest() {
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.doNothing().when(sqlDatabaseConnection).addWorker(senderID, worker, worker.getForgetPassword());
} catch (CriticalError | ClientAlreadyExist | ClientNotConnected e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Aggregations