Search in sources :

Example 41 with UserDto

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());
}
Also used : User(de.symeda.sormas.backend.user.User) HashMap(java.util.HashMap) UserDto(de.symeda.sormas.api.user.UserDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) HashMap(java.util.HashMap) Map(java.util.Map) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 42 with UserDto

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());
}
Also used : User(de.symeda.sormas.backend.user.User) UserDto(de.symeda.sormas.api.user.UserDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) Region(de.symeda.sormas.backend.infrastructure.region.Region) HashMap(java.util.HashMap) Map(java.util.Map) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 43 with UserDto

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"));
}
Also used : RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) MapContactDto(de.symeda.sormas.api.contact.MapContactDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 44 with UserDto

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));
}
Also used : PersonDto(de.symeda.sormas.api.person.PersonDto) Visit(de.symeda.sormas.backend.visit.Visit) UserDto(de.symeda.sormas.api.user.UserDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) MapContactDto(de.symeda.sormas.api.contact.MapContactDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) VisitDto(de.symeda.sormas.api.visit.VisitDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 45 with UserDto

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());
}
Also used : RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

UserDto (de.symeda.sormas.api.user.UserDto)274 Test (org.junit.Test)210 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)160 PersonDto (de.symeda.sormas.api.person.PersonDto)142 Date (java.util.Date)138 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)121 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)64 ContactDto (de.symeda.sormas.api.contact.ContactDto)57 LocalDate (java.time.LocalDate)57 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)56 EventDto (de.symeda.sormas.api.event.EventDto)52 TestDataCreator (de.symeda.sormas.backend.TestDataCreator)47 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)43 AbstractBeanTest (de.symeda.sormas.ui.AbstractBeanTest)43 SampleDto (de.symeda.sormas.api.sample.SampleDto)41 File (java.io.File)41 TestDataCreator (de.symeda.sormas.ui.TestDataCreator)31 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)30 CasePersonDto (de.symeda.sormas.api.caze.CasePersonDto)27 ImportResultStatus (de.symeda.sormas.ui.importer.ImportResultStatus)27