use of org.hisp.dhis.webapi.json.domain.JsonAttributeValue in project dhis2-core by dhis2.
the class MetadataImportExportControllerTest method testPostValidGeoJsonAttribute.
@Test
void testPostValidGeoJsonAttribute() throws IOException {
POST("/metadata", "{\"organisationUnits\": [ {\"id\":\"rXnqqH2Pu6N\",\"name\": \"My Unit 2\",\"shortName\": \"OU2\",\"openingDate\": \"2020-01-01\"," + "\"attributeValues\": [{\"value\": \"{\\\"type\\\": \\\"Polygon\\\"," + "\\\"coordinates\\\": [[[100,0],[101,0],[101,1],[100,1],[100,0]]] }\"," + "\"attribute\": {\"id\": \"RRH9IFiZZYN\"}}]}]," + "\"attributes\":[{\"id\":\"RRH9IFiZZYN\",\"valueType\":\"GEOJSON\",\"organisationUnitAttribute\":true,\"name\":\"testgeojson\"}]}").content(HttpStatus.OK);
JsonIdentifiableObject organisationUnit = GET("/organisationUnits/{id}", "rXnqqH2Pu6N").content().asObject(JsonIdentifiableObject.class);
assertEquals(1, organisationUnit.getAttributeValues().size());
JsonAttributeValue attributeValue = organisationUnit.getAttributeValues().get(0);
GeoJsonObject geoJSON = new ObjectMapper().readValue(attributeValue.getValue(), GeoJsonObject.class);
assertTrue(geoJSON instanceof Polygon);
Polygon polygon = (Polygon) geoJSON;
assertEquals(100, polygon.getCoordinates().get(0).get(0).getLongitude());
}
Aggregations