use of de.symeda.sormas.backend.TestDataCreator.RDCF in project SORMAS-Project by hzi-braunschweig.
the class UserServiceTest method testGetReferenceList.
@Test
public void testGetReferenceList() {
List<String> regionUuids = null;
List<String> districtUuids = null;
List<String> communityUuids = null;
boolean includeSupervisors = false;
boolean filterByJurisdiction = false;
boolean activeOnly = false;
List<UserRole> userRoles = null;
// 0. No conditions, test signature with userRoles varArg parameter
List<UserReference> result = getUserService().getReferenceList(regionUuids, districtUuids, includeSupervisors, filterByJurisdiction, activeOnly);
assertThat(result, hasSize(1));
UserReference admin = result.get(0);
assertThat(admin.getUserRoles(), containsInAnyOrder(UserRole.ADMIN, UserRole.NATIONAL_USER));
// 1a. Find admin with several conditions
activeOnly = true;
userRoles = Arrays.asList(UserRole.ADMIN);
result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
assertThat(result, contains(admin));
userRoles = Arrays.asList(UserRole.NATIONAL_USER);
result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
assertThat(result, contains(admin));
userRoles = Arrays.asList(UserRole.ADMIN, UserRole.CASE_OFFICER);
result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
assertThat(result, contains(admin));
// 1b. Exclude admin by role
userRoles = Arrays.asList(UserRole.CASE_OFFICER);
result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
assertThat(result, is(empty()));
// 2. Include supervisors
userRoles = Arrays.asList(UserRole.CONTACT_OFFICER);
RDCF rdcf = creator.createRDCF();
UserDto supervisor = creator.createUser(rdcf, UserRole.CONTACT_SUPERVISOR);
result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
assertThat(result, is(empty()));
includeSupervisors = true;
result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
assertThat(result, hasSize(1));
assertThat(result.get(0).getUuid(), equalTo(supervisor.getUuid()));
// 3. Exclude inactive user as overall condition
getUserFacade().disableUsers(Arrays.asList(supervisor.getUuid()));
result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
assertThat(result, is(empty()));
// 4. filterByJurisdiction to test that the invocation works and filters correctly concerning activeOnly
filterByJurisdiction = true;
result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
assertThat(result, is(empty()));
activeOnly = false;
result = getUserService().getReferenceList(regionUuids, districtUuids, communityUuids, includeSupervisors, filterByJurisdiction, activeOnly, userRoles);
assertThat(result, hasSize(1));
assertThat(result.get(0).getUuid(), equalTo(supervisor.getUuid()));
// 5. regions filter
result = getUserService().getReferenceList(Arrays.asList(rdcf.region.getUuid()), null, false, false, false);
assertThat(result, hasSize(1));
assertThat(result.get(0).getUuid(), equalTo(supervisor.getUuid()));
// 6. districts filter
result = getUserService().getReferenceList(null, Arrays.asList(rdcf.district.getUuid()), false, false, false);
assertThat(result, hasSize(1));
assertThat(result.get(0).getUuid(), equalTo(supervisor.getUuid()));
}
use of de.symeda.sormas.backend.TestDataCreator.RDCF 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);
}
use of de.symeda.sormas.backend.TestDataCreator.RDCF in project SORMAS-Project by hzi-braunschweig.
the class PersonFacadeEjbTest method testGetMatchingNameDtos.
@Test
public void testGetMatchingNameDtos() {
RDCFEntities rdcf = creator.createRDCFEntities();
UserDto user = creator.createUser(rdcf, UserRole.SURVEILLANCE_SUPERVISOR);
// 1-3 = Active persons; 4 = Person without reference; 5-7 = Inactive persons
PersonDto person1 = creator.createPerson("James", "Smith", Sex.MALE, 1980, 1, 1);
PersonDto person2 = creator.createPerson("James", "Smith", Sex.MALE, 1979, 5, 12);
PersonDto person3 = creator.createPerson("James", "Smith", Sex.MALE, 1980, 1, 5);
PersonDto person4 = creator.createPerson("Maria", "Garcia", Sex.FEMALE, 1984, 12, 2);
PersonDto person5 = creator.createPerson("Maria", "Garcia", Sex.UNKNOWN, 1984, 7, 12);
PersonDto person6 = creator.createPerson("Maria", "Garcia", Sex.FEMALE, 1984, null, null);
PersonDto person7 = creator.createPerson("James", "Smith", Sex.MALE, null, null, null);
CaseDataDto activeCase = creator.createCase(user.toReference(), person1.toReference(), rdcf);
creator.createContact(user.toReference(), person2.toReference(), activeCase);
EventDto activeEvent = creator.createEvent(user.toReference());
creator.createEventParticipant(activeEvent.toReference(), person3, user.toReference());
CaseDataDto inactiveCase = creator.createCase(user.toReference(), person5.toReference(), rdcf);
creator.createContact(user.toReference(), person6.toReference(), inactiveCase);
EventDto inactiveEvent = creator.createEvent(user.toReference());
creator.createEventParticipant(inactiveEvent.toReference(), person7, user.toReference());
getCaseFacade().archive(inactiveCase.getUuid(), null);
getEventFacade().archive(inactiveEvent.getUuid(), null);
// Only persons that have active case, contact or event participant associations should be retrieved
List<String> relevantNameUuids = getPersonFacade().getSimilarPersonDtos(new PersonSimilarityCriteria()).stream().map(dto -> dto.getUuid()).collect(Collectors.toList());
assertThat(relevantNameUuids, hasSize(6));
assertThat(relevantNameUuids, containsInAnyOrder(person1.getUuid(), person2.getUuid(), person3.getUuid(), person5.getUuid(), person6.getUuid(), person7.getUuid()));
creator.createCase(user.toReference(), person4.toReference(), rdcf);
getCaseFacade().dearchive(Collections.singletonList(inactiveCase.getUuid()), null);
getEventFacade().dearchive(Collections.singletonList(inactiveEvent.getUuid()), null);
PersonSimilarityCriteria criteria = new PersonSimilarityCriteria().sex(Sex.MALE).birthdateYYYY(1980).birthdateMM(1).birthdateDD(1);
List<String> matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
assertThat(matchingUuids, hasSize(2));
assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person7.getUuid()));
criteria.birthdateMM(null).birthdateDD(null);
matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
assertThat(matchingUuids, hasSize(3));
assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid()));
criteria.sex(Sex.FEMALE).birthdateYYYY(1984);
matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
assertThat(matchingUuids, hasSize(3));
assertThat(matchingUuids, containsInAnyOrder(person4.getUuid(), person5.getUuid(), person6.getUuid()));
criteria.sex(null);
matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
assertThat(matchingUuids, hasSize(4));
assertThat(matchingUuids, containsInAnyOrder(person4.getUuid(), person5.getUuid(), person6.getUuid(), person7.getUuid()));
final String passportNr = "passportNr";
final String otherPassportNr = "otherPassportNr";
final String healthId = "healthId";
final String otherHealthId = "otherHealthId";
PersonDto person8 = creator.createPerson("James", "Smith", Sex.MALE, 1980, 1, 1, passportNr, healthId);
PersonDto person9 = creator.createPerson("James", "Smith", Sex.MALE, 1980, 1, 1, null, otherHealthId);
PersonDto person10 = creator.createPerson("Maria", "Garcia", Sex.FEMALE, 1970, 1, 1, passportNr, null);
PersonDto person11 = creator.createPerson("John", "Doe", Sex.MALE, 1970, 1, 1, otherPassportNr, null);
creator.createCase(user.toReference(), person8.toReference(), rdcf);
creator.createCase(user.toReference(), person9.toReference(), rdcf);
creator.createCase(user.toReference(), person10.toReference(), rdcf);
creator.createCase(user.toReference(), person11.toReference(), rdcf);
criteria.sex(Sex.MALE).birthdateYYYY(1980);
criteria.passportNumber(passportNr);
matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
assertThat(matchingUuids, hasSize(6));
assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid(), person8.getUuid(), person9.getUuid(), person10.getUuid()));
criteria.nationalHealthId(healthId).passportNumber(null);
matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
assertThat(matchingUuids, hasSize(4));
assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid(), person8.getUuid()));
criteria.nationalHealthId(otherHealthId);
matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
assertThat(matchingUuids, hasSize(4));
assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid(), person9.getUuid()));
criteria.passportNumber(otherPassportNr);
matchingUuids = getPersonFacade().getSimilarPersonDtos(criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList());
assertThat(matchingUuids, hasSize(5));
assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid(), person9.getUuid(), person11.getUuid()));
}
use of de.symeda.sormas.backend.TestDataCreator.RDCF in project SORMAS-Project by hzi-braunschweig.
the class PersonFacadeEjbTest method testGetPersonByContext.
@Test
public void testGetPersonByContext() {
RDCF rdcf = creator.createRDCF();
UserReferenceDto userRef = creator.createUser(rdcf, UserRole.REST_EXTERNAL_VISITS_USER).toReference();
PersonDto casePerson = creator.createPerson();
CaseDataDto caze = creator.createCase(userRef, casePerson.toReference(), rdcf);
assertThat(getPersonFacade().getByContext(PersonContext.CASE, caze.getUuid()), equalTo(casePerson));
PersonDto contactPerson = creator.createPerson();
ContactDto contact = creator.createContact(userRef, contactPerson.toReference());
assertThat(getPersonFacade().getByContext(PersonContext.CONTACT, contact.getUuid()), equalTo(contactPerson));
PersonDto eventParticipantPerson = creator.createPerson();
EventParticipantDto eventParticipant = creator.createEventParticipant(creator.createEvent(userRef).toReference(), eventParticipantPerson, userRef);
assertThat(getPersonFacade().getByContext(PersonContext.EVENT_PARTICIPANT, eventParticipant.getUuid()), equalTo(eventParticipantPerson));
}
use of de.symeda.sormas.backend.TestDataCreator.RDCF in project SORMAS-Project by hzi-braunschweig.
the class EventFacadeEjbTest method testArchiveAllArchivableEvents.
@Test
public void testArchiveAllArchivableEvents() {
RDCFEntities rdcfEntities = creator.createRDCFEntities();
RDCF rdcf = creator.createRDCF();
UserReferenceDto user = creator.createUser(rdcfEntities).toReference();
// One archived event
EventDto event1 = creator.createEvent(EventStatus.EVENT, EventInvestigationStatus.PENDING, "", "", "", "", "", TypeOfPlace.MEANS_OF_TRANSPORT, new Date(), new Date(), user, user, Disease.ANTHRAX, rdcf.district);
EventFacadeEjbLocal cut = getBean(EventFacadeEjbLocal.class);
cut.archive(event1.getUuid(), null);
// One other event
EventDto event2 = creator.createEvent(EventStatus.SIGNAL, EventInvestigationStatus.PENDING, "", "", "", "", "", TypeOfPlace.FACILITY, new Date(), new Date(), user, user, Disease.DENGUE, rdcf.district);
assertTrue(cut.isArchived(event1.getUuid()));
assertFalse(cut.isArchived(event2.getUuid()));
// Event of "today" shouldn't be archived
cut.archiveAllArchivableEvents(70, LocalDate.now().plusDays(69));
assertTrue(cut.isArchived(event1.getUuid()));
assertFalse(cut.isArchived(event2.getUuid()));
// Event of "yesterday" should be archived
cut.archiveAllArchivableEvents(70, LocalDate.now().plusDays(71));
assertTrue(cut.isArchived(event1.getUuid()));
assertTrue(cut.isArchived(event2.getUuid()));
}
Aggregations