root / org.gvsig.wfs.app / trunk / org.gvsig.wfs.app / org.gvsig.wfs.app.mainplugin / src / test / java / org / gvsig / mobile / extension / wfs / dal / store / WFSMobileTest.java @ 416
History | View | Annotate | Download (8.27 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program 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
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {Iver T.I.} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.mobile.extension.wfs.dal.store; |
29 |
|
30 |
import java.io.File; |
31 |
import java.util.Iterator; |
32 |
|
33 |
import junit.framework.TestCase; |
34 |
|
35 |
import org.gvsig.fmap.dal.DALLibrary; |
36 |
import org.gvsig.fmap.dal.DALLocator; |
37 |
import org.gvsig.fmap.dal.DataManager; |
38 |
import org.gvsig.fmap.dal.DataStoreParameters; |
39 |
import org.gvsig.fmap.dal.exception.DataException; |
40 |
import org.gvsig.fmap.dal.exception.InitializeException; |
41 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
42 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
43 |
import org.gvsig.fmap.dal.feature.Feature; |
44 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
45 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
46 |
import org.gvsig.fmap.dal.feature.FeatureType; |
47 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
48 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
49 |
import org.gvsig.fmap.dal.impl.DALDefaultImplLibrary; |
50 |
import org.gvsig.fmap.dal.impl.DefaultDataManager; |
51 |
import org.gvsig.fmap.dal.resource.impl.DefaultResourceManager; |
52 |
import org.gvsig.fmap.dal.store.wfs.WFSLibrary; |
53 |
import org.gvsig.fmap.dal.store.wfs.WFSOpenStoreParameters; |
54 |
import org.gvsig.fmap.dal.store.wfs.WFSStoreProvider; |
55 |
import org.gvsig.fmap.geom.Geometry; |
56 |
import org.gvsig.fmap.geom.primitive.Envelope; |
57 |
import org.gvsig.metadata.MetadataLocator; |
58 |
import org.gvsig.metadata.lib.basic.impl.BasicMetadataManager; |
59 |
import org.gvsig.remoteclient.wfs.WFSStatus; |
60 |
import org.gvsig.tools.ToolsLibrary; |
61 |
import org.gvsig.tools.persistence.xml.XMLPersistenceLibrary; |
62 |
|
63 |
/**
|
64 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
65 |
*/
|
66 |
public class WFSMobileTest extends TestCase { |
67 |
private String url = "http://www.idee.es/IDEE-WFS/ogcwebservice"; |
68 |
private String version = "1.1.0"; |
69 |
private String featureType = "ideewfs:VerticeRedBalear98"; |
70 |
private String namespace = "http://www.idee.es/wfs"; |
71 |
private String namespacePrefix = "ideewfs"; |
72 |
private String bodyNamespace="http://www.idee.es/wfs"; |
73 |
private String infoLayerQuery="DefaultWFSLayer"; |
74 |
private WFSStatus wfsStatus = new WFSStatus(infoLayerQuery); |
75 |
|
76 |
private String parsersFile = "config" + File.separatorChar + "parser.properties"; |
77 |
|
78 |
private static DataManager dataManager = null; |
79 |
private boolean baseTestInitialized=false; |
80 |
private DataStoreParameters params;
|
81 |
private DefaultFeatureStore store;
|
82 |
|
83 |
|
84 |
protected void setUp() throws Exception { |
85 |
super.setUp();
|
86 |
|
87 |
if (baseTestInitialized) {
|
88 |
return;
|
89 |
} |
90 |
ToolsLibrary tools = new ToolsLibrary();
|
91 |
tools.initialize(); |
92 |
tools.postInitialize(); |
93 |
|
94 |
XMLPersistenceLibrary xmlPersistence = new XMLPersistenceLibrary();
|
95 |
xmlPersistence.initialize(); |
96 |
xmlPersistence.postInitialize(); |
97 |
|
98 |
DALLocator.registerDataManager(DefaultDataManager.class); |
99 |
DALLocator.registerResourceManager(DefaultResourceManager.class); |
100 |
MetadataLocator.registerMetadataManager(BasicMetadataManager.class); |
101 |
|
102 |
DALLibrary lib = new DALLibrary();
|
103 |
lib.initialize(); |
104 |
lib.postInitialize(); |
105 |
|
106 |
DALDefaultImplLibrary libImpl = new DALDefaultImplLibrary();
|
107 |
libImpl.initialize(); |
108 |
libImpl.postInitialize(); |
109 |
|
110 |
dataManager = DALLocator.getDataManager(); |
111 |
|
112 |
//DALFileLibrary libFile = new DALFileLibrary();
|
113 |
//libFile.initialize();
|
114 |
//libFile.postInitialize();
|
115 |
|
116 |
// DefaultGPEDataTypesLibrary gpeDataTypesLibrary = new DefaultGPEDataTypesLibrary();
|
117 |
// gpeDataTypesLibrary.initialize();
|
118 |
// gpeDataTypesLibrary.postInitialize();
|
119 |
//
|
120 |
// DALGPELibrary gpeLibrary = new DALGPELibrary();
|
121 |
// gpeLibrary.initialize();
|
122 |
// gpeLibrary.postInitialize();
|
123 |
//
|
124 |
// DefaultGPELibrary defaultGPElibrary = new DefaultGPELibrary();
|
125 |
// defaultGPElibrary.initialize();
|
126 |
// defaultGPElibrary.postInitialize();
|
127 |
|
128 |
|
129 |
// DefaultXmlLibrary defaultXmllibrary = new DefaultXmlLibrary();
|
130 |
// defaultXmllibrary.initialize();
|
131 |
// defaultXmllibrary.postInitialize();
|
132 |
//
|
133 |
// DefaultKmlLibrary kmlLibrary = new DefaultKmlLibrary();
|
134 |
// kmlLibrary.initialize();
|
135 |
// kmlLibrary.postInitialize();
|
136 |
//
|
137 |
// DefaultGmlLibrary gmlLibrary = new DefaultGmlLibrary();
|
138 |
// gmlLibrary.initialize();
|
139 |
// gmlLibrary.postInitialize();
|
140 |
|
141 |
// gpeManager = GPELocator.getGPEManager();
|
142 |
|
143 |
WFSLibrary wfslibrary = new WFSLibrary();
|
144 |
wfslibrary.initialize(); |
145 |
wfslibrary.postInitialize(); |
146 |
|
147 |
baseTestInitialized = true;
|
148 |
} |
149 |
|
150 |
|
151 |
/*
|
152 |
* (non-Javadoc)
|
153 |
*
|
154 |
* @see
|
155 |
* org.gvsig.fmap.dal.feature.BaseTestFeatureStore#getDefaultDataStoreParameters
|
156 |
* ()
|
157 |
*/
|
158 |
public DataStoreParameters getDefaultDataStoreParameters()
|
159 |
throws DataException {
|
160 |
WFSOpenStoreParameters parameters = null;
|
161 |
|
162 |
parameters = (WFSOpenStoreParameters) dataManager |
163 |
.createStoreParameters(WFSStoreProvider.NAME); |
164 |
|
165 |
parameters.setUrl(url); |
166 |
parameters.getFeatureNamespace(); |
167 |
parameters.setFeatureType(namespacePrefix, namespace, featureType); |
168 |
parameters.setVersion(version); |
169 |
//parameters.setFields(fields);
|
170 |
return parameters;
|
171 |
} |
172 |
|
173 |
public void testSetParams(){ |
174 |
try {
|
175 |
params = getDefaultDataStoreParameters(); |
176 |
} catch (DataException e) {
|
177 |
// TODO Auto-generated catch block
|
178 |
e.printStackTrace(); |
179 |
fail(); |
180 |
} |
181 |
} |
182 |
|
183 |
public void testOpenStore(){ |
184 |
try {
|
185 |
WFSStatus wfsStatus = new WFSStatus(infoLayerQuery);
|
186 |
params = getDefaultDataStoreParameters(); |
187 |
store = (DefaultFeatureStore) dataManager.createStore(params); |
188 |
FeatureStoreProvider shppro = new WFSStoreProvider(params, store);
|
189 |
|
190 |
FeatureSet set; |
191 |
// FeatureType type = store.getDefaultFeatureType();
|
192 |
set = store.getFeatureSet(); |
193 |
|
194 |
System.out.println("Feature count: " + set.getSize()); |
195 |
Iterator it = set.iterator();
|
196 |
// Iterator ftIt;
|
197 |
// FeatureAttributeDescriptor desc;
|
198 |
|
199 |
int i = 0; |
200 |
Feature feature; |
201 |
while (it.hasNext()) {
|
202 |
// ftIt = type.iterator();
|
203 |
|
204 |
System.out.println("====================================="); |
205 |
System.out.println("Feature " + i + ": "); |
206 |
System.out.println("-------------------------------------"); |
207 |
feature = (Feature) it.next(); |
208 |
Geometry geom = (Geometry) feature.getDefaultGeometry(); // .getGeometries().get(0);
|
209 |
|
210 |
FeatureType ft = feature.getType(); |
211 |
FeatureAttributeDescriptor[] atts = ft.getAttributeDescriptors();
|
212 |
int len = atts.length;
|
213 |
FeatureAttributeDescriptor att; |
214 |
for (int j=0; j<len; j++) { |
215 |
att = ft.getAttributeDescriptor(j); |
216 |
System.out.println("ATT: " + att.getName() + "; VAL = " + feature.get(j).toString()); |
217 |
} |
218 |
System.out.println("-------------------------------------"); |
219 |
Envelope env = geom.getEnvelope(); |
220 |
System.out.println("GEOM BB: " |
221 |
+ env.getMinimum(0)
|
222 |
+ ", " + env.getMinimum(1) |
223 |
+ ", " + env.getMaximum(0) |
224 |
+ ", " + env.getMaximum(1)); |
225 |
System.out.println("====================================="); |
226 |
i++; |
227 |
} |
228 |
set.dispose(); |
229 |
store.dispose(); |
230 |
} catch (ValidateDataParametersException e) {
|
231 |
// TODO Auto-generated catch block
|
232 |
e.printStackTrace(); |
233 |
fail(); |
234 |
} catch (InitializeException e) {
|
235 |
// TODO Auto-generated catch block
|
236 |
e.printStackTrace(); |
237 |
fail(); |
238 |
} catch (ProviderNotRegisteredException e) {
|
239 |
// TODO Auto-generated catch block
|
240 |
e.printStackTrace(); |
241 |
fail(); |
242 |
} catch (DataException e) {
|
243 |
// TODO Auto-generated catch block
|
244 |
e.printStackTrace(); |
245 |
fail(); |
246 |
} |
247 |
|
248 |
} |
249 |
|
250 |
/*
|
251 |
* (non-Javadoc)
|
252 |
*
|
253 |
* @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer()
|
254 |
*/
|
255 |
public boolean hasExplorer() { |
256 |
return true; |
257 |
} |
258 |
|
259 |
/* (non-Javadoc)
|
260 |
* @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#usesResources()
|
261 |
*/
|
262 |
public boolean usesResources() { |
263 |
// TODO Auto-generated method stub
|
264 |
return false; |
265 |
} |
266 |
|
267 |
} |
268 |
|