@Test public void testGetFeatureAxisSwap() throws Exception { // Check that a NORTH_EAST source is swapped doAxisSwapTest(POINT_LATLON, CRS.AxisOrder.NORTH_EAST); }
@Test public void testGetFeatureCRS() throws Exception { QName layer = SystemTestData.LINES; JSONObject collection = (JSONObject) getAsJSON( "wfs?request=GetFeature&version=1.0.0&typename=" + getLayerId(layer) + "&outputformat=" + JSONType.json); CoordinateReferenceSystem expectedCrs = getCatalog().getLayerByName(getLayerId(layer)).getResource().getCRS(); JSONObject aCRS = collection.getJSONObject("crs"); assertThat(aCRS, encodesCRS(expectedCrs)); }
@Test public void testGetFeatureCountMaxFeatures() throws Exception { // check if maxFeatures doesn't affect totalFeatureCount; set Filter and maxFeatures String out3 = getAsString( "wfs?request=GetFeature&version=1.0.0&typename=sf:PrimitiveGeoFeature&maxfeatures=1&outputformat=" + JSONType.json + "&featureid=PrimitiveGeoFeature.f001,PrimitiveGeoFeature.f002"); JSONObject rootObject3 = JSONObject.fromObject(out3); assertEquals(rootObject3.get("totalFeatures"), 2); }
protected void setUpInternal(SystemTestData data) throws Exception { super.setUpInternal(data); File security = new File(getTestData().getDataDirectoryRoot(), "security"); security.mkdir(); File layers = new File(security, "layers.properties"); IOUtils.copy(GeoJSONTest.class.getResourceAsStream("layers_ro.properties"), layers); data.addVectorLayer(LINE3D, Collections.EMPTY_MAP, getClass(), getCatalog()); data.addVectorLayer(POINT_LATLON, Collections.EMPTY_MAP, getClass(), getCatalog()); CoordinateReferenceSystem crsLatLon = CRS.decode("urn:ogc:def:crs:EPSG::4326"); FeatureTypeInfo pointLatLon = getCatalog() .getFeatureTypeByName( POINT_LATLON.getPrefix(), POINT_LATLON.getLocalPart()); pointLatLon.setSRS("urn:ogc:def:crs:EPSG::4326"); pointLatLon.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED); getCatalog().save(pointLatLon); data.addVectorLayer(POINT_LONLAT, Collections.EMPTY_MAP, getClass(), getCatalog()); CoordinateReferenceSystem crsLonLat = CRS.decode("EPSG:4326", true); FeatureTypeInfo pointLonLat = getCatalog() .getFeatureTypeByName( POINT_LONLAT.getPrefix(), POINT_LONLAT.getLocalPart()); pointLatLon.setSRS("EPSG:4326"); pointLatLon.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED); getCatalog().save(pointLonLat);
@Test public void testGetFeatureWhereLayerHasDecimalPointsSet() throws Exception { JSONObject collection = (JSONObject) getAsJSON( "wfs?request=GetFeature&version=1.0.0&typename=" + getLayerId(POINT_REDUCED) + "&outputformat=" + JSONType.json); assertThat(collection.getInt("totalFeatures"), is(3)); JSONArray features = collection.getJSONArray("features"); assertThat((Collection<?>) features, Matchers.hasSize(3)); JSONObject feature = features.getJSONObject(0); JSONObject geometry = feature.getJSONObject("geometry"); assertThat(geometry.getString("type"), is("Point")); JSONArray coords = geometry.getJSONArray("coordinates"); assertThat((Iterable<?>) coords, contains((Object) 120.12, 0.56)); JSONArray bbox = collection.getJSONArray("bbox"); assertThat( (Iterable<?>) bbox, Matchers.contains((Object) (-170.19), -30.13, 120.12, 45.23)); CoordinateReferenceSystem expectedCrs = CRS.decode("EPSG:4326"); JSONObject aCRS = collection.getJSONObject("crs"); assertThat(aCRS, encodesCRS(expectedCrs)); }
@Test public void testGeometryCollection() throws Exception { String out = getAsString( "wfs?request=GetFeature&version=1.0.0&typename=sf:AggregateGeoFeature&maxfeatures=3&outputformat=" + JSONType.json); JSONObject rootObject = JSONObject.fromObject(out); assertEquals(rootObject.get("type"), "FeatureCollection"); JSONArray featureCol = rootObject.getJSONArray("features"); JSONObject aFeature = featureCol.getJSONObject(1); JSONObject aPropeties = aFeature.getJSONObject("properties"); JSONObject aGeometry = aPropeties.getJSONObject("multiCurveProperty"); assertEquals(aGeometry.getString("type"), "MultiLineString"); JSONArray geomArray = aGeometry.getJSONArray("coordinates"); geomArray = geomArray.getJSONArray(0); geomArray = geomArray.getJSONArray(0); assertEquals(geomArray.getString(0), "55.174"); CoordinateReferenceSystem expectedCrs = getCatalog() .getLayerByName(getLayerId(SystemTestData.AGGREGATEGEOFEATURE)) .getResource() .getCRS(); JSONObject aCRS = rootObject.getJSONObject("crs"); assertThat(aCRS.getString("type"), equalTo("name")); assertThat(aCRS, encodesCRS(expectedCrs)); }
getAsString( "wfs?request=GetFeature&version=2.0.0&typename=sf:PrimitiveGeoFeature" + "&startIndex=2&&count=2&outputformat=" + JSONType.json); JSONObject rootObject = JSONObject.fromObject(out); print(rootObject); assertEquals(rootObject.get("totalFeatures"), 5); assertEquals(rootObject.get("numberMatched"), 5); assertEquals(2, links.size()); JSONObject prev = links.getJSONObject(0); assertLink( prev, "previous page", + "&OUTPUTFORMAT=application%2Fjson&VERSION=2.0.0&COUNT=2&STARTINDEX=0"); JSONObject next = links.getJSONObject(1); assertLink( next, "next page",
@Test public void testGetSkipCounting() throws Exception { Catalog catalog = getCatalog(); try { // skip the feature count FeatureTypeInfo primitive = catalog.getFeatureTypeByName(getLayerId(MockData.PRIMITIVEGEOFEATURE)); primitive.setSkipNumberMatched(true); catalog.save(primitive); MockHttpServletResponse response = getAsServletResponse( "wfs?request=GetFeature&version=2.0.0&typename=sf:PrimitiveGeoFeature&outputformat=" + JSONType.json); assertEquals("application/json", response.getContentType()); String out = response.getContentAsString(); JSONObject rootObject = JSONObject.fromObject(out); assertEquals(rootObject.get("type"), "FeatureCollection"); JSONArray featureCol = rootObject.getJSONArray("features"); JSONObject aFeature = featureCol.getJSONObject(0); assertEquals(aFeature.getString("geometry_name"), "surfaceProperty"); } finally { FeatureTypeInfo primitive = catalog.getFeatureTypeByName(getLayerId(MockData.PRIMITIVEGEOFEATURE)); primitive.setSkipNumberMatched(false); catalog.save(primitive); } }
GeoServer gs = getGeoServer(); WFSInfo wfs = getWFS(); boolean before = wfs.isFeatureBounding(); wfs.setFeatureBounding(false); getAsString( "wfs?request=GetFeature&version=1.0.0&typename=sf:AggregateGeoFeature&maxfeatures=3&outputformat=" + JSONType.json);
JSONObject collection = (JSONObject) getAsJSON( "wfs?request=GetFeature&version=1.0.0&typename=" + getLayerId(MULTI_GEOMETRIES_WITH_NULL) + "&outputformat=" + JSONType.json); print(collection); assertEquals(3, collection.getInt("totalFeatures"));
@Test public void testCallbackFunction() throws Exception { JSONType.setJsonpEnabled(true); MockHttpServletResponse resp = getAsServletResponse( "wfs?request=GetFeature&version=1.0.0&typename=sf:PrimitiveGeoFeature&maxfeatures=1&outputformat=" + JSONType.jsonp + "&format_options=" + JSONType.CALLBACK_FUNCTION_KEY + ":myFunc"); JSONType.setJsonpEnabled(false); String out = resp.getContentAsString(); assertEquals(JSONType.jsonp, resp.getContentType()); assertTrue(out.startsWith("myFunc(")); assertTrue(out.endsWith(")")); // extract the json and check it out = out.substring(7, out.length() - 1); JSONObject rootObject = JSONObject.fromObject(out); assertEquals(rootObject.get("type"), "FeatureCollection"); JSONArray featureCol = rootObject.getJSONArray("features"); JSONObject aFeature = featureCol.getJSONObject(0); assertEquals(aFeature.getString("geometry_name"), "surfaceProperty"); }
@Test public void getGetFeatureWithPagingFirstPage() throws Exception { // request with paging String out = getAsString( "wfs?request=GetFeature&version=2.0.0&typename=sf:PrimitiveGeoFeature" + "&startIndex=0&&count=2&outputformat=" + JSONType.json); JSONObject rootObject = JSONObject.fromObject(out); // print(rootObject); assertEquals(rootObject.get("totalFeatures"), 5); assertEquals(rootObject.get("numberMatched"), 5); assertEquals(rootObject.get("numberReturned"), 2); JSONArray links = rootObject.getJSONArray("links"); assertNotNull(links); assertEquals(1, links.size()); JSONObject link = links.getJSONObject(0); assertLink( link, "next page", "application/json", "next", "http://localhost:8080/geoserver" + "/wfs?TYPENAME=sf%3APrimitiveGeoFeature&REQUEST=GetFeature" + "&OUTPUTFORMAT=application%2Fjson&VERSION=2.0.0&COUNT=2&STARTINDEX=2"); }
JSONObject collection = (JSONObject) getAsJSON( "wfs?request=GetFeature&version=1.0.0&typename=" + getLayerId(LINE3D) + "&outputformat=" + JSONType.json); assertThat(aCRS, encodesCRS(expectedCrs));
@Test public void getGetFeatureWithPagingLastPage() throws Exception { // request with paging String out = getAsString( "wfs?request=GetFeature&version=2.0.0&typename=sf:PrimitiveGeoFeature" + "&startIndex=4&&count=2&outputformat=" + JSONType.json); JSONObject rootObject = JSONObject.fromObject(out); print(rootObject); assertEquals(rootObject.get("totalFeatures"), 5); assertEquals(rootObject.get("numberMatched"), 5); assertEquals(rootObject.get("numberReturned"), 1); JSONArray links = rootObject.getJSONArray("links"); assertNotNull(links); assertEquals(1, links.size()); JSONObject prev = links.getJSONObject(0); assertLink( prev, "previous page", "application/json", "previous", "http://localhost:8080/geoserver" + "/wfs?TYPENAME=sf%3APrimitiveGeoFeature&REQUEST=GetFeature" + "&OUTPUTFORMAT=application%2Fjson&VERSION=2.0.0&COUNT=2&STARTINDEX=2"); }
@Test public void testGet() throws Exception { MockHttpServletResponse response = getAsServletResponse( "wfs?request=GetFeature&version=1.0.0&typename=sf:PrimitiveGeoFeature&maxfeatures=1&outputformat=" + JSONType.json); assertEquals("application/json", response.getContentType()); String out = response.getContentAsString(); JSONObject rootObject = JSONObject.fromObject(out); // print(rootObject); assertEquals(rootObject.get("type"), "FeatureCollection"); JSONArray featureCol = rootObject.getJSONArray("features"); JSONObject aFeature = featureCol.getJSONObject(0); assertEquals(aFeature.getString("geometry_name"), "surfaceProperty"); // check a timestamp exists and matches the structure of a ISO timestamp String timeStamp = rootObject.getString("timeStamp"); assertNotNull(timeStamp); assertTrue( timeStamp.matches( "(\\d{4})-(\\d{2})-(\\d{2})" + "T(\\d{2})\\:(\\d{2})\\:(\\d{2})\\.(\\d{3})Z")); }
getCatalog() .getFeatureTypeByName(layer.getPrefix(), layer.getLocalPart()) .getCRS()), getAsJSON( "wfs?request=GetFeature&version=1.0.0&typename=" + getLayerId(layer) + "&outputformat=" + JSONType.json); assertThat(aCRS, encodesCRS(expectedCrs));
@Test public void testGetSimpleJson() throws Exception { MockHttpServletResponse response = getAsServletResponse( "wfs?request=GetFeature&version=1.0.0&typename=sf:PrimitiveGeoFeature&maxfeatures=1&outputformat=" + JSONType.simple_json, ""); assertEquals("application/json", response.getContentType()); assertEquals("UTF-8", response.getCharacterEncoding()); String out = response.getContentAsString(); JSONObject rootObject = JSONObject.fromObject(out); assertEquals(rootObject.get("type"), "FeatureCollection"); JSONArray featureCol = rootObject.getJSONArray("features"); JSONObject aFeature = featureCol.getJSONObject(0); assertEquals(aFeature.getString("geometry_name"), "surfaceProperty"); }
@Test public void testGetFeatureCountNoFilter() throws Exception { // request without filter String out = getAsString( "wfs?request=GetFeature&version=1.0.0&typename=sf:PrimitiveGeoFeature&maxfeatures=10&outputformat=" + JSONType.json); JSONObject rootObject = JSONObject.fromObject(out); assertEquals(rootObject.get("totalFeatures"), 5); }
@Test public void testGetFeatureNoAxisSwap() throws Exception { // Check that an EAST_NORTH source is not swapped doAxisSwapTest(POINT_LONLAT, CRS.AxisOrder.EAST_NORTH); }
@Test public void testGetJsonIdPolicyFalse() throws Exception { MockHttpServletResponse response = getAsServletResponse( "wfs?request=GetFeature&version=1.0.0&typename=sf:PrimitiveGeoFeature&maxfeatures=1&outputformat=" + JSONType.simple_json + "&format_options=" + JSONType.ID_POLICY + ":false"); assertEquals("application/json", response.getContentType()); String out = response.getContentAsString(); JSONObject rootObject = JSONObject.fromObject(out); assertEquals(rootObject.get("type"), "FeatureCollection"); JSONArray featureCol = rootObject.getJSONArray("features"); JSONObject aFeature = featureCol.getJSONObject(0); assertFalse("supress id", aFeature.containsKey("id")); }