001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.wms.test;
017:
018: import java.io.BufferedReader;
019: import java.io.IOException;
020: import java.io.InputStreamReader;
021: import java.net.URISyntaxException;
022: import java.net.URL;
023: import java.util.Properties;
024:
025: import org.geotools.data.ows.CRSEnvelope;
026: import org.geotools.data.ows.Layer;
027: import org.geotools.data.ows.Specification;
028: import org.geotools.data.ows.WMSCapabilities;
029: import org.geotools.data.wms.WMS1_3_0;
030: import org.geotools.data.wms.WebMapServer;
031: import org.geotools.data.wms.request.GetFeatureInfoRequest;
032: import org.geotools.data.wms.request.GetMapRequest;
033: import org.geotools.data.wms.response.GetFeatureInfoResponse;
034: import org.xml.sax.SAXException;
035:
036: /**
037: * @author rgould
038: *
039: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/wms/src/test/java/org/geotools/data/wms/test/WMS1_3_0_OnlineTest.java $
040: */
041: public class WMS1_3_0_OnlineTest extends WMS1_1_1_OnlineTest {
042:
043: private URL server2;
044:
045: public WMS1_3_0_OnlineTest() throws Exception {
046: this .spec = new WMS1_3_0();
047: this .server = new URL(
048: "http://www2.demis.nl/mapserver/Request.asp?Service=WMS&Version=1.3.0&Request=GetCapabilities");
049:
050: //TODO this server has changed - need to update the three commented out tests below - preferably, find a new server
051: this .server2 = new URL(
052: "http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi?CONFIG=main&REQUEST=GetCapabilities&VERSION=1.3.0");
053: }
054:
055: public void testGetVersion() {
056: assertEquals(spec.getVersion(), "1.3.0");
057: }
058:
059: protected void checkProperties(Properties properties) {
060: assertEquals(properties.get("VERSION"), "1.3.0");
061: assertEquals(properties.get("REQUEST"), "GetCapabilities");
062: assertEquals(properties.get("SERVICE"), "WMS");
063: }
064:
065: public void testCreateParser() throws Exception {
066: try {
067: WMSCapabilities capabilities = createCapabilities("1.3.0Capabilities.xml");
068:
069: assertNotNull(capabilities);
070:
071: assertEquals(capabilities.getVersion(), "1.3.0");
072: assertEquals(capabilities.getService().getName(), "WMS");
073: assertEquals(capabilities.getService().getTitle(),
074: "World Map");
075: assertEquals(capabilities.getService().get_abstract(),
076: "None");
077: assertEquals(capabilities.getService().getOnlineResource(),
078: new URL("http://www2.demis.nl"));
079:
080: assertEquals(capabilities.getService().getLayerLimit(), 40);
081: assertEquals(capabilities.getService().getMaxWidth(), 2000);
082: assertEquals(capabilities.getService().getMaxHeight(), 2000);
083:
084: assertEquals(capabilities.getRequest().getGetCapabilities()
085: .getFormats().get(0), "text/xml");
086: assertEquals(capabilities.getRequest().getGetCapabilities()
087: .getGet(), new URL(
088: "http://www2.demis.nl/wms/wms.asp?wms=WorldMap&"));
089: assertEquals(capabilities.getRequest().getGetCapabilities()
090: .getPost(), new URL(
091: "http://www2.demis.nl/wms/wms.asp?wms=WorldMap&"));
092:
093: assertEquals(capabilities.getRequest().getGetMap()
094: .getFormats().size(), 5);
095: assertEquals(capabilities.getRequest().getGetMap()
096: .getFormats().get(0), "image/gif");
097: assertEquals(capabilities.getRequest().getGetMap()
098: .getFormats().get(1), "image/png");
099: assertEquals(capabilities.getRequest().getGetMap()
100: .getFormats().get(2), "image/jpeg");
101: assertEquals(capabilities.getRequest().getGetMap()
102: .getFormats().get(3), "image/bmp");
103: assertEquals(capabilities.getRequest().getGetMap()
104: .getFormats().get(4), "image/swf");
105: assertEquals(
106: capabilities.getRequest().getGetMap().getGet(),
107: new URL(
108: "http://www2.demis.nl/wms/wms.asp?wms=WorldMap&"));
109:
110: assertEquals(capabilities.getRequest().getGetFeatureInfo()
111: .getFormats().size(), 4);
112: assertEquals(capabilities.getRequest().getGetFeatureInfo()
113: .getFormats().get(0), "text/xml");
114: assertEquals(capabilities.getRequest().getGetFeatureInfo()
115: .getFormats().get(1), "text/plain");
116: assertEquals(capabilities.getRequest().getGetFeatureInfo()
117: .getFormats().get(2), "text/html");
118: assertEquals(capabilities.getRequest().getGetFeatureInfo()
119: .getFormats().get(3), "text/swf");
120: assertEquals(capabilities.getRequest().getGetFeatureInfo()
121: .getGet(), new URL(
122: "http://www2.demis.nl/wms/wms.asp?wms=WorldMap&"));
123:
124: Layer topLayer = (Layer) capabilities.getLayerList().get(0);
125: assertNotNull(topLayer);
126: assertNull(topLayer.getParent());
127: assertFalse(topLayer.isQueryable());
128: assertEquals(topLayer.getTitle(), "World Map");
129: assertEquals(topLayer.getSrs().size(), 1);
130: assertTrue(topLayer.getSrs().contains("CRS:84"));
131:
132: CRSEnvelope llbbox = topLayer.getLatLonBoundingBox();
133: assertNotNull(llbbox);
134: assertEquals(llbbox.getMinX(), -180, 0.0);
135: assertEquals(llbbox.getMaxX(), 180, 0.0);
136: assertEquals(llbbox.getMinY(), -90, 0.0);
137: assertEquals(llbbox.getMaxY(), 90, 0.0);
138:
139: assertEquals(topLayer.getBoundingBoxes().size(), 1);
140:
141: CRSEnvelope bbox = (CRSEnvelope) topLayer
142: .getBoundingBoxes().get("CRS:84");
143: assertNotNull(bbox);
144: assertEquals(bbox.getEPSGCode(), "CRS:84");
145: assertEquals(bbox.getMinX(), -184, 0.0);
146: assertEquals(bbox.getMaxX(), 180, 0.0);
147: assertEquals(bbox.getMinY(), -90.0000000017335, 0.0);
148: assertEquals(bbox.getMaxY(), 90, 0.0);
149:
150: Layer layer = (Layer) capabilities.getLayerList().get(1);
151: assertEquals(layer.getParent(), topLayer);
152: assertTrue(layer.isQueryable());
153: assertEquals(layer.getName(), "Bathymetry");
154: assertEquals(layer.getTitle(), "Bathymetry");
155:
156: // Added test to verify inheritance, should be same as previous llbbox
157: llbbox = topLayer.getLatLonBoundingBox();
158: assertNotNull(llbbox);
159: assertEquals(llbbox.getMinX(), -180, 0.0);
160: assertEquals(llbbox.getMaxX(), 180, 0.0);
161: assertEquals(llbbox.getMinY(), -90, 0.0);
162: assertEquals(llbbox.getMaxY(), 90, 0.0);
163:
164: bbox = (CRSEnvelope) layer.getBoundingBoxes().get("CRS:84");
165: assertNotNull(bbox);
166: assertEquals(bbox.getEPSGCode(), "CRS:84");
167: assertEquals(bbox.getMinX(), -180, 0.0);
168: assertEquals(bbox.getMaxX(), 180, 0.0);
169: assertEquals(bbox.getMinY(), -90, 0.0);
170: assertEquals(bbox.getMaxY(), 90, 0.0);
171:
172: assertEquals(capabilities.getLayerList().size(), 21);
173:
174: layer = (Layer) capabilities.getLayerList().get(20);
175: assertEquals(layer.getParent(), topLayer);
176: assertTrue(layer.isQueryable());
177: assertEquals(layer.getName(), "Ocean features");
178: assertEquals(layer.getTitle(), "Ocean features");
179:
180: // Added test to verify inheritance, should be same as previous llbbox
181: llbbox = topLayer.getLatLonBoundingBox();
182: assertNotNull(llbbox);
183: assertEquals(llbbox.getMinX(), -180, 0.0);
184: assertEquals(llbbox.getMaxX(), 180, 0.0);
185: assertEquals(llbbox.getMinY(), -90, 0.0);
186: assertEquals(llbbox.getMaxY(), 90, 0.0);
187:
188: bbox = (CRSEnvelope) layer.getBoundingBoxes().get("CRS:84");
189: assertNotNull(bbox);
190: assertEquals(bbox.getEPSGCode(), "CRS:84");
191: assertEquals(bbox.getMinX(), -180, 0.0);
192: assertEquals(bbox.getMaxX(), 179.999420166016, 0.0);
193: assertEquals(bbox.getMinY(), -62.9231796264648, 0.0);
194: assertEquals(bbox.getMaxY(), 68.6906585693359, 0.0);
195: } catch (java.net.ConnectException ce) {
196: if (ce.getMessage().indexOf("timed out") > 0) {
197: System.err.println("Unable to test - timed out: " + ce);
198: } else {
199: throw (ce);
200: }
201: }
202: }
203:
204: public void testCreateGetMapRequest() throws Exception {
205: WebMapServer wms = new WebMapServer(server2);
206: GetMapRequest request = wms.createGetMapRequest();
207: request.setFormat("image/jpeg");
208: System.out.println(request.getFinalURL().toExternalForm());
209:
210: assertTrue(request.getFinalURL().toExternalForm().indexOf(
211: "image%2Fjpeg") >= 0);
212: }
213:
214: public void testCreateGetFeatureInfoRequest() throws Exception {
215: try {
216: URL featureURL = new URL(
217: "http://demo.cubewerx.com/cipi12/cubeserv/cubeserv.cgi?service=wms&request=getcapabilities");
218: WebMapServer wms = getCustomWMS(featureURL);
219: WMSCapabilities caps = wms.getCapabilities();
220: assertNotNull(caps);
221: assertNotNull(caps.getRequest().getGetFeatureInfo());
222:
223: GetMapRequest getMapRequest = wms.createGetMapRequest();
224:
225: getMapRequest.setProperty(GetMapRequest.LAYERS,
226: "ETOPO2:Foundation");
227: // List simpleLayers = getMapRequest.getAvailableLayers();
228: // Iterator iter = simpleLayers.iterator();
229: // while (iter.hasNext()) {
230: // SimpleLayer simpleLayer = (SimpleLayer) iter.next();
231: // Object[] styles = simpleLayer.getValidStyles().toArray();
232: // if (styles.length == 0) {
233: // simpleLayer.setStyle("");
234: // continue;
235: // }
236: // Random random = new Random();
237: // int randomInt = random.nextInt(styles.length);
238: // simpleLayer.setStyle((String) styles[randomInt]);
239: // }
240: // getMapRequest.setLayers(simpleLayers);
241:
242: getMapRequest.setSRS("EPSG:4326");
243: getMapRequest.setDimensions("400", "400");
244: getMapRequest.setFormat("image/png");
245: // http://demo.cubewerx.com/cipi12/cubeserv/cubeserv.cgi?INFO_FORMAT=text/html&LAYERS=ETOPO2:Foundation&FORMAT=image/png&HEIGHT=400&J=200&REQUEST=GetFeatureInfo&I=200&BBOX=-34.12087,15.503481,1.8462441,35.6043956&WIDTH=400&STYLES=&SRS=EPSG:4326&QUERY_LAYERS=ETOPO2:Foundation&VERSION=1.3.0
246: getMapRequest
247: .setBBox("-34.12087,15.503481,1.8462441,35.6043956");
248: URL url2 = getMapRequest.getFinalURL();
249:
250: GetFeatureInfoRequest request = wms
251: .createGetFeatureInfoRequest(getMapRequest);
252: // request.setQueryLayers(request.getQueryableLayers());
253: request.setProperty(GetFeatureInfoRequest.QUERY_LAYERS,
254: "ETOPO2:Foundation");
255: request.setQueryPoint(200, 200);
256: request.setInfoFormat("text/html");
257:
258: //System.out.println(request.getFinalURL());
259:
260: // TODO Currently this server rtreturns code 400 !?
261: GetFeatureInfoResponse response = (GetFeatureInfoResponse) wms
262: .issueRequest(request);
263: //System.out.println(response.getContentType());
264: assertTrue(response.getContentType().indexOf("text/html") != -1);
265: BufferedReader in = new BufferedReader(
266: new InputStreamReader(response.getInputStream()));
267: String line;
268:
269: boolean textFound = false;
270: while ((line = in.readLine()) != null) {
271: //System.out.println(line);
272: if (line.indexOf("CubeSERV Feature Query") != -1) {
273: textFound = true;
274: break;
275: }
276: }
277: assertTrue(textFound);
278: } catch (java.net.ConnectException ce) {
279: if (ce.getMessage().indexOf("timed out") > 0) {
280: System.err.println("Unable to test - timed out: " + ce);
281: } else {
282: throw (ce);
283: }
284: }
285:
286: }
287:
288: public void testCreateDescribeLayerRequest() throws Exception {
289: /*try{
290:
291: WebMapServer wms = new CustomWMS(server2);
292:
293: DescribeLayerRequest request = wms.createDescribeLayerRequest();
294: assertNotNull(request);
295: // http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi?CONFIG=main&REQUEST=DescribeLayer&SERVICE=wms&VERSION=1.3.0&LAYERS=BARRIERL_1M:Foundation,POLBNDP_1M:Foundation,DQLINE_UTIL_1M:Foundation
296: request.setLayers("BARRIERL_1M:Foundation,POLBNDP_1M:Foundation,DQLINE_UTIL_1M:Foundation");
297: System.out.println(request.getFinalURL());
298: DescribeLayerResponse response = (DescribeLayerResponse) wms.issueRequest(request);
299: assertNotNull(response);
300:
301: LayerDescription[] layerDescs = response.getLayerDescs();
302: assertEquals(layerDescs.length, 3);
303:
304: assertEquals(layerDescs[0].getName(), "BARRIERL_1M:Foundation");
305: assertEquals(layerDescs[1].getName(), "POLBNDP_1M:Foundation");
306: assertEquals(layerDescs[2].getName(), "DQLINE_UTIL_1M:Foundation");
307:
308: assertEquals(layerDescs[0].getWfs(), new URL("http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi?CONFIG=main&SERVICE=WFS&DATASTORE=Foundation&"));
309: assertEquals(layerDescs[1].getWfs(), new URL("http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi?CONFIG=main&SERVICE=WFS&DATASTORE=Foundation&"));
310: assertEquals(layerDescs[2].getWfs(), new URL("http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi?CONFIG=main&SERVICE=WFS&DATASTORE=Foundation&"));
311:
312: assertEquals(layerDescs[0].getQueries().length, 1);
313: assertEquals(layerDescs[1].getQueries().length, 1);
314: assertEquals(layerDescs[2].getQueries().length, 1);
315:
316: assertEquals(layerDescs[0].getQueries()[0], "BARRIERL_1M");
317: assertEquals(layerDescs[1].getQueries()[0], "POLBNDP_1M");
318: assertEquals(layerDescs[2].getQueries()[0], "DQLINE_UTIL_1M");
319: } catch(java.net.ConnectException ce){
320: if(ce.getMessage().indexOf("timed out")>0){
321: System.err.println("Unable to test - timed out: "+ce);
322: } else{
323: throw(ce);
324: }
325: }*/
326: }
327:
328: public void testCreateGetLegendGraphicRequest() throws Exception {
329: /*try{
330: WebMapServer wms = new CustomWMS(server2);
331: GetLegendGraphicRequest request = wms.createGetLegendGraphicRequest();
332:
333: assertNotNull(request);
334:
335: Layer[] layers = WMSUtils.getNamedLayers(wms.getCapabilities());
336: SimpleLayer layer = null;
337: for (int i = 0; i < layers.length; i++) {
338: if (layers[i].getName().equals("BARRIERL_1M:Foundation")) {
339: layer = new SimpleLayer(layers[i].getName(), "");
340: break;
341: }
342: }
343:
344: assertNotNull(layer);
345:
346: layer.setStyle("");
347: request.setLayer(layer);
348:
349: request.setFormat("image/gif");
350:
351: request.setWidth("50");
352: request.setHeight("50");
353:
354: System.out.println(request.getFinalURL());
355:
356: GetLegendGraphicResponse response = (GetLegendGraphicResponse) wms.issueRequest(request);
357: assertNotNull(response);
358:
359: assertEquals(response.getContentType(), "image/gif");
360:
361: BufferedImage image = ImageIO.read(response.getInputStream());
362: assertEquals(image.getHeight(), 50);
363: } catch(java.net.ConnectException ce){
364: if(ce.getMessage().indexOf("timed out")>0){
365: System.err.println("Unable to test - timed out: "+ce);
366: } else{
367: throw(ce);
368: }
369: }*/
370: }
371:
372: public void testParamEncoding() throws Exception {
373: //this request does not work because it is encoded properly
374: //Let's make sure that this doesn't happen again.
375: // http://demo.cubewerx.com/cipi12/cubeserv/cubeserv.cgi?LAYERS=BARRIERL_1M%3AFoundation%2CBNDTXT_1M%3AFoundation&
376: // FORMAT=image%2Fpng&TRANSPARENT=TRUE&HEIGHT=296&REQUEST=GetMap&
377: // BBOX=9.543194770812995%2C2.9407237508305797%2C119.99700164794902%2C59.50530305123241&
378: // WIDTH=577&STYLES=%2C&SRS=EPSG%3A4269&VERSION=1.1.1
379: /* try{
380: WebMapServer wms = new CustomWMS(server2);
381: GetMapRequest request = wms.createGetMapRequest();
382:
383: List layers = new ArrayList();
384: layers.add(new SimpleLayer("BARRIERL_1M:Foundation", ""));
385: layers.add(new SimpleLayer("BNDTXT_1M:Foundation", ""));
386: request.setLayers(layers);
387: request.setSRS("EPSG:4269");
388: request.setDimensions("566", "296");
389: request.setTransparent(true);
390: request.setFormat("image/png");
391: request.setBBox("9.543194770812995,2.9407237508305797,119.99700164794902,59.50530305123241");
392:
393: GetMapResponse response = wms.issueRequest(request);
394:
395: BufferedImage image = ImageIO.read(response.getInputStream());
396: assertEquals(image.getHeight(), 296);
397: } catch(java.net.ConnectException ce){
398: if(ce.getMessage().indexOf("timed out")>0){
399: System.err.println("Unable to test - timed out: "+ce);
400: } else{
401: throw(ce);
402: }
403: }*/
404: }
405:
406: protected WebMapServer getCustomWMS(URL featureURL)
407: throws SAXException, URISyntaxException, IOException {
408: return new CustomWMS(featureURL);
409: }
410:
411: //forces use of 1.3.0 spec
412: private class CustomWMS extends WebMapServer {
413:
414: /**
415: * @param serverURL
416: * @param wait
417: * @throws SAXException
418: * @throws URISyntaxException
419: * @throws IOException
420: */
421: public CustomWMS(URL serverURL) throws SAXException,
422: URISyntaxException, IOException {
423: super (serverURL);
424: // TODO Auto-generated constructor stub
425: }
426:
427: protected void setupSpecifications() {
428: specs = new Specification[1];
429: specs[0] = new WMS1_3_0();
430: }
431: }
432: }
|