Search in sources :

Example 16 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class UserServiceTest method createUser_shouldNotAllowUsernameEqualsExistingSystemId.

@Test
public void createUser_shouldNotAllowUsernameEqualsExistingSystemId() {
    User someUser = userService.getUserByUsername(SOME_USERNAME);
    User newUser = userWithValidPerson();
    newUser.setUsername(someUser.getSystemId());
    expectedException.expect(DAOException.class);
    expectedException.expectMessage(String.format("Username %s or system id %s is already in use.", newUser.getUsername(), Context.getUserService().generateSystemId()));
    userService.createUser(newUser, SOME_VALID_PASSWORD);
}
Also used : User(org.openmrs.User) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 17 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class UserServiceTest method setUserProperty_shouldThrowErrorWhenUserIsNotAuthorizedToEditUsers.

/**
 * @see UserService#setUserProperty(User,String,String)
 */
@Test
public void setUserProperty_shouldThrowErrorWhenUserIsNotAuthorizedToEditUsers() {
    User user = userService.getUser(502);
    Context.logout();
    expectedException.expect(APIException.class);
    userService.setUserProperty(user, "some key", "some value");
}
Also used : User(org.openmrs.User) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 18 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class UserServiceTest method getUserByUuid_shouldFetchUserWithGivenUuid.

@Test
@SkipBaseSetup
public void getUserByUuid_shouldFetchUserWithGivenUuid() throws SQLException {
    initializeInMemoryDatabase();
    executeDataSet(XML_FILENAME);
    authenticate();
    User user = userService.getUserByUuid("013c49c6-e132-11de-babe-001e378eb67e");
    assertEquals("Did not fetch user with given uuid", user, userService.getUser(5505));
}
Also used : User(org.openmrs.User) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) SkipBaseSetup(org.openmrs.test.SkipBaseSetup)

Example 19 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class UserServiceTest method retireUser_shouldRetireUserAndSetAttributes.

/**
 * @see UserService#retireUser(User,String)
 */
@Test
public void retireUser_shouldRetireUserAndSetAttributes() {
    User user = userService.getUser(502);
    userService.retireUser(user, "because");
    Assert.assertTrue(user.getRetired());
    Assert.assertNotNull(user.getDateRetired());
    Assert.assertNotNull(user.getRetiredBy());
    Assert.assertEquals("because", user.getRetireReason());
}
Also used : User(org.openmrs.User) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 20 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class UserServiceTest method changePassword_shouldThrowAPIExceptionIfGivenUserDoesNotExist.

/**
 * @see UserService#changePassword(User,String,String)
 */
@Test
public void changePassword_shouldThrowAPIExceptionIfGivenUserDoesNotExist() {
    // user.getUserId is null - so it is not existing user
    User notExistingUser = new User();
    String anyString = "anyString";
    expectedException.expect(APIException.class);
    expectedException.expectMessage(messages.getMessage("user.must.exist"));
    userService.changePassword(notExistingUser, anyString, anyString);
}
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