Search in sources :

Example 1 with IReferenceDtoResolver

use of de.symeda.sormas.api.EntityDtoAccessHelper.IReferenceDtoResolver in project SORMAS-Project by hzi-braunschweig.

the class EntityDtoAccessHelperTest method setup.

@Before
public void setup() {
    caseDataDto = new CaseDataDto();
    caseDataDto.setDisease(Disease.DENGUE);
    caseDataDto.setUuid("ABCDEF");
    hospitalizationDto = new HospitalizationDto();
    hospitalizationDto.setDischargeDate(new Date(1600387200000L));
    hospitalizationDto.setIsolated(YesNoUnknown.NO);
    personReferenceDto = new PersonReferenceDto();
    personReferenceDto.setUuid("GHIJKL");
    personDto = new PersonDto();
    personDto.setUuid("GHIJKL");
    personDto.setFirstName("Tenzing");
    personDto.setLastName("Mike");
    personDto.setBirthdateDD(26);
    personDto.setBirthdateMM(11);
    personDto.setBirthdateYYYY(1973);
    personDto.setPhone("+49 681 1234");
    LocationDto address = new LocationDto();
    address.setStreet("Elm Street");
    personDto.setAddress(address);
    referenceDtoResolver = new IReferenceDtoResolver() {

        @Override
        public EntityDto resolve(ReferenceDto referenceDto) {
            if (referenceDto != null && "GHIJKL".equals(referenceDto.getUuid())) {
                return personDto;
            }
            return null;
        }
    };
}
Also used : PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) HospitalizationDto(de.symeda.sormas.api.hospitalization.HospitalizationDto) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) IReferenceDtoResolver(de.symeda.sormas.api.EntityDtoAccessHelper.IReferenceDtoResolver) Date(java.util.Date) LocationDto(de.symeda.sormas.api.location.LocationDto) Before(org.junit.Before)

Example 2 with IReferenceDtoResolver

use of de.symeda.sormas.api.EntityDtoAccessHelper.IReferenceDtoResolver in project SORMAS-Project by hzi-braunschweig.

the class EntityDtoAccessHelperTest method readReferencedEntityDto.

@Test
public void readReferencedEntityDto() {
    IReferenceDtoResolver referenceDtoResolver = new EntityDtoAccessHelper.IReferenceDtoResolver() {

        @Override
        public EntityDto resolve(ReferenceDto referenceDto) {
            if (referenceDto != null && "GHIJKL".equals(referenceDto.getUuid())) {
                return personDto;
            }
            return null;
        }
    };
    assertNull(EntityDtoAccessHelper.getPropertyPathValue(caseDataDto, "person.firstName", null));
    caseDataDto.setPerson(personReferenceDto);
    assertNull(EntityDtoAccessHelper.getPropertyPathValue(caseDataDto, "person.firstName", null));
    assertEquals("Tenzing", EntityDtoAccessHelper.getPropertyPathValue(caseDataDto, "person.firstName", referenceDtoResolver));
    assertEquals(26, EntityDtoAccessHelper.getPropertyPathValue(caseDataDto, "person.BirthdateDD", referenceDtoResolver));
    assertEquals(11, EntityDtoAccessHelper.getPropertyPathValue(caseDataDto, "person.BirthdateMM", referenceDtoResolver));
    assertEquals(1973, EntityDtoAccessHelper.getPropertyPathValue(caseDataDto, "person.BirthdateYYYY", referenceDtoResolver));
    assertEquals("+49 681 1234", EntityDtoAccessHelper.getPropertyPathValue(caseDataDto, "person.phone", referenceDtoResolver));
}
Also used : PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) IReferenceDtoResolver(de.symeda.sormas.api.EntityDtoAccessHelper.IReferenceDtoResolver) Test(org.junit.Test)

Example 3 with IReferenceDtoResolver

use of de.symeda.sormas.api.EntityDtoAccessHelper.IReferenceDtoResolver in project SORMAS-Project by hzi-braunschweig.

the class EntityDtoAccessHelperTest method readCachedReferencedEntityDto.

@Test
public void readCachedReferencedEntityDto() {
    IReferenceDtoResolver mockResolver = mock(IReferenceDtoResolver.class);
    CachedReferenceDtoResolver cachedReferenceDtoResolver = new CachedReferenceDtoResolver(mockResolver);
    when(mockResolver.resolve(personReferenceDto)).thenReturn(personDto);
    caseDataDto.setPerson(personReferenceDto);
    assertEquals("Tenzing", EntityDtoAccessHelper.getPropertyPathValue(caseDataDto, "person.firstName", cachedReferenceDtoResolver));
    assertEquals("Tenzing", EntityDtoAccessHelper.getPropertyPathValue(caseDataDto, "person.firstName", cachedReferenceDtoResolver));
    verify(mockResolver, times(1)).resolve(personReferenceDto);
}
Also used : CachedReferenceDtoResolver(de.symeda.sormas.api.EntityDtoAccessHelper.CachedReferenceDtoResolver) IReferenceDtoResolver(de.symeda.sormas.api.EntityDtoAccessHelper.IReferenceDtoResolver) Test(org.junit.Test)

Example 4 with IReferenceDtoResolver

use of de.symeda.sormas.api.EntityDtoAccessHelper.IReferenceDtoResolver in project SORMAS-Project by hzi-braunschweig.

the class EntityDtoAccessHelperTest method failOnImplausibleProperty.

@Test
public void failOnImplausibleProperty() {
    try {
        EntityDtoAccessHelper.getPropertyPathValue(caseDataDto, "blubber.blubber");
        fail("expected: IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        assertEquals("In CaseData: No property blubber in class CaseData", e.getMessage());
    }
    try {
        EntityDtoAccessHelper.getPropertyPathValue(caseDataDto, "disease.blubber");
        fail("expected: IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        assertEquals("In CaseData.disease: Disease.blubber cannot be resolved.", e.getMessage());
    }
    IReferenceDtoResolver mockResolver = mock(IReferenceDtoResolver.class);
    CachedReferenceDtoResolver cachedReferenceDtoResolver = new CachedReferenceDtoResolver(mockResolver);
    when(mockResolver.resolve(personReferenceDto)).thenReturn(personDto);
    caseDataDto.setPerson(personReferenceDto);
    try {
        EntityDtoAccessHelper.getPropertyPathValue(caseDataDto, "person.blubber", cachedReferenceDtoResolver);
        fail("expected: IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        assertEquals("In CaseData.person: No property blubber in class Person", e.getMessage());
    }
    try {
        EntityDtoAccessHelper.getPropertyPathValue(caseDataDto, "person.firstName.blubber", cachedReferenceDtoResolver);
        fail("expected: IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        assertEquals("In CaseData.person.firstName: String.blubber cannot be resolved.", e.getMessage());
    }
}
Also used : CachedReferenceDtoResolver(de.symeda.sormas.api.EntityDtoAccessHelper.CachedReferenceDtoResolver) IReferenceDtoResolver(de.symeda.sormas.api.EntityDtoAccessHelper.IReferenceDtoResolver) Test(org.junit.Test)

Aggregations

IReferenceDtoResolver (de.symeda.sormas.api.EntityDtoAccessHelper.IReferenceDtoResolver)4 Test (org.junit.Test)3 CachedReferenceDtoResolver (de.symeda.sormas.api.EntityDtoAccessHelper.CachedReferenceDtoResolver)2 PersonReferenceDto (de.symeda.sormas.api.person.PersonReferenceDto)2 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 HospitalizationDto (de.symeda.sormas.api.hospitalization.HospitalizationDto)1 LocationDto (de.symeda.sormas.api.location.LocationDto)1 PersonDto (de.symeda.sormas.api.person.PersonDto)1 Date (java.util.Date)1 Before (org.junit.Before)1