use of de.symeda.sormas.backend.person.PersonService in project SORMAS-Project by hzi-braunschweig.
the class ExternalJournalServiceTest method givenRelevantChangeShouldNotify.
@Test
public /*
* If you need to change this test to make it pass, you probably changed the behaviour of the ExternalVisitsResource.
* Please note that other system used alongside with SORMAS are depending on this, so that their developers must be notified of any
* relevant API changes some time before they go into any test and productive system. Please inform the SORMAS core development team at
* https://gitter.im/SORMAS-Project!
*/
void givenRelevantChangeShouldNotify() {
EntityManager entityManager = getEntityManager();
PersonFacadeEjb.PersonFacadeEjbLocal personFacade = (PersonFacadeEjb.PersonFacadeEjbLocal) getPersonFacade();
personFacade.setExternalJournalService(getExternalJournalService());
PersonService personService = getPersonService();
Person person = personService.createPerson();
setPersonRelevantFields(person);
// cannot use PersonFacade save since it also calls the method being tested
EntityTransaction transaction = entityManager.getTransaction();
transaction.begin();
entityManager.persist(person);
entityManager.flush();
transaction.commit();
// need to create a case with the person to avoid pseudonymization related errors
creator.createCase(natUser.toReference(), new PersonReferenceDto(person.getUuid()), rdcf);
JournalPersonDto journalPerson = personFacade.getPersonForJournal(person.getUuid());
assertFalse(getExternalJournalService().notifyExternalJournalPersonUpdate(journalPerson).getElement0());
// Define relevant changes
HashMap<String, Object> relevantChanges = new HashMap<String, Object>() {
{
put(Person.FIRST_NAME, "Heinz");
put(Person.LAST_NAME, "Müller");
put(Person.SEX, Sex.FEMALE);
put(Person.BIRTHDATE_YYYY, 2001);
put(Person.BIRTHDATE_MM, 7);
put(Person.BIRTHDATE_DD, 2);
}
};
person.setPhone("+496211218491");
person.setEmailAddress("heinz@test.de");
// Apply each change and make sure it makes notification considered necessary
for (String propertyName : relevantChanges.keySet()) {
journalPerson = personFacade.getPersonForJournal(person.getUuid());
setPersonProperty(person, propertyName, relevantChanges.get(propertyName));
person = entityManager.merge(person);
assertTrue(getExternalJournalService().notifyExternalJournalPersonUpdate(journalPerson).getElement0());
// Modify the SymptomJournalStatus of the original person
journalPerson = personFacade.getPersonForJournal(person.getUuid());
person.setSymptomJournalStatus(SymptomJournalStatus.DELETED);
person = entityManager.merge(person);
assertFalse(getExternalJournalService().notifyExternalJournalPersonUpdate(journalPerson).getElement0());
journalPerson = personFacade.getPersonForJournal(person.getUuid());
person.setSymptomJournalStatus(SymptomJournalStatus.REJECTED);
person = entityManager.merge(person);
assertFalse(getExternalJournalService().notifyExternalJournalPersonUpdate(journalPerson).getElement0());
journalPerson = personFacade.getPersonForJournal(person.getUuid());
person.setSymptomJournalStatus(SymptomJournalStatus.UNREGISTERED);
person = entityManager.merge(person);
assertFalse(getExternalJournalService().notifyExternalJournalPersonUpdate(journalPerson).getElement0());
journalPerson = personFacade.getPersonForJournal(person.getUuid());
person.setSymptomJournalStatus(SymptomJournalStatus.ACCEPTED);
person = entityManager.merge(person);
assertFalse(getExternalJournalService().notifyExternalJournalPersonUpdate(journalPerson).getElement0());
// Apply any other relevant change and make sure notification is still considered necessary
for (String secondPropertyName : relevantChanges.keySet()) {
if (!secondPropertyName.equals(propertyName)) {
journalPerson = personFacade.getPersonForJournal(person.getUuid());
setPersonProperty(person, secondPropertyName, relevantChanges.get(secondPropertyName));
person = entityManager.merge(person);
assertTrue(getExternalJournalService().notifyExternalJournalPersonUpdate(journalPerson).getElement0());
}
}
setPersonRelevantFields(person);
person = entityManager.merge(person);
}
}
Aggregations