use of SQLDatabase.SQLDatabaseException.ClientAlreadyExist in project SmartCity-Market by TechnionYP5777.
the class CommandExecuter method registerNewWorker.
private void registerNewWorker(SQLDatabaseConnection c) {
Login login = null;
log.info("Register new worker from serderID " + inCommandWrapper.getSenderID() + " command called");
try {
login = Serialization.deserialize(inCommandWrapper.getData(), Login.class);
} catch (java.lang.RuntimeException e) {
log.fatal("Failed to parse data for Register New Worker command");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
return;
}
log.info("Trying to register new worker " + login.getUserName() + " to system");
try {
c.addWorker(inCommandWrapper.getSenderID(), login, login.getForgetPassword());
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
} catch (CriticalError e) {
log.fatal("Register new worker command failed, critical error occured from SQL Database connection");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} catch (ClientAlreadyExist e) {
log.info("Register new worker command failed, worker already exists");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_ALREADY_EXISTS);
} catch (ClientNotConnected e) {
log.info("Register new worker command failed, manager is not connected");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
}
log.info("Register new worker " + login.getUserName() + " to system finished");
}
use of SQLDatabase.SQLDatabaseException.ClientAlreadyExist in project SmartCity-Market by TechnionYP5777.
the class CommandExecuter method registerNewCustomer.
private void registerNewCustomer(SQLDatabaseConnection c) {
CustomerProfile profile = null;
log.info("Register new customer from serderID " + inCommandWrapper.getSenderID() + " command called");
try {
profile = Serialization.deserialize(inCommandWrapper.getData(), CustomerProfile.class);
} catch (java.lang.RuntimeException e) {
log.fatal("Failed to parse data for Register New Customer command");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
return;
}
log.info("Trying to register new customer " + profile + " to system");
try {
c.registerCustomer(profile.getUserName(), profile.getPassword());
c.setCustomerProfile(profile.getUserName(), profile);
c.setSecurityQACustomer(profile.getUserName(), profile.getForgetPassword());
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
} catch (CriticalError e) {
log.fatal("Register new customer command failed, critical error occured from SQL Database connection");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} catch (ClientAlreadyExist e) {
log.info("Register new customer command failed, client already exists");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_ALREADY_EXISTS);
} catch (ClientNotExist e) {
log.fatal("Register new customer command failed, the sql report that the client not exists but i added it just now");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} catch (IngredientNotExist e) {
log.info("Register new customer command failed, client try to use not existed ingredient");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
}
log.info("Register new customer " + profile + " to system finished");
}
use of SQLDatabase.SQLDatabaseException.ClientAlreadyExist in project SmartCity-Market by TechnionYP5777.
the class RegisterNewCustomerTest method registerNewCustomerProfileCriticalErrorTest2.
@Test
public void registerNewCustomerProfileCriticalErrorTest2() {
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 ClientNotExist()).when(sqlDatabaseConnection).setCustomerProfile(customerProfile.getUserName(), customerProfile);
} catch (CriticalError | IngredientNotExist e1) {
fail();
} catch (ClientNotExist e) {
/* success */
}
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 RegisterNewCustomerTest method registerNewCustomerProfileClientAlreadyExistTest.
@Test
public void registerNewCustomerProfileClientAlreadyExistTest() {
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 ClientAlreadyExist()).when(sqlDatabaseConnection).registerCustomer(customerProfile.getUserName(), customerProfile.getPassword());
} catch (CriticalError e) {
fail();
} catch (ClientAlreadyExist 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_USERNAME_ALREADY_EXISTS, out.getResultDescriptor());
}
use of SQLDatabase.SQLDatabaseException.ClientAlreadyExist in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testAddRemoveWorker.
@Test
public void testAddRemoveWorker() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
String result = null;
//test add worker
try {
sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
result = sqlConnection.getWorkersList(null);
} catch (CriticalError | ClientNotConnected | ClientAlreadyExist e) {
fail();
}
assert result != null;
HashMap<String, Boolean> map = Serialization.deserializeWorkersHashMap(result);
assert map != null;
assert map.containsKey(workerName);
assertEquals(false, map.get(workerName));
//test remove worker
try {
sqlConnection.removeWorker(null, workerName);
result = sqlConnection.getWorkersList(null);
} catch (CriticalError | ClientNotConnected | ClientNotExist e) {
fail();
}
assert result != null;
map = Serialization.deserializeWorkersHashMap(result);
assert map != null;
assert !map.containsKey(workerName);
}
Aggregations