Source Code Cross Referenced for WFServiceTest.java in  » GIS » deegree » org » deegree » ogcwebservices » wfs » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » deegree » org.deegree.ogcwebservices.wfs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //$Header: /deegreerepository/deegree/test/org/deegree/ogcwebservices/wfs/WFServiceTest.java,v 1.54 2007/01/06 23:13:50 mschneider Exp $
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.wfs;
045:
046:        import java.io.FileOutputStream;
047:        import java.net.URL;
048:        import java.util.ArrayList;
049:        import java.util.List;
050:        import java.util.Map;
051:        import java.util.concurrent.Callable;
052:
053:        import org.deegree.framework.concurrent.ExecutionFinishedEvent;
054:        import org.deegree.framework.concurrent.ExecutionFinishedListener;
055:        import org.deegree.framework.concurrent.Executor;
056:        import org.deegree.framework.xml.XMLFragment;
057:        import org.deegree.io.datastore.DatastoreTransaction;
058:        import org.deegree.io.datastore.sql.AbstractSQLDatastore;
059:        import org.deegree.model.feature.FeatureCollection;
060:        import org.deegree.model.feature.GMLFeatureAdapter;
061:        import org.deegree.ogcwebservices.AbstractServiceTest;
062:        import org.deegree.ogcwebservices.wfs.capabilities.WFSCapabilities;
063:        import org.deegree.ogcwebservices.wfs.capabilities.WFSCapabilitiesDocument;
064:        import org.deegree.ogcwebservices.wfs.configuration.WFSConfiguration;
065:        import org.deegree.ogcwebservices.wfs.configuration.WFSConfigurationDocument;
066:        import org.deegree.ogcwebservices.wfs.operation.DescribeFeatureType;
067:        import org.deegree.ogcwebservices.wfs.operation.DescribeFeatureTypeDocument;
068:        import org.deegree.ogcwebservices.wfs.operation.FeatureResult;
069:        import org.deegree.ogcwebservices.wfs.operation.FeatureTypeDescription;
070:        import org.deegree.ogcwebservices.wfs.operation.GetFeature;
071:        import org.deegree.ogcwebservices.wfs.operation.GetFeatureDocument;
072:        import org.deegree.ogcwebservices.wfs.operation.LockFeature;
073:        import org.deegree.ogcwebservices.wfs.operation.LockFeatureDocument;
074:        import org.deegree.ogcwebservices.wfs.operation.LockFeatureResponse;
075:        import org.deegree.ogcwebservices.wfs.operation.WFSGetCapabilities;
076:        import org.deegree.ogcwebservices.wfs.operation.WFSGetCapabilitiesDocument;
077:        import org.deegree.ogcwebservices.wfs.operation.transaction.Transaction;
078:        import org.deegree.ogcwebservices.wfs.operation.transaction.TransactionDocument;
079:        import org.deegree.ogcwebservices.wfs.operation.transaction.TransactionResponse;
080:
081:        import alltests.AllTests;
082:        import alltests.Configuration;
083:
084:        /**
085:         * Sets up an example WFS instance (Philosopher) and performs the example requests from the
086:         * "resources/wfs/example/deegree/requests" directory.
087:         * 
088:         * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
089:         * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider</a>
090:         * @author last edited by: $Author: apoth $
091:         * 
092:         * @version $Revision: 9336 $, $Date: 2007-12-27 03:31:18 -0800 (Thu, 27 Dec 2007) $
093:         */
094:        public class WFServiceTest extends AbstractServiceTest {
095:
096:            private WFService wfs;
097:
098:            private URL requestDir = new URL(Configuration.getWFSBaseDir(),
099:                    "example/philosopher/requests/");
100:
101:            private URL outputDir = new URL(Configuration.getWFSBaseDir(),
102:                    Configuration.GENERATED_DIR + "/");
103:
104:            /**
105:             * @throws Exception
106:             */
107:            public WFServiceTest() throws Exception {
108:                wfs = createWFS();
109:            }
110:
111:            /**
112:             * Performs the <code>GetCapabilities</code> XML requests from the example/deegree directory.
113:             * 
114:             * @throws Exception
115:             */
116:            public void testGetCapabilitiesXMLExamples() throws Exception {
117:
118:                URL directoryURL = new URL(requestDir, "GetCapabilities/xml");
119:                List<URL> exampleFiles = scanDirectory(directoryURL, "xml");
120:
121:                for (URL example : exampleFiles) {
122:                    AllTests.LOG
123:                            .logInfo("Reading GetCapabilities XML example '"
124:                                    + example + "'.");
125:                    WFSGetCapabilitiesDocument requestDoc = new WFSGetCapabilitiesDocument();
126:                    requestDoc.load(example);
127:                    WFSGetCapabilities request = requestDoc.parse("");
128:                    Object o = wfs.doService(request);
129:                    assertTrue(o instanceof  WFSCapabilities);
130:                    WFSCapabilitiesDocument document = XMLFactory
131:                            .export((WFSCapabilities) o);
132:                    String outputFile = getResultFilename(example, outputDir);
133:                    document.write(new FileOutputStream(outputFile));
134:                    AllTests.LOG.logInfo("Wrote '" + outputFile + "'.");
135:                }
136:            }
137:
138:            /**
139:             * Performs the <code>GetCapabilities</code> KVP requests from the example/deegree directory.
140:             * 
141:             * @throws Exception
142:             */
143:            public void testGetCapabilitiesKVPExamples() throws Exception {
144:
145:                URL directoryURL = new URL(requestDir, "GetCapabilities/kvp");
146:                List<URL> exampleFiles = scanDirectory(directoryURL, "kvp");
147:
148:                for (URL example : exampleFiles) {
149:                    AllTests.LOG
150:                            .logInfo("Reading GetCapabilities KVP example '"
151:                                    + example + "'.");
152:                    Map<String, String> map = createKVPMap(example);
153:                    WFSGetCapabilities request = WFSGetCapabilities.create(map);
154:                    Object o = wfs.doService(request);
155:                    assertTrue(o instanceof  WFSCapabilities);
156:                    WFSCapabilitiesDocument document = XMLFactory
157:                            .export((WFSCapabilities) o);
158:                    String outputFile = getResultFilename(example, outputDir);
159:                    document.write(new FileOutputStream(outputFile));
160:                    AllTests.LOG.logInfo("Wrote '" + outputFile + "'.");
161:                }
162:            }
163:
164:            /**
165:             * Performs the <code>DescribeFeatureType</code> XML requests from the example/deegree
166:             * directory.
167:             * 
168:             * @throws Exception
169:             */
170:            public void testDescribeFeatureTypeXMLExamples() throws Exception {
171:
172:                URL directoryURL = new URL(requestDir,
173:                        "DescribeFeatureType/xml");
174:                List<URL> exampleFiles = scanDirectory(directoryURL, "xml");
175:
176:                for (URL example : exampleFiles) {
177:                    AllTests.LOG
178:                            .logInfo("Reading DescribeFeatureType XML example '"
179:                                    + example + "'.");
180:                    DescribeFeatureTypeDocument requestDoc = new DescribeFeatureTypeDocument();
181:                    requestDoc.load(example);
182:                    DescribeFeatureType request = requestDoc.parse("");
183:                    Object o = wfs.doService(request);
184:                    assertTrue(o instanceof  FeatureTypeDescription);
185:                    FeatureTypeDescription description = (FeatureTypeDescription) o;
186:                    XMLFragment document = description.getFeatureTypeSchema();
187:                    String outputFile = getResultFilename(example, outputDir);
188:                    document.write(new FileOutputStream(outputFile));
189:                    AllTests.LOG.logInfo("Wrote '" + outputFile + "'.");
190:                }
191:            }
192:
193:            /**
194:             * Performs the <code>DescribeFeatureType</code> KVP requests from the example/deegree
195:             * directory.
196:             * 
197:             * @throws Exception
198:             */
199:            public void testDescribeFeatureTypeKVPExamples() throws Exception {
200:
201:                URL directoryURL = new URL(requestDir,
202:                        "DescribeFeatureType/kvp");
203:                List<URL> exampleFiles = scanDirectory(directoryURL, "kvp");
204:
205:                for (URL example : exampleFiles) {
206:                    AllTests.LOG
207:                            .logInfo("Reading DescribeFeatureType KVP example '"
208:                                    + example + "'.");
209:                    Map<String, String> map = createKVPMap(example);
210:                    DescribeFeatureType request = DescribeFeatureType
211:                            .create(map);
212:                    Object o = wfs.doService(request);
213:                    assertTrue(o instanceof  FeatureTypeDescription);
214:                    FeatureTypeDescription description = (FeatureTypeDescription) o;
215:                    XMLFragment document = description.getFeatureTypeSchema();
216:                    String outputFile = getResultFilename(example, outputDir);
217:                    document.write(new FileOutputStream(outputFile));
218:                    AllTests.LOG.logInfo("Wrote '" + outputFile + "'.");
219:                }
220:            }
221:
222:            /**
223:             * Performs the <code>Transaction</code> XML requests from the example/deegree directory.
224:             * 
225:             * @throws Exception
226:             */
227:            public void testTransactionXMLExamples() throws Exception {
228:
229:                URL directoryURL = new URL(requestDir, "Transaction/xml");
230:                List<URL> exampleFiles = scanDirectory(directoryURL, "xml");
231:
232:                for (URL example : exampleFiles) {
233:                    AllTests.LOG.logInfo("Reading Transaction XML example '"
234:                            + example + "'.");
235:                    TransactionDocument requestDoc = new TransactionDocument();
236:                    requestDoc.load(example);
237:                    Transaction request = requestDoc.parse("");
238:                    Object o = wfs.doService(request);
239:                    assertTrue(o instanceof  TransactionResponse);
240:                    XMLFragment document = XMLFactory
241:                            .export((TransactionResponse) o);
242:                    String outputFile = getResultFilename(example, outputDir);
243:                    document.write(new FileOutputStream(outputFile));
244:                    AllTests.LOG.logInfo("Wrote '" + outputFile + "'.");
245:                }
246:            }
247:
248:            /**
249:             * Performs the <code>GetFeature</code> XML requests from the example/deegree directory.
250:             * 
251:             * @throws Exception
252:             */
253:            public void testGetFeatureXMLExamples() throws Exception {
254:
255:                URL directoryURL = new URL(requestDir, "GetFeature/xml");
256:                List<URL> exampleFiles = scanDirectory(directoryURL, "xml");
257:
258:                for (URL example : exampleFiles) {
259:                    AllTests.LOG.logInfo("Reading GetFeature XML example '"
260:                            + example + "'.");
261:                    GetFeatureDocument requestDoc = new GetFeatureDocument();
262:                    requestDoc.load(example);
263:                    GetFeature request = requestDoc.parse("");
264:                    Object o = wfs.doService(request);
265:                    assertTrue(o instanceof  FeatureResult);
266:                    FeatureResult result = (FeatureResult) o;
267:                    assertTrue(result.getResponse() instanceof  FeatureCollection);
268:                    FeatureCollection fc = (FeatureCollection) result
269:                            .getResponse();
270:                    String outputFile = getResultFilename(example, outputDir);
271:                    GMLFeatureAdapter gmlAdapter = new GMLFeatureAdapter();
272:                    gmlAdapter.export(fc, new FileOutputStream(outputFile));
273:                    AllTests.LOG.logInfo("Wrote '" + outputFile + "'.");
274:                }
275:            }
276:
277:            /**
278:             * Performs the <code>GetFeature</code> KVP requests from the example/deegree directory.
279:             * 
280:             * @throws Exception
281:             */
282:            public void testGetFeatureKVPExamples() throws Exception {
283:
284:                URL directoryURL = new URL(requestDir, "GetFeature/kvp");
285:                List<URL> exampleFiles = scanDirectory(directoryURL, "kvp");
286:
287:                for (URL example : exampleFiles) {
288:                    AllTests.LOG.logInfo("Reading GetFeature KVP example '"
289:                            + example + "'.");
290:                    Map<String, String> map = createKVPMap(example);
291:                    GetFeature request = GetFeature.create(map);
292:                    Object o = wfs.doService(request);
293:                    assertTrue(o instanceof  FeatureResult);
294:                    FeatureResult result = (FeatureResult) o;
295:                    assertTrue(result.getResponse() instanceof  FeatureCollection);
296:                    FeatureCollection fc = (FeatureCollection) result
297:                            .getResponse();
298:                    String outputFile = getResultFilename(example, outputDir);
299:                    GMLFeatureAdapter gmlAdapter = new GMLFeatureAdapter();
300:                    gmlAdapter.export(fc, new FileOutputStream(outputFile));
301:                    AllTests.LOG.logInfo("Wrote '" + outputFile + "'.");
302:                }
303:            }
304:
305:            /**
306:             * Performs the <code>LockFeature</code> XML requests from the example/deegree directory.
307:             * 
308:             * @throws Exception
309:             */
310:            public void testLockFeatureXMLExamples() throws Exception {
311:
312:                URL directoryURL = new URL(requestDir, "LockFeature/xml");
313:                List<URL> exampleFiles = scanDirectory(directoryURL, "xml");
314:
315:                for (URL example : exampleFiles) {
316:                    AllTests.LOG.logInfo("Reading LockFeature XML example '"
317:                            + example + "'.");
318:                    LockFeatureDocument requestDoc = new LockFeatureDocument();
319:                    requestDoc.load(example);
320:                    LockFeature request = requestDoc.parse("");
321:                    Object o = wfs.doService(request);
322:                    assertTrue(o instanceof  LockFeatureResponse);
323:                    XMLFragment document = XMLFactory
324:                            .export((LockFeatureResponse) o);
325:                    String outputFile = getResultFilename(example, outputDir);
326:                    document.write(new FileOutputStream(outputFile));
327:                    AllTests.LOG.logInfo("Wrote '" + outputFile + "'.");
328:                }
329:            }
330:
331:            /**
332:             * Tests the assigning of the {@link DatastoreTransaction} in parallel threads. 
333:             * 
334:             * @throws Throwable
335:             */
336:            public void testParallelTransactionAcquisition() throws Throwable {
337:
338:                // get reference to datastore
339:                AbstractSQLDatastore ds = (AbstractSQLDatastore) this .wfs
340:                        .getMappedFeatureTypes().values().iterator().next()
341:                        .getGMLSchema().getDatastore();
342:
343:                // create 10 TransactionAcquirers that should all get the Transaction one-by-one
344:                List<Callable<TransactionAcquirer>> tasks = new ArrayList<Callable<TransactionAcquirer>>(
345:                        10);
346:                tasks.add(new TransactionAcquirer("1", ds, 0, 1 * 1000));
347:                tasks.add(new TransactionAcquirer("2", ds, 100, 1 * 1000));
348:                tasks.add(new TransactionAcquirer("3", ds, 200, 1 * 1000));
349:                tasks.add(new TransactionAcquirer("4", ds, 300, 1 * 1000));
350:                tasks.add(new TransactionAcquirer("5", ds, 400, 1 * 1000));
351:                tasks.add(new TransactionAcquirer("6", ds, 1550, 0 * 1000));
352:                tasks.add(new TransactionAcquirer("7", ds, 2000, 0 * 1000));
353:                tasks.add(new TransactionAcquirer("8", ds, 2000, 1 * 1000));
354:                tasks.add(new TransactionAcquirer("9", ds, 2500, 1 * 1000));
355:                tasks.add(new TransactionAcquirer("10", ds, 2500, 1 * 1000));
356:
357:                // create a TransactionAcquirer that will join the transaction waiting queue, but will be
358:                // zapped before it will get it
359:                Callable<TransactionAcquirer> task = new TransactionAcquirer(
360:                        "zapped-1", ds, 2000, 0 * 1000);
361:                Executor.getInstance().performAsynchronously(task,
362:                        new ExecutionFinishedListener<TransactionAcquirer>() {
363:
364:                            public void executionFinished(
365:                                    ExecutionFinishedEvent<TransactionAcquirer> finishedEvent) {
366:                                // don't do anything
367:                            }
368:                        }, 500);
369:
370:                List<ExecutionFinishedEvent<TransactionAcquirer>> results = Executor
371:                        .getInstance().performSynchronously(tasks, 60 * 1000);
372:                assertTrue(results.size() == tasks.size());
373:                for (int i = 0; i < results.size(); i++) {
374:                    ExecutionFinishedEvent<TransactionAcquirer> result = results
375:                            .get(i);
376:                    assertTrue(result.getResult() == tasks.get(i));
377:                }
378:            }
379:
380:            private WFService createWFS() throws Exception {
381:                WFSConfigurationDocument confDoc = new WFSConfigurationDocument();
382:                confDoc.load(Configuration.getWFSConfigurationURL());
383:                WFSConfiguration conf = confDoc.getConfiguration();
384:                WFServiceFactory.setConfiguration(conf);
385:                return WFServiceFactory.createInstance();
386:            }
387:
388:            private class TransactionAcquirer implements 
389:                    Callable<TransactionAcquirer> {
390:
391:                private String name;
392:
393:                private AbstractSQLDatastore ds;
394:
395:                private long acquisitionDelay;
396:
397:                private long holdTime;
398:
399:                TransactionAcquirer(String name, AbstractSQLDatastore ds,
400:                        long acquisitionDelay, long holdTime) {
401:                    this .name = name;
402:                    this .ds = ds;
403:                    this .acquisitionDelay = acquisitionDelay;
404:                    this .holdTime = holdTime;
405:                }
406:
407:                public TransactionAcquirer call() throws Exception {
408:
409:                    AllTests.LOG.logInfo(this  + " created: sleeping for "
410:                            + acquisitionDelay
411:                            + " milliseconds before acquisition.");
412:                    Thread.sleep(acquisitionDelay);
413:                    AllTests.LOG.logInfo(this  + ": acquiring transaction...");
414:                    DatastoreTransaction ta = this .ds.acquireTransaction();
415:                    AllTests.LOG.logInfo(this 
416:                            + ": got transaction. Waiting for " + holdTime
417:                            + " milliseconds before releasing it.");
418:                    AllTests.LOG.logInfo(this  + ": releasing transaction...");
419:                    ds.releaseTransaction(ta);
420:                    return this ;
421:                }
422:
423:                @Override
424:                public String toString() {
425:                    return "TransactionAcquirer " + name;
426:                }
427:            }
428:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.