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