List of usage examples for org.springframework.mock.web MockHttpServletResponse getStatus
@Override public int getStatus()
From source file:org.geoserver.catalog.rest.StyleTest.java
@Test public void testPostByLayerWithDefault() throws Exception { getTestData().addVectorLayer(SystemTestData.BASIC_POLYGONS, getCatalog()); LayerInfo l = catalog.getLayerByName("cite:BasicPolygons"); int nstyles = l.getStyles().size(); String xml = "<style>" + "<name>Ponds</name>" + "</style>"; MockHttpServletResponse response = postAsServletResponse( "/rest/layers/cite:BasicPolygons/styles?default=true", xml, "text/xml"); assertEquals(201, response.getStatus()); LayerInfo l2 = catalog.getLayerByName("cite:BasicPolygons"); assertEquals(nstyles + 1, l2.getStyles().size()); assertEquals(catalog.getStyleByName("Ponds"), l2.getDefaultStyle()); }
From source file:org.geoserver.catalog.rest.StyleTest.java
@Test public void testPostByLayerExistingWithDefault() throws Exception { getTestData().addVectorLayer(SystemTestData.BASIC_POLYGONS, getCatalog()); testPostByLayer();/*from w w w .j ava 2s . c om*/ LayerInfo l = catalog.getLayerByName("cite:BasicPolygons"); int nstyles = l.getStyles().size(); String xml = "<style>" + "<name>Ponds</name>" + "</style>"; MockHttpServletResponse response = postAsServletResponse( "/rest/layers/cite:BasicPolygons/styles?default=true", xml, "text/xml"); assertEquals(201, response.getStatus()); LayerInfo l2 = catalog.getLayerByName("cite:BasicPolygons"); assertEquals(nstyles, l2.getStyles().size()); assertEquals(catalog.getStyleByName("Ponds"), l2.getDefaultStyle()); }
From source file:org.geoserver.catalog.rest.StyleTest.java
@Test public void testPostAsPSL() throws Exception { Properties props = new Properties(); props.put("type", "point"); props.put("color", "ff0000"); StringWriter out = new StringWriter(); props.store(out, "comment!"); MockHttpServletResponse response = postAsServletResponse("/rest/styles?name=foo", out.toString(), PropertyStyleHandler.MIMETYPE); assertEquals(201, response.getStatus()); assertNotNull(response.getHeader("Location")); assertTrue(response.getHeader("Location").endsWith("/styles/foo")); assertNotNull(catalog.getStyleByName("foo")); Resource style = getDataDirectory().style(getCatalog().getStyleByName("foo")); InputStream in = style.in();/*from www.j av a 2 s . com*/ props = new Properties(); try { props.load(in); assertEquals("point", props.getProperty("type")); } finally { in.close(); } in = style.in(); try { out = new StringWriter(); IOUtils.copy(in, out); assertFalse(out.toString().startsWith("#comment!")); } finally { in.close(); } }
From source file:org.geoserver.catalog.rest.StyleTest.java
@Test public void testPostAsPSLRaw() throws Exception { Properties props = new Properties(); props.put("type", "point"); props.put("color", "ff0000"); StringWriter out = new StringWriter(); props.store(out, "comment!"); MockHttpServletResponse response = postAsServletResponse("/rest/styles?name=foo&raw=true", out.toString(), PropertyStyleHandler.MIMETYPE); assertEquals(201, response.getStatus()); assertNotNull(response.getHeader("Location")); assertTrue(response.getHeader("Location").endsWith("/styles/foo")); // check style on disk to ensure the exact contents was preserved Resource style = getDataDirectory().style(getCatalog().getStyleByName("foo")); InputStream in = style.in();/*from w w w . j a v a2s . c o m*/ try { out = new StringWriter(); IOUtils.copy(in, out); assertTrue(out.toString().startsWith("#comment!")); } finally { in.close(); } }
From source file:org.geoserver.catalog.rest.StyleTest.java
@Test public void testPutAsPSL() throws Exception { testPostAsPSL();/*www .ja v a2s .com*/ Properties props = new Properties(); props.put("type", "line"); props.put("color", "00ff00"); StringWriter out = new StringWriter(); props.store(out, "comment!"); MockHttpServletResponse response = putAsServletResponse("/rest/styles/foo", out.toString(), PropertyStyleHandler.MIMETYPE); assertEquals(200, response.getStatus()); Resource style = getDataDirectory().style(getCatalog().getStyleByName("foo")); InputStream in = style.in(); try { props = new Properties(); props.load(in); assertEquals("line", props.getProperty("type")); } finally { in.close(); } in = style.in(); try { out = new StringWriter(); IOUtils.copy(in, out); assertFalse(out.toString().startsWith("#comment!")); } finally { in.close(); } }
From source file:org.geoserver.catalog.rest.StyleTest.java
@Test public void testPutAsPSLRaw() throws Exception { testPostAsPSL();//from ww w . j a v a 2s . co m Properties props = new Properties(); props.put("type", "line"); props.put("color", "00ff00"); StringWriter out = new StringWriter(); props.store(out, "comment!"); MockHttpServletResponse response = putAsServletResponse("/rest/styles/foo?raw=true", out.toString(), PropertyStyleHandler.MIMETYPE); assertEquals(200, response.getStatus()); Resource style = getDataDirectory().style(getCatalog().getStyleByName("foo")); InputStream in = style.in(); try { props = new Properties(); props.load(in); assertEquals("line", props.getProperty("type")); } finally { in.close(); } in = style.in(); try { out = new StringWriter(); IOUtils.copy(in, out); assertTrue(out.toString().startsWith("#comment!")); } finally { in.close(); } }
From source file:org.geoserver.catalog.rest.StyleTest.java
@Test public void testPostAsSE() throws Exception { String xml = "<StyledLayerDescriptor xmlns=\"http://www.opengis.net/sld\" " + " xmlns:se=\"http://www.opengis.net/se\" version=\"1.1.0\"> " + " <NamedLayer> " + " <UserStyle> " + " <se:Name>UserSelection</se:Name> " + " <se:FeatureTypeStyle> " + " <se:Rule> " + " <se:PolygonSymbolizer> " + " <se:Fill> " + " <se:SvgParameter name=\"fill\">#FF0000</se:SvgParameter> " + " </se:Fill> " + " </se:PolygonSymbolizer> " + " </se:Rule> " + " </se:FeatureTypeStyle> " + " </UserStyle> " + " </NamedLayer> " + "</StyledLayerDescriptor>"; MockHttpServletResponse response = postAsServletResponse("/rest/styles?name=foo", xml, SLDHandler.MIMETYPE_11);/* www . ja va 2 s.c o m*/ assertEquals(201, response.getStatus()); assertNotNull(response.getHeader("Location")); assertTrue(response.getHeader("Location").endsWith("/styles/foo")); StyleInfo style = catalog.getStyleByName("foo"); assertNotNull(style); assertEquals("sld", style.getFormat()); assertEquals(SLDHandler.VERSION_11, style.getFormatVersion()); }
From source file:org.geoserver.catalog.rest.StyleTest.java
@Test public void testPostToWorkspaceSLDPackage() throws Exception { Catalog cat = getCatalog();/*from w w w . j av a2 s.co m*/ assertNull(cat.getStyleByName("gs", "foo")); URL zip = getClass().getResource("test-data/foo.zip"); byte[] bytes = FileUtils.readFileToByteArray(DataUtilities.urlToFile(zip)); MockHttpServletResponse response = postAsServletResponse("/rest/workspaces/gs/styles", bytes, "application/zip"); assertEquals(201, response.getStatus()); assertNotNull(cat.getStyleByName("gs", "foo")); Document d = getAsDOM("/rest/workspaces/gs/styles/foo.sld"); assertEquals("StyledLayerDescriptor", d.getDocumentElement().getNodeName()); XpathEngine engine = XMLUnit.newXpathEngine(); NodeList list = engine.getMatchingNodes( "//sld:StyledLayerDescriptor/sld:NamedLayer/sld:UserStyle/sld:FeatureTypeStyle/sld:Rule/sld:PointSymbolizer/sld:Graphic/sld:ExternalGraphic/sld:OnlineResource", d); assertEquals(1, list.getLength()); Element onlineResource = (Element) list.item(0); assertEquals("gear.png", onlineResource.getAttribute("xlink:href")); assertNotNull(getCatalog().getResourceLoader().find("workspaces/gs/styles/gear.png")); assertNotNull(getCatalog().getResourceLoader().find("workspaces/gs/styles/foo.sld")); }
From source file:org.geoserver.catalog.rest.StyleTest.java
@Test public void testPostWithExternalEntities() throws Exception { URL zip = getClass().getResource("test-data/externalEntities.zip"); byte[] bytes = FileUtils.readFileToByteArray(DataUtilities.urlToFile(zip)); MockHttpServletResponse response = postAsServletResponse("/rest/workspaces/gs/styles", bytes, "application/zip"); // expecting a failure with explanation assertEquals(400, response.getStatus()); final String content = response.getContentAsString(); assertThat(content, containsString("Entity resolution disallowed")); assertThat(content, containsString("/this/file/does/not/exist")); }
From source file:org.geoserver.catalog.rest.StyleTest.java
@Test public void testPutToWorkspaceSLDPackage() throws Exception { testPostAsSLDToWorkspace();/* w w w . java 2 s . c o m*/ Catalog cat = getCatalog(); assertNotNull(cat.getStyleByName("gs", "foo")); URL zip = getClass().getResource("test-data/foo.zip"); byte[] bytes = FileUtils.readFileToByteArray(DataUtilities.urlToFile(zip)); MockHttpServletResponse response = putAsServletResponse("/rest/workspaces/gs/styles/foo.zip", bytes, "application/zip"); assertEquals(200, response.getStatus()); assertNotNull(cat.getStyleByName("gs", "foo")); Document d = getAsDOM("/rest/workspaces/gs/styles/foo.sld"); assertEquals("StyledLayerDescriptor", d.getDocumentElement().getNodeName()); XpathEngine engine = XMLUnit.newXpathEngine(); NodeList list = engine.getMatchingNodes( "//sld:StyledLayerDescriptor/sld:NamedLayer/sld:UserStyle/sld:FeatureTypeStyle/sld:Rule/sld:PointSymbolizer/sld:Graphic/sld:ExternalGraphic/sld:OnlineResource", d); assertEquals(1, list.getLength()); Element onlineResource = (Element) list.item(0); assertEquals("gear.png", onlineResource.getAttribute("xlink:href")); assertNotNull(getCatalog().getResourceLoader().find("workspaces/gs/styles/gear.png")); assertNotNull(getCatalog().getResourceLoader().find("workspaces/gs/styles/foo.sld")); }