001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/test/junit/org/deegree/ogcwebservices/wcs/WCServiceTest.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.wcs;
045:
046: import java.awt.image.BufferedImage;
047: import java.io.FileOutputStream;
048: import java.io.StringReader;
049: import java.net.URL;
050: import java.util.HashMap;
051: import java.util.Map;
052:
053: import junit.framework.Test;
054: import junit.framework.TestCase;
055: import junit.framework.TestSuite;
056:
057: import org.deegree.framework.util.ImageUtils;
058: import org.deegree.framework.util.StringTools;
059: import org.deegree.framework.xml.XMLFragment;
060: import org.deegree.framework.xml.XMLTools;
061: import org.deegree.model.coverage.grid.AbstractGridCoverage;
062: import org.deegree.ogcwebservices.OGCRequestFactory;
063: import org.deegree.ogcwebservices.wcs.configuration.WCSConfiguration;
064: import org.deegree.ogcwebservices.wcs.describecoverage.CoverageDescription;
065: import org.deegree.ogcwebservices.wcs.describecoverage.DescribeCoverage;
066: import org.deegree.ogcwebservices.wcs.getcapabilities.WCSGetCapabilities;
067: import org.deegree.ogcwebservices.wcs.getcoverage.GetCoverage;
068: import org.deegree.ogcwebservices.wcs.getcoverage.ResultCoverage;
069: import org.w3c.dom.Document;
070:
071: import alltests.Configuration;
072:
073: /**
074: *
075: *
076: * @version $Revision: 9336 $
077: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
078: * @author last edited by: $Author: apoth $
079: *
080: * @version 1.0. $Revision: 9336 $, $Date: 2007-12-27 03:31:18 -0800 (Thu, 27 Dec 2007) $
081: *
082: * @since 2.0
083: */
084: public class WCServiceTest extends TestCase {
085:
086: /**
087: * @return a test
088: */
089: public static Test suite() {
090: return new TestSuite(WCServiceTest.class);
091: }
092:
093: /*
094: * @see TestCase#setUp()
095: */
096: @Override
097: protected void setUp() throws Exception {
098: super .setUp();
099: }
100:
101: /*
102: * @see TestCase#tearDown()
103: */
104: @Override
105: protected void tearDown() throws Exception {
106: super .tearDown();
107: }
108:
109: /**
110: * Constructor for GetCoverageTest
111: *
112: * @param arg0
113: */
114: public WCServiceTest(String arg0) {
115: super (arg0);
116: }
117:
118: /**
119: * reads a deegree WCS configuration file and performs a GetCapbilities request Steps:
120: * <ul>
121: * <li>read configuration file
122: * <li>read a GetCapabilites request object
123: * <li>perform the request
124: * </ul>
125: *
126: */
127: public void testGetCapabilities() {
128: try {
129: WCSConfiguration configuration = WCSConfiguration
130: .create(Configuration.getWCSConfigurationURL());
131: WCService service = new WCService(configuration);
132: // StringBuffer sb = new StringBuffer();
133: // sb.append( "http://127.0.0.1/deegreewcs/wcs?service=WCS&" );
134: // sb.append( "request=GetCapabilities&version=1.0.0" );
135: Map<String, String> map = new HashMap<String, String>();
136: map.put("REQUEST", "GetCapabilities");
137: map.put("VERSION", "1.0.0");
138: map.put("SERVICE", "WCS");
139: WCSGetCapabilities getCapa = (WCSGetCapabilities) WCSGetCapabilities
140: .create(map);
141: // (WCSGetCapabilities) OGCRequestFactory.createFromKVP(sb.toString());
142: Object o = service.doService(getCapa);
143: XMLFragment xml = XMLFactory.export((WCSConfiguration) o);
144: xml.write(System.out);
145: } catch (Exception e) {
146: System.out.println(StringTools.stackTraceToString(e));
147: fail(StringTools.stackTraceToString(e));
148: }
149: }
150:
151: /**
152: * reads a deegree WCS configuration file and performs a GetCoverage request Steps:
153: * <ul>
154: * <li>read configuration file
155: * <li>read a GetCoverage request object
156: * <li>perform the request
157: * </ul>
158: */
159: public void _testGetCoverage1() {
160: try {
161: WCSConfiguration configuration = WCSConfiguration
162: .create(Configuration.getWCSConfigurationURL());
163: WCService service = new WCService(configuration);
164: StringBuffer sb = new StringBuffer();
165: sb
166: .append(
167: Configuration.PROTOCOL + "://"
168: + Configuration.HOST).append(':')
169: .append(Configuration.PORT).append(
170: Configuration.WCS_WEB_CONTEXT).append('/')
171: .append(Configuration.WCS_SERVLET);
172:
173: String req = "<?xml version='1.0' encoding='UTF-8'?><GetCoverage "
174: + "xmlns='http://www.opengis.net/wcs' xmlns:gml='http://www.opengis.net/gml' "
175: + "service='WCS' version='1.0.0'><sourceCoverage>Mapneatline</sourceCoverage>"
176: + "<domainSubset><spatialSubset><gml:Envelope srsName='EPSG:4326'>"
177: + "<gml:pos dimension='2'>-1,-1</gml:pos><gml:pos dimension='2'>1,1"
178: + "</gml:pos></gml:Envelope><gml:Grid dimension='2'><gml:limits>"
179: + "<gml:GridEnvelope><gml:low>0 0</gml:low><gml:high>300 300</gml:high>"
180: + "</gml:GridEnvelope></gml:limits><gml:axisName>x</gml:axisName>"
181: + "<gml:axisName>y</gml:axisName></gml:Grid></spatialSubset></domainSubset>"
182: + "<output><crs>EPSG:4326</crs><format>jpeg</format></output></GetCoverage>";
183: StringReader reader = new StringReader(req);
184: Document doc = XMLTools.parse(reader);
185:
186: GetCoverage desc = (GetCoverage) OGCRequestFactory
187: .createFromXML(doc);
188: ResultCoverage o = (ResultCoverage) service.doService(desc);
189: BufferedImage bi = ((AbstractGridCoverage) o.getCoverage())
190: .getAsImage(500, 500);
191:
192: FileOutputStream fos = new FileOutputStream(Configuration
193: .getWCSBaseDir().getPath()
194: + "/kannweg1.tif");
195: ImageUtils.saveImage(bi, fos, "tif", 1);
196: fos.close();
197: } catch (Exception e) {
198: System.out.println(StringTools.stackTraceToString(e));
199: fail(StringTools.stackTraceToString(e));
200: }
201: }
202:
203: /**
204: * reads a deegree WCS configuration file and performs a GetCoverage request. same as
205: * testGetCoverage1() but uses nameIndexed data source Steps:
206: * <ul>
207: * <li>read configuration file
208: * <li>read a GetCoverage request object
209: * <li>perform the request
210: * </ul>
211: *
212: */
213: public void _testGetCoverage2() {
214: try {
215: WCSConfiguration configuration = WCSConfiguration
216: .create(Configuration.getWCSConfigurationURL());
217: WCService service = new WCService(configuration);
218:
219: Map<String, String> map = new HashMap<String, String>();
220: map.put("SERVICE", "WCS");
221: map.put("REQUEST", "GetCoverage");
222: map.put("VERSION", "1.0.0");
223: map.put("COVERAGE", "dem");
224: map.put("CRS", "EPSG:4326");
225: map.put("BBOX", "-122.6261,37.4531,-122.0777,38.0");
226: map.put("WIDTH", "828");
227: map.put("HEIGHT", "823");
228: map.put("FORMAT", "GeoTiff");
229:
230: // StringBuffer sb = new StringBuffer();
231: // sb.append(Configuration.PROTOCOL + "://" + Configuration.HOST).append(':').append(
232: // Configuration.PORT).append('/').append(Configuration.WCS_WEB_CONTEXT).append(
233: // '/').append(Configuration.WCS_SERVLET).append("?service=WCS&").append(
234: // "request=GetCoverage&version=1.0.0&coverage=dem&").append(
235: // "crs=EPSG:4326&BBOX=-122.6261,37.4531,-122.0777,38.0&Width=828&height=823&")
236: // .append("format=GeoTiff");
237: GetCoverage desc = GetCoverage.create(map);
238: ResultCoverage o = (ResultCoverage) service.doService(desc);
239: BufferedImage bi = ((AbstractGridCoverage) o.getCoverage())
240: .getAsImage(828, 823);
241: System.out.println(o);
242: FileOutputStream fos = new FileOutputStream(new URL(
243: Configuration.getWCSBaseDir(), "/kannweg2.tif")
244: .getFile());
245: ImageUtils.saveImage(bi, fos, "tif", 1);
246: fos.close();
247: } catch (Exception e) {
248: System.out.println(StringTools.stackTraceToString(e));
249: fail(StringTools.stackTraceToString(e));
250: }
251: }
252:
253: /**
254: * reads a deegree WCS configuration file and performs a GetCoverage request Steps:
255: * <ul>
256: * <li>read configuration file
257: * <li>read a GetCoverage request object
258: * <li>perform the request
259: * </ul>
260: *
261: */
262: public void _testGetCoverage3() {
263: try {
264: WCSConfiguration configuration = WCSConfiguration
265: .create(Configuration.getWCSConfigurationURL());
266: WCService service = new WCService(configuration);
267:
268: Map<String, String> map = new HashMap<String, String>();
269: map.put("SERVICE", "WCS");
270: map.put("REQUEST", "GetCoverage");
271: map.put("VERSION", "1.0.0");
272: map.put("COVERAGE", "europe");
273: map.put("CRS", "EPSG:4326");
274: map.put("BBOX", "-5,40,20,60");
275: map.put("WIDTH", "800");
276: map.put("HEIGHT", "800");
277: map.put("FORMAT", "jpeg");
278:
279: // StringBuffer sb = new StringBuffer();
280: // sb.append(Configuration.PROTOCOL + "://" + Configuration.HOST)
281: // .append(':').append(Configuration.PORT).append('/')
282: // .append(Configuration.WCS_WEB_CONTEXT).append('/')
283: // .append(Configuration.WCS_SERVLET).append("?service=WCS&")
284: // .append("request=GetCoverage&version=1.0.0&coverage=europe&")
285: // .append( "crs=EPSG:4326&BBOX=-5,40,20,60&Width=800&height=800&")
286: // .append("format=jpeg");
287: GetCoverage desc = GetCoverage.create(map);
288: ResultCoverage o = (ResultCoverage) service.doService(desc);
289: BufferedImage bi = ((AbstractGridCoverage) o.getCoverage())
290: .getAsImage(800, 800);
291:
292: FileOutputStream fos = new FileOutputStream(Configuration
293: .getWCSBaseDir().getPath()
294: + "/kannweg3.tif");
295: ImageUtils.saveImage(bi, fos, "tif", 1);
296: fos.close();
297: } catch (Exception e) {
298: System.out.println(StringTools.stackTraceToString(e));
299: fail(StringTools.stackTraceToString(e));
300: }
301: }
302:
303: /**
304: * reads a deegree WCS configuration file and performs a DescribeCoverage request Steps:
305: * <ul>
306: * <li>read configuration file
307: * <li>read a DescribeCoverage request object
308: * <li>perform the request
309: * </ul>
310: *
311: */
312: public void _testDescribeCoverage() {
313: try {
314: WCSConfiguration configuration = WCSConfiguration
315: .create(Configuration.getWCSConfigurationURL());
316: WCService service = new WCService(configuration);
317:
318: Map<String, String> map = new HashMap<String, String>();
319: map.put("SERVICE", "WCS");
320: map.put("REQUEST", "DescribeCoverage");
321: map.put("VERSION", "1.0.0");
322: map.put("COVERAGE", "europe");
323:
324: // StringBuffer sb = new StringBuffer();
325: // sb.append(Configuration.PROTOCOL + "://" + Configuration.HOST).append(':').append(
326: // Configuration.PORT).append('/').append(Configuration.WCS_WEB_CONTEXT).append(
327: // '/').append(Configuration.WCS_SERVLET).append("?service=WCS&").append(
328: // "request=DescribeCoverage&version=1.0.0&coverage=europe");
329:
330: DescribeCoverage desc = DescribeCoverage.create(map);
331: CoverageDescription o = (CoverageDescription) service
332: .doService(desc);
333: System.out.println(o.getCoverageOfferings());
334: } catch (Exception e) {
335: System.out.println(StringTools.stackTraceToString(e));
336: fail(StringTools.stackTraceToString(e));
337: }
338: }
339:
340: }
|