List of usage examples for org.springframework.mock.web MockHttpServletResponse getStatus
@Override public int getStatus()
From source file:org.geoserver.rest.catalog.StyleControllerTest.java
@Test public void testStyleWithSpaceInName() throws Exception { String xml = newSLDXML();//w w w . j a va2 s . co m MockHttpServletResponse response = postAsServletResponse( RestBaseController.ROOT_PATH + "/styles?name=Default%20Styler", xml, SLDHandler.MIMETYPE_10); assertEquals(201, response.getStatus()); assertNotNull(response.getHeader("Location")); assertThat(response.getHeader("Location"), endsWith("/styles/Default%20Styler")); assertNotNull(catalog.getStyleByName("Default Styler")); // now delete it, using a + instead of %20, the old code supported it response = deleteAsServletResponse(RestBaseController.ROOT_PATH + "/styles/Default+Styler"); assertEquals(200, response.getStatus()); }
From source file:org.geoserver.rest.catalog.StyleControllerTest.java
@Test public void testPostToWorkspace() throws Exception { Catalog cat = getCatalog();// w w w .j a va 2s . c om assertNull(cat.getStyleByName("gs", "foo")); String xml = "<style>" + "<name>foo</name>" + "<filename>foo.sld</filename>" + "</style>"; MockHttpServletResponse response = postAsServletResponse( RestBaseController.ROOT_PATH + "/workspaces/gs/styles", xml); assertEquals(201, response.getStatus()); assertNotNull(cat.getStyleByName("gs", "foo")); }
From source file:org.geoserver.rest.catalog.StyleControllerTest.java
@Test public void testPut() throws Exception { StyleInfo style = catalog.getStyleByName("Ponds"); assertEquals("Ponds.sld", style.getFilename()); String xml = "<style>" + "<name>Ponds</name>" + "<filename>Forests.sld</filename>" + "</style>"; MockHttpServletResponse response = putAsServletResponse(RestBaseController.ROOT_PATH + "/styles/Ponds", xml.getBytes(), "text/xml"); assertEquals(200, response.getStatus()); style = catalog.getStyleByName("Ponds"); assertEquals("Forests.sld", style.getFilename()); }
From source file:org.geoserver.rest.catalog.StyleControllerTest.java
@Test public void testPutAsSLD() throws Exception { String xml = newSLDXML();/* w w w .j av a 2 s . c o m*/ MockHttpServletResponse response = putAsServletResponse(RestBaseController.ROOT_PATH + "/styles/Ponds", xml, SLDHandler.MIMETYPE_10); assertEquals(200, response.getStatus()); Style s = catalog.getStyleByName("Ponds").getStyle(); ByteArrayOutputStream out = new ByteArrayOutputStream(); SLDHandler handler = new SLDHandler(); handler.encode(Styles.sld(s), SLDHandler.VERSION_10, false, out); xml = new String(out.toByteArray()); assertTrue(xml.contains("<sld:Name>foo</sld:Name>")); }
From source file:org.geoserver.rest.catalog.StyleControllerTest.java
@Test public void testPutAsSLDWithExtension() throws Exception { String xml = newSLDXML();//from w w w . ja va2 s . c om MockHttpServletResponse response = putAsServletResponse(RestBaseController.ROOT_PATH + "/styles/Ponds.sld", xml, SLDHandler.MIMETYPE_10); assertEquals(200, response.getStatus()); Style s = catalog.getStyleByName("Ponds").getStyle(); ByteArrayOutputStream out = new ByteArrayOutputStream(); SLDHandler handler = new SLDHandler(); handler.encode(Styles.sld(s), SLDHandler.VERSION_10, false, out); xml = new String(out.toByteArray()); assertTrue(xml.contains("<sld:Name>foo</sld:Name>")); }
From source file:org.geoserver.rest.catalog.StyleControllerTest.java
@Test public void testRawPutAsSLD() throws Exception { String xml = newSLDXML();//ww w . j ava2 s . c om MockHttpServletResponse response = putAsServletResponse( RestBaseController.ROOT_PATH + "/styles/Ponds?raw=true", xml, SLDHandler.MIMETYPE_10); assertEquals(200, response.getStatus()); Style s = catalog.getStyleByName("Ponds").getStyle(); ByteArrayOutputStream out = new ByteArrayOutputStream(); SLDHandler handler = new SLDHandler(); handler.encode(Styles.sld(s), SLDHandler.VERSION_10, false, out); xml = new String(out.toByteArray()); assertTrue(xml.contains("<sld:Name>foo</sld:Name>")); }
From source file:org.geoserver.rest.catalog.StyleControllerTest.java
@Test public void testRawPutAsInvalidSLD() throws Exception { String xml = "This is not valid SLD"; MockHttpServletResponse response = putAsServletResponse( RestBaseController.ROOT_PATH + "/styles/Ponds?raw=true", xml, SLDHandler.MIMETYPE_10); assertEquals(200, response.getStatus()); StyleInfo styleInfo = catalog.getStyleByName("Ponds"); String fileName = styleInfo.getFilename(); GeoServerResourceLoader resources = getGeoServer().getCatalog().getResourceLoader(); Resource resource = resources.get("styles/" + fileName); String content = new String(resource.getContents()); assertFalse("replaced", content.contains("<sld:Name>foo</sld:Name>")); assertTrue("replaced", content.contains("not valid")); }
From source file:org.geoserver.rest.catalog.StyleControllerTest.java
@Test public void testPutToWorkspace() throws Exception { testPostToWorkspace();// w w w . j a v a 2s . c o m Catalog cat = getCatalog(); assertEquals("foo.sld", cat.getStyleByName("gs", "foo").getFilename()); String xml = "<style>" + "<filename>bar.sld</filename>" + "</style>"; MockHttpServletResponse response = putAsServletResponse( RestBaseController.ROOT_PATH + "/workspaces/gs/styles/foo", xml, "application/xml"); assertEquals(200, response.getStatus()); assertEquals("bar.sld", cat.getStyleByName("gs", "foo").getFilename()); }
From source file:org.geoserver.rest.catalog.StyleControllerTest.java
@Test public void testPutToWorkspaceChangeWorkspace() throws Exception { testPostToWorkspace();/*w w w . ja va 2 s.c o m*/ String xml = "<style>" + "<workspace>cite</workspace>" + "</style>"; MockHttpServletResponse response = putAsServletResponse( RestBaseController.ROOT_PATH + "/workspaces/gs/styles/foo", xml, "application/xml"); assertEquals(403, response.getStatus()); }