use of SQLDatabase.SQLDatabaseException.ClientNotExist in project SmartCity-Market by TechnionYP5777.
the class CommandExecuter method removeWorker.
private void removeWorker(SQLDatabaseConnection c) {
String username = null;
log.info("Remove worker from serderID " + inCommandWrapper.getSenderID() + " command called");
try {
username = Serialization.deserialize(inCommandWrapper.getData(), String.class);
} catch (java.lang.RuntimeException e) {
log.fatal("Failed to parse data for Remove Worker command");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
return;
}
log.info("Trying to remove worker " + username + " from system");
try {
c.removeWorker(inCommandWrapper.getSenderID(), username);
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
} catch (CriticalError e) {
log.fatal("Remove worker command failed, critical error occured from SQL Database connection");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} catch (ClientNotExist e) {
log.info("Remove worker command failed, worker is not exist");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST);
} catch (ClientNotConnected e) {
log.info("Remove worker command failed, manager is not connected");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
}
log.info("Remove worker " + username + " from system finished");
}
use of SQLDatabase.SQLDatabaseException.ClientNotExist 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 SQLDatabase.SQLDatabaseException.ClientNotExist 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 SQLDatabase.SQLDatabaseException.ClientNotExist 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.ClientNotExist in project SmartCity-Market by TechnionYP5777.
the class RemoveCustomerTest method removeCustomerSuccessfulTest.
@Test
public void removeCustomerSuccessfulTest() {
String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_CUSTOMER, new Gson().toJson(username, String.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doNothing().when(sqlDatabaseConnection).removeCustomer(username);
} catch (CriticalError | ClientNotExist e) {
fail();
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Aggregations