use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCantAddWorkerAlreadyExisted.
@Test
public void testCantAddWorkerAlreadyExisted() {
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 add again the same worker
try {
sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
fail();
} catch (CriticalError | ClientNotConnected e) {
fail();
} catch (ClientAlreadyExist e) {
}
//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);
}
use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.
the class ForgotPasswordHandler method sendAnswerWithNewPassword.
public boolean sendAnswerWithNewPassword(String ans, String newPass) throws CriticalError, WrongAnswer, NoSuchUserName {
CommandWrapper cmdwrppr = null;
log.info("Creating 'send answer and password' command wrapper for username: " + username);
ForgotPasswordData forgotPassData = new ForgotPasswordData(question, ans);
Login ansAndPassContainer = new Login(username, newPass, forgotPassData);
String serverResponse = sendRequestWithRespondToServer(new CommandWrapper(senderId, CommandDescriptor.FORGOT_PASSWORD_SEND_ANSWER_WITH_NEW_PASSWORD, Serialization.serialize(ansAndPassContainer)).serialize());
cmdwrppr = getCommandWrapper(serverResponse);
resultDescriptorHandler(cmdwrppr.getResultDescriptor());
log.info("Successfully recovered forgotten password for username: " + username);
return Serialization.deserialize(cmdwrppr.getData(), Boolean.class);
}
use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.
the class ForgotPasswordTest method sendCorrectAnswerWithNewPassword.
@Test
public void sendCorrectAnswerWithNewPassword() {
ForgotPasswordData forgotPassData = new ForgotPasswordData(null, authQuestionAnswer);
Login ansAndPassContainer = new Login(worker.getUsername(), newPass, forgotPassData);
try {
Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(WorkerDefs.loginCommandSenderId, CommandDescriptor.FORGOT_PASSWORD_SEND_ANSWER_WITH_NEW_PASSWORD, Serialization.serialize(ansAndPassContainer)).serialize())).thenReturn(new CommandWrapper(ResultDescriptor.SM_OK, Serialization.serialize(true)).serialize());
} catch (IOException ยข) {
fail();
}
try {
((IForgotPasswordHandler) worker).sendAnswerAndNewPassword(authQuestionAnswer, newPass);
} catch (NoSuchUserName | WrongAnswer e) {
fail();
}
}
use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.
the class ManageEmployeesTab method finishBtnPressed.
@FXML
void finishBtnPressed(ActionEvent __) {
try {
manager.registerNewWorker(new Login(userTxt.getText(), passTxt.getText(), new ForgotPasswordData(securityCombo.getSelectionModel().getSelectedItem(), securityAnswerTxt.getText())));
} catch (InvalidParameter | CriticalError | EmployeeNotConnected | ConnectionFailure | WorkerAlreadyExists e) {
log.fatal(e);
log.debug(StackTraceUtil.getStackTrace(e));
e.showInfoToUser();
}
createEmployeesList();
enableRemoveButton();
}
use of BasicCommonClasses.ForgotPasswordData in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testCustomerCanSetProfile.
@Test
public void testCustomerCanSetProfile() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
CustomerProfile p = new CustomerProfile(customerName, customerName, "name", "last", "number", "email", "city", "street", date112000, new HashSet<>(), new ForgotPasswordData("question", "answer"));
CustomerProfile result = null;
try {
sqlConnection.registerCustomer(customerName, customerName);
} catch (CriticalError | ClientAlreadyExist e) {
fail();
}
try {
sqlConnection.setCustomerProfile(customerName, p);
result = Serialization.deserialize(sqlConnection.getCustomerProfile(customerName), CustomerProfile.class);
} catch (CriticalError | ClientNotExist | IngredientNotExist e1) {
fail();
} finally {
try {
sqlConnection.removeCustomer(customerName);
} catch (CriticalError | ClientNotExist e) {
e.printStackTrace();
}
}
assertEquals(p.getBirthdate(), result.getBirthdate());
assertEquals(p.getCity(), result.getCity());
assertEquals(p.getEmailAddress(), result.getEmailAddress());
assertEquals(p.getFirstName(), result.getFirstName());
assertEquals(p.getLastName(), result.getLastName());
assertEquals(p.getPhoneNumber(), result.getPhoneNumber());
assertEquals(p.getStreet(), result.getStreet());
assertEquals(p.getUserName(), result.getUserName());
}
Aggregations