@Test public void catalogAddLayerGroup() throws Exception { ReceiverService service = new ReceiverService(1); rc.receive(service); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); lg.setName("sfLayerGroup"); LayerInfo l = catalog.getLayerByName("cite:Buildings"); lg.getLayers().add(l); lg.getStyles().add(catalog.getStyleByName(StyleInfo.DEFAULT_POLYGON)); lg.setBounds(new ReferencedEnvelope(-180, -90, 180, 90, CRS.decode("EPSG:4326"))); catalog.add(lg); List<byte[]> ret = service.getMessages(); assertEquals(1, ret.size()); KombuMessage groupMsg = Utils.toKombu(ret.get(0)); assertEquals("Catalog", groupMsg.getType()); assertEquals(Notification.Action.Add.name(), groupMsg.getAction()); KombuLayerGroupInfo source = (KombuLayerGroupInfo) groupMsg.getSource(); assertEquals("LayerGroupInfo", source.getType()); assertEquals(1, source.getLayers().size()); KombuLayerSimpleInfo kl = source.getLayers().get(0); assertEquals(l.getName(), kl.getName()); assertEquals(l.getDefaultStyle().getName(), kl.getStyle()); }
@Test public void catalogAddNamespaces() throws Exception { ReceiverService service = new ReceiverService(2); rc.receive(service); String json = "{'namespace':{ 'prefix':'foo', 'uri':'http://foo.com' }}"; postAsServletResponse("/rest/namespaces", json, "text/json"); List<byte[]> ret = service.getMessages(); assertEquals(2, ret.size()); KombuMessage nsMsg = Utils.toKombu(ret.get(0)); assertEquals(Notification.Action.Add.name(), nsMsg.getAction()); assertEquals("Catalog", nsMsg.getType()); assertEquals("NamespaceInfo", nsMsg.getSource().getType()); KombuMessage wsMsg = Utils.toKombu(ret.get(1)); assertEquals("Catalog", wsMsg.getType()); assertEquals("WorkspaceInfo", wsMsg.getSource().getType()); } }
@Test public void catalogAddNamespaces() throws Exception { ReceiverService service = new ReceiverService(2); rc.receive(service); String json = "{'namespace':{ 'prefix':'foo', 'uri':'http://foo.com' }}"; postAsServletResponse("/rest/namespaces", json, "text/json"); List<byte[]> ret = service.getMessages(); assertEquals(2, ret.size()); KombuMessage nsMsg = Utils.toKombu(ret.get(0)); assertEquals(Notification.Action.Add.name(), nsMsg.getAction()); assertEquals("Catalog", nsMsg.getType()); assertEquals("NamespaceInfo", nsMsg.getSource().getType()); KombuMessage wsMsg = Utils.toKombu(ret.get(1)); assertEquals("Catalog", wsMsg.getType()); assertEquals("WorkspaceInfo", wsMsg.getSource().getType()); }
message.setType(notification.getType() != null ? notification.getType().name() : null); message.setAction( notification.getAction() != null ? notification.getAction().name() : null); message.setTimestamp(new Date()); message.setUser(notification.getUser());
@Test public void catalogAddAndDeleteWMSLayer() throws Exception { ReceiverService service = new ReceiverService(3); rc.receive(service); CatalogBuilder cb = new CatalogBuilder(catalog); cb.setWorkspace(catalog.getWorkspaceByName("sf")); WMSStoreInfo wms = cb.buildWMSStore("demo"); wms.setCapabilitiesURL("http://demo.opengeo.org/geoserver/wms?"); catalog.add(wms); addStatesWmsLayer(); assertNotNull(catalog.getResourceByName("sf", "states", WMSLayerInfo.class)); deleteAsServletResponse("/rest/workspaces/sf/wmsstores/demo/wmslayers/states"); List<byte[]> ret = service.getMessages(); assertEquals(3, ret.size()); KombuMessage addStrMsg = Utils.toKombu(ret.get(0)); assertEquals(Notification.Action.Add.name(), addStrMsg.getAction()); KombuStoreInfo source1 = (KombuStoreInfo) addStrMsg.getSource(); assertEquals("StoreInfo", source1.getType()); KombuMessage addLayerMsg = Utils.toKombu(ret.get(1)); assertEquals(Notification.Action.Add.name(), addLayerMsg.getAction()); KombuWMSLayerInfo source2 = (KombuWMSLayerInfo) addLayerMsg.getSource(); assertEquals("WMSLayerInfo", source2.getType()); KombuMessage deleteMsg = Utils.toKombu(ret.get(2)); assertEquals("Catalog", deleteMsg.getType()); assertEquals(Notification.Action.Remove.name(), deleteMsg.getAction()); KombuWMSLayerInfo source3 = (KombuWMSLayerInfo) deleteMsg.getSource(); assertEquals("WMSLayerInfo", source3.getType()); assertEquals("states", source3.getName()); catalog.remove(wms); }
@Test public void catalogChangeLayerStyles() throws Exception { ReceiverService service = new ReceiverService(1); rc.receive(service); String xml = "<style>" + "<name>foo</name>" + "<filename>foo.sld</filename>" + "</style>"; postAsServletResponse("/rest/workspaces/cite/styles", xml); xml = "<layer>" + "<styles>" + "<style>" + "<name>foo</name>" + "<workspace>cite</workspace>" + "</style>" + "</styles>" + "<enabled>true</enabled>" + "</layer>"; putAsServletResponse("/rest/layers/cite:Buildings", xml, "application/xml"); List<byte[]> ret = service.getMessages(); assertEquals(1, ret.size()); KombuMessage updateMsg = Utils.toKombu(ret.get(0)); assertEquals("Catalog", updateMsg.getType()); assertEquals(Notification.Action.Update.name(), updateMsg.getAction()); KombuLayerInfo source = (KombuLayerInfo) updateMsg.getSource(); assertEquals("LayerInfo", source.getType()); assertEquals("foo", source.getStyles()); }
@Test public void catalogAddCoverage() throws Exception { ReceiverService service = new ReceiverService(4); rc.receive(service); addCoverageStore(); NamespaceInfo ns = catalog.getFactory().createNamespace(); ns.setPrefix("bar"); ns.setURI("http://bar"); catalog.add(ns); CoverageInfo ft = catalog.getFactory().createCoverage(); ft.setName("foo"); ft.setNamespace(ns); ft.setStore(catalog.getCoverageStoreByName("acme", "foostore")); catalog.add(ft); List<byte[]> ret = service.getMessages(); assertEquals(4, ret.size()); KombuMessage coverageMsg = Utils.toKombu(ret.get(3)); assertEquals("Catalog", coverageMsg.getType()); assertEquals(Notification.Action.Add.name(), coverageMsg.getAction()); KombuCoverageInfo source = (KombuCoverageInfo) coverageMsg.getSource(); assertEquals("CoverageInfo", source.getType()); assertEquals(ft.getName(), source.getName()); }
@Test public void catalogChangeLayerStyle() throws Exception { ReceiverService service = new ReceiverService(1); rc.receive(service); LayerInfo l = catalog.getLayerByName("cite:Buildings"); assertEquals("Buildings", l.getDefaultStyle().getName()); JSONObject json = (JSONObject) getAsJSON("/rest/layers/cite:Buildings.json"); JSONObject layer = (JSONObject) json.get("layer"); JSONObject style = (JSONObject) layer.get("defaultStyle"); style.put("name", "polygon"); style.put("href", "http://localhost:8080/geoserver/rest/styles/polygon.json"); String updatedJson = json.toString(); putAsServletResponse("/rest/layers/cite:Buildings", updatedJson, "application/json"); List<byte[]> ret = service.getMessages(); assertEquals(1, ret.size()); KombuMessage nsMsg = Utils.toKombu(ret.get(0)); assertEquals(Notification.Action.Update.name(), nsMsg.getAction()); assertEquals("Catalog", nsMsg.getType()); KombuLayerInfo source = (KombuLayerInfo) nsMsg.getSource(); assertEquals("LayerInfo", source.getType()); assertEquals("polygon", source.getDefaultStyle()); }