@Test public void testRenameGroup() throws Exception { nature.setName("renamed"); catalog.save(nature); LayerGroupSummary summary = cc.groupCache.get(nature.getId()); assertEquals("renamed", summary.getName()); assertEquals(WS, summary.getWorkspace()); }
@Test public void testAddLayerToContainer() throws Exception { LayerInfo neatline = catalog.getLayerByName(getLayerId(MockData.MAP_NEATLINE)); container.getLayers().add(neatline); container.getStyles().add(null); catalog.save(container); assertThat(containerNamesForResource(MockData.MAP_NEATLINE), equalTo(set(CONTAINER_GROUP))); }
@Test public void testRemoveNatureFromContainer() throws Exception { container.getLayers().remove(nature); container.getStyles().remove(0); catalog.save(container); assertThat(containerNamesForGroup(nature), empty()); assertThat(containerNamesForResource(MockData.LAKES), empty()); assertThat(containerNamesForResource(MockData.FORESTS), empty()); assertThat( containerNamesForResource(MockData.ROAD_SEGMENTS), equalTo(set(CONTAINER_GROUP))); }
@Test public void testLayerEvents() { addFeatureType(); addStyle(); TestListener tl = new TestListener(); catalog.addListener(tl); assertTrue(tl.added.isEmpty()); catalog.add(l); assertEquals(1, tl.added.size()); assertEquals(l, tl.added.get(0).getSource()); LayerInfo l2 = catalog.getLayerByName(l.getName()); l2.setPath("newPath"); assertTrue(tl.modified.isEmpty()); catalog.save(l2); assertEquals(1, tl.modified.size()); assertEquals(l2, tl.modified.get(0).getSource()); assertTrue(tl.modified.get(0).getPropertyNames().contains("path")); assertTrue(tl.modified.get(0).getOldValues().contains(null)); assertTrue(tl.modified.get(0).getNewValues().contains("newPath")); assertEquals(1, tl.postModified.size()); assertEquals(l2, tl.postModified.get(0).getSource()); assertTrue(tl.postModified.get(0).getPropertyNames().contains("path")); assertTrue(tl.postModified.get(0).getOldValues().contains(null)); assertTrue(tl.postModified.get(0).getNewValues().contains("newPath")); assertTrue(tl.removed.isEmpty()); catalog.remove(l2); assertEquals(1, tl.removed.size()); assertEquals(l2, tl.removed.get(0).getSource()); }
@Test public void testCacheClearing() throws IOException { cleared = false; ResourcePool pool = new ResourcePool(getCatalog()) { @Override public void clear(FeatureTypeInfo info) { cleared = true; super.clear(info); } }; FeatureTypeInfo info = getCatalog() .getFeatureTypeByName( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertNotNull(pool.getFeatureType(info)); info.setTitle("changed"); assertFalse(cleared); getCatalog().save(info); assertTrue(cleared); cleared = false; assertNotNull(pool.getFeatureType(info)); for (LayerInfo l : getCatalog().getLayers(info)) { getCatalog().remove(l); } getCatalog().remove(info); assertTrue(cleared); }
/** 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>(); }
void setupExtras(org.geoserver.data.test.SystemTestData testData, Catalog catalog) throws IOException { LayerInfo buildings = catalog.getLayerByName(getLayerId(BUILDINGS)); buildings.getStyles().add(catalog.getStyleByName(LAKES.getLocalPart())); catalog.save(buildings); LayerGroupInfo globalGroup = factory.createLayerGroup(); globalGroup.setName(LAKES_GROUP); globalGroup.getLayers().add(catalog.getLayerByName(getLayerId(LAKES))); globalGroup.getLayers().add(catalog.getLayerByName(getLayerId(FORESTS))); globalGroup.getLayers().add(catalog.getLayerByName(getLayerId(BRIDGES))); globalGroup.getStyles().add(null);
} else { builder.updateCoverage(cov, coverage); catalog.save(cov); coverage = cov; LayerInfo layer = catalog.getLayerByName(new NameImpl(qName)); if (layer == null) { layer = catalog.getFactory().createLayer(); catalog.add(layer); } else { catalog.save(layer);
@Test public void testChangeGroupMode() throws Exception { LayerGroupSummary summary = cc.groupCache.get(nature.getId()); assertEquals(Mode.SINGLE, summary.getMode()); nature.setMode(Mode.OPAQUE_CONTAINER); catalog.save(nature); summary = cc.groupCache.get(nature.getId()); assertEquals(Mode.OPAQUE_CONTAINER, summary.getMode()); } }
@Test public void testModifyLayer() { addLayer(); LayerInfo l2 = catalog.getLayerByName(l.getName()); // l2.setName( null ); l2.setResource(null); LayerInfo l3 = catalog.getLayerByName(l.getName()); assertEquals(l.getName(), l3.getName()); // try { // catalog.save(l2); // fail( "setting name to null should throw exception"); // } // catch( Exception e ) {} // // l2.setName( "changed" ); try { catalog.save(l2); fail("setting resource to null should throw exception"); } catch (Exception e) { } l2.setResource(ft); catalog.save(l2); // TODO: reinstate with resource/publishing split done // l3 = catalog.getLayerByName( "changed" ); l3 = catalog.getLayerByName(ft.getName()); assertNotNull(l3); }
@Test public void testModifyStyle() throws Exception { testAddStyle(); StyleInfo s = catalog.getStyleByName("foostyle"); s.setFilename("foostyle2.sld"); catalog.save(s); File f = new File(testData.getDataDirectoryRoot(), "styles/foostyle.xml"); Document dom = dom(f); assertXpathEvaluatesTo("foostyle2.sld", "/style/filename", dom); }
@Test public void testAddLayerToNature() throws Exception { LayerInfo neatline = catalog.getLayerByName(getLayerId(MockData.MAP_NEATLINE)); nature.getLayers().add(neatline); nature.getStyles().add(null); catalog.save(nature); assertThat(containerNamesForResource(MockData.MAP_NEATLINE), equalTo(set(CONTAINER_GROUP))); }
/** * Configures the dimension of a vector layer * * @param featureTypeName The feature type name * @param dimensionName The dimension name (key in the resource metadata map) * @param presentation The chosen presentation * @param resolution The resolution * @param units The units * @param unitSymbol The unit symbol */ protected void setupRasterDimension( QName layer, String dimensionName, DimensionPresentation presentation, Double resolution, String units, String unitSymbol) { CoverageInfo info = getCatalog().getCoverageByName(layer.getLocalPart()); DimensionInfo di = new DimensionInfoImpl(); di.setEnabled(true); di.setPresentation(presentation); if (resolution != null) { di.setResolution(new BigDecimal(resolution)); } di.setUnits(units); di.setUnitSymbol(unitSymbol); info.getMetadata().put(dimensionName, di); getCatalog().save(info); }
throws IOException { String prefix = qName.getPrefix(); String name = qName.getLocalPart(); String uri = qName.getNamespaceURI(); LayerInfo layer = catalog.getLayerByName(new NameImpl(uri, name)); if (ft == null) { ft = featureType; } else { new CatalogBuilder(catalog).updateFeatureType(ft, featureType); catalog.save(ft); catalog.add(layer); } else { catalog.save(layer);
@Override protected void handleObjectPut(Object object) throws Exception { String l = getAttribute( "layer" ); LayerInfo original = catalog.getLayerByName(l); LayerInfo layer = (LayerInfo) object; //ensure this is not a name change // TODO: Uncomment this when the resource/layer split is not, now by definition // we cannot rename a layer, it's just not possible and it's not un-marshalled either // if ( layer.getName() != null && !layer.getName().equals( original.getName() ) ) { // throw new RestletException( "Can't change name of a layer", Status.CLIENT_ERROR_FORBIDDEN ); // } // force in the same resource otherwise the update will simply fail as we cannot reach the name layer.setResource(original.getResource()); new CatalogBuilder( catalog ).updateLayer( original, layer ); catalog.save( original ); LOGGER.info( "PUT layer " + l); }
@Test public void testRenameWorkspace() throws Exception { WorkspaceInfo ws = catalog.getDefaultWorkspace(); ws.setName("renamed"); try { catalog.save(ws); LayerGroupSummary summary = cc.groupCache.get(nature.getId()); assertEquals(NATURE_GROUP, summary.getName()); assertEquals("renamed", summary.getWorkspace()); } finally { ws.setName(WS); catalog.save(ws); } }
@Test public void testCascadeLayerDuplicate() { Catalog catalog = getCatalog(); String name = toString(LAKES); LayerInfo layer = catalog.getLayerByName(name); assertNotNull(layer); LayerGroupInfo group = catalog.getLayerGroupByName(LAKES_GROUP); group.getLayers().add(layer); group.getStyles().add(null); catalog.save(group); CascadeDeleteVisitor visitor = new CascadeDeleteVisitor(catalog); visitor.visit(layer); group = catalog.getLayerGroupByName(LAKES_GROUP); assertEquals(2, group.getLayers().size()); assertFalse(group.getLayers().contains(layer)); }
@Test public void testModifyDataStore() throws Exception { testAddDataStore(); DataStoreInfo ds = catalog.getDataStoreByName("acme", "foostore"); assertTrue(ds.getConnectionParameters().isEmpty()); ds.getConnectionParameters().put("foo", "bar"); catalog.save(ds); File f = new File(testData.getDataDirectoryRoot(), "workspaces/acme/foostore/datastore.xml"); Document dom = dom(f); assertXpathExists("/dataStore/connectionParameters/entry[@key='foo']", dom); }
@Test public void testModifyLayer() throws Exception { testAddLayer(); LayerInfo l = catalog.getLayerByName("foo"); l.setPath("/foo/bar"); catalog.save(l); File f = new File(testData.getDataDirectoryRoot(), "workspaces/acme/foostore/foo/layer.xml"); Document dom = dom(f); assertXpathEvaluatesTo("/foo/bar", "/layer/path", dom); }
private void setAliasedType(QName qName, String alias, Catalog catalog) throws IOException { String name = qName.getLocalPart(); FeatureTypeInfo featureType = catalog.getFeatureTypeByName(name); featureType.setName(alias); getCatalog().save(featureType); }