Refine search
/** * Get the FeatureTypeInfo for a featuretype to allow configuration tweaks for tests. * * @param typename the QName for the type */ protected FeatureTypeInfo getFeatureTypeInfo(QName typename) { return getCatalog() .getFeatureTypeByName(typename.getNamespaceURI(), typename.getLocalPart()); }
@Test public void testContextStartup() { GeoServer config = (GeoServer) applicationContext.getBean("geoServer"); assertNotNull( config.getCatalog() .getFeatureTypeByName( MockData.BUILDINGS.getNamespaceURI(), MockData.BUILDINGS.getLocalPart())); assertNotNull( config.getCatalog() .getFeatureTypeByName( MockData.BASIC_POLYGONS.getNamespaceURI(), MockData.BASIC_POLYGONS.getLocalPart())); } }
@Test public void testRemoveFeatureType() throws Exception { testAddFeatureType(); File d = new File(testData.getDataDirectoryRoot(), "workspaces/acme/foostore/foo"); assertTrue(d.exists()); FeatureTypeInfo ft = catalog.getFeatureTypeByName("bar", "foo"); catalog.remove(ft); assertFalse(d.exists()); }
@RunTestSetup @Test public void testGeoServerReload() throws Exception { Catalog cat = getCatalog(); FeatureTypeInfo lakes = cat.getFeatureTypeByName( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertFalse("foo".equals(lakes.getTitle())); GeoServerDataDirectory dd = new GeoServerDataDirectory(getResourceLoader()); File info = dd.findResourceFile(lakes); // File info = getResourceLoader().find("featureTypes", "cite_Lakes", "info.xml"); FileReader in = new FileReader(info); Element dom = ReaderUtils.parse(in); Element title = ReaderUtils.getChildElement(dom, "title"); title.getFirstChild().setNodeValue("foo"); OutputStream output = new FileOutputStream(info); try { TransformerFactory.newInstance() .newTransformer() .transform(new DOMSource(dom), new StreamResult(output)); } finally { output.close(); } getGeoServer().reload(); lakes = cat.getFeatureTypeByName( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertEquals("foo", lakes.getTitle()); }
@Test public void testNoMapping() throws Exception { reloadCatalogAndConfiguration(); FeatureTypeInfo ft = getCatalog().getFeatureTypeByName("DividedRoutes"); assertEquals(4, ft.attributes().size()); }
/** * Get the FeatureTypeInfo for a featuretype to allow configuration tweaks for tests. * * @param typename the QName for the type */ protected FeatureTypeInfo getFeatureTypeInfo(QName typename) { return getCatalog() .getFeatureTypeByName(typename.getNamespaceURI(), typename.getLocalPart()); }
/** * Test that the {@link FeatureType} cache returns the same instance every time. This is assumed * by some nasty code in other places that tampers with the CRS. If a new {@link FeatureType} is * constructed for the same {@link FeatureTypeInfo}, Bad Things Happen (TM). */ @Test public void testFeatureTypeCacheInstance() throws Exception { ResourcePool pool = ResourcePool.create(getCatalog()); FeatureTypeInfo info = getCatalog() .getFeatureTypeByName( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); FeatureType ft1 = pool.getFeatureType(info); FeatureType ft2 = pool.getFeatureType(info); FeatureType ft3 = pool.getFeatureType(info); assertSame(ft1, ft2); assertSame(ft1, ft3); }
@Test public void testXsdMapping() throws Exception { getDataDirectory() .copyToResourceDir( getDividedRoutes(), getClass().getResourceAsStream("schema.xsd"), "schema.xsd"); reloadCatalogAndConfiguration(); FeatureTypeInfo ft = getCatalog().getFeatureTypeByName("DividedRoutes"); assertEquals(3, ft.attributes().size()); }
/** * As per GEOS-3513, make sure the old SRS codes are imported by adding the EPSG: prefix where * needed */ public void testCRSPrefix() throws Exception { MockData mockData = (MockData) getTestData(); mockData.getCoveragesDirectory().delete(); Catalog catalog = new CatalogImpl(); LegacyCatalogImporter importer = new LegacyCatalogImporter(catalog); File dataDirectoryRoot = mockData.getDataDirectoryRoot(); importer.imprt(dataDirectoryRoot); FeatureTypeInfo typeInfo = catalog.getFeatureTypeByName(typeName.getNamespaceURI(), typeName.getLocalPart()); assertEquals("EPSG:4326", typeInfo.getSRS()); } }
@Test public void testForce() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.BASIC_POLYGONS.getLocalPart()); assertEquals("EPSG:4269", fti.getSRS()); assertEquals(ProjectionPolicy.FORCE_DECLARED, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:4269"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); fi.close(); assertEquals(CRS.decode("EPSG:4269"), f.getType().getCoordinateReferenceSystem()); }
@Test public void testXmlMapping() throws Exception { getDataDirectory() .copyToResourceDir( getDividedRoutes(), getClass().getResourceAsStream("schema.xml"), "schema.xml"); reloadCatalogAndConfiguration(); FeatureTypeInfo ft = getCatalog().getFeatureTypeByName("DividedRoutes"); assertEquals(2, ft.attributes().size()); }
FeatureTypeInfo featureTypeInfo(QName name, GetFeatureRequest request) throws WFSException, IOException { FeatureTypeInfo meta = catalog.getFeatureTypeByName(name.getNamespaceURI(), name.getLocalPart()); if (meta == null) { String msg = "Could not locate " + name + " in catalog."; throw new WFSException(request, msg, "InvalidParameterValue").locator("typeName"); } return meta; }
@Test public void testLeaveNative() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.LINES.getLocalPart()); assertEquals("EPSG:3004", fti.getSRS()); assertEquals(ProjectionPolicy.NONE, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:32615"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); // test that the geometry was left in tact Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue(); assertTrue(g.equalsExact(WKT.read("LINESTRING(500125 500025,500175 500075)"))); fi.close(); assertEquals(CRS.decode("EPSG:32615"), f.getType().getCoordinateReferenceSystem()); }
@Test public void testModifyFeatureType() throws Exception { testAddFeatureType(); FeatureTypeInfo ft = catalog.getFeatureTypeByName("bar", "foo"); ft.setTitle("fooTitle"); catalog.save(ft); File f = new File( testData.getDataDirectoryRoot(), "workspaces/acme/foostore/foo/featuretype.xml"); Document dom = dom(f); assertXpathEvaluatesTo("fooTitle", "/featureType/title", dom); }
private FeatureTypeInfo getFeatureType(GetFeatureRequest request) { // a WFS3 always has a collection reference, so one query Query query = request.getQueries().get(0); QName typeName = query.getTypeNames().get(0); return gs.getCatalog() .getFeatureTypeByName( new NameImpl(typeName.getNamespaceURI(), typeName.getLocalPart())); }
@Test public void testReproject() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.POLYGONS.getLocalPart()); assertEquals("EPSG:4326", fti.getSRS()); assertEquals(ProjectionPolicy.REPROJECT_TO_DECLARED, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:4326"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); // test that geometry was actually reprojected Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue(); assertFalse( g.equalsExact( WKT.read( "POLYGON((500225 500025,500225 500075,500275 500050,500275 500025,500225 500025))"))); fi.close(); assertEquals(CRS.decode("EPSG:4326"), f.getType().getCoordinateReferenceSystem()); }
@Test public void testAddLayer() throws Exception { testAddFeatureType(); testAddStyle(); File f = new File(testData.getDataDirectoryRoot(), "workspaces/acme/foostore/foo/layer.xml"); assertFalse(f.exists()); LayerInfo l = catalog.getFactory().createLayer(); // l.setName("foo"); l.setResource(catalog.getFeatureTypeByName("bar", "foo")); StyleInfo s = catalog.getStyleByName("foostyle"); l.setDefaultStyle(s); catalog.add(l); assertTrue(f.exists()); }
private List<String> getTimeProperties(QName typeName) throws IOException { Catalog catalog = geoServer.getCatalog(); NamespaceInfo ns = catalog.getNamespaceByURI(typeName.getNamespaceURI()); FeatureTypeInfo ft = catalog.getFeatureTypeByName(ns, typeName.getLocalPart()); if (ft == null) { return Collections.emptyList(); } FeatureType schema = ft.getFeatureType(); return schema.getDescriptors() .stream() .filter(pd -> Date.class.isAssignableFrom(pd.getType().getBinding())) .map(pd -> pd.getName().getLocalPart()) .collect(Collectors.toList()); }
@Test public void testAttributeCache() throws Exception { final Catalog catalog = getCatalog(); catalog.getFeatureTypeByName( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); List<LayerInfo> layers = catalog.getLayers(oldInfo); for (LayerInfo layerInfo : layers) { builder.buildFeatureType( new NameImpl( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()));
@Test public void testModifyDataLinks() { addFeatureType(); FeatureTypeInfo ft2 = catalog.getFeatureTypeByName(ft.getName()); DataLinkInfo ml = catalog.getFactory().createDataLink(); ml.setContent("http://www.geoserver.org/meta"); ml.setType("text/plain"); ft2.getDataLinks().clear(); ft2.getDataLinks().add(ml); catalog.save(ft2); FeatureTypeInfo ft3 = catalog.getFeatureTypeByName(ft.getName()); DataLinkInfo ml3 = ft3.getDataLinks().get(0); ml3.setType("application/json"); // do not save and grab another, the metadata link must not have been modified FeatureTypeInfo ft4 = catalog.getFeatureTypeByName(ft.getName()); DataLinkInfo ml4 = ft4.getDataLinks().get(0); assertEquals("text/plain", ml4.getType()); // now save and grab yet another, the modification must have happened catalog.save(ft3); FeatureTypeInfo ft5 = catalog.getFeatureTypeByName(ft.getName()); DataLinkInfo ml5 = ft5.getDataLinks().get(0); assertEquals("application/json", ml5.getType()); }