List of usage examples for org.springframework.mock.web MockHttpServletResponse getStatus
@Override public int getStatus()
From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java
@Test public void testPutProductGranules() throws Exception { testCreateProduct();/*from w w w. jav a2 s .c o m*/ // add the granules MockHttpServletResponse response = putAsServletResponse( "/rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04/granules", getTestData("/product-granules.json"), MediaType.APPLICATION_JSON_VALUE); assertEquals(200, response.getStatus()); assertProductGranules(); }
From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java
@Test public void testPutProductGranulesWithBands() throws Exception { testCreateProduct();/*from ww w . j av a2 s . c o m*/ // add the granules MockHttpServletResponse response = putAsServletResponse( "/rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04/granules", getTestData("/product-granules-bands.json"), MediaType.APPLICATION_JSON_VALUE); assertEquals(200, response.getStatus()); assertProductGranules(); DocumentContext json = getAsJSONPath( "/rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04/granules", 200); assertEquals("B1", json.read("$.features[0].properties.band")); assertEquals("B2", json.read("$.features[1].properties.band")); }
From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java
@Test public void testDeleteProductGranules() throws Exception { testPutProductDescription();/* w w w .j av a 2s . c o m*/ // now delete it MockHttpServletResponse response = deleteAsServletResponse( "rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04/granules"); assertEquals(200, response.getStatus()); // no more there now DocumentContext json = getAsJSONPath( "rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04/granules", 200); assertEquals(200, response.getStatus()); assertEquals("FeatureCollection", json.read("$.type")); assertEquals(new Integer(0), json.read("$.features.length()")); }
From source file:org.geoserver.opensearch.rest.ProductsControllerTest.java
private void testCreateProductAsZip(Set<ProductPart> parts) throws Exception { LOGGER.info("Testing: " + parts); byte[] zip = null; try (final ByteArrayOutputStream bos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(bos)) { for (ProductPart part : parts) { String resource, name; switch (part) { case Product: resource = "/product.json"; name = "product.json"; break; case Description: resource = "/product-description.html"; name = "description.html"; break; case Metadata: resource = "/product-metadata.xml"; name = "metadata.xml"; break; case Thumbnail: resource = "/product-thumb.jpeg"; name = "thumbnail.jpeg"; break; case OwsLinks: resource = "/product-links.json"; name = "owsLinks.json"; break; case Granules: resource = "/product-granules.json"; name = "granules.json"; break; default: throw new RuntimeException("Unexpected part " + part); }/*from ww w .jav a 2 s. c om*/ ZipEntry entry = new ZipEntry(name); zos.putNextEntry(entry); IOUtils.copy(getClass().getResourceAsStream(resource), zos); zos.flush(); zos.closeEntry(); } zip = bos.toByteArray(); } MockHttpServletResponse response = postAsServletResponse("rest/oseo/collections/SENTINEL2/products", zip, MediaTypeExtensions.APPLICATION_ZIP_VALUE); if (parts.contains(ProductPart.Product)) { assertEquals(201, response.getStatus()); assertEquals( "http://localhost:8080/geoserver/rest/oseo/collections/SENTINEL2/products/S2A_OPER_MSI_L1C_TL_SGS__20180101T000000_A006640_T32TPP_N02.04", response.getHeader("location")); assertProductCreated(); } else { assertEquals(400, response.getStatus()); assertThat(response.getContentAsString(), containsString("product.json")); // failed, nothing else to check return; } if (parts.contains(ProductPart.Description)) { assertProductDescription(); } if (parts.contains(ProductPart.Metadata)) { assertProductMetadata(); } if (parts.contains(ProductPart.Thumbnail)) { assertProductThumbnail(); } if (parts.contains(ProductPart.OwsLinks)) { assertProductLinks(); } if (parts.contains(ProductPart.Granules)) { assertProductGranules(); } }
From source file:org.geoserver.ows.StylePublisherTest.java
@Test public void testEncoding() throws Exception { for (String[] path : paths) { MockHttpServletResponse response = request(path, null); assertEquals(Arrays.toString(path), 200, response.getStatus()); assertArrayEquals(// w ww. j a v a 2s. c o m IOUtils.toByteArray(this.getClass().getClassLoader() .getResourceAsStream("org/geoserver/ows/" + path[path.length - 1])), response.getContentAsByteArray()); } }
From source file:org.geoserver.ows.StylePublisherTest.java
@Test public void testOverride() throws Exception { String[] path = new String[] { "styles", "override.png" }; MockHttpServletResponse response = request(path, null); assertEquals(Arrays.toString(path), 200, response.getStatus()); assertArrayEquals(//from w ww. j av a 2 s. c om IOUtils.toByteArray( this.getClass().getClassLoader().getResourceAsStream("org/geoserver/ows/smileyface.png")), response.getContentAsByteArray()); path = new String[] { "styles", "cite", "override.png" }; response = request(path, null); assertEquals(Arrays.toString(path), 200, response.getStatus()); assertArrayEquals( IOUtils.toByteArray( this.getClass().getClassLoader().getResourceAsStream("org/geoserver/ows/grass_fill.png")), response.getContentAsByteArray()); path = new String[] { "styles", "icons", "override.png" }; response = request(path, null); assertEquals(Arrays.toString(path), 200, response.getStatus()); assertArrayEquals( IOUtils.toByteArray( this.getClass().getClassLoader().getResourceAsStream("org/geoserver/ows/smileyface.png")), response.getContentAsByteArray()); path = new String[] { "styles", "cite", "icons", "override.png" }; response = request(path, null); assertEquals(Arrays.toString(path), 200, response.getStatus()); assertArrayEquals( IOUtils.toByteArray( this.getClass().getClassLoader().getResourceAsStream("org/geoserver/ows/grass_fill.png")), response.getContentAsByteArray()); }
From source file:org.geoserver.ows.StylePublisherTest.java
@Test public void testLastModified() throws Exception { for (String[] path : paths) { MockHttpServletResponse response = request(path, null); String lastModified = response.getHeader("Last-Modified"); assertNotNull(lastModified);/*from w w w . j a v a2 s . c o m*/ response = request(path, lastModified); assertEquals(304, response.getStatus()); long timeStamp = AbstractURLPublisher.lastModified(lastModified) + 10000; response = request(path, AbstractURLPublisher.lastModified(timeStamp)); assertEquals(304, response.getStatus()); timeStamp -= 20000; response = request(path, AbstractURLPublisher.lastModified(timeStamp)); assertEquals(200, response.getStatus()); assertArrayEquals( IOUtils.toByteArray(this.getClass().getClassLoader() .getResourceAsStream("org/geoserver/ows/" + path[path.length - 1])), response.getContentAsByteArray()); } }
From source file:org.geoserver.qos.web.QosWfsPanelTest.java
protected void setupQosConfig() throws Exception { String xml = getFileData("test-data/wfs-data.xml"); MockHttpServletResponse response = putAsServletResponse( RestBaseController.ROOT_PATH + QosWFSRestTest.QOS_WFS_PATH, xml, "text/xml"); assertEquals(200, response.getStatus()); }
From source file:org.geoserver.qos.web.QosWfsPanelTest.java
protected void disableQosConfig() throws Exception { String xml = getFileData("test-data/disabled-config.xml"); MockHttpServletResponse response = putAsServletResponse( RestBaseController.ROOT_PATH + QosWFSRestTest.QOS_WFS_PATH, xml, "text/xml"); assertEquals(200, response.getStatus()); }
From source file:org.geoserver.qos.web.QosWmsPanelTest.java
protected void setupQosConfig() throws Exception { String xml = getFileData("test-data/wms-data.xml"); MockHttpServletResponse response = putAsServletResponse( RestBaseController.ROOT_PATH + QosWMSRestTest.QOS_WMS_PATH, xml, "text/xml"); assertEquals(200, response.getStatus()); }