Search in sources :

Example 51 with User

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());
}
Also used : User(org.openmrs.User) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 52 with User

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);
}
Also used : User(org.openmrs.User) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 53 with User

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);
}
Also used : User(org.openmrs.User) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 54 with User

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);
}
Also used : User(org.openmrs.User) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 55 with User

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"));
}
Also used : User(org.openmrs.User) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

User (org.openmrs.User)201 Test (org.junit.Test)150 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)132 Date (java.util.Date)38 Person (org.openmrs.Person)33 Encounter (org.openmrs.Encounter)21 Patient (org.openmrs.Patient)18 PersonName (org.openmrs.PersonName)17 Role (org.openmrs.Role)13 GlobalProperty (org.openmrs.GlobalProperty)11 Location (org.openmrs.Location)11 ArrayList (java.util.ArrayList)10 EncounterType (org.openmrs.EncounterType)10 Locale (java.util.Locale)7 UserService (org.openmrs.api.UserService)7 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)7 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 EncounterRole (org.openmrs.EncounterRole)6 PatientIdentifier (org.openmrs.PatientIdentifier)6