@Test public void testAddLayerGroupWithWorkspaceWithResourceFromAnotherWorkspace() { WorkspaceInfo ws = catalog.getFactory().createWorkspace(); ws.setName("other"); catalog.add(ws); LayerGroupInfo lg2 = catalog.getFactory().createLayerGroup(); lg2.setWorkspace(ws); lg2.setName("layerGroup2"); lg2.getLayers().add(l); lg2.getStyles().add(s); try { catalog.add(lg2); fail(); } catch (IllegalArgumentException expected) { } }
@Test public void testAddDataStoreDefaultWorkspace() { catalog.add(ws); catalog.setDefaultWorkspace(ws); DataStoreInfo ds2 = catalog.getFactory().createDataStore(); ds2.setName("ds2Name"); catalog.add(ds2); assertEquals(ws, ds2.getWorkspace()); }
@Test public void testAddWorkspace() throws Exception { File ws = new File(testData.getDataDirectoryRoot(), "workspaces/acme"); assertFalse(ws.exists()); WorkspaceInfo acme = catalog.getFactory().createWorkspace(); acme.setName("acme"); catalog.add(acme); assertTrue(ws.exists()); }
public List<AttributeTypeInfo> loadAttributes(FeatureTypeInfo info) throws IOException { List<AttributeTypeInfo> attributes = new ArrayList(); FeatureType ft = getFeatureType(info); for (PropertyDescriptor pd : ft.getDescriptors()) { AttributeTypeInfo att = catalog.getFactory().createAttribute(); att.setFeatureType(info); att.setName(pd.getName().getLocalPart()); att.setMinOccurs(pd.getMinOccurs()); att.setMaxOccurs(pd.getMaxOccurs()); att.setNillable(pd.isNillable()); att.setBinding(pd.getType().getBinding()); int length = FeatureTypes.getFieldLength(pd); if (length > 0) { att.setLength(length); } attributes.add(att); } return attributes; }
store = catalog.getFactory().createDataStore(); store.setName(prefix); store.setWorkspace(catalog.getWorkspaceByName(prefix)); catalog.add(store); FeatureTypeInfo featureType = catalog.getFactory().createFeatureType(); featureType.setStore(store); featureType.setNamespace(catalog.getNamespaceByPrefix(prefix)); featureType.getKeywords().add(new Keyword(name)); featureType.setEnabled(true); featureType.setProjectionPolicy( if (ft == null) { ft = featureType; catalog.add(featureType); } else { if (layer == null) { catalog.add(featureType); } else { new CatalogBuilder(catalog).updateFeatureType(ft, featureType); .getNamespace() .equals(catalog.getNamespaceByPrefix(prefix))) { layer = catalog.getFactory().createLayer();
@Test public void testLayerLocalWithContainingGroup() throws Exception { CatalogFactory factory = catalog.getFactory(); WorkspaceInfo citeWs = catalog.getWorkspaceByName("cite"); addLocalGroup(factory, citeWs); // set a local layer that's in the group final LayerInfo buildingsLayer = getBuildingsLayer(); LocalPublished.set(buildingsLayer); assertNotNull(catalog.getLayerByName(buildingsLayer.prefixedName())); assertNull(catalog.getLayerGroupByName(GLOBAL_GROUP)); assertNull(catalog.getLayerGroupByName(LOCAL_GROUP)); assertEquals(1, catalog.getLayers().size()); assertThat(catalog.getLayerGroups(), empty()); }
@Test public void testEmptyLayerGroupBounds() throws Exception { Catalog cat = getCatalog(); LayerGroupInfo group = cat.getFactory().createLayerGroup(); group.setName("empty_group"); assertNull(group.getBounds()); // force bounds computation CatalogBuilder cb = new CatalogBuilder(cat); cb.calculateLayerGroupBounds(group); assertNull(group.getBounds()); }
@Test public void testGetParamsFixesDatabaseFilePath() { Catalog catalog = getCatalog(); ResourcePool pool = new ResourcePool(catalog); DataStoreInfo ds = getCatalog().getFactory().createDataStore(); ds.getConnectionParameters().put("database", "file:data/test.gpkg"); Map newParams = pool.getParams(ds.getConnectionParameters(), getResourceLoader()); GeoServerDataDirectory dataDir = new GeoServerDataDirectory(getResourceLoader()); String absolutePath = dataDir.get("data/test.gpkg").dir().getAbsolutePath(); assertNotEquals(newParams.get("database"), "file:data/test.gpkg"); assertTrue(((String) newParams.get("database")).contains(absolutePath)); }
/** Keys for overriding default layer properties */ public static class StyleProperty<T> { T get(Map<StyleProperty, Object> map, T def) { return map != null && map.containsKey(this) ? (T) map.get(this) : def; } public static StyleProperty<String> FORMAT = new StyleProperty<String>(); public static StyleProperty<Version> FORMAT_VERSION = new StyleProperty<Version>(); public static StyleProperty<LegendInfo> LEGEND_INFO = new StyleProperty<LegendInfo>(); }
@Test public void testAddLayerGroupNameConflict() throws Exception { addLayerGroup(); LayerGroupInfo lg2 = catalog.getFactory().createLayerGroup(); lg2.setName("layerGroup"); lg2.getLayers().add(l); lg2.getStyles().add(s); try { catalog.add(lg2); fail("should have failed because same name and no workspace set"); } catch (IllegalArgumentException expected) { } // setting a workspace shluld pass lg2.setWorkspace(ws); catalog.add(lg2); }
@Test public void testAutoCascadeDefaultWorksapce() { CatalogFactory factory = catalog.getFactory(); WorkspaceInfo ws1 = factory.createWorkspace(); ws1.setName("ws1Name"); WorkspaceInfo ws2 = factory.createWorkspace(); ws2.setName("ws2Name"); catalog.add(ws1); catalog.add(ws2); assertEquals(ws1, catalog.getDefaultWorkspace()); catalog.remove(ws1); assertEquals(ws2, catalog.getDefaultWorkspace()); }
/** * Extracts the AttributeTypeInfo by copying them from the specified feature type. * * @param ft The schema to be harvested * @param info The optional feature type info from which all the attributes belong to */ public List<AttributeTypeInfo> getAttributes(FeatureType ft, FeatureTypeInfo info) { List<AttributeTypeInfo> attributes = new ArrayList<AttributeTypeInfo>(); for (PropertyDescriptor pd : ft.getDescriptors()) { AttributeTypeInfo att = catalog.getFactory().createAttribute(); att.setFeatureType(info); att.setName(pd.getName().getLocalPart()); att.setMinOccurs(pd.getMinOccurs()); att.setMaxOccurs(pd.getMaxOccurs()); att.setNillable(pd.isNillable()); att.setBinding(pd.getType().getBinding()); int length = FeatureTypes.getFieldLength(pd); if (length > 0) { att.setLength(length); } attributes.add(att); } return attributes; }
@Test public void testEqualsWithAttributes() { CatalogFactory factory = catalog.getFactory(); FeatureTypeInfoImpl ft1 = (FeatureTypeInfoImpl) factory.createFeatureType(); FeatureTypeInfoImpl ft2 = (FeatureTypeInfoImpl) factory.createFeatureType(); ft1.setName("featureType"); ft2.setName("featureType"); AttributeTypeInfo at1 = factory.createAttribute(); AttributeTypeInfo at2 = factory.createAttribute(); at1.setName("attribute"); at2.setName("attribute"); at1.setFeatureType(ft1); at2.setFeatureType(ft2); ft1.setAttributes(Collections.singletonList(at1)); ft2.setAttributes(Collections.singletonList(at2)); assertEquals(ft1, ft2); } }
@Test public void testAddStyle() throws Exception { File f = new File(testData.getDataDirectoryRoot(), "styles/foostyle.xml"); assertFalse(f.exists()); StyleInfo s = catalog.getFactory().createStyle(); s.setName("foostyle"); s.setFilename("foostyle.sld"); catalog.add(s); assertTrue(f.exists()); }
private void testSerializationWithMode(Mode mode) throws Exception { Catalog catalog = new CatalogImpl(); CatalogFactory cFactory = catalog.getFactory(); LayerGroupInfo group1 = cFactory.createLayerGroup(); group1.setName("foo"); group1.setTitle("foo title"); group1.setAbstract("foo abstract"); group1.setMode(mode); ByteArrayOutputStream out = out(); persister.save(group1, out); // print(in(out)); ByteArrayInputStream in = in(out); LayerGroupInfo group2 = persister.load(in, LayerGroupInfo.class); assertEquals(group1.getName(), group2.getName()); assertEquals(group1.getTitle(), group2.getTitle()); assertEquals(group1.getAbstract(), group2.getAbstract()); assertEquals(group1.getMode(), group2.getMode()); Document dom = dom(in(out)); assertEquals("layerGroup", dom.getDocumentElement().getNodeName()); }
@Test public void testLookupSRSDetached() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); DataStoreInfo sf = cat.getDataStoreByName("sf"); FeatureSource fs = sf.getDataStore(null).getFeatureSource(toName(MockData.PRIMITIVEGEOFEATURE)); FeatureTypeInfo ft = cat.getFactory().createFeatureType(); ft.setNativeName("PrimitiveGeoFeature"); assertNull(ft.getSRS()); assertNull(ft.getCRS()); cb.lookupSRS(ft, fs, true); assertNotNull(ft.getSRS()); assertNotNull(ft.getCRS()); }
@Test public void testLayerGroupNullLayerReferences() { addLayer(); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); lg.setWorkspace(null); lg.setName("layerGroup2"); lg.getLayers().add(null); lg.getStyles().add(null); lg.getLayers().add(l); lg.getStyles().add(s); lg.getLayers().add(null); lg.getStyles().add(null); catalog.add(lg); LayerGroupInfo resolved = catalog.getLayerGroupByName("layerGroup2"); assertEquals(1, resolved.layers().size()); assertEquals(1, resolved.styles().size()); assertEquals(s, resolved.styles().get(0)); }
@Test public void testAddWorkspace() { assertTrue(catalog.getWorkspaces().isEmpty()); catalog.add(ws); assertEquals(1, catalog.getWorkspaces().size()); WorkspaceInfo ws2 = catalog.getFactory().createWorkspace(); try { catalog.getWorkspaces().add(ws2); fail("adding directly should throw an exception"); } catch (Exception e) { } try { catalog.add(ws2); fail("addign without a name should throw an exception"); } catch (Exception e) { } ws2.setName("ws2"); catalog.add(ws2); }
@Test public void testCoverageStore() throws Exception { Catalog catalog = new CatalogImpl(); CatalogFactory cFactory = catalog.getFactory(); WorkspaceInfo ws = cFactory.createWorkspace(); ws.setName("foo"); CoverageStoreInfo cs1 = cFactory.createCoverageStore(); cs1.setName("bar"); cs1.setWorkspace(ws); ByteArrayOutputStream out = out(); persister.save(cs1, out); CoverageStoreInfo ds2 = persister.load(in(out), CoverageStoreInfo.class); assertEquals("bar", ds2.getName()); assertNotNull(ds2.getWorkspace()); assertEquals("foo", ds2.getWorkspace().getId()); Document dom = dom(in(out)); assertEquals("coverageStore", dom.getDocumentElement().getNodeName()); }
@Test public void testAddCoverageStore() throws Exception { testAddWorkspace(); File dir = new File(testData.getDataDirectoryRoot(), "workspaces/acme/foostore"); assertFalse(dir.exists()); CoverageStoreInfo cs = catalog.getFactory().createCoverageStore(); cs.setName("foostore"); cs.setWorkspace(catalog.getWorkspaceByName("acme")); catalog.add(cs); assertTrue(dir.exists()); assertTrue(new File(dir, "coveragestore.xml").exists()); }