Search in sources :

Example 6 with User

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

Example 7 with User

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

Example 8 with User

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);
}
Also used : PersonName(org.openmrs.PersonName) User(org.openmrs.User) Person(org.openmrs.Person)

Example 9 with User

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

Example 10 with User

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);
}
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