List of usage examples for org.springframework.mock.web MockHttpServletResponse getContentAsString
public String getContentAsString() throws UnsupportedEncodingException
From source file:org.geoserver.wps.ExecuteTest.java
@Test public void testReferenceOutputKVP() throws Exception { String request = "wps?service=WPS&version=1.0.0&request=Execute&Identifier=gs:BufferFeatureCollection" + "&DataInputs=" + urlEncode("features=" + readFileIntoString("states-FeatureCollection.xml") + "@mimetype=application/wfs-collection-1.1;distance=10") + "&ResponseDocument=" + urlEncode("result=@asReference=true"); Document d = getAsDOM(request); // print(d);//from ww w . jav a2s .c o m // check we got a valid response with the document as a reference checkValidationErrors(d); assertEquals("wps:ExecuteResponse", d.getDocumentElement().getNodeName()); assertXpathExists("/wps:ExecuteResponse/wps:Status/wps:ProcessSucceeded", d); assertXpathExists("/wps:ExecuteResponse/wps:ProcessOutputs/wps:Output/wps:Reference", d); XpathEngine xpath = XMLUnit.newXpathEngine(); String fullLocation = xpath .evaluate("/wps:ExecuteResponse/wps:ProcessOutputs/wps:Output/wps:Reference/@href", d); String resourceLocation = fullLocation.substring(fullLocation.indexOf('?') - 3); MockHttpServletResponse response = getAsServletResponse(resourceLocation); assertEquals("text/xml; subtype=wfs-collection/1.0", response.getContentType()); d = dom(new ByteArrayInputStream(response.getContentAsString().getBytes())); assertXpathExists("wfs:FeatureCollection", d); }
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 . jav 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());//from w ww. j a va 2 s .co m }
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.ExecuteTest.java
/** * Checks the bounds process returned the expected envelope * @param request/* w w w . j a v a2 s.co m*/ * @param id */ void executeState1BoundsTest(String request, String id) throws Exception { if (!RemoteOWSTestSupport.isRemoteWMSStatesAvailable(LOGGER)) { LOGGER.warning("Remote OWS tests disabled, skipping test with " + id + " reference source"); return; } MockHttpServletResponse resp = postAsServletResponse(root(), request); ReferencedEnvelope re = toEnvelope(resp.getContentAsString()); Assert.assertEquals(-91.516129, re.getMinX(), 0.001); Assert.assertEquals(36.986771, re.getMinY(), 0.001); Assert.assertEquals(-87.507889, re.getMaxX(), 0.001); Assert.assertEquals(42.509361, re.getMaxY(), 0.001); }
From source file:org.geowebcache.service.wmts.WMTSRestTest.java
@Test public void testGetCap() throws Exception { MockHttpServletRequest req = new MockHttpServletRequest(); req.setPathInfo("geowebcache/service/wmts/rest/WMTSCapabilities.xml"); MockHttpServletResponse resp = dispatch(req); assertEquals(200, resp.getStatus()); assertEquals("text/xml", resp.getContentType()); final Document doc = XMLUnit.buildTestDocument(resp.getContentAsString()); assertXpathExists("//wmts:Contents/wmts:Layer", doc); assertXpathExists("//wmts:Contents/wmts:Layer[ows:Identifier='mockLayer']", doc); assertXpathEvaluatesTo("2", "count(//wmts:Contents/wmts:Layer/wmts:Style/ows:Identifier)", doc); assertXpathExists("//wmts:Contents/wmts:Layer/wmts:Style[ows:Identifier='style-a']", doc); assertXpathExists("//wmts:Contents/wmts:Layer/wmts:Style[ows:Identifier='style-b']/wmts:LegendURL" + "[@width='125'][@height='130'][@format='image/png']" + "[@minScaleDenominator='5000.0'][@maxScaleDenominator='10000.0']" + "[@xlink:href='https://some-url?some-parameter=value3&another-parameter=value4']", doc); assertXpathExists("//wmts:Contents/wmts:Layer/wmts:ResourceURL[@resourceType='tile']" + "[@format='image/jpeg']" + "[@template='http://localhost/service/wmts/rest/" + "mockLayer/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}?format=image/jpeg&time={time}&elevation={elevation}']", doc);//w ww .ja v a 2 s .c o m assertXpathExists("//wmts:Contents/wmts:Layer/wmts:ResourceURL[@resourceType='FeatureInfo']" + "[@format='text/plain']" + "[@template='http://localhost/service/wmts/rest" + "/mockLayer/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}/{J}/{I}?format=text/plain&time={time}&elevation={elevation}']", doc); assertXpathExists("//wmts:ServiceMetadataURL[@xlink:href='http://localhost/service/wmts/rest" + "/WMTSCapabilities.xml']", doc); }
From source file:org.geowebcache.service.wmts.WMTSRestTest.java
@Test public void testOWSException() throws Exception { MockHttpServletRequest req = new MockHttpServletRequest(); req.setPathInfo("geowebcache/service/wmts/rest/mockLayer/EPSG:4326/EPSG:4326:0/0/0/0/0"); req.addParameter("format", "text/none"); MockHttpServletResponse resp = dispatch(req); assertEquals(HttpStatus.SC_BAD_REQUEST, resp.getStatus()); assertEquals("text/xml", resp.getContentType()); Document doc = XMLUnit.buildTestDocument(resp.getContentAsString()); assertXpathExists("//ows:ExceptionReport/ows:Exception[@exceptionCode='InvalidParameterValue']", doc); }
From source file:org.gwtwidgets.server.spring.test.TestRPCExporter.java
public void testExporter() throws Exception { try {/* www .ja v a2s . c o m*/ logger.info("stressTestExporter: testing RPC"); HttpServletRequest serviceRequest = getServiceRequest(); HandlerExecutionChain chain = handlerMapping.getHandler(serviceRequest); GWTRPCServiceExporter exporter = (GWTRPCServiceExporter) chain.getHandler(); long start = System.currentTimeMillis(); for (int i = 0; i < testCount; i++) { MockHttpServletResponse serviceResponse = getServiceResponse(); exporter.handleRequest(serviceRequest, serviceResponse); String sResponse = serviceResponse.getContentAsString(); assertEquals(responsePayload, sResponse); } long end = System.currentTimeMillis(); logger.info("stressTestExporter: " + testCount + " invocations in " + (end - start) + " ms"); } catch (Throwable t) { logger.error(t.getMessage(), t); fail(); } }
From source file:org.jasig.cas.support.oauth.web.OAuth20AccessTokenControllerTests.java
@Test public void verifyNoClientId() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.ACCESS_TOKEN_URL); mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI); mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET); mockRequest.setParameter(OAuthConstants.CODE, CODE); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.afterPropertiesSet(); oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertEquals(400, mockResponse.getStatus()); assertEquals("error=" + OAuthConstants.INVALID_REQUEST, mockResponse.getContentAsString()); }