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);
}
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");
}
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));
}
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());
}
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);
}
Aggregations