Search in sources :

Example 1 with PersonFacade

use of de.symeda.sormas.api.person.PersonFacade in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjbTest method testCountAndGetIndexListWithAssociations.

/**
 * Test all {@link PersonAssociation} variants if they work. Also serves to review the generated SQL.
 */
@Test
public void testCountAndGetIndexListWithAssociations() {
    PersonFacade cut = getPersonFacade();
    Integer offset = null;
    Integer limit = null;
    List<SortProperty> sortProperties = null;
    RDCF rdcf = creator.createRDCF();
    UserDto user = creator.createUser(rdcf.region.getUuid(), null, null, null, "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    loginWith(user);
    // 1a. Test for all available PersonAssociations
    for (PersonAssociation pa : PersonAssociation.values()) {
        PersonCriteria criteria = new PersonCriteria().personAssociation(pa);
        assertThat("Failed for testing association on count: " + pa.name(), cut.count(criteria), equalTo(0L));
        assertThat(criteria.getPersonAssociation(), equalTo(pa));
        assertThat("Failed for testing association on getIndexList: " + pa.name(), cut.getIndexList(criteria, offset, limit, sortProperties), is(empty()));
        assertThat(criteria.getPersonAssociation(), equalTo(pa));
    }
    // 1b. Test that calling with "null" as criteria also works
    assertThat(cut.count(null), equalTo(0L));
    assertThat(cut.getIndexList(null, offset, limit, sortProperties), is(empty()));
    // 2. Test paging windows
    final PersonDto person1 = creator.createPerson("James", "Smith", Sex.MALE, 1920, 1, 1);
    final CaseDataDto case1 = creator.createCase(user.toReference(), person1.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    final PersonDto person2 = creator.createPerson("Maria", "Garcia", Sex.FEMALE, 1920, 1, 1);
    final ContactDto contact2 = creator.createContact(user.toReference(), user.toReference(), person2.toReference(), null, new Date(), new Date(), Disease.EVD, rdcf);
    // 2a. count
    assertThat(cut.count(new PersonCriteria().personAssociation(PersonAssociation.ALL)), equalTo(2L));
    assertThat(cut.count(new PersonCriteria().personAssociation(PersonAssociation.CASE)), equalTo(1L));
    assertThat(cut.count(new PersonCriteria().personAssociation(PersonAssociation.CONTACT)), equalTo(1L));
    // 2b. getIndexList with all persons in the paging window
    assertPersonsFound(case1, contact2, cut, offset, limit, sortProperties);
    offset = 0;
    limit = 2;
    assertPersonsFound(case1, contact2, cut, offset, limit, sortProperties);
    offset = 0;
    limit = 1;
    assertPersonsFound(case1, contact2, cut, offset, limit, sortProperties);
    // 2c. getIndexList [PersonAssociation.ALL] with only the contact person in the paging window (default sorting by changeDate)
    offset = 1;
    limit = 2;
    assertPersonsFound(null, null, Arrays.asList(contact2.getPerson()), cut, offset, limit, sortProperties);
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) PersonFacade(de.symeda.sormas.api.person.PersonFacade) UserDto(de.symeda.sormas.api.user.UserDto) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) ContactDto(de.symeda.sormas.api.contact.ContactDto) PersonAssociation(de.symeda.sormas.api.person.PersonAssociation) Date(java.util.Date) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 ContactDto (de.symeda.sormas.api.contact.ContactDto)1 JournalPersonDto (de.symeda.sormas.api.person.JournalPersonDto)1 PersonAssociation (de.symeda.sormas.api.person.PersonAssociation)1 PersonCriteria (de.symeda.sormas.api.person.PersonCriteria)1 PersonDto (de.symeda.sormas.api.person.PersonDto)1 PersonFacade (de.symeda.sormas.api.person.PersonFacade)1 UserDto (de.symeda.sormas.api.user.UserDto)1 SortProperty (de.symeda.sormas.api.utils.SortProperty)1 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)1 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)1 Date (java.util.Date)1 Test (org.junit.Test)1