use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.
the class NotificationServiceTest method testSendNotifications_filterUserMessagesByroles.
@Test
public void testSendNotifications_filterUserMessagesByroles() throws NotificationDeliveryFailedException {
TestDataCreator.RDCF rdcf = creator.createRDCF();
UserDto survSup = creator.createUser(rdcf, "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
UserDto caseSup = creator.createUser(rdcf, "Case", "Sup", UserRole.CASE_SUPERVISOR);
UserDto contSup = creator.createUser(rdcf, "Cont", "Sup", UserRole.CONTACT_SUPERVISOR);
User survSupUser = getUserService().getByReferenceDto(survSup.toReference());
User survOffUser = getUserService().getByReferenceDto(caseSup.toReference());
User contSupUser = getUserService().getByReferenceDto(contSup.toReference());
Mockito.doAnswer(invocation -> {
Map<User, String> userMessages = (Map<User, String>) invocation.getArgument(0);
assertThat(userMessages.size(), is(2));
assertThat(userMessages.get(survSupUser), is("Test message SS"));
assertThat(userMessages.get(survOffUser), is("Test message SO"));
return null;
}).when(messagingService).sendEmail(any(), any(), any());
notificationService.sendNotifications(NotificationType.CASE_LAB_RESULT_ARRIVED, MessageSubject.LAB_RESULT_ARRIVED, () -> {
Map<User, String> userMessages = new HashMap<>();
userMessages.put(survOffUser, "Test message SO");
userMessages.put(survSupUser, "Test message SS");
userMessages.put(contSupUser, "Test message CS");
return userMessages;
});
Mockito.verify(messagingService, Mockito.times(1)).sendEmail(any(), any(), any());
Mockito.verify(messagingService, Mockito.times(1)).sendSms(any(), any(), any());
}
use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.
the class NotificationServiceTest method testSendNotifications_additionalUsers.
@Test
public void testSendNotifications_additionalUsers() throws NotificationDeliveryFailedException {
TestDataCreator.RDCF rdcf = creator.createRDCF();
Region region = getRegionService().getByReferenceDto(rdcf.region);
UserDto survSup = creator.createUser(rdcf, "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
UserDto caseSup = creator.createUser(rdcf, "Case", "Sup", UserRole.CASE_SUPERVISOR);
User caseSupUser = getUserService().getByReferenceDto(caseSup.toReference());
Mockito.when(userService.getAllByRegionsAndUserRoles(any(), any())).then(invocation -> {
// load only for SURVEILLANCE_SUPERVISOR, so the additional CASE_SUPERVISOR user will be added in the notification service
return getUserService().getAllByRegionsAndUserRoles((List<Region>) invocation.getArgument(0), UserRole.SURVEILLANCE_SUPERVISOR);
});
Mockito.doAnswer(invocation -> {
Map<User, String> userMessages = (Map<User, String>) invocation.getArgument(0);
assertThat(userMessages.size(), is(2));
assertThat(userMessages.get(getUserService().getByReferenceDto(survSup.toReference())), is("Test message"));
assertThat(userMessages.get(getUserService().getByReferenceDto(caseSup.toReference())), is("Test message"));
return null;
}).when(messagingService).sendEmail(any(), any(), any());
notificationService.sendNotifications(NotificationType.VISIT_COMPLETED, Collections.singletonList(region), Collections.singletonList(caseSupUser), MessageSubject.VISIT_COMPLETED, "Test message");
Mockito.verify(messagingService, Mockito.times(1)).sendEmail(any(), any(), any());
Mockito.verify(messagingService, Mockito.times(1)).sendSms(any(), any(), any());
}
use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjbTest method testCreatedContactExistWhenValidatedByUUID.
@Test
public void testCreatedContactExistWhenValidatedByUUID() {
RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
PersonDto cazePerson = creator.createPerson("Case", "Person");
CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
PersonDto contactPerson = creator.createPerson("Contact", "Person");
ContactDto contact = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
// database contains the created contact
assertEquals(true, getContactFacade().exists(contact.getUuid()));
// database contains the created contact
assertEquals(false, getContactFacade().exists("nonExistingContactUUID"));
}
use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjbTest method testUpdateContactVisitAssociations.
@Test
public void testUpdateContactVisitAssociations() {
UserDto user = creator.createUser(creator.createRDCFEntities(), UserRole.SURVEILLANCE_SUPERVISOR);
PersonDto person = creator.createPerson();
VisitDto visit = creator.createVisit(Disease.EVD, person.toReference());
ContactDto contact = creator.createContact(user.toReference(), person.toReference());
Contact contactEntity = getContactService().getByUuid(contact.getUuid());
Visit visitEntity = getVisitService().getByUuid(visit.getUuid());
// Saved contact should have visit association
assertThat(getVisitService().getAllByContact(contactEntity), hasSize(1));
// Updating the contact but not changing the report date or last contact date should not alter the association
contact.setDescription("Description");
getContactFacade().save(contact);
assertThat(getVisitService().getAllByContact(contactEntity), hasSize(1));
// Changing the report date to a value beyond the threshold should remove the association
contact.setReportDateTime(DateHelper.addDays(visit.getVisitDateTime(), FollowUpLogic.ALLOWED_DATE_OFFSET + 20));
getContactFacade().save(contact);
assertThat(getVisitService().getAllByContact(contactEntity), empty());
// Changing the report date back to a value in the threshold should re-add the association
contact.setReportDateTime(new Date());
getContactFacade().save(contact);
assertThat(getVisitService().getAllByContact(contactEntity), hasSize(1));
// Adding another contact that matches the visit person, disease and time frame should increase the collection size
ContactDto contact2 = creator.createContact(user.toReference(), person.toReference());
assertThat(getContactService().getAllByVisit(visitEntity), hasSize(2));
// Adding another contact with the same person and disease, but an incompatible time frame should not increase the collection size
creator.createContact(user.toReference(), person.toReference(), DateHelper.addDays(visit.getVisitDateTime(), FollowUpLogic.ALLOWED_DATE_OFFSET + 1));
assertThat(getContactService().getAllByVisit(visitEntity), hasSize(2));
// Adding another contact that is compatible to the time frame, but has a different person and/or disease should not increase the collection size
PersonDto person2 = creator.createPerson();
creator.createContact(user.toReference(), person2.toReference());
creator.createContact(user.toReference(), person.toReference(), Disease.CSM);
assertThat(getContactService().getAllByVisit(visitEntity), hasSize(2));
// Changing the contact disease should decrease the collection size
contact2.setDisease(Disease.CSM);
getContactFacade().save(contact2);
assertThat(getContactService().getAllByVisit(visitEntity), hasSize(1));
}
use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjbTest method testArchiveOrDearchiveContact.
@Test
public void testArchiveOrDearchiveContact() {
RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
PersonDto cazePerson = creator.createPerson("Case", "Person");
CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
PersonDto contactPerson = creator.createPerson("Contact", "Person");
creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
creator.createVisit(caze.getDisease(), contactPerson.toReference(), new Date(), VisitStatus.COOPERATIVE, VisitOrigin.USER);
when(MockProducer.getPrincipal().getName()).thenReturn("SurvSup");
// getAllActiveContacts and getAllUuids should return length 1
assertEquals(1, getContactFacade().getAllAfter(null).size());
assertEquals(1, getContactFacade().getAllActiveUuids().size());
assertEquals(1, getVisitFacade().getAllActiveVisitsAfter(null).size());
assertEquals(1, getVisitFacade().getAllActiveUuids().size());
getCaseFacade().archive(caze.getUuid(), null);
// getAllActiveContacts and getAllUuids should return length 0
assertEquals(0, getContactFacade().getAllAfter(null).size());
assertEquals(0, getContactFacade().getAllActiveUuids().size());
assertEquals(0, getVisitFacade().getAllActiveVisitsAfter(null).size());
assertEquals(0, getVisitFacade().getAllActiveUuids().size());
getCaseFacade().dearchive(Collections.singletonList(caze.getUuid()), null);
// getAllActiveContacts and getAllUuids should return length 1
assertEquals(1, getContactFacade().getAllAfter(null).size());
assertEquals(1, getContactFacade().getAllActiveUuids().size());
assertEquals(1, getVisitFacade().getAllActiveVisitsAfter(null).size());
assertEquals(1, getVisitFacade().getAllActiveUuids().size());
}
Aggregations