public List<FeatureTypeInfo> getFeatureTypes() { return delegate.getFeatureTypes(); }
.anyTimes(); expect(catalog.getResources(CoverageInfo.class)).andReturn(coverages).anyTimes(); expect(catalog.getFeatureTypes()).andReturn(featureTypesAll).anyTimes(); expect(catalog.getCoverages()).andReturn(coveragesAll).anyTimes();
public List<FeatureTypeInfo> getFeatureTypes() { return filterResources(delegate.getFeatureTypes()); }
public List<FeatureTypeInfo> getFeatureTypes() { return filterResources(user(), delegate.getFeatureTypes()); }
@Test public void testRemoveFeatureType() { addFeatureType(); assertFalse(catalog.getFeatureTypes().isEmpty()); try { catalog.getFeatureTypes().remove(ft); fail("removing directly should cause exception"); } catch (Exception e) { } catalog.remove(ft); assertTrue(catalog.getFeatureTypes().isEmpty()); }
@Test public void testAddFeatureType() { assertTrue(catalog.getFeatureTypes().isEmpty()); addFeatureType(); assertEquals(1, catalog.getFeatureTypes().size()); FeatureTypeInfo ft2 = catalog.getFactory().createFeatureType(); try { catalog.add(ft2); fail("adding with no name should throw exception"); } catch (Exception e) { } ft2.setName("ft2Name"); try { catalog.add(ft2); fail("adding with no store should throw exception"); } catch (Exception e) { } ft2.setStore(ds); ft2.getKeywords().add(new Keyword("keyword")); catalog.add(ft2); FeatureTypeInfo ft3 = catalog.getFactory().createFeatureType(); ft3.setName("ft3Name"); try { catalog.getFeatureTypes().add(ft3); fail("adding directly should throw an exception"); } catch (Exception e) { } }
protected void featureTypeList() { if (catalog.getFeatureTypes().isEmpty()) { return; } start("FeatureTypeList"); // TODO: namespace filtering delegate.featureTypes(true, request.getNamespace()); end("FeatureTypeList"); }
@Test public void testTypeNameCount() throws Exception { // filter on an existing namespace Document doc = getAsDOM("wfs?service=WFS&version=2.0.0&request=getCapabilities"); Element e = doc.getDocumentElement(); assertEquals("WFS_Capabilities", e.getLocalName()); XpathEngine xpath = XMLUnit.newXpathEngine(); final List<FeatureTypeInfo> enabledTypes = getCatalog().getFeatureTypes(); for (Iterator<FeatureTypeInfo> it = enabledTypes.iterator(); it.hasNext(); ) { FeatureTypeInfo ft = it.next(); if (!ft.isEnabled()) { it.remove(); } } final int enabledCount = enabledTypes.size(); assertEquals( enabledCount, xpath.getMatchingNodes( "/wfs:WFS_Capabilities/wfs:FeatureTypeList/wfs:FeatureType", doc) .getLength()); }
@Test public void testCollectionsWorkspaceSpecificJson() throws Exception { DocumentContext json = getAsJSONPath("cdf/wfs3/collections", 200); long expected = getCatalog() .getFeatureTypes() .stream() .filter(ft -> "cdf".equals(ft.getStore().getWorkspace().getName())) .count(); assertEquals(expected, (int) json.read("collections.length()", Integer.class)); }
@Test public void testTypeNameCount() throws Exception { // filter on an existing namespace Document doc = getAsDOM("wfs?service=WFS&version=1.0.0&request=getCapabilities"); Element e = doc.getDocumentElement(); assertEquals("WFS_Capabilities", e.getLocalName()); XpathEngine xpath = XMLUnit.newXpathEngine(); final List<FeatureTypeInfo> enabledTypes = getCatalog().getFeatureTypes(); for (Iterator<FeatureTypeInfo> it = enabledTypes.iterator(); it.hasNext(); ) { FeatureTypeInfo ft = it.next(); if (!ft.enabled()) { it.remove(); } } final int enabledCount = enabledTypes.size(); assertEquals( enabledCount, xpath.getMatchingNodes( "/wfs:WFS_Capabilities/wfs:FeatureTypeList/wfs:FeatureType", doc) .getLength()); }
@Test public void testTypeNames() throws Exception { // filter on an existing namespace Document doc = getAsDOM("wfs?service=WFS&version=1.1.0&request=getCapabilities"); Element e = doc.getDocumentElement(); assertEquals("WFS_Capabilities", e.getLocalName()); final List<FeatureTypeInfo> enabledTypes = getCatalog().getFeatureTypes(); for (Iterator<FeatureTypeInfo> it = enabledTypes.iterator(); it.hasNext(); ) { FeatureTypeInfo ft = it.next(); if (ft.enabled()) { String prefixedName = ft.prefixedName(); String xpathExpr = "/wfs:WFS_Capabilities/wfs:FeatureTypeList/" + "wfs:FeatureType/wfs:Name[text()=\"" + prefixedName + "\"]"; XMLAssert.assertXpathExists(xpathExpr, doc); } } }
@Test public void testTypeNameCount() throws Exception { // filter on an existing namespace Document doc = getAsDOM("wfs?service=WFS&version=1.1.0&request=getCapabilities"); Element e = doc.getDocumentElement(); assertEquals("WFS_Capabilities", e.getLocalName()); XpathEngine xpath = XMLUnit.newXpathEngine(); final List<FeatureTypeInfo> enabledTypes = getCatalog().getFeatureTypes(); for (Iterator<FeatureTypeInfo> it = enabledTypes.iterator(); it.hasNext(); ) { FeatureTypeInfo ft = it.next(); if (!ft.enabled()) { it.remove(); } } final int enabledCount = enabledTypes.size(); assertEquals( enabledCount, xpath.getMatchingNodes( "/wfs:WFS_Capabilities/wfs:FeatureTypeList/wfs:FeatureType", doc) .getLength()); }
@Test public void testTypeNames() throws Exception { // filter on an existing namespace Document doc = getAsDOM("wfs?service=WFS&version=2.0.0&request=getCapabilities"); Element e = doc.getDocumentElement(); assertEquals("WFS_Capabilities", e.getLocalName()); final List<FeatureTypeInfo> enabledTypes = getCatalog().getFeatureTypes(); for (Iterator<FeatureTypeInfo> it = enabledTypes.iterator(); it.hasNext(); ) { FeatureTypeInfo ft = it.next(); if (ft.isEnabled()) { String prefixedName = ft.getPrefixedName(); String xpathExpr = "/wfs:WFS_Capabilities/wfs:FeatureTypeList/" + "wfs:FeatureType/wfs:Name[text()=\"" + prefixedName + "\"]"; XMLAssert.assertXpathExists(xpathExpr, doc); } } }
@Test public void testTypeNames() throws Exception { // filter on an existing namespace Document doc = getAsDOM("wfs?service=WFS&version=1.0.0&request=getCapabilities"); print(doc); Element e = doc.getDocumentElement(); assertEquals("WFS_Capabilities", e.getLocalName()); final List<FeatureTypeInfo> enabledTypes = getCatalog().getFeatureTypes(); for (Iterator<FeatureTypeInfo> it = enabledTypes.iterator(); it.hasNext(); ) { FeatureTypeInfo ft = it.next(); if (ft.enabled()) { String prefixedName = ft.getPrefixedName(); String xpathExpr = "/wfs:WFS_Capabilities/wfs:FeatureTypeList/" + "wfs:FeatureType/wfs:Name[text()=\"" + prefixedName + "\"]"; XMLAssert.assertXpathExists(xpathExpr, doc); } } }
@Test public void testCollectionsJson() throws Exception { DocumentContext json = getAsJSONPath("wfs3/collections", 200); int expected = getCatalog().getFeatureTypes().size(); assertEquals(expected, (int) json.read("collections.length()", Integer.class)); // check we have the expected number of links and they all use the right "rel" relation List<String> formats = DefaultWebFeatureService30.getAvailableFormats(FeatureCollectionResponse.class); assertEquals( formats.size(), (int) json.read("collections[0].links.length()", Integer.class)); for (String format : formats) { // check title and rel. List items = json.read("collections[0].links[?(@.type=='" + format + "')]", List.class); Map item = (Map) items.get(0); assertEquals("item", item.get("rel")); } }
@Test public void testDefaultStyle() throws Exception { List<org.geoserver.catalog.FeatureTypeInfo> typeInfos = getCatalog().getFeatureTypes(); for (org.geoserver.catalog.FeatureTypeInfo info : typeInfos) { if (info.getQualifiedName().getNamespaceURI().equals(MockData.CITE_URI) && info.getFeatureType().getGeometryDescriptor() != null) testDefaultStyle(info.getFeatureSource(null, null)); } }
@Test public void testDeleteRecursive() throws Exception { assertNotNull(catalog.getDataStoreByName("sf", "sf")); MockHttpServletResponse response = deleteAsServletResponse(ROOT_PATH + "/workspaces/sf/datastores/sf?recurse=true"); assertEquals(200, response.getStatus()); assertNull(catalog.getDataStoreByName("sf", "sf")); for (FeatureTypeInfo ft : catalog.getFeatureTypes()) { if (ft.getStore().getName().equals("sf")) { fail(); } } }
@Override protected void onSetUp(SystemTestData testData) throws Exception { super.onSetUp(testData); Catalog catalog = getCatalog(); for (FeatureTypeInfo ft : catalog.getFeatureTypes()) { ft.setLatLonBoundingBox(null); catalog.save(ft); } // create a misconfigured layer group LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); lg.getLayers().add(catalog.getLayerByName(getLayerId(MockData.LAKES))); lg.getStyles().add(null); lg.setName("test"); lg.setMode(Mode.NAMED); catalog.add(lg); }
@Test public void testSkipMisconfiguredLayers() throws Exception { // configure geoserver to skip misconfigured layers GeoServerInfo global = getGeoServer().getGlobal(); global.setResourceErrorHandling(ResourceErrorHandling.SKIP_MISCONFIGURED_LAYERS); getGeoServer().save(global); // introduce misconfiguration FeatureTypeInfo ftype = getCatalog().getFeatureTypeByName(CiteTestData.UPDATES.getLocalPart()); ftype.setLatLonBoundingBox(null); getCatalog().save(ftype); // fetch capabilities document Document doc = getAsDOM("wfs?version=1.0.0&service=WFS&request=getCapabilities"); // print(doc); int count = 0; for (FeatureTypeInfo ft : getCatalog().getFeatureTypes()) { if (ft.enabled()) count++; } // print(doc); assertXpathEvaluatesTo(String.valueOf(count - 1), "count(//wfs:FeatureType)", doc); }
@Test public void testBasicContents() throws Exception { MockHttpServletResponse response = getAsServletResponse(root() + "capabilities"); assertEquals(200, response.getErrorCode()); JSONArray json = (JSONArray) json(response); // print(json); // check we have the right number of layers assertEquals(getCatalog().getFeatureTypes().size(), json.size()); // extract and check one JXPathContext context = JXPathContext.newContext(json); JSONObject primitive = (JSONObject) context.getValue(".[name = 'sf:PrimitiveGeoFeature']"); assertNotNull(primitive); assertEquals("urn:ogc:def:crs:EPSG:4326", primitive.get("crs")); assertEquals("xy", primitive.get("axisorder")); JSONArray bbox = (JSONArray) primitive.get("bbox"); assertEquals(-180.0, bbox.getDouble(0), 1E-7); assertEquals(-90.0, bbox.getDouble(1), 1E-7); assertEquals(180.0, bbox.getDouble(2), 1E-7); assertEquals(90.0, bbox.getDouble(3), 1E-7); } }