use of org.openmrs.User in project openmrs-core by openmrs.
the class UserServiceTest method unretireUser_shouldUnretireAndUnmarkAllAttributes.
/**
* @see UserService#unretireUser(User)
*/
@Test
public void unretireUser_shouldUnretireAndUnmarkAllAttributes() {
User user = userService.getUser(501);
userService.unretireUser(user);
Assert.assertFalse(user.getRetired());
Assert.assertNull(user.getDateRetired());
Assert.assertNull(user.getRetiredBy());
Assert.assertNull(user.getRetireReason());
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class UserServiceTest method changePassword_shouldThrowAPIExceptionIfOldPasswordIsNotCorrect.
/**
* @see UserService#changePassword(User,String,String)
*/
@Test
public void changePassword_shouldThrowAPIExceptionIfOldPasswordIsNotCorrect() {
executeDataSet(XML_FILENAME_WITH_DATA_FOR_CHANGE_PASSWORD_ACTION);
// user 6001 has password userServiceTest
User user6001 = userService.getUser(6001);
String wrongPassword = "wrong password!";
String newPassword = "newPasswordString";
// log in user without change user passwords privileges
// user6001 has not got required priviliges
Context.authenticate(user6001.getUsername(), "userServiceTest");
expectedException.expect(APIAuthenticationException.class);
expectedException.expectMessage(messages.getMessage("error.privilegesRequired", new Object[] { PrivilegeConstants.EDIT_USER_PASSWORDS }, null));
userService.changePassword(user6001, wrongPassword, newPassword);
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class UserServiceTest method changePassword_shouldThrowExceptionIfOldPasswordIsNullAndChangingUserHaveNotPrivileges.
/**
* @see UserService#changePassword(User,String,String)
*/
@Test
public void changePassword_shouldThrowExceptionIfOldPasswordIsNullAndChangingUserHaveNotPrivileges() {
executeDataSet(XML_FILENAME_WITH_DATA_FOR_CHANGE_PASSWORD_ACTION);
// user 6001 has password userServiceTest
User user6001 = userService.getUser(6001);
assertFalse(user6001.hasPrivilege(PrivilegeConstants.EDIT_USER_PASSWORDS));
String oldPassword = null;
String newPassword = "newPasswordString";
// log in user without change user passwords privileges
// user6001 has not got required priviliges
Context.authenticate(user6001.getUsername(), "userServiceTest");
expectedException.expect(APIException.class);
expectedException.expectMessage(messages.getMessage("error.privilegesRequired", new Object[] { PrivilegeConstants.EDIT_USER_PASSWORDS }, null));
userService.changePassword(user6001, oldPassword, newPassword);
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class UserServiceTest method changePassword_shouldChangePasswordForGivenUserIfOldPasswordIsNullAndChangingUserHavePrivileges.
/**
* @see UserService#changePassword(User,String,String)
*/
@Test
public void changePassword_shouldChangePasswordForGivenUserIfOldPasswordIsNullAndChangingUserHavePrivileges() {
executeDataSet(XML_FILENAME_WITH_DATA_FOR_CHANGE_PASSWORD_ACTION);
// user 6001 has password userServiceTest
User user6001 = userService.getUser(6001);
String oldPassword = null;
String newPassword = "newPasswordString123";
userService.changePassword(user6001, oldPassword, newPassword);
Context.authenticate(user6001.getUsername(), newPassword);
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class UserServiceTest method isSecretAnswer_shouldReturnFalseWhenGivenAnswerDoesNotMatchTheStoredSecretAnswer.
/**
* @see UserService#isSecretAnswer(User,String)
*/
@Test
public void isSecretAnswer_shouldReturnFalseWhenGivenAnswerDoesNotMatchTheStoredSecretAnswer() {
User user = userService.getUser(502);
Assert.assertFalse(userService.isSecretAnswer(user, "not the answer"));
}
Aggregations