List of usage examples for org.springframework.mock.web MockHttpServletResponse getContentType
@Override
@Nullable
public String getContentType()
From source file:org.geoserver.wcs2_0.WCSNetCDFMosaicTest.java
@Test public void testRequestNetCDF4() throws Exception { boolean isNC4Available = NetCDFUtilities.isNC4CAvailable(); if (!isNC4Available && LOGGER.isLoggable(Level.INFO)) { LOGGER.info("NetCDF C library not found. NetCDF4 output will not be created"); }/* w ww. jav a 2 s .c o m*/ // http response from the request inside the string MockHttpServletResponse response = getAsServletResponse("ows?request=GetCoverage&service=WCS&version=2.0.1" + "&coverageId=wcs__dummyView&format=application/x-netcdf4&subset=http://www.opengis.net/def/axis/OGC/0/time(\"2013-01-08T00:00:00.000Z\")"); assertNotNull(response); assertEquals((isNC4Available ? "application/x-netcdf4" : "application/xml"), response.getContentType()); if (isNC4Available) { byte[] netcdfOut = getBinary(response); File file = File.createTempFile("netcdf", "out.nc", new File("./target")); FileUtils.writeByteArrayToFile(file, netcdfOut); NetcdfDataset dataset = NetcdfDataset.openDataset(file.getAbsolutePath()); assertNotNull(dataset); dataset.close(); } }
From source file:org.geoserver.wcs2_0.WCSNetCDFMosaicTest.java
@Test public void testRequestNetCDFCompression() throws Exception { boolean isNC4Available = NetCDFUtilities.isNC4CAvailable(); if (!isNC4Available && LOGGER.isLoggable(Level.INFO)) { LOGGER.info("NetCDF C library not found. NetCDF4 output will not be created"); }// w w w . j a va2s .c o m // http response from the request inside the string MockHttpServletResponse response = getAsServletResponse("ows?request=GetCoverage&service=WCS&version=2.0.1" + "&coverageId=wcs__visibilityCompressed&format=application/x-netcdf4"); assertNotNull(response); assertEquals((isNC4Available ? "application/x-netcdf4" : "application/xml"), response.getContentType()); if (isNC4Available) { byte[] netcdfOut = getBinary(response); File file = File.createTempFile("netcdf", "outCompressed.nc", new File("./target")); FileUtils.writeByteArrayToFile(file, netcdfOut); NetcdfDataset dataset = NetcdfDataset.openDataset(file.getAbsolutePath()); assertNotNull(dataset); Variable var = dataset.findVariable(STANDARD_NAME); assertNotNull(var); final long varByteSize = var.getSize() * var.getDataType().getSize(); // The output file is smaller than the size of the underlying variable. // Compression successfully occurred assertTrue(netcdfOut.length < varByteSize); dataset.close(); } }
From source file:org.geoserver.wcs2_0.WCSNetCDFTest.java
/** * This test checks if an exception is not thrown when is requested an image with a total size lower than the maximum * geoserver output size./*from w ww . j a v a2 s . com*/ * */ @Test public void testOutputMemoryNotExceeded() throws Exception { // Setting of the output limit to 40 Kb setOutputLimit(40); // http response from the request inside the string MockHttpServletResponse response = getAsServletResponse("ows?request=GetCoverage&service=WCS&version=2.0.1" + "&coverageId=wcs__NO2&format=application/x-netcdf&subset=http://www.opengis.net/def/axis/OGC/0/elevation(450)"); // The status code should be correct assertEquals(200, response.getStatus()); // The output format should be netcdf assertEquals("application/x-netcdf", response.getContentType()); // Reset output limit setOutputLimit(-1); }
From source file:org.geoserver.wcs2_0.WCSNetCDFTest.java
/** * This test checks if an exception is thrown when is requested an image with a total size greater than the maximum * geoserver output memory allowed.// w w w .ja va 2s. co m * */ @Test public void testOutputMemoryExceeded() throws Exception { // Setting of the output limit to 40 Kb setOutputLimit(40); // http response from the request inside the string MockHttpServletResponse response = getAsServletResponse("ows?request=GetCoverage&service=WCS&version=2.0.1" + "&coverageId=wcs__NO2&format=application/x-netcdf"); // The output format should be xml because an exception must be thrown assertEquals("application/xml", response.getContentType()); // Reset output limit setOutputLimit(-1); }
From source file:org.geoserver.wcs2_0.WCSNetCDFTest.java
/** * This test checks if an exception is not thrown when is requested an image with a total size lower than the maximum * geoserver input size.//from w ww . ja va 2 s. com * */ @Test public void testInputMemoryCorrect() throws Exception { // Setting of the input limit to 40 Kb setInputLimit(40); // http response from the request inside the string MockHttpServletResponse response = getAsServletResponse("ows?request=GetCoverage&service=WCS&version=2.0.1" + "&coverageId=wcs__NO2&format=application/x-netcdf&subset=http://www.opengis.net/def/axis/OGC/0/elevation(450)"); // The status code should be correct assertEquals(200, response.getStatus()); // The output format should be netcdf assertEquals("application/x-netcdf", response.getContentType()); // Reset input limit setInputLimit(-1); }
From source file:org.geoserver.wcs2_0.WCSNetCDFTest.java
/** * This test checks if an exception is thrown when is requested an image with a total size greater than the maximum * geoserver input memory allowed.// ww w .j av a 2s . c o m * */ @Test public void testInputMemoryExceeded() throws Exception { // Setting of the input limit to 40 Kb setInputLimit(40); // http response from the request inside the string MockHttpServletResponse response = getAsServletResponse("ows?request=GetCoverage&service=WCS&version=2.0.1" + "&coverageId=wcs__NO2&format=application/x-netcdf"); // The output format should be xml because an exception must be thrown assertEquals("application/xml", response.getContentType()); // Reset input limit setInputLimit(-1); }
From source file:org.geoserver.wcs2_0.WCSNetCDFTest.java
/** * Test NetCDF output from a NetCDF file with a rotated pole projection. *//*from w w w . jav a2 s . com*/ @Test public void testNetcdfRotatedPole() throws Exception { MockHttpServletResponse response = getAsServletResponse("ows?request=GetCoverage&service=WCS&version=2.0.1" + "&coverageid=wcs__Temperature_surface_NetCDF&format=application/x-netcdf"); assertEquals(200, response.getStatus()); assertEquals("application/x-netcdf", response.getContentType()); byte[] responseBytes = getBinary(response); File file = File.createTempFile("netcdf-rotated-pole-", "-wcs__Temperature_surface_NetCDF.nc", new File("./target")); FileUtils.writeByteArrayToFile(file, responseBytes); try (NetcdfDataset dataset = NetcdfDataset.openDataset(file.getAbsolutePath())) { assertNotNull(dataset); // check dimensions Dimension rlonDim = dataset.findDimension("rlon"); assertNotNull(rlonDim); assertEquals(7, rlonDim.getLength()); Dimension rlatDim = dataset.findDimension("rlat"); assertNotNull(rlatDim); assertEquals(5, rlatDim.getLength()); // check coordinate variables Variable rlonVar = dataset.findVariable("rlon"); assertNotNull(rlonVar); assertEquals(1, rlonVar.getDimensions().size()); assertEquals(rlonDim, rlonVar.getDimensions().get(0)); assertEquals("grid_longitude", rlonVar.findAttribute("long_name").getStringValue()); assertEquals("grid_longitude", rlonVar.findAttribute("standard_name").getStringValue()); assertEquals("degrees", rlonVar.findAttribute("units").getStringValue()); assertArrayEquals(new float[] { -30, -20, -10, 0, 10, 20, 30 }, (float[]) rlonVar.read().copyTo1DJavaArray(), (float) DELTA); Variable rlatVar = dataset.findVariable("rlat"); assertNotNull(rlatVar); assertEquals(1, rlatVar.getDimensions().size()); assertEquals(rlatDim, rlatVar.getDimensions().get(0)); assertEquals("grid_latitude", rlatVar.findAttribute("long_name").getStringValue()); assertEquals("grid_latitude", rlatVar.findAttribute("standard_name").getStringValue()); assertEquals("degrees", rlatVar.findAttribute("units").getStringValue()); assertArrayEquals(new float[] { -20, -10, 0, 10, 20 }, (float[]) rlatVar.read().copyTo1DJavaArray(), (float) DELTA); // check projection variable Variable projVar = dataset.findVariable("rotated_latitude_longitude"); assertNotNull(projVar); assertEquals("rotated_latitude_longitude", projVar.findAttribute("grid_mapping_name").getStringValue()); assertEquals(74.0, projVar.findAttribute("grid_north_pole_longitude").getNumericValue().doubleValue(), DELTA); assertEquals(36.0, projVar.findAttribute("grid_north_pole_latitude").getNumericValue().doubleValue(), DELTA); // check data variable Variable tempVar = dataset.findVariable("Temperature_surface_NetCDF"); assertNotNull(tempVar); assertEquals("rotated_latitude_longitude", tempVar.findAttribute("grid_mapping").getStringValue()); assertEquals("K", tempVar.findAttribute("units").getStringValue()); assertEquals(2, tempVar.getDimensions().size()); assertEquals(rlatDim, tempVar.getDimensions().get(0)); assertEquals(rlonDim, tempVar.getDimensions().get(1)); assertArrayEquals(new float[] { 300, 299, 298, 297, 296, 295, 294, 299, 300, 299, 298, 297, 296, 295, 298, 299, 300, 299, 298, 297, 296, 297, 298, 299, 300, 299, 298, 297, 296, 297, 298, 299, 300, 299, 298 }, (float[]) tempVar.read().copyTo1DJavaArray(), (float) DELTA); } finally { FileUtils.deleteQuietly(file); } }
From source file:org.geoserver.wcs2_0.WCSNetCDFTest.java
/** * Test NetCDF output from an RAP native GRIB2 file with a GDS template 32769 rotated pole projection. *///from www. j ava2s. c o m @Test public void testRapNativeGribRotatedPole() throws Exception { MockHttpServletResponse response = getAsServletResponse("ows?request=GetCoverage&service=WCS&version=2.0.1" + "&coverageid=wcs__Temperature_surface&format=application/x-netcdf"); assertEquals(200, response.getStatus()); assertEquals("application/x-netcdf", response.getContentType()); byte[] responseBytes = getBinary(response); File file = File.createTempFile("rap-native-grib-rotated-pole-", "-wcs__Temperature_surface.nc", new File("./target")); FileUtils.writeByteArrayToFile(file, responseBytes); try (NetcdfDataset dataset = NetcdfDataset.openDataset(file.getAbsolutePath())) { assertNotNull(dataset); // check dimensions Dimension rlonDim = dataset.findDimension("rlon"); assertNotNull(rlonDim); assertEquals(7, rlonDim.getLength()); Dimension rlatDim = dataset.findDimension("rlat"); assertNotNull(rlatDim); assertEquals(5, rlatDim.getLength()); // check coordinate variables Variable rlonVar = dataset.findVariable("rlon"); assertNotNull(rlonVar); assertEquals(1, rlonVar.getDimensions().size()); assertEquals(rlonDim, rlonVar.getDimensions().get(0)); assertEquals("grid_longitude", rlonVar.findAttribute("long_name").getStringValue()); assertEquals("grid_longitude", rlonVar.findAttribute("standard_name").getStringValue()); assertEquals("degrees", rlonVar.findAttribute("units").getStringValue()); assertArrayEquals(new float[] { -30, -20, -10, 0, 10, 20, 30 }, (float[]) rlonVar.read().copyTo1DJavaArray(), (float) DELTA); Variable rlatVar = dataset.findVariable("rlat"); assertNotNull(rlatVar); assertEquals(1, rlatVar.getDimensions().size()); assertEquals(rlatDim, rlatVar.getDimensions().get(0)); assertEquals("grid_latitude", rlatVar.findAttribute("long_name").getStringValue()); assertEquals("grid_latitude", rlatVar.findAttribute("standard_name").getStringValue()); assertEquals("degrees", rlatVar.findAttribute("units").getStringValue()); assertArrayEquals(new float[] { -20, -10, 0, 10, 20 }, (float[]) rlatVar.read().copyTo1DJavaArray(), (float) DELTA); // check projection variable Variable projVar = dataset.findVariable("rotated_latitude_longitude"); assertNotNull(projVar); assertEquals("rotated_latitude_longitude", projVar.findAttribute("grid_mapping_name").getStringValue()); assertEquals(74.0, projVar.findAttribute("grid_north_pole_longitude").getNumericValue().doubleValue(), DELTA); assertEquals(36.0, projVar.findAttribute("grid_north_pole_latitude").getNumericValue().doubleValue(), DELTA); // check data variable Variable dataVar = dataset.findVariable("Temperature_surface"); assertNotNull(dataVar); assertEquals("rotated_latitude_longitude", dataVar.findAttribute("grid_mapping").getStringValue()); assertEquals("K", dataVar.findAttribute("units").getStringValue()); assertEquals(2, dataVar.getDimensions().size()); assertEquals(rlatDim, dataVar.getDimensions().get(0)); assertEquals(rlonDim, dataVar.getDimensions().get(1)); assertArrayEquals(new float[] { 300, 299, 298, 297, 296, 295, 294, 299, 300, 299, 298, 297, 296, 295, 298, 299, 300, 299, 298, 297, 296, 297, 298, 299, 300, 299, 298, 297, 296, 297, 298, 299, 300, 299, 298 }, (float[]) dataVar.read().copyTo1DJavaArray(), (float) DELTA); } finally { FileUtils.deleteQuietly(file); } }
From source file:org.geoserver.wcs2_0.WCSNetCDFTest.java
/** * Test NetCDF output from a COSMO EU GRIB2 file with a GDS template 1 rotated pole projection. *//*from w ww . j a v a2 s . c om*/ @Test public void testCosmoEuGribRotatedPole() throws Exception { MockHttpServletResponse response = getAsServletResponse("ows?request=GetCoverage&service=WCS&version=2.0.1" + "&coverageid=wcs__Snow_depth_water_equivalent_surface&format=application/x-netcdf"); assertEquals(200, response.getStatus()); assertEquals("application/x-netcdf", response.getContentType()); byte[] responseBytes = getBinary(response); File file = File.createTempFile("cosmo-eu-grib-rotated-pole-", "-wcs__Snow_depth_water_equivalent_surface.nc", new File("./target")); FileUtils.writeByteArrayToFile(file, responseBytes); try (NetcdfDataset dataset = NetcdfDataset.openDataset(file.getAbsolutePath())) { assertNotNull(dataset); // check dimensions Dimension rlonDim = dataset.findDimension("rlon"); assertNotNull(rlonDim); assertEquals(5, rlonDim.getLength()); Dimension rlatDim = dataset.findDimension("rlat"); assertNotNull(rlatDim); assertEquals(5, rlatDim.getLength()); // check coordinate variables Variable rlonVar = dataset.findVariable("rlon"); assertNotNull(rlonVar); assertEquals(1, rlonVar.getDimensions().size()); assertEquals(rlonDim, rlonVar.getDimensions().get(0)); assertEquals("grid_longitude", rlonVar.findAttribute("long_name").getStringValue()); assertEquals("grid_longitude", rlonVar.findAttribute("standard_name").getStringValue()); assertEquals("degrees", rlonVar.findAttribute("units").getStringValue()); assertArrayEquals(new float[] { -18, -8, 2, 12, 22 }, (float[]) rlonVar.read().copyTo1DJavaArray(), (float) DELTA); Variable rlatVar = dataset.findVariable("rlat"); assertNotNull(rlatVar); assertEquals(1, rlatVar.getDimensions().size()); assertEquals(rlatDim, rlatVar.getDimensions().get(0)); assertEquals("grid_latitude", rlatVar.findAttribute("long_name").getStringValue()); assertEquals("grid_latitude", rlatVar.findAttribute("standard_name").getStringValue()); assertEquals("degrees", rlatVar.findAttribute("units").getStringValue()); assertArrayEquals(new float[] { -20, -10, 0, 10, 20 }, (float[]) rlatVar.read().copyTo1DJavaArray(), (float) DELTA); // check projection variable Variable projVar = dataset.findVariable("rotated_latitude_longitude"); assertNotNull(projVar); assertEquals("rotated_latitude_longitude", projVar.findAttribute("grid_mapping_name").getStringValue()); assertEquals(-170.0, projVar.findAttribute("grid_north_pole_longitude").getNumericValue().doubleValue(), DELTA); assertEquals(40.0, projVar.findAttribute("grid_north_pole_latitude").getNumericValue().doubleValue(), DELTA); // check data variable Variable dataVar = dataset.findVariable("Snow_depth_water_equivalent_surface"); assertNotNull(dataVar); assertEquals("rotated_latitude_longitude", dataVar.findAttribute("grid_mapping").getStringValue()); assertEquals(2, dataVar.getDimensions().size()); assertEquals(rlatDim, dataVar.getDimensions().get(0)); assertEquals(rlonDim, dataVar.getDimensions().get(1)); assertArrayEquals( new float[] { 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124 }, (float[]) dataVar.read().copyTo1DJavaArray(), (float) DELTA); } finally { FileUtils.deleteQuietly(file); } }
From source file:org.geoserver.wms.map.PDFGetMapTest.java
@Test public void testBasicPolygonMap() throws Exception { MockHttpServletResponse response = getAsServletResponse(requestBase + "&styles="); assertEquals("application/pdf", response.getContentType()); PDTilingPattern tilingPattern = getTilingPattern(response.getContentAsByteArray()); assertNull(tilingPattern);/*from w ww . j a v a2 s.c o m*/ }