List of usage examples for org.springframework.mock.web MockHttpServletResponse getContentAsString
public String getContentAsString() throws UnsupportedEncodingException
From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java
@Test public void testGetCollectionMetadata() throws Exception { MockHttpServletResponse response = getAsServletResponse("/rest/oseo/collections/SENTINEL2/metadata"); assertEquals(200, response.getStatus()); assertEquals("text/xml", response.getContentType()); assertThat(response.getContentAsString(), both(containsString("gmi:MI_Metadata")).and(containsString("Sentinel-2"))); }
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 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
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
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 ww w . j a va2s .c om*/ 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 w ww . j a v a2 s .com assertEquals(expectedHttpCode, response.getStatus()); assertThat(response.getContentType(), startsWith("application/json")); return JsonPath.parse(response.getContentAsString()); }
From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java
@Test public void testGetProductsForNonExistingCollection() throws Exception { MockHttpServletResponse response = getAsServletResponse("/rest/oseo/collections/fooBar/products"); assertEquals(404, response.getStatus()); assertThat(response.getContentAsString(), containsString("fooBar")); }
From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java
@Test public void testNonExistingProduct() throws Exception { MockHttpServletResponse response = getAsServletResponse("/rest/oseo/collections/SENTINEL2/products/foobar"); assertEquals(404, response.getStatus()); assertThat(response.getContentAsString(), containsString("foobar")); }
From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java
@Test public void testGetProductMetadata() throws Exception { MockHttpServletResponse response = getAsServletResponse( "/rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20160117T141030_A002979_T32TPL_N02.01/metadata"); assertEquals(200, response.getStatus()); assertEquals("text/xml", response.getContentType()); assertThat(response.getContentAsString(), both(containsString("opt:EarthObservation")) .and(containsString("S2A_OPER_MSI_L1C_TL_SGS__20160117T141030_A002979_T32TPL_N02.01"))); }
From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java
private void assertProductMetadata() throws Exception, UnsupportedEncodingException { MockHttpServletResponse response; response = getAsServletResponse(//ww w.ja v a 2 s. c o m "rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04/metadata"); assertEquals(200, response.getStatus()); assertEquals("text/xml", response.getContentType()); assertThat(response.getContentAsString(), both(containsString("opt:EarthObservation")) .and(containsString("S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04"))); }