Search in sources :

Example 6 with SormasToSormasOriginInfoDto

use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.

the class SormasToSormasCaseFacadeEjbTest method testSaveReturnedCaseWithKnownOtherFacility.

@Test
public void testSaveReturnedCaseWithKnownOtherFacility() throws SormasToSormasException {
    UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
    PersonDto person = creator.createPerson();
    CaseDataDto caze = creator.createCase(officer, rdcf, c -> {
        c.setPerson(person.toReference());
        c.setHealthFacility(getFacilityFacade().getByUuid(FacilityDto.OTHER_FACILITY_UUID).toReference());
        c.setHealthFacilityDetails("Test HF details");
    });
    User officerUser = getUserService().getByReferenceDto(officer);
    getShareRequestInfoService().persist(createShareRequestInfo(officerUser, DEFAULT_SERVER_ID, true, i -> i.setCaze(getCaseService().getByReferenceDto(caze.toReference()))));
    caze.setHealthFacilityDetails(rdcf.facility.getCaption());
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(caze.getChangeDate());
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    caze.setChangeDate(calendar.getTime());
    SormasToSormasOriginInfoDto originInfo = createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, true);
    SormasToSormasDto shareData = new SormasToSormasDto();
    shareData.setOriginInfo(originInfo);
    shareData.setCases(Collections.singletonList(new SormasToSormasCaseDto(person, caze)));
    SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
    try {
        getSormasToSormasCaseFacade().saveSharedEntities(encryptedData);
    } catch (Exception e) {
        e.printStackTrace();
    }
    CaseDataDto returnedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
    assertThat(returnedCase.getHealthFacility(), is(rdcf.facility));
    assertThat(returnedCase.getHealthFacilityDetails(), is(nullValue()));
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) Arrays(java.util.Arrays) SormasToSormasShareTree(de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree) ArgumentMatchers(org.mockito.ArgumentMatchers) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Date(java.util.Date) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SormasToSormasOptionsDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto) ExposureType(de.symeda.sormas.api.exposure.ExposureType) PersonDto(de.symeda.sormas.api.person.PersonDto) PortHealthInfoDto(de.symeda.sormas.api.caze.porthealthinfo.PortHealthInfoDto) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) Matchers.nullValue(org.hamcrest.Matchers.nullValue) PointOfEntryType(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryType) UserRole(de.symeda.sormas.api.user.UserRole) AnimalContactType(de.symeda.sormas.api.exposure.AnimalContactType) PointOfEntryDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) SormasToSormasException(de.symeda.sormas.api.sormastosormas.SormasToSormasException) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) List(java.util.List) User(de.symeda.sormas.backend.user.User) Response(javax.ws.rs.core.Response) EpiDataDto(de.symeda.sormas.api.epidata.EpiDataDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) Matchers.is(org.hamcrest.Matchers.is) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SamplePurpose(de.symeda.sormas.api.sample.SamplePurpose) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) Matchers.arrayWithSize(org.hamcrest.Matchers.arrayWithSize) MockProducer(de.symeda.sormas.backend.MockProducer) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) RunWith(org.junit.runner.RunWith) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) QuarantineType(de.symeda.sormas.api.contact.QuarantineType) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) Calendar(java.util.Calendar) SymptomState(de.symeda.sormas.api.symptoms.SymptomState) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DataHelper(de.symeda.sormas.api.utils.DataHelper) ContactStatus(de.symeda.sormas.api.contact.ContactStatus) SormasToSormasShareRequestDto(de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto) UserDto(de.symeda.sormas.api.user.UserDto) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Test(org.junit.Test) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) ShareRequestStatus(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) SormasToSormasConfig(de.symeda.sormas.api.sormastosormas.SormasToSormasConfig) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) Mockito(org.mockito.Mockito) ExposureDto(de.symeda.sormas.api.exposure.ExposureDto) Disease(de.symeda.sormas.api.Disease) SampleDto(de.symeda.sormas.api.sample.SampleDto) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) Collections(java.util.Collections) SormasToSormasCaseDto(de.symeda.sormas.api.sormastosormas.caze.SormasToSormasCaseDto) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) User(de.symeda.sormas.backend.user.User) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) Calendar(java.util.Calendar) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) SormasToSormasCaseDto(de.symeda.sormas.api.sormastosormas.caze.SormasToSormasCaseDto) SormasToSormasException(de.symeda.sormas.api.sormastosormas.SormasToSormasException) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 7 with SormasToSormasOriginInfoDto

use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.

the class SormasToSormasCaseFacadeEjbTest method testSaveReturnedCaseWithKnownOtherPointOfEntry.

@Test
public void testSaveReturnedCaseWithKnownOtherPointOfEntry() throws SormasToSormasException {
    UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
    PersonDto person = creator.createPerson();
    CaseDataDto caze = creator.createCase(officer, rdcf, c -> {
        c.setPerson(person.toReference());
        c.setCaseOrigin(CaseOrigin.POINT_OF_ENTRY);
        c.setPointOfEntry(new PointOfEntryReferenceDto(PointOfEntryDto.OTHER_SEAPORT_UUID, null, null, null));
        c.setPointOfEntryDetails("Test Seaport");
    });
    User officerUser = getUserService().getByReferenceDto(officer);
    getSormasToSormasShareInfoService().persist(createShareInfo(DEFAULT_SERVER_ID, true, i -> i.setCaze(getCaseService().getByReferenceDto(caze.toReference()))));
    caze.setPointOfEntryDetails(rdcf.pointOfEntry.getCaption());
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(caze.getChangeDate());
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    caze.setChangeDate(calendar.getTime());
    SormasToSormasOriginInfoDto originInfo = createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, true);
    SormasToSormasDto shareData = new SormasToSormasDto();
    shareData.setOriginInfo(originInfo);
    shareData.setCases(Collections.singletonList(new SormasToSormasCaseDto(person, caze)));
    SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
    try {
        getSormasToSormasCaseFacade().saveSharedEntities(encryptedData);
    } catch (Exception e) {
        e.printStackTrace();
    }
    CaseDataDto returnedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
    assertThat(returnedCase.getPointOfEntry(), is(rdcf.pointOfEntry));
    assertThat(returnedCase.getPointOfEntryDetails(), is(nullValue()));
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) Arrays(java.util.Arrays) SormasToSormasShareTree(de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree) ArgumentMatchers(org.mockito.ArgumentMatchers) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Date(java.util.Date) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SormasToSormasOptionsDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto) ExposureType(de.symeda.sormas.api.exposure.ExposureType) PersonDto(de.symeda.sormas.api.person.PersonDto) PortHealthInfoDto(de.symeda.sormas.api.caze.porthealthinfo.PortHealthInfoDto) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) Matchers.nullValue(org.hamcrest.Matchers.nullValue) PointOfEntryType(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryType) UserRole(de.symeda.sormas.api.user.UserRole) AnimalContactType(de.symeda.sormas.api.exposure.AnimalContactType) PointOfEntryDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) SormasToSormasException(de.symeda.sormas.api.sormastosormas.SormasToSormasException) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) List(java.util.List) User(de.symeda.sormas.backend.user.User) Response(javax.ws.rs.core.Response) EpiDataDto(de.symeda.sormas.api.epidata.EpiDataDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) Matchers.is(org.hamcrest.Matchers.is) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SamplePurpose(de.symeda.sormas.api.sample.SamplePurpose) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) Matchers.arrayWithSize(org.hamcrest.Matchers.arrayWithSize) MockProducer(de.symeda.sormas.backend.MockProducer) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) RunWith(org.junit.runner.RunWith) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) QuarantineType(de.symeda.sormas.api.contact.QuarantineType) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) Calendar(java.util.Calendar) SymptomState(de.symeda.sormas.api.symptoms.SymptomState) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DataHelper(de.symeda.sormas.api.utils.DataHelper) ContactStatus(de.symeda.sormas.api.contact.ContactStatus) SormasToSormasShareRequestDto(de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto) UserDto(de.symeda.sormas.api.user.UserDto) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Test(org.junit.Test) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) ShareRequestStatus(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) SormasToSormasConfig(de.symeda.sormas.api.sormastosormas.SormasToSormasConfig) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) Mockito(org.mockito.Mockito) ExposureDto(de.symeda.sormas.api.exposure.ExposureDto) Disease(de.symeda.sormas.api.Disease) SampleDto(de.symeda.sormas.api.sample.SampleDto) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) Collections(java.util.Collections) SormasToSormasCaseDto(de.symeda.sormas.api.sormastosormas.caze.SormasToSormasCaseDto) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) User(de.symeda.sormas.backend.user.User) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) Calendar(java.util.Calendar) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) SormasToSormasCaseDto(de.symeda.sormas.api.sormastosormas.caze.SormasToSormasCaseDto) SormasToSormasException(de.symeda.sormas.api.sormastosormas.SormasToSormasException) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 8 with SormasToSormasOriginInfoDto

use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.

the class SormasToSormasTest method createSormasToSormasOriginInfo.

protected SormasToSormasOriginInfoDto createSormasToSormasOriginInfo(String serverId, boolean ownershipHandedOver) {
    SormasToSormasOriginInfoDto source = new SormasToSormasOriginInfoDto();
    source.setOrganizationId(serverId);
    source.setSenderName("John doe");
    source.setOwnershipHandedOver(ownershipHandedOver);
    return source;
}
Also used : SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto)

Example 9 with SormasToSormasOriginInfoDto

use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.

the class SormasToSormasEncryptionServiceTest method testEncryptDecrypt.

@Test
public void testEncryptDecrypt() throws SormasToSormasException {
    useSurveillanceOfficerLogin(rdcf);
    PersonDto person = creator.createPerson("FirstName", "LastName");
    UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
    CaseDataDto caze = creator.createCase(officer, rdcf, dto -> {
        dto.setPerson(person.toReference());
        dto.setSurveillanceOfficer(officer);
        dto.setClassificationUser(officer);
    });
    SormasToSormasDto bodyToEncrypt = new SormasToSormasDto();
    SormasToSormasOriginInfoDto s2sOriginInfo = new SormasToSormasOriginInfoDto();
    s2sOriginInfo.setComment("Test comment");
    bodyToEncrypt.setOriginInfo(s2sOriginInfo);
    bodyToEncrypt.setCases(Collections.singletonList(new SormasToSormasCaseDto(person, caze)));
    mockS2Snetwork();
    // encrypt
    mockDefaultServerAccess();
    SormasToSormasEncryptedDataDto encryptedBody = getSormasToSormasEncryptionFacade().signAndEncrypt(bodyToEncrypt, SECOND_SERVER_ID);
    mockSecondServerAccess();
    assertThat(encryptedBody.getSenderId(), is(DEFAULT_SERVER_ID));
    assertThat(encryptedBody.getData(), instanceOf(byte[].class));
    // decrypt
    mockSecondServerAccess();
    SormasToSormasDto decryptedBody = getSormasToSormasEncryptionFacade().decryptAndVerify(encryptedBody, SormasToSormasDto.class);
    mockDefaultServerAccess();
    assertThat(decryptedBody.getCases().size(), is(1));
    SormasToSormasCaseDto decryptedCase = decryptedBody.getCases().get(0);
    assertThat(decryptedCase.getPerson().getFirstName(), is("FirstName"));
    assertThat(decryptedCase.getPerson().getLastName(), is("LastName"));
    assertThat(decryptedBody.getOriginInfo().getComment(), is("Test comment"));
    assertThat(decryptedBody.getSamples(), is(nullValue()));
    assertThat(decryptedBody.getContacts(), is(nullValue()));
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) SormasToSormasCaseDto(de.symeda.sormas.api.sormastosormas.caze.SormasToSormasCaseDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 10 with SormasToSormasOriginInfoDto

use of de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto in project SORMAS-Project by hzi-braunschweig.

the class SormasToSormasCaseFacadeEjbTest method testSyncCases.

@Test
public void testSyncCases() throws SormasToSormasValidationException, SormasToSormasException {
    UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
    PersonDto casePerson = creator.createPerson();
    CaseDataDto caze = creator.createCase(officer, casePerson.toReference(), rdcf, c -> {
        SormasToSormasOriginInfoDto originInfo = new SormasToSormasOriginInfoDto();
        originInfo.setSenderName("Test Name");
        originInfo.setSenderEmail("test@email.com");
        originInfo.setOrganizationId(DEFAULT_SERVER_ID);
        originInfo.setWithAssociatedContacts(true);
        originInfo.setOwnershipHandedOver(true);
        c.setSormasToSormasOriginInfo(originInfo);
    });
    PersonDto contactPerson = creator.createPerson();
    ContactDto contact = creator.createContact(officer, officer, contactPerson.toReference(), caze, new Date(), new Date(), Disease.CORONAVIRUS, rdcf, (c) -> c.setSormasToSormasOriginInfo(caze.getSormasToSormasOriginInfo()));
    ShareRequestInfo shareRequestInfo = createShareRequestInfo(getUserService().getByUuid(officer.getUuid()), SECOND_SERVER_ID, false, ShareRequestStatus.ACCEPTED, i -> i.setCaze(getCaseService().getByUuid(caze.getUuid())));
    shareRequestInfo.setWithAssociatedContacts(true);
    shareRequestInfo.getShares().add(createShareInfo(SECOND_SERVER_ID, false, i -> i.setContact(getContactService().getByUuid(contact.getUuid()))));
    getShareRequestInfoService().persist(shareRequestInfo);
    PersonDto newContactPerson = creator.createPerson();
    ContactDto newContact = creator.createContact(officer, officer, newContactPerson.toReference(), caze, new Date(), new Date(), Disease.CORONAVIRUS, rdcf, (c) -> c.setSormasToSormasOriginInfo(caze.getSormasToSormasOriginInfo()));
    caze.setAdditionalDetails("Test updated details");
    contact.setContactStatus(ContactStatus.DROPPED);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(caze.getChangeDate());
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    caze.setChangeDate(calendar.getTime());
    SormasToSormasDto shareData = new SormasToSormasDto();
    SormasToSormasOriginInfoDto originInfo = createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, true);
    originInfo.setWithAssociatedContacts(true);
    shareData.setOriginInfo(originInfo);
    shareData.setCases(Collections.singletonList(new SormasToSormasCaseDto(casePerson, caze)));
    shareData.setContacts(Arrays.asList(new SormasToSormasContactDto(contactPerson, contact), new SormasToSormasContactDto(newContactPerson, newContact)));
    SormasToSormasEncryptedDataDto encryptedData = encryptShareData(new SyncDataDto(shareData, new ShareTreeCriteria(caze.getUuid(), null, false)));
    MockProducer.getProperties().setProperty(SormasToSormasConfig.SORMAS2SORMAS_IGNORE_ADDITIONAL_DETAILS, Boolean.FALSE.toString());
    Mockito.when(MockProducer.getManagedScheduledExecutorService().schedule(ArgumentMatchers.any(Runnable.class), ArgumentMatchers.anyLong(), ArgumentMatchers.any())).then(invocation -> {
        ((Runnable) invocation.getArgument(0)).run();
        return null;
    });
    Mockito.when(MockProducer.getSormasToSormasClient().post(eq(DEFAULT_SERVER_ID), ArgumentMatchers.contains("/cases/sync"), ArgumentMatchers.any(), ArgumentMatchers.any())).then(invocation -> {
        SyncDataDto syncData = invocation.getArgument(2);
        assertThat(syncData.getCriteria().getEntityUuid(), is(caze.getUuid()));
        assertThat(syncData.getCriteria().getExceptedOrganizationId(), is(SECOND_SERVER_ID));
        assertThat(syncData.getCriteria().isForwardOnly(), is(false));
        assertThat(syncData.getShareData().getCases().get(0).getEntity().getUuid(), is(caze.getUuid()));
        assertThat(syncData.getShareData().getCases().get(0).getEntity().getAdditionalDetails(), is("Test updated details"));
        assertThat(syncData.getShareData().getContacts(), hasSize(2));
        return Response.noContent().build();
    });
    Mockito.when(MockProducer.getSormasToSormasClient().post(eq(SECOND_SERVER_ID), ArgumentMatchers.contains("/cases/sync"), ArgumentMatchers.any(), ArgumentMatchers.any())).then(invocation -> {
        SyncDataDto syncData = invocation.getArgument(2);
        assertThat(syncData.getCriteria().getEntityUuid(), is(caze.getUuid()));
        assertThat(syncData.getCriteria().getExceptedOrganizationId(), is(nullValue()));
        assertThat(syncData.getCriteria().isForwardOnly(), is(true));
        assertThat(syncData.getShareData().getCases().get(0).getEntity().getUuid(), is(caze.getUuid()));
        assertThat(syncData.getShareData().getCases().get(0).getEntity().getAdditionalDetails(), is("Test updated details"));
        // new contact should not be shared
        assertThat(syncData.getShareData().getContacts(), hasSize(1));
        assertThat(syncData.getShareData().getContacts().get(0).getEntity().getUuid(), is(contact.getUuid()));
        return Response.noContent().build();
    });
    getSormasToSormasCaseFacade().saveSyncedEntity(encryptedData);
    Mockito.verify(MockProducer.getSormasToSormasClient(), Mockito.times(1)).post(eq(DEFAULT_SERVER_ID), ArgumentMatchers.contains("/cases/sync"), ArgumentMatchers.any(), ArgumentMatchers.any());
    Mockito.verify(MockProducer.getSormasToSormasClient(), Mockito.times(1)).post(eq(SECOND_SERVER_ID), ArgumentMatchers.contains("/cases/sync"), ArgumentMatchers.any(), ArgumentMatchers.any());
}
Also used : Arrays(java.util.Arrays) SormasToSormasShareTree(de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree) ArgumentMatchers(org.mockito.ArgumentMatchers) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Date(java.util.Date) SormasToSormasSampleDto(de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto) SormasToSormasOptionsDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto) ExposureType(de.symeda.sormas.api.exposure.ExposureType) PersonDto(de.symeda.sormas.api.person.PersonDto) PortHealthInfoDto(de.symeda.sormas.api.caze.porthealthinfo.PortHealthInfoDto) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) Matchers.nullValue(org.hamcrest.Matchers.nullValue) PointOfEntryType(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryType) UserRole(de.symeda.sormas.api.user.UserRole) AnimalContactType(de.symeda.sormas.api.exposure.AnimalContactType) PointOfEntryDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) SormasToSormasException(de.symeda.sormas.api.sormastosormas.SormasToSormasException) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) List(java.util.List) User(de.symeda.sormas.backend.user.User) Response(javax.ws.rs.core.Response) EpiDataDto(de.symeda.sormas.api.epidata.EpiDataDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) Matchers.is(org.hamcrest.Matchers.is) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SamplePurpose(de.symeda.sormas.api.sample.SamplePurpose) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) Matchers.arrayWithSize(org.hamcrest.Matchers.arrayWithSize) MockProducer(de.symeda.sormas.backend.MockProducer) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) SormasToSormasValidationException(de.symeda.sormas.api.sormastosormas.validation.SormasToSormasValidationException) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) RunWith(org.junit.runner.RunWith) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) QuarantineType(de.symeda.sormas.api.contact.QuarantineType) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) Calendar(java.util.Calendar) SymptomState(de.symeda.sormas.api.symptoms.SymptomState) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DataHelper(de.symeda.sormas.api.utils.DataHelper) ContactStatus(de.symeda.sormas.api.contact.ContactStatus) SormasToSormasShareRequestDto(de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto) UserDto(de.symeda.sormas.api.user.UserDto) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Test(org.junit.Test) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) ShareRequestStatus(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) SormasToSormasConfig(de.symeda.sormas.api.sormastosormas.SormasToSormasConfig) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) Mockito(org.mockito.Mockito) ExposureDto(de.symeda.sormas.api.exposure.ExposureDto) Disease(de.symeda.sormas.api.Disease) SampleDto(de.symeda.sormas.api.sample.SampleDto) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) Collections(java.util.Collections) SormasToSormasCaseDto(de.symeda.sormas.api.sormastosormas.caze.SormasToSormasCaseDto) SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) ShareTreeCriteria(de.symeda.sormas.api.sormastosormas.ShareTreeCriteria) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) ShareRequestInfo(de.symeda.sormas.backend.sormastosormas.share.shareinfo.ShareRequestInfo) Calendar(java.util.Calendar) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) Date(java.util.Date) SormasToSormasCaseDto(de.symeda.sormas.api.sormastosormas.caze.SormasToSormasCaseDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) SormasToSormasContactDto(de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Aggregations

SormasToSormasOriginInfoDto (de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto)20 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)13 SormasToSormasTest (de.symeda.sormas.backend.sormastosormas.SormasToSormasTest)13 Test (org.junit.Test)13 Date (java.util.Date)12 PersonDto (de.symeda.sormas.api.person.PersonDto)11 SormasServerDescriptor (de.symeda.sormas.api.sormastosormas.SormasServerDescriptor)11 SampleDto (de.symeda.sormas.api.sample.SampleDto)10 SormasToSormasOptionsDto (de.symeda.sormas.api.sormastosormas.SormasToSormasOptionsDto)10 SormasToSormasSampleDto (de.symeda.sormas.api.sormastosormas.sample.SormasToSormasSampleDto)10 SormasToSormasShareRequestDto (de.symeda.sormas.api.sormastosormas.sharerequest.SormasToSormasShareRequestDto)10 SormasToSormasDto (de.symeda.sormas.api.sormastosormas.SormasToSormasDto)9 SormasToSormasEncryptedDataDto (de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto)9 SormasToSormasShareInfoDto (de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto)9 User (de.symeda.sormas.backend.user.User)9 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)8 ContactDto (de.symeda.sormas.api.contact.ContactDto)8 ShareTreeCriteria (de.symeda.sormas.api.sormastosormas.ShareTreeCriteria)8 SormasToSormasContactDto (de.symeda.sormas.api.sormastosormas.contact.SormasToSormasContactDto)8 SormasToSormasShareInfoCriteria (de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria)8