List of usage examples for org.springframework.mock.web MockHttpServletResponse getStatus
@Override public int getStatus()
From source file:org.geoserver.importer.rest.ImportTaskControllerTest.java
private void verifyInvalidCRSErrorResponse(MockHttpServletResponse resp) throws UnsupportedEncodingException { assertEquals(HttpStatus.BAD_REQUEST.value(), resp.getStatus()); //TODO: Implement JSON error format /*//from w w w .j ava 2s . c o m JSONObject errorResponse = JSONObject.fromObject(resp.getContentAsString()); JSONArray errors = errorResponse.getJSONArray("errors"); assertTrue(errors.get(0).toString().startsWith("Invalid SRS")); */ }
From source file:org.geoserver.importer.rest.ImportTaskControllerTest.java
@Test public void testDeleteTask2() throws Exception { MockHttpServletResponse response = deleteAsServletResponse( RestBaseController.ROOT_PATH + "/imports/0/tasks/0"); assertEquals(204, response.getStatus()); JSONObject json = (JSONObject) getAsJSON(RestBaseController.ROOT_PATH + "/imports/0/tasks"); JSONArray items = json.getJSONArray("tasks"); assertEquals(1, items.size());//w ww .jav a 2s. c o m assertEquals(1, items.getJSONObject(0).getInt("id")); }
From source file:org.geoserver.opensearch.eo.OSEOTestSupport.java
/** * Returns the DOM after checking the status code is 200 and the returned mime type is the expected one * /*from w w w . j a v a 2s .c o m*/ * @param path * @param expectedMimeType * @return * @throws Exception */ protected Document getAsDOM(String path, int expectedStatusCode, String expectedMimeType) throws Exception { MockHttpServletResponse response = getAsServletResponse(path); assertEquals(expectedMimeType, response.getContentType()); assertEquals(expectedStatusCode, response.getStatus()); Document dom = dom(new ByteArrayInputStream(response.getContentAsByteArray())); return dom; }
From source file:org.geoserver.opensearch.rest.CollectionLayerTest.java
@Before public void setupTestCollectionAndProduct() throws IOException, Exception { // create the collection createTest123Collection();/*from ww w. j a v a2 s. c om*/ // create the product MockHttpServletResponse response = postAsServletResponse("rest/oseo/collections/TEST123/products", getTestData("/test123-product.json"), MediaType.APPLICATION_JSON_VALUE); assertEquals(201, response.getStatus()); assertEquals("http://localhost:8080/geoserver/rest/oseo/collections/TEST123/products/TEST123_P1", response.getHeader("location")); // setup the base granule location File file = new File("./src/test/resources"); resourceBase = file.getCanonicalFile().getAbsolutePath(); }
From source file:org.geoserver.opensearch.rest.CollectionLayerTest.java
@Test public void testCreateCollectionSimpleLayer() throws Exception { // setup the granules String granulesTemplate = getTestStringData("/test123-product-granules-rgb.json"); String granules = granulesTemplate.replace("$resources", resourceBase); MockHttpServletResponse response = putAsServletResponse( "/rest/oseo/collections/TEST123/products/TEST123_P1/granules", granules, MediaType.APPLICATION_JSON_VALUE); assertEquals(200, response.getStatus()); // create the layer boolean previousConfiguration = getAsServletResponse("rest/oseo/collections/TEST123/layer") .getStatus() == HttpStatus.OK.value(); response = putAsServletResponse("rest/oseo/collections/TEST123/layer", getTestData("/test123-layer-simple.json"), MediaType.APPLICATION_JSON_VALUE); assertEquals(previousConfiguration ? 200 : 201, response.getStatus()); // check it has been created from REST DocumentContext json = getAsJSONPath("rest/oseo/collections/TEST123/layer", 200); assertEquals("gs", json.read("$.workspace")); assertEquals("test123", json.read("$.layer")); assertEquals(Boolean.FALSE, json.read("$.separateBands")); assertEquals(Boolean.FALSE, json.read("$.heterogeneousCRS")); // check the configuration elements are there too Catalog catalog = getCatalog();// w w w . j a v a2 s . co m // ... the store CoverageStoreInfo store = catalog.getCoverageStoreByName("gs", "test123"); assertNotNull(store); assertThat(store.getFormat(), instanceOf(ImageMosaicFormat.class)); // ... the layer LayerInfo layer = catalog.getLayerByName("gs:test123"); assertNotNull(layer); final CoverageInfo coverageInfo = (CoverageInfo) layer.getResource(); assertThat(coverageInfo.getStore(), equalTo(store)); // ... the resource is time enabled DimensionInfo dimension = coverageInfo.getMetadata().get(ResourceInfo.TIME, DimensionInfo.class); assertThat(dimension.getAttribute(), equalTo("timeStart")); assertThat(dimension.getDefaultValue().getStrategyType(), equalTo(Strategy.MAXIMUM)); // ... its style is the default one assertThat(layer.getDefaultStyle().getName(), equalTo("raster")); BufferedImage image = getAsImage("wms/reflect?layers=gs:test123&format=image/png&width=200", "image/png"); File expected = new File("src/test/resources/test123-simple-rgb.png"); ImageAssert.assertEquals(expected, image, 1000); }
From source file:org.geoserver.opensearch.rest.CollectionLayerTest.java
@Test public void testCreateCollectionSimpleLayerWithCustomStyle() throws Exception { // setup the granules String granulesTemplate = getTestStringData("/test123-product-granules-rgb.json"); String granules = granulesTemplate.replace("$resources", resourceBase); MockHttpServletResponse response = putAsServletResponse( "/rest/oseo/collections/TEST123/products/TEST123_P1/granules", granules, MediaType.APPLICATION_JSON_VALUE); assertEquals(200, response.getStatus()); // create the layer boolean previousConfiguration = getAsServletResponse("rest/oseo/collections/TEST123/layer") .getStatus() == HttpStatus.OK.value(); response = putAsServletResponse("rest/oseo/collections/TEST123/layer", getTestData("/test123-layer-simple-graystyle.json"), MediaType.APPLICATION_JSON_VALUE); assertEquals(previousConfiguration ? 200 : 201, response.getStatus()); // check it has been created from REST DocumentContext json = getAsJSONPath("rest/oseo/collections/TEST123/layer", 200); assertEquals("gs", json.read("$.workspace")); assertEquals("test123", json.read("$.layer")); assertEquals(Boolean.FALSE, json.read("$.separateBands")); assertEquals(Boolean.FALSE, json.read("$.heterogeneousCRS")); // check the configuration elements are there too Catalog catalog = getCatalog();/*from w ww. j av a2 s . c o m*/ // ... the store CoverageStoreInfo store = catalog.getCoverageStoreByName("gs", "test123"); assertNotNull(store); assertThat(store.getFormat(), instanceOf(ImageMosaicFormat.class)); // ... the layer LayerInfo layer = catalog.getLayerByName("gs:test123"); assertNotNull(layer); final CoverageInfo coverageInfo = (CoverageInfo) layer.getResource(); assertThat(coverageInfo.getStore(), equalTo(store)); // ... the resource is time enabled DimensionInfo dimension = coverageInfo.getMetadata().get(ResourceInfo.TIME, DimensionInfo.class); assertThat(dimension.getAttribute(), equalTo("timeStart")); assertThat(dimension.getDefaultValue().getStrategyType(), equalTo(Strategy.MAXIMUM)); // ... its style is a gray one based on the RED band assertThat(layer.getDefaultStyle().prefixedName(), equalTo("gs:test123")); Style style = layer.getDefaultStyle().getStyle(); List<FeatureTypeStyle> fts = style.featureTypeStyles(); assertEquals(1, fts.size()); List<Rule> rules = fts.get(0).rules(); assertEquals(1, rules.size()); List<Symbolizer> symbolizers = rules.get(0).symbolizers(); assertEquals(1, symbolizers.size()); RasterSymbolizer rs = (RasterSymbolizer) symbolizers.get(0); ChannelSelection cs = rs.getChannelSelection(); assertNull(cs.getRGBChannels()[0]); assertNull(cs.getRGBChannels()[1]); assertNull(cs.getRGBChannels()[2]); assertEquals("1", cs.getGrayChannel().getChannelName()); BufferedImage image = getAsImage("wms/reflect?layers=gs:test123&format=image/png&width=200", "image/png"); File expected = new File("src/test/resources/test123-simple-gray.png"); ImageAssert.assertEquals(expected, image, 1000); }
From source file:org.geoserver.opensearch.rest.CollectionLayerTest.java
@Test public void testCreateCollectionMultiband() throws Exception { // setup the granules String granulesTemplate = getTestStringData("/test123-product-granules-multiband.json"); String granules = granulesTemplate.replace("$resources", resourceBase); MockHttpServletResponse response = putAsServletResponse( "/rest/oseo/collections/TEST123/products/TEST123_P1/granules", granules, MediaType.APPLICATION_JSON_VALUE); assertEquals(200, response.getStatus()); // create the layer boolean previousConfiguration = getAsServletResponse("rest/oseo/collections/TEST123/layer") .getStatus() == HttpStatus.OK.value(); response = putAsServletResponse("rest/oseo/collections/TEST123/layer", getTestData("/test123-layer-multiband.json"), MediaType.APPLICATION_JSON_VALUE); assertEquals(previousConfiguration ? 200 : 201, response.getStatus()); // check it has been created from REST DocumentContext json = getAsJSONPath("rest/oseo/collections/TEST123/layer", 200); assertEquals("gs", json.read("$.workspace")); assertEquals("test123", json.read("$.layer")); assertEquals(Boolean.TRUE, json.read("$.separateBands")); assertEquals(Boolean.TRUE, json.read("$.heterogeneousCRS")); // check the configuration elements are there too Catalog catalog = getCatalog();// w w w . j a v a 2s . c o m // ... the store CoverageStoreInfo store = catalog.getCoverageStoreByName("gs", "test123"); assertNotNull(store); assertThat(store.getFormat(), instanceOf(ImageMosaicFormat.class)); // ... the layer LayerInfo layer = catalog.getLayerByName("gs:test123"); assertNotNull(layer); final CoverageInfo coverageInfo = (CoverageInfo) layer.getResource(); assertThat(coverageInfo.getStore(), equalTo(store)); // ... the resource is time enabled DimensionInfo dimension = coverageInfo.getMetadata().get(ResourceInfo.TIME, DimensionInfo.class); assertThat(dimension.getAttribute(), equalTo("timeStart")); assertThat(dimension.getDefaultValue().getStrategyType(), equalTo(Strategy.MAXIMUM)); // ... its style is a RGB one based on the B2, B3, B4 assertThat(layer.getDefaultStyle().prefixedName(), equalTo("gs:test123")); Style style = layer.getDefaultStyle().getStyle(); List<FeatureTypeStyle> fts = style.featureTypeStyles(); assertEquals(1, fts.size()); List<Rule> rules = fts.get(0).rules(); assertEquals(1, rules.size()); List<Symbolizer> symbolizers = rules.get(0).symbolizers(); assertEquals(1, symbolizers.size()); RasterSymbolizer rs = (RasterSymbolizer) symbolizers.get(0); ChannelSelection cs = rs.getChannelSelection(); assertEquals("4", cs.getRGBChannels()[0].getChannelName()); assertEquals("3", cs.getRGBChannels()[1].getChannelName()); assertEquals("2", cs.getRGBChannels()[2].getChannelName()); assertNull(cs.getGrayChannel()); BufferedImage image = getAsImage("wms/reflect?layers=gs:test123&format=image/png&width=200", "image/png"); File expected = new File("src/test/resources/test123-multiband.png"); ImageAssert.assertEquals(expected, image, 1000); }
From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java
@Test public void testGetCollectionsPagingValidation() throws Exception { MockHttpServletResponse response = getAsServletResponse("/rest/oseo/collections?offset=-1"); assertEquals(400, response.getStatus()); assertThat(response.getErrorMessage(), containsString("offset")); response = getAsServletResponse("/rest/oseo/collections?limit=-1"); assertEquals(400, response.getStatus()); assertThat(response.getErrorMessage(), containsString("limit")); response = getAsServletResponse("/rest/oseo/collections?limit=1000"); assertEquals(400, response.getStatus()); assertThat(response.getErrorMessage(), containsString("limit")); }
From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java
@Test public void testNonExistingCollection() throws Exception { MockHttpServletResponse response = getAsServletResponse("/rest/oseo/collections/foobar"); assertEquals(404, response.getStatus()); assertThat(response.getContentAsString(), containsString("foobar")); }
From source file:org.geoserver.opensearch.rest.CollectionsControllerTest.java
@Test public void testCreateCollectionNotJson() throws Exception { MockHttpServletResponse response = postAsServletResponse("rest/oseo/collections", "This is not JSON", MediaType.APPLICATION_JSON_VALUE); assertEquals(400, response.getStatus()); }