Search in sources :

Example 1 with CachedReferenceDtoResolver

use of de.symeda.sormas.api.EntityDtoAccessHelper.CachedReferenceDtoResolver 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 2 with CachedReferenceDtoResolver

use of de.symeda.sormas.api.EntityDtoAccessHelper.CachedReferenceDtoResolver 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

CachedReferenceDtoResolver (de.symeda.sormas.api.EntityDtoAccessHelper.CachedReferenceDtoResolver)2 IReferenceDtoResolver (de.symeda.sormas.api.EntityDtoAccessHelper.IReferenceDtoResolver)2 Test (org.junit.Test)2