Search in sources :

Example 46 with Person

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

the class DropMillisecondsHibernateInterceptorTest method shouldClearMillisecondsWhenUpdatingAnExistingObject.

@Test
public void shouldClearMillisecondsWhenUpdatingAnExistingObject() {
    Date dateWithMillisecond = new Date(567L);
    Date dateWithoutMillisecond = new Date(0L);
    Person person = personService.getPerson(1);
    person.setBirthdate(dateWithMillisecond);
    personService.savePerson(person);
    Context.flushSession();
    assertThat(person.getBirthdate(), is(dateWithoutMillisecond));
}
Also used : Person(org.openmrs.Person) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 47 with Person

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

the class DropMillisecondsHibernateInterceptorTest method shouldClearMillisecondsWhenSavingANewObject.

@Test
public void shouldClearMillisecondsWhenSavingANewObject() {
    Date dateWithMillisecond = new Date(567L);
    Date dateWithoutMillisecond = new Date(0L);
    Person person = new Person();
    person.addName(new PersonName("Alice", null, "Paul"));
    person.setGender("F");
    person.setBirthdate(dateWithMillisecond);
    personService.savePerson(person);
    Context.flushSession();
    assertThat(person.getBirthdate(), is(dateWithoutMillisecond));
}
Also used : PersonName(org.openmrs.PersonName) Person(org.openmrs.Person) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 48 with Person

use of org.openmrs.Person 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 49 with Person

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

the class RequiredDataAdviceTest method before_shouldCallHandlersNotAnnotatedAsDisabled.

@Test
public void before_shouldCallHandlersNotAnnotatedAsDisabled() throws Throwable {
    Method m = WithAppropriatelyNamedMethod.class.getMethod("voidClassWithDisableHandlersAnnotation", ClassWithDisableHandlersAnnotation.class);
    ClassWithDisableHandlersAnnotation openmrsObject = new ClassWithDisableHandlersAnnotation();
    // create a couple locations and associate them with this openmrsObject
    List<Person> persons = new ArrayList<>();
    Person person = new Person();
    persons.add(person);
    openmrsObject.setNotAnnotatedPersons(persons);
    requiredDataAdvice.before(m, new Object[] { openmrsObject, "void reason" }, new WithAppropriatelyNamedMethod());
    // verify that the handle method was called on this object
    verify(voidHandler, times(1)).handle(eq(person), Matchers.anyObject(), Matchers.anyObject(), anyString());
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Person(org.openmrs.Person) BaseContextMockTest(org.openmrs.test.BaseContextMockTest) Test(org.junit.Test)

Example 50 with Person

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

the class RequiredDataAdviceTest method before_shouldNotCallHandlersAnnotatedAsDisabled.

@Test
public void before_shouldNotCallHandlersAnnotatedAsDisabled() throws Throwable {
    Method m = WithAppropriatelyNamedMethod.class.getMethod("voidClassWithDisableHandlersAnnotation", ClassWithDisableHandlersAnnotation.class);
    ClassWithDisableHandlersAnnotation openmrsObject = new ClassWithDisableHandlersAnnotation();
    // create a couple locations and associate them with this openmrsObject
    List<Person> persons = new ArrayList<>();
    Person person = new Person();
    persons.add(person);
    openmrsObject.setPersons(persons);
    requiredDataAdvice.before(m, new Object[] { openmrsObject, "void reason" }, new WithAppropriatelyNamedMethod());
    // verify that the handle method was never called on this object
    verify(voidHandler, never()).handle(eq(person), Matchers.anyObject(), Matchers.anyObject(), anyString());
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Person(org.openmrs.Person) BaseContextMockTest(org.openmrs.test.BaseContextMockTest) Test(org.junit.Test)

Aggregations

Person (org.openmrs.Person)172 Test (org.junit.Test)140 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)107 PersonName (org.openmrs.PersonName)41 User (org.openmrs.User)36 Date (java.util.Date)33 Relationship (org.openmrs.Relationship)19 Obs (org.openmrs.Obs)16 Patient (org.openmrs.Patient)15 BindException (org.springframework.validation.BindException)15 Message (ca.uhn.hl7v2.model.Message)14 Concept (org.openmrs.Concept)14 Provider (org.openmrs.Provider)14 Voidable (org.openmrs.Voidable)14 Errors (org.springframework.validation.Errors)14 ArrayList (java.util.ArrayList)10 PersonMergeLog (org.openmrs.person.PersonMergeLog)9 RelationshipType (org.openmrs.RelationshipType)8 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)7 NK1 (ca.uhn.hl7v2.model.v25.segment.NK1)7