Search in sources :

Example 1 with SaveHandler

use of org.openmrs.api.handler.SaveHandler 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)

Aggregations

Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Person (org.openmrs.Person)1 PersonName (org.openmrs.PersonName)1 Role (org.openmrs.Role)1 User (org.openmrs.User)1 BaseVoidHandler (org.openmrs.api.handler.BaseVoidHandler)1 OpenmrsObjectSaveHandler (org.openmrs.api.handler.OpenmrsObjectSaveHandler)1 SaveHandler (org.openmrs.api.handler.SaveHandler)1 VoidHandler (org.openmrs.api.handler.VoidHandler)1