List of usage examples for org.springframework.mock.web MockHttpServletResponse getContentType
@Override
@Nullable
public String getContentType()
From source file:org.geoserver.wps.ExecuteTest.java
@Test public void testInlineGeoJSON() throws Exception { String xml = "<wps:Execute service='WPS' version='1.0.0' xmlns:wps='http://www.opengis.net/wps/1.0.0' " + "xmlns:ows='http://www.opengis.net/ows/1.1'>" + "<ows:Identifier>gs:BufferFeatureCollection</ows:Identifier>" + "<wps:DataInputs>" + "<wps:Input>" + "<ows:Identifier>features</ows:Identifier>" + "<wps:Data>" + "<wps:ComplexData mimeType=\"application/json\"><![CDATA[" + readFileIntoString("states-FeatureCollection.json") + "]]></wps:ComplexData>" + "</wps:Data>" + "</wps:Input>" + "<wps:Input>" + "<ows:Identifier>distance</ows:Identifier>" + "<wps:Data>" + "<wps:LiteralData>10</wps:LiteralData>" + "</wps:Data>" + "</wps:Input>" + "</wps:DataInputs>" + "<wps:ResponseForm>" + "<wps:RawDataOutput mimeType=\"application/json\">" + "<ows:Identifier>result</ows:Identifier>" + "</wps:RawDataOutput>" + "</wps:ResponseForm>" + "</wps:Execute>"; MockHttpServletResponse r = postAsServletResponse("wps", xml); assertEquals("application/json", r.getContentType()); // System.out.println(r.getOutputStreamContent()); FeatureCollection fc = new FeatureJSON().readFeatureCollection(r.getContentAsString()); assertEquals(2, fc.size());// w w w . j a v a 2 s . c o m }
From source file:org.geoserver.wps.ExecuteTest.java
@Test public void testInlineShapezip() throws Exception { String xml = "<wps:Execute service='WPS' version='1.0.0' xmlns:wps='http://www.opengis.net/wps/1.0.0' " + "xmlns:ows='http://www.opengis.net/ows/1.1'>" + "<ows:Identifier>gs:BufferFeatureCollection</ows:Identifier>" + "<wps:DataInputs>" + "<wps:Input>" + "<ows:Identifier>features</ows:Identifier>" + "<wps:Data>" + "<wps:ComplexData mimeType=\"application/zip\" encoding=\"base64\"><![CDATA[" + readFileIntoString("states-zip-base64.txt") + "]]></wps:ComplexData>" + "</wps:Data>" + "</wps:Input>" + "<wps:Input>" + "<ows:Identifier>distance</ows:Identifier>" + "<wps:Data>" + "<wps:LiteralData>10</wps:LiteralData>" + "</wps:Data>" + "</wps:Input>" + "</wps:DataInputs>" + "<wps:ResponseForm>" + "<wps:RawDataOutput mimeType=\"application/json\">" + "<ows:Identifier>result</ows:Identifier>" + "</wps:RawDataOutput>" + "</wps:ResponseForm>" + "</wps:Execute>"; MockHttpServletResponse r = postAsServletResponse("wps", xml); // System.out.println(r.getOutputStreamContent()); assertEquals("application/json", r.getContentType()); // System.out.println(r.getOutputStreamContent()); FeatureCollection fc = new FeatureJSON().readFeatureCollection(r.getContentAsString()); assertEquals(2, fc.size());/* w w w .j ava 2 s . c om*/ }
From source file:org.geoserver.wps.ExecuteTest.java
@Test public void testShapeZip() throws Exception { String xml = "<wps:Execute service='WPS' version='1.0.0' xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + "xmlns:wps='http://www.opengis.net/wps/1.0.0' xmlns:wfs='http://www.opengis.net/wfs' " + "xmlns:ows='http://www.opengis.net/ows/1.1'>" + "<ows:Identifier>gs:BufferFeatureCollection</ows:Identifier>" + "<wps:DataInputs>" + " <wps:Input>\n" + "<ows:Identifier>features</ows:Identifier>" + "<wps:Data>" + "<wps:ComplexData>" + readFileIntoString("states-FeatureCollection.xml") + "</wps:ComplexData>" + "</wps:Data>" + "</wps:Input>" + "<wps:Input>" + "<ows:Identifier>distance</ows:Identifier>" + "<wps:Data>" + "<wps:LiteralData>10</wps:LiteralData>" + "</wps:Data>" + "</wps:Input>" + "</wps:DataInputs>" + "<wps:ResponseForm>" + "<wps:RawDataOutput mimeType=\"application/zip\">" + "<ows:Identifier>result</ows:Identifier>" + "</wps:RawDataOutput>" + "</wps:ResponseForm>" + "</wps:Execute>"; MockHttpServletResponse r = postAsServletResponse("wps", xml); assertEquals("application/zip", r.getContentType()); checkShapefileIntegrity(new String[] { "states" }, getBinaryInputStream(r)); }
From source file:org.geoserver.wps.ExecuteTest.java
@Test public void testProcessChaining() throws Exception { // chain two JTS processes String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<wps:Execute version=\"1.0.0\" service=\"WPS\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.opengis.net/wps/1.0.0\" xmlns:wfs=\"http://www.opengis.net/wfs\" xmlns:wps=\"http://www.opengis.net/wps/1.0.0\" xmlns:ows=\"http://www.opengis.net/ows/1.1\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:wcs=\"http://www.opengis.net/wcs/1.1.1\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xsi:schemaLocation=\"http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd\">\n" + " <ows:Identifier>JTS:area</ows:Identifier>\n" + " <wps:DataInputs>\n" + " <wps:Input>\n" + " <ows:Identifier>geom</ows:Identifier>\n" + " <wps:Reference mimeType=\"text/xml; subtype=gml/3.1.1\" xlink:href=\"http://geoserver/wps\" method=\"POST\">\n" + " <wps:Execute>\n" + " <ows:Identifier>JTS:buffer</ows:Identifier>\n" + " <wps:DataInputs>\n" + " <wps:Input>\n" + " <ows:Identifier>geom</ows:Identifier>\n" + " <wps:Data>\n" + " <wps:ComplexData mimeType=\"application/wkt\"><![CDATA[POINT(0 0)]]></wps:ComplexData>\n" + " </wps:Data>\n" + " </wps:Input>\n" + " <wps:Input>\n" + " <ows:Identifier>distance</ows:Identifier>\n" + " <wps:Data>\n" + " <wps:LiteralData>10</wps:LiteralData>\n" + " </wps:Data>\n" + " </wps:Input>\n" + " </wps:DataInputs>\n" + " <wps:ResponseForm>\n" + " <wps:RawDataOutput mimeType=\"text/xml; subtype=gml/3.1.1\">\n" + " <ows:Identifier>result</ows:Identifier>\n" + " </wps:RawDataOutput>\n" + " </wps:ResponseForm>\n" + " </wps:Execute>\n" + " </wps:Reference>\n" + " </wps:Input>\n" + " </wps:DataInputs>\n" + " <wps:ResponseForm>\n" + " <wps:RawDataOutput>\n" + " <ows:Identifier>result</ows:Identifier>\n" + " </wps:RawDataOutput>\n" + " </wps:ResponseForm>\n" + "</wps:Execute>"; MockHttpServletResponse resp = postAsServletResponse(root(), xml); assertEquals("text/plain", resp.getContentType()); // the result is inaccurate since the buffer is just a poor approximation of a circle Assert.assertTrue(resp.getContentAsString().matches("312\\..*")); }
From source file:org.geoserver.wps.ExecuteTest.java
@Test public void testProcessChainingKVP() throws Exception { String nested = "http://geoserver/wps?service=WPS&version=1.0.0&request=Execute&Identifier=JTS:buffer" + "&DataInputs=" + urlEncode("geom=POINT(0 0)@mimetype=application/wkt;distance=10") + "&RawDataOutput=result"; String request = "wps?service=WPS&version=1.0.0&request=Execute&Identifier=JTS:area" + "&DataInputs=" + urlEncode("geom=@href=" + nested) + "&RawDataOutput=result"; MockHttpServletResponse resp = getAsServletResponse(request); assertEquals("text/plain", resp.getContentType()); // the result is inaccurate since the buffer is just a poor approximation of a circle Assert.assertTrue(resp.getContentAsString().matches("312\\..*")); }
From source file:org.geoserver.wps.gs.download.DownloadAnimationProcessTest.java
@Test public void testAnimateBmTime() throws Exception { String xml = IOUtils.toString(getClass().getResourceAsStream("animateBlueMarble.xml")); MockHttpServletResponse response = postAsServletResponse("wps", xml); assertEquals("video/mp4", response.getContentType()); // JCodec API works off files only... File testFile = new File("target/animateBmTime.mp4"); FileUtils.writeByteArrayToFile(testFile, response.getContentAsByteArray()); // check frames and duration Format f = JCodecUtil.detectFormat(testFile); Demuxer d = JCodecUtil.createDemuxer(f, testFile); DemuxerTrack vt = d.getVideoTracks().get(0); DemuxerTrackMeta dtm = vt.getMeta(); assertEquals(4, dtm.getTotalFrames()); assertEquals(8, dtm.getTotalDuration(), 0d); // grab frames for checking File source = new File("src/test/resources/org/geoserver/wps/gs/download/bm_time.zip"); FrameGrab grabber = FrameGrab.createFrameGrab(NIOUtils.readableChannel(testFile)); // first//from w w w. j a v a 2 s . co m BufferedImage frame1 = AWTUtil.toBufferedImage(grabber.getNativeFrame()); BufferedImage expected1 = grabImageFromZip(source, "world.200402.3x5400x2700.tiff"); ImageAssert.assertEquals(expected1, frame1, 100); // second BufferedImage frame2 = AWTUtil.toBufferedImage(grabber.getNativeFrame()); BufferedImage expected2 = grabImageFromZip(source, "world.200403.3x5400x2700.tiff"); ImageAssert.assertEquals(expected2, frame2, 100); // third BufferedImage frame3 = AWTUtil.toBufferedImage(grabber.getNativeFrame()); BufferedImage expected3 = grabImageFromZip(source, "world.200404.3x5400x2700.tiff"); ImageAssert.assertEquals(expected3, frame3, 100); // fourth BufferedImage frame4 = AWTUtil.toBufferedImage(grabber.getNativeFrame()); BufferedImage expected4 = grabImageFromZip(source, "world.200405.3x5400x2700.tiff"); ImageAssert.assertEquals(expected4, frame4, 100); }
From source file:org.geoserver.wps.gs.download.DownloadAnimationProcessTest.java
@Test public void testAnimateDecoration() throws Exception { String xml = IOUtils.toString(getClass().getResourceAsStream("animateDecoration.xml")); MockHttpServletResponse response = postAsServletResponse("wps", xml); assertEquals("video/mp4", response.getContentType()); // JCodec API works off files only... File testFile = new File("target/animateWaterDecoration.mp4"); FileUtils.writeByteArrayToFile(testFile, response.getContentAsByteArray()); // check frames and duration Format f = JCodecUtil.detectFormat(testFile); Demuxer d = JCodecUtil.createDemuxer(f, testFile); DemuxerTrack vt = d.getVideoTracks().get(0); DemuxerTrackMeta dtm = vt.getMeta(); assertEquals(2, dtm.getTotalFrames()); assertEquals(2, dtm.getTotalDuration(), 0d); // grab first frame for test FrameGrab grabber = FrameGrab.createFrameGrab(NIOUtils.readableChannel(testFile)); BufferedImage frame1 = AWTUtil.toBufferedImage(grabber.getNativeFrame()); ImageAssert.assertEquals(new File(SAMPLES + "animateDecorateFirstFrame.png"), frame1, 100); }
From source file:org.geoserver.wps.gs.download.DownloadAnimationProcessTest.java
@Test public void testAnimateTimestamped() throws Exception { String xml = IOUtils.toString(getClass().getResourceAsStream("animateBlueMarbleTimestamped.xml")); MockHttpServletResponse response = postAsServletResponse("wps", xml); assertEquals("video/mp4", response.getContentType()); // JCodec API works off files only... File testFile = new File("target/animateTimestamped.mp4"); FileUtils.writeByteArrayToFile(testFile, response.getContentAsByteArray()); // check frames and duration Format f = JCodecUtil.detectFormat(testFile); Demuxer d = JCodecUtil.createDemuxer(f, testFile); DemuxerTrack vt = d.getVideoTracks().get(0); DemuxerTrackMeta dtm = vt.getMeta(); assertEquals(4, dtm.getTotalFrames()); assertEquals(8, dtm.getTotalDuration(), 0d); // grab first frame for test FrameGrab grabber = FrameGrab.createFrameGrab(NIOUtils.readableChannel(testFile)); BufferedImage frame1 = AWTUtil.toBufferedImage(grabber.getNativeFrame()); ImageAssert.assertEquals(new File(SAMPLES + "animateBlueMarbleTimestampedFrame1.png"), frame1, 100); }
From source file:org.geoserver.wps.gs.download.DownloadMapProcessTest.java
@Test public void testExecuteSingleLayer() throws Exception { String xml = IOUtils.toString(getClass().getResourceAsStream("mapSimple.xml")); MockHttpServletResponse response = postAsServletResponse("wps", xml); assertEquals("image/png", response.getContentType()); BufferedImage image = ImageIO.read(new ByteArrayInputStream(response.getContentAsByteArray())); ImageAssert.assertEquals(new File(SAMPLES + "mapSimple.png"), image, 100); }
From source file:org.geoserver.wps.gs.download.DownloadMapProcessTest.java
@Test public void testExecuteSingleLayerFilter() throws Exception { String xml = IOUtils.toString(getClass().getResourceAsStream("mapSimpleFilter.xml")); MockHttpServletResponse response = postAsServletResponse("wps", xml); assertEquals("image/png", response.getContentType()); BufferedImage image = ImageIO.read(new ByteArrayInputStream(response.getContentAsByteArray())); ImageAssert.assertEquals(new File(SAMPLES + "mapSimpleFilter.png"), image, 100); }