001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/test/junit/org/deegree/ogcwebservices/wms/WMServiceTest.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstr. 19
030: 53115 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042:
043: ---------------------------------------------------------------------------*/
044: package org.deegree.ogcwebservices.wms;
045:
046: import java.awt.image.BufferedImage;
047: import java.io.File;
048: import java.io.FileOutputStream;
049: import java.net.URL;
050: import java.util.HashMap;
051: import java.util.Map;
052:
053: import javax.imageio.ImageIO;
054:
055: import junit.framework.Test;
056: import junit.framework.TestCase;
057: import junit.framework.TestSuite;
058:
059: import org.deegree.framework.util.StringTools;
060: import org.deegree.ogcwebservices.wms.operation.GetFeatureInfo;
061: import org.deegree.ogcwebservices.wms.operation.GetFeatureInfoResult;
062: import org.deegree.ogcwebservices.wms.operation.GetMap;
063: import org.deegree.ogcwebservices.wms.operation.GetMapResult;
064: import org.deegree.ogcwebservices.wms.operation.WMSGetCapabilities;
065:
066: /**
067: *
068: *
069: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
070: * @author last edited by: $Author: apoth $
071: * @version 1.0. $Revision: 9336 $, $Date: 2007-12-27 03:31:18 -0800 (Thu, 27 Dec 2007) $
072: * @since 2.0
073: */
074: public class WMServiceTest extends TestCase {
075:
076: /**
077: * @return a new instance
078: */
079: public static Test suite() {
080: return new TestSuite(WMServiceTest.class);
081: }
082:
083: /*
084: * @see TestCase#setUp()
085: */
086: @Override
087: protected void setUp() throws Exception {
088: super .setUp();
089: }
090:
091: /*
092: * @see TestCase#tearDown()
093: */
094: @Override
095: protected void tearDown() throws Exception {
096: super .tearDown();
097: }
098:
099: /**
100: * Constructor for GetCoverageTest
101: *
102: * @param arg0
103: */
104: public WMServiceTest(String arg0) {
105: super (arg0);
106: }
107:
108: /**
109: * reads a deegree WCS configuration file and performs a GetCapbilities
110: * request Steps:
111: * <ul>
112: * <li>read configuration file
113: * <li>read a GetCapabilites request object
114: * <li>perform the request
115: * </ul>
116: *
117: */
118: public void testGetCapabilities() {
119: try {
120: URL url = new File(
121: "resources/wms/wms_configuration_1-3-0_schema-supported_version_1-3-0.xml")
122: .toURL();
123: WMServiceFactory.setConfiguration(url);
124: WMService service = WMServiceFactory.getService();
125:
126: Map<String, String> map = new HashMap<String, String>();
127: map.put("SERVICE", "WMS");
128: map.put("REQUEST", "GetCapabilities");
129: map.put("VERSION", "1.1.1");
130:
131: // StringBuffer sb = new StringBuffer();
132: // sb.append("http://127.0.0.1/deegree/ogcwebservice?service=WMS&");
133: // sb.append("request=GetCapabilities&version=1.1.1");
134:
135: WMSGetCapabilities getCapa = WMSGetCapabilities.create(map);
136: Object o = service.doService(getCapa);
137: System.out.println("------------------------");
138: System.out.println(o);
139: System.out.println("------------------------");
140: } catch (Exception e) {
141: System.out.println(StringTools.stackTraceToString(e));
142: fail(StringTools.stackTraceToString(e));
143: }
144: }
145:
146: /**
147: * reads a deegree WMS configuration file and performs a GetMap request
148: * Steps:
149: * <ul>
150: * <li>read configuration file
151: * <li>read a GetMap request object
152: * <li>perform the request
153: * </ul>
154: *
155: */
156: public void testGetMap() {
157: try {
158: URL url = new File(
159: "resources/wms/wms_configuration_1-3-0_schema-supported_version_1-3-0.xml")
160: .toURL();
161: WMServiceFactory.setConfiguration(url);
162: WMService service = WMServiceFactory.getService();
163:
164: Map<String, String> map = new HashMap<String, String>();
165: map.put("ID", "89");
166: map.put("SERVICE", "WMS");
167: map.put("REQUEST", "GetMap");
168: map.put("VERSION", "1.1.1");
169: map.put("FORMAT", "image/jpeg");
170: map.put("TRANSPARENT", "false");
171: map.put("WIDTH", "450");
172: map.put("HEIGHT", "450");
173: map.put("EXCEPTIONS", "application/vnd.ogc.se_inimage");
174: map.put("BBOX", "-0.01,-0.01,0.01,0.01");
175: map.put("BGCOLOR", "0xffffff");
176: map.put("LAYERS", "cite:Buildings");
177: map.put("STYLES", "");
178: map.put("SRS", "EPSG:4326");
179:
180: //StringBuffer sb = new StringBuffer();
181: // sb.append("http://127.0.0.1/deegree/ogcwebservice?SERVICE=WMS&VERSION=1.1.1&");
182: // sb.append("REQUEST=GetMap&FORMAT=image/jpeg&TRANSPARENT=false&WIDTH=450&");
183: // sb.append("HEIGHT=450&EXCEPTIONS=application/vnd.ogc.se_inimage&");
184: // sb.append("BGCOLOR=0xffffff&BBOX=-0.01,-0.01,0.01,0.01");
185: // sb.append("&LAYERS=cite:Buildings");
186: // sb.append("&STYLES=&SRS=EPSG:4326");
187:
188: GetMap getMap = GetMap.create(map);
189:
190: Object o = service.doService(getMap);
191: BufferedImage bi = (BufferedImage) ((GetMapResult) o)
192: .getMap();
193: //FileOutputStream fos = new FileOutputStream(Configuration.WMS_BASEDIR + "/kannweg2.tif");
194: FileOutputStream fos = new FileOutputStream(File
195: .createTempFile("deegree", ".png"));
196: ImageIO.write(bi, "png", fos);
197: fos.close();
198: } catch (Exception e) {
199: //e.printStackTrace();
200: fail(StringTools.stackTraceToString(e));
201: }
202: }
203:
204: /**
205: * reads a deegree WMS configuration file and performs a GetMap request
206: * Steps:
207: * <ul>
208: * <li>read configuration file
209: * <li>read a GetMap request object
210: * <li>perform the request
211: * </ul>
212: *
213: */
214: public void testGetFeatureInfo() {
215: try {
216: URL url = new File(
217: "resources/wms/wms_configuration_1-3-0_schema-supported_version_1-3-0.xml")
218: .toURL();
219: WMServiceFactory.setConfiguration(url);
220: WMService service = WMServiceFactory.getService();
221:
222: Map<String, String> map = new HashMap<String, String>();
223: map.put("ID", "89");
224: map.put("SERVICE", "WMS");
225: map.put("REQUEST", "GetFeatureInfo");
226: map.put("VERSION", "1.1.1");
227: map.put("FORMAT", "image/jpeg");
228: map.put("TRANSPARENT", "false");
229: map.put("WIDTH", "450");
230: map.put("HEIGHT", "450");
231: map.put("EXCEPTIONS", "application/vnd.ogc.se_xml");
232: map
233: .put(
234: "BBOX",
235: "-9.920374269209355E-4,-4.833549380567929E-4,0.001381009448079065,0.0018896919369432081");
236: map.put("BGCOLOR", "0xffffff");
237: map
238: .put(
239: "LAYERS",
240: "cite:Forests,cite:Lakes,cite:Ponds,cite:NamedPlaces,"
241: + "cite:RoadSegments,cite:MapNeatline,cite:Streams,cite:DividedRoutes,"
242: + "cite:Buildings,cite:BuildingCenters,cite:Bridges");
243: map.put("STYLES", "");
244: map.put("SRS", "EPSG:4326");
245: map
246: .put(
247: "QUERY_LAYERS",
248: "cite:Forests,cite:Lakes,cite:Ponds,cite:NamedPlaces,"
249: + "cite:RoadSegments,cite:DividedRoutes,cite:Buildings,"
250: + "cite:BuildingCenters,cite:Bridges");
251: map.put("FEATURE_COUNT", "999");
252: map.put("INFO_FORMAT", "text/html");
253: map.put("X", "224");
254: map.put("Y", "226");
255:
256: // StringBuffer sb = new StringBuffer();
257: // sb.append("http://127.0.0.1/deegreewms/wms?service=WMS&VERSION=1.1.1&");
258: // sb.append("REQUEST=GetFeatureInfo&TRANSPARENCY=false&WIDTH=450&HEIGHT");
259: // sb.append("=450&FORMAT=image/jpeg&EXCEPTIONS=application/vnd.ogc.se_xml");
260: // sb.append("&BGCOLOR=0xffffff&SRS=EPSG:4326&BBOX=-9.920374269209355E-4,");
261: // sb.append("-4.833549380567929E-4,0.001381009448079065,0.0018896919369432081");
262: // sb.append("&LAYERS=cite:Forests,cite:Lakes,cite:Ponds,cite:NamedPlaces,");
263: // sb.append("cite:RoadSegments,cite:MapNeatline,cite:Streams,cite:DividedRoutes,");
264: // sb.append("cite:Buildings,cite:BuildingCenters,cite:Bridges&STYLES=&");
265: // sb.append("QUERY_LAYERS=cite:Forests,cite:Lakes,cite:Ponds,cite:NamedPlaces,");
266: // sb.append("cite:RoadSegments,cite:DividedRoutes,cite:Buildings,");
267: // sb.append("cite:BuildingCenters,cite:Bridges&FEATURE_COUNT=999&INFO_FORMAT=");
268: // sb.append("text/html&X=224&Y=226");
269:
270: GetFeatureInfo getFI = GetFeatureInfo.create(map);
271: Object o = service.doService(getFI);
272: System.out.println("------------------------");
273: System.out.println(((GetFeatureInfoResult) o)
274: .getFeatureInfo());
275: System.out.println("------------------------");
276: } catch (Exception e) {
277: System.out.println(StringTools.stackTraceToString(e));
278: fail(StringTools.stackTraceToString(e));
279: }
280: }
281:
282: }
|