use of org.openmrs.User in project openmrs-core by openmrs.
the class PersonServiceTest method savePerson_shouldCreateNewObjectWhenPersonIdIsNull.
/**
* @see PersonService#savePerson(Person)
*/
@Test
public void savePerson_shouldCreateNewObjectWhenPersonIdIsNull() throws Exception {
User user = Context.getAuthenticatedUser();
Person person = new Person();
person.setPersonCreator(user);
person.setPersonDateCreated(new Date());
person.setPersonChangedBy(user);
person.setPersonDateChanged(new Date());
person.setGender("F");
Assert.assertNull(person.getId());
person.addName(new PersonName("givenName", "middleName", "familyName"));
Person personSaved = Context.getPersonService().savePerson(person);
Assert.assertNotNull(personSaved.getId());
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class PersonServiceTest method voidPerson_shouldRetireUsers.
/**
* @see PersonService#voidPerson(Person,String)
*/
@Test
public void voidPerson_shouldRetireUsers() throws Exception {
// given
Person person = personService.getPerson(2);
User user = new User(person);
Context.getUserService().createUser(user, "Admin123");
Assert.assertFalse(Context.getUserService().getUsersByPerson(person, false).isEmpty());
// when
personService.voidPerson(person, "reason");
// then
assertTrue(Context.getUserService().getUsersByPerson(person, false).isEmpty());
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class UserServiceTest method userWithValidPerson.
private User userWithValidPerson() {
Person person = new Person();
person.addName(new PersonName("jane", "sue", "doe"));
person.setGender("F");
return new User(person);
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class UserServiceTest method getUserByUuid_shouldFindObjectGivenValidUuid.
/**
* @see UserService#getUserByUuid(String)
*/
@Test
public void getUserByUuid_shouldFindObjectGivenValidUuid() {
String uuid = "c1d8f5c2-e131-11de-babe-001e378eb67e";
User user = userService.getUserByUuid(uuid);
Assert.assertEquals(501, (int) user.getUserId());
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class UserServiceTest method changePassword_shouldThrowExceptionIfNewPasswortIsTooShort.
/**
* @see UserService#changePassword(User,String,String)
*/
@Test
public void changePassword_shouldThrowExceptionIfNewPasswortIsTooShort() {
executeDataSet(XML_FILENAME_WITH_DATA_FOR_CHANGE_PASSWORD_ACTION);
// user 6001 has password userServiceTest
User user6001 = userService.getUser(6001);
String oldPassword = "userServiceTest";
String weakPassword = "weak";
expectedException.expectMessage(messages.getMessage("error.password.length", new Object[] { "8" }, null));
userService.changePassword(user6001, oldPassword, weakPassword);
}
Aggregations