Search in sources :

Example 56 with Attribute

use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.

the class GeoFeatureServiceMockTest method testGeoJsonAttributeWithNoValue.

/**
 * GET Request has "coordinateField" parameter.
 * <p>
 * OrganisationUnit has coordinates from geometry property but not GeoJson
 * Attribute.
 * <p>
 * Expected: only return GeoFeature which has the coordinateField value.
 *
 * @throws IOException
 */
@Test
public void testGeoJsonAttributeWithNoValue() throws IOException {
    OrganisationUnit ouA = createOrgUnitWithCoordinates();
    User user = rnd.nextObject(User.class);
    DataQueryParams params = DataQueryParams.newBuilder().withOrganisationUnits(getList(ouA)).build();
    when(dataQueryService.getFromRequest(any())).thenReturn(params);
    when(currentUserService.getCurrentUser()).thenReturn(user);
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    Attribute attribute = new Attribute();
    attribute.setValueType(ValueType.GEOJSON);
    attribute.setOrganisationUnitAttribute(true);
    when(attributeService.getAttribute("GeoJSON_Attribute_ID")).thenReturn(attribute);
    List<GeoFeature> features = geoFeatureService.getGeoFeatures(GeoFeatureService.Parameters.builder().request(request).response(response).coordinateField("GeoJSON_Attribute_ID").organisationUnit("ou:LEVEL-2;LEVEL-3").build());
    assertEquals(0, features.size());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) User(org.hisp.dhis.user.User) Attribute(org.hisp.dhis.attribute.Attribute) HttpServletResponse(javax.servlet.http.HttpServletResponse) GeoFeature(org.hisp.dhis.webapi.webdomain.GeoFeature) Test(org.junit.jupiter.api.Test)

Aggregations

Attribute (org.hisp.dhis.attribute.Attribute)56 Test (org.junit.jupiter.api.Test)28 AttributeValue (org.hisp.dhis.attribute.AttributeValue)27 HashMap (java.util.HashMap)13 DhisSpringTest (org.hisp.dhis.DhisSpringTest)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 List (java.util.List)8 DataElement (org.hisp.dhis.dataelement.DataElement)8 ArrayList (java.util.ArrayList)7 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)7 Property (org.hisp.dhis.schema.Property)7 Schema (org.hisp.dhis.schema.Schema)7 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)6 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)6 Test (org.junit.Test)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Lists (com.google.common.collect.Lists)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4