List of usage examples for org.springframework.mock.web MockHttpServletResponse getStatus
@Override public int getStatus()
From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java
private void assertTest123Metadata() throws Exception, UnsupportedEncodingException { MockHttpServletResponse response; response = getAsServletResponse("rest/oseo/collections/TEST123/metadata"); assertEquals(200, response.getStatus()); assertEquals("text/xml", response.getContentType()); assertThat(response.getContentAsString(), both(containsString("gmi:MI_Metadata")).and(containsString("TEST123"))); }
From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java
@Test public void testDeleteCollectionMetadata() throws Exception { // creates the collection and adds the metadata testPutCollectionMetadata();/*from www . ja v a 2s. c o m*/ // now remove MockHttpServletResponse response = deleteAsServletResponse("rest/oseo/collections/TEST123/metadata"); assertEquals(200, response.getStatus()); // check it's not there anymore response = getAsServletResponse("rest/oseo/collections/TEST123/metadata"); assertEquals(404, response.getStatus()); }
From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java
@Test public void testGetCollectionDescription() throws Exception { MockHttpServletResponse response = getAsServletResponse("/rest/oseo/collections/SENTINEL2/description"); assertEquals(200, response.getStatus()); assertEquals("text/html", response.getContentType()); assertThat(response.getContentAsString(), both(containsString("<table>")).and(containsString("Sentinel-2"))); }
From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java
@Test public void testPutCollectionDescription() throws Exception { MockHttpServletResponse response; createTest123Collection();//from w w w .j a va 2 s .c o m // create the description response = putAsServletResponse("rest/oseo/collections/TEST123/description", getTestData("/test123-description.html"), MediaType.TEXT_HTML_VALUE); assertEquals(200, response.getStatus()); // grab and check assertTest123Description(); }
From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java
private void assertTest123Description() throws Exception, UnsupportedEncodingException { MockHttpServletResponse response; response = getAsServletResponse("rest/oseo/collections/TEST123/description"); assertEquals(200, response.getStatus()); assertEquals("text/html", response.getContentType()); assertThat(response.getContentAsString(), both(containsString("<table")).and(containsString("TEST123"))); }
From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java
@Test public void testDeleteCollectionDescription() throws Exception { // creates the collection and adds the metadata testPutCollectionDescription();/*from w w w .j a v a 2 s . co m*/ // now remove MockHttpServletResponse response = deleteAsServletResponse("rest/oseo/collections/TEST123/description"); assertEquals(200, response.getStatus()); // check it's not there anymore response = getAsServletResponse("rest/oseo/collections/TEST123/description"); assertEquals(404, response.getStatus()); }
From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java
@Test public void testGetCollectionThumbnail() throws Exception { // missing from the DB right now MockHttpServletResponse response = getAsServletResponse("/rest/oseo/collections/SENTINEL2/thumbnail"); assertEquals(404, response.getStatus()); }
From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java
@Test public void testDeleteCollectionLayer() throws Exception { // remove// w w w.ja v a 2 s. c om MockHttpServletResponse response = deleteAsServletResponse("/rest/oseo/collections/SENTINEL2/layer"); assertEquals(200, response.getStatus()); // no more there response = getAsServletResponse("/rest/oseo/collections/SENTINEL2/layer"); assertEquals(404, response.getStatus()); }
From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java
private void testCreateCollectionAsZip(Set<CollectionPart> parts) throws Exception { LOGGER.info("Testing: " + parts); byte[] zip = null; try (final ByteArrayOutputStream bos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(bos)) { for (CollectionPart part : parts) { String resource, name; switch (part) { case Collection: resource = "/collection.json"; name = "collection.json"; break; case Description: resource = "/test123-description.html"; name = "description.html"; break; case Metadata: resource = "/test123-metadata.xml"; name = "metadata.xml"; break; case OwsLinks: resource = "/test123-links.json"; name = "owsLinks.json"; break; default: throw new RuntimeException("Unexpected part " + part); }//from w w w. j a va2s. c o m ZipEntry entry = new ZipEntry(name); zos.putNextEntry(entry); IOUtils.copy(getClass().getResourceAsStream(resource), zos); zos.closeEntry(); } zip = bos.toByteArray(); } MockHttpServletResponse response = postAsServletResponse("rest/oseo/collections", zip, MediaTypeExtensions.APPLICATION_ZIP_VALUE); if (parts.contains(CollectionPart.Collection)) { assertEquals(201, response.getStatus()); assertEquals("http://localhost:8080/geoserver/rest/oseo/collections/TEST123", response.getHeader("location")); assertTest123CollectionCreated(); } else { assertEquals(400, response.getStatus()); assertThat(response.getContentAsString(), containsString("collection.json")); // failed, nothing else to check return; } if (parts.contains(CollectionPart.Description)) { assertTest123Description(); } if (parts.contains(CollectionPart.Metadata)) { assertTest123Metadata(); } if (parts.contains(CollectionPart.OwsLinks)) { assertTest123Links(); } }
From source file:org.geoserver.opensearch.rest.OSEORestTestSupport.java
protected DocumentContext getAsJSONPath(String path, int expectedHttpCode) throws Exception { MockHttpServletResponse response = getAsServletResponse(path); if (!isQuietTests()) { System.out.println(response.getContentAsString()); }//from ww w.j a v a2 s .c o m assertEquals(expectedHttpCode, response.getStatus()); assertThat(response.getContentType(), startsWith("application/json")); return JsonPath.parse(response.getContentAsString()); }