01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.data.wms.test;
17:
18: import java.io.IOException;
19: import java.io.InputStream;
20: import java.net.URL;
21: import java.util.HashMap;
22: import java.util.StringTokenizer;
23:
24: import org.geotools.data.ows.AbstractGetCapabilitiesRequest;
25: import org.geotools.data.ows.Response;
26: import org.geotools.data.wms.response.WMSGetCapabilitiesResponse;
27: import org.geotools.ows.ServiceException;
28:
29: /**
30: *
31: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/wms/src/test/java/org/geotools/data/wms/test/GetCapabilitiesRequestTest.java $
32: */
33: public class GetCapabilitiesRequestTest extends ServerTestCase {
34: public void testGetCapabilitiesRequest() throws Exception {
35: URL testURL = new URL(
36: "http://office.refractions.net:4001/cgi-bin/mapserv?map=/opt/dra2/orthophotos/tiles.map&");
37: AbstractGetCapabilitiesRequest request = new Request(testURL);
38: URL finalURL = request.getFinalURL();
39:
40: int index = finalURL.toExternalForm().lastIndexOf("?");
41: String urlWithoutQuery = null;
42: urlWithoutQuery = finalURL.toExternalForm().substring(0, index);
43:
44: assertEquals(urlWithoutQuery,
45: "http://office.refractions.net:4001/cgi-bin/mapserv");
46:
47: HashMap map = new HashMap();
48: map.put("VERSION", "1.1.1");
49: map.put("MAP", "/opt/dra2/orthophotos/tiles.map");
50: map.put("REQUEST", "GetCapabilities");
51: map.put("SERVICE", "WMS");
52:
53: StringTokenizer tokenizer = new StringTokenizer(finalURL
54: .getQuery(), "&");
55:
56: while (tokenizer.hasMoreTokens()) {
57: String token = tokenizer.nextToken();
58: String[] param = token.split("=");
59:
60: assertEquals((String) map.get(param[0]), param[1]);
61: }
62: }
63:
64: protected class Request extends AbstractGetCapabilitiesRequest {
65: /**
66: * DOCUMENT ME!
67: *
68: * @param serverURL
69: */
70: public Request(URL serverURL) {
71: super (serverURL);
72:
73: // TODO Auto-generated constructor stub
74: }
75:
76: /* (non-Javadoc)
77: * @see org.geotools.data.wms.request.AbstractGetCapabilitiesRequest#initVersion()
78: */
79: protected void initVersion() {
80: setProperty("VERSION", "1.1.1");
81: }
82:
83: protected void initService() {
84: setProperty("SERVICE", "WMS");
85: }
86:
87: public Response createResponse(String contentType,
88: InputStream inputStream) throws ServiceException,
89: IOException {
90: return new WMSGetCapabilitiesResponse(contentType,
91: inputStream);
92: }
93: }
94: }
|