Search in sources :

Example 56 with User

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

the class UserServiceTest method getUsersByPerson_shouldNotFetchRetiredAccountsWhenIncludeRetiredIsFalse.

/**
 * @see UserService#getUsersByPerson(Person,null)
 */
@Test
public void getUsersByPerson_shouldNotFetchRetiredAccountsWhenIncludeRetiredIsFalse() {
    executeDataSet(XML_FILENAME);
    Person person = new Person(5508);
    List<User> users = userService.getUsersByPerson(person, false);
    Assert.assertEquals(2, users.size());
}
Also used : User(org.openmrs.User) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 57 with User

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

the class SerializedObjectDAOTest method saveObject_shouldSaveThePassedObjectIfSupported.

@Test
public void saveObject_shouldSaveThePassedObjectIfSupported() {
    Program data = new Program();
    data.setName("NewProgram");
    data.setDescription("This is to test saving a Program");
    data.setCreator(new User(1));
    data.setDateCreated(new Date());
    data = dao.saveObject(data);
    Assert.assertNotNull(data.getId());
    Program newData = dao.getObject(Program.class, data.getId());
    assertEquals("NewProgram", newData.getName());
}
Also used : Program(org.openmrs.Program) User(org.openmrs.User) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 58 with User

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

the class RequiredDataAdviceTest method setUp.

@Before
public void setUp() {
    Context.setUserContext(userContext);
    context.setServiceContext(serviceContext);
    Context.setContext(serviceContext);
    serviceContext.setApplicationContext(applicationContext);
    User user = new User();
    user.setUuid("1010d442-e134-11de-babe-001e378eb67e");
    user.setUserId(1);
    user.setUsername("admin");
    user.addRole(new Role(RoleConstants.SUPERUSER));
    Person person = new Person();
    person.setUuid("6adb7c42-cfd2-4301-b53b-ff17c5654ff7");
    person.setId(1);
    person.addName(new PersonName("Bob", "", "Smith"));
    Calendar calendar = Calendar.getInstance();
    calendar.set(1980, 01, 01);
    person.setBirthdate(calendar.getTime());
    person.setGender("M");
    user.setPerson(person);
    when(userContext.getAuthenticatedUser()).thenReturn(user);
    when(userContext.isAuthenticated()).thenReturn(true);
    Map<String, SaveHandler> saveHandlers = new HashMap<>();
    saveHandlers.put("saveHandler", saveHandler);
    when(applicationContext.getBeansOfType(SaveHandler.class)).thenReturn(saveHandlers);
    Map<String, VoidHandler> voidHandlers = new HashMap<>();
    voidHandlers.put("voidHandler", voidHandler);
    when(applicationContext.getBeansOfType(VoidHandler.class)).thenReturn(voidHandlers);
    // Clear cache since handlers are updated
    HandlerUtil.clearCachedHandlers();
}
Also used : Role(org.openmrs.Role) BaseVoidHandler(org.openmrs.api.handler.BaseVoidHandler) VoidHandler(org.openmrs.api.handler.VoidHandler) PersonName(org.openmrs.PersonName) SaveHandler(org.openmrs.api.handler.SaveHandler) OpenmrsObjectSaveHandler(org.openmrs.api.handler.OpenmrsObjectSaveHandler) User(org.openmrs.User) HashMap(java.util.HashMap) Calendar(java.util.Calendar) Matchers.anyString(org.mockito.Matchers.anyString) Person(org.openmrs.Person) Before(org.junit.Before)

Example 59 with User

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

the class BaseRetireHandlerTest method handle_shouldNotSetRetiredByIfNonNull.

/**
 * @see BaseRetireHandler#handle(Retireable,User,Date,String)
 */
@Test
public void handle_shouldNotSetRetiredByIfNonNull() {
    RetireHandler<Retireable> handler = new BaseRetireHandler();
    Retireable retireable = new Location();
    retireable.setRetiredBy(new User(3));
    handler.handle(retireable, new User(2), null, " ");
    Assert.assertEquals(3, retireable.getRetiredBy().getId().intValue());
}
Also used : User(org.openmrs.User) Retireable(org.openmrs.Retireable) Location(org.openmrs.Location) Test(org.junit.Test)

Example 60 with User

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

the class BaseUnvoidHandlerTest method handle_shouldUnsetTheVoider.

/**
 * @see BaseUnvoidHandler#handle(Voidable,User,Date,String)
 */
@Test
public void handle_shouldUnsetTheVoider() {
    UnvoidHandler<Voidable> handler = new BaseUnvoidHandler();
    Voidable voidable = new Person();
    voidable.setVoided(true);
    voidable.setVoidedBy(new User(1));
    handler.handle(voidable, null, null, null);
    Assert.assertNull(voidable.getVoidedBy());
}
Also used : User(org.openmrs.User) Voidable(org.openmrs.Voidable) Person(org.openmrs.Person) Test(org.junit.Test)

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