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;
}
};
}
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));
}
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);
}
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());
}
}
Aggregations