root / branches / v2_0_0_prep / extensions / extWFS2 / src-test / org / gvsig / fmap / dal / store / wfs / WFSTest.java @ 34026
History | View | Annotate | Download (6.74 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.fmap.dal.store.wfs; |
29 |
|
30 |
import java.io.File; |
31 |
import java.util.Iterator; |
32 |
|
33 |
import org.gvsig.fmap.dal.DALLocator; |
34 |
import org.gvsig.fmap.dal.DataManager; |
35 |
import org.gvsig.fmap.dal.DataStoreParameters; |
36 |
import org.gvsig.fmap.dal.exception.DataException; |
37 |
import org.gvsig.fmap.dal.exception.InitializeException; |
38 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
39 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
40 |
import org.gvsig.fmap.dal.feature.Feature; |
41 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
42 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
43 |
import org.gvsig.fmap.dal.feature.FeatureType; |
44 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
45 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
46 |
import org.gvsig.fmap.geom.Geometry; |
47 |
import org.gvsig.fmap.geom.primitive.Envelope; |
48 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
49 |
|
50 |
/**
|
51 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
52 |
*/
|
53 |
public class WFSTest extends AbstractLibraryAutoInitTestCase { |
54 |
private String url = "http://inspire.cop.gva.es/geoserver/wfs"; |
55 |
private String version = "1.0.0"; |
56 |
private String featureType = "comunic_lin_300k"; |
57 |
private String namespace = "http://inspire.cop.gva.es"; |
58 |
private String namespacePrefix = "cit"; |
59 |
|
60 |
private String parsersFile = "config" + File.separatorChar + "parser.properties"; |
61 |
|
62 |
private static DataManager dataManager = null; |
63 |
private boolean baseTestInitialized=false; |
64 |
private DataStoreParameters params;
|
65 |
private DefaultFeatureStore store;
|
66 |
|
67 |
@Override
|
68 |
protected void doSetUp() throws Exception { |
69 |
dataManager = DALLocator.getDataManager(); |
70 |
} |
71 |
|
72 |
/*
|
73 |
* (non-Javadoc)
|
74 |
*
|
75 |
* @see
|
76 |
* org.gvsig.fmap.dal.feature.BaseTestFeatureStore#getDefaultDataStoreParameters
|
77 |
* ()
|
78 |
*/
|
79 |
public DataStoreParameters getDefaultDataStoreParameters()
|
80 |
throws DataException {
|
81 |
WFSStoreParameters parameters = null;
|
82 |
|
83 |
parameters = (WFSStoreParameters) dataManager |
84 |
.createStoreParameters(WFSStoreProvider.NAME); |
85 |
|
86 |
parameters.setUrl(url); |
87 |
parameters.setFeatureType(namespacePrefix, namespace, featureType); |
88 |
parameters.setVersion(version); |
89 |
//parameters.setFields(fields);
|
90 |
return parameters;
|
91 |
} |
92 |
|
93 |
public void testSetParams(){ |
94 |
try {
|
95 |
params = getDefaultDataStoreParameters(); |
96 |
} catch (DataException e) {
|
97 |
// TODO Auto-generated catch block
|
98 |
e.printStackTrace(); |
99 |
fail(); |
100 |
} |
101 |
} |
102 |
|
103 |
public void testOpenStore(){ |
104 |
try {
|
105 |
params = getDefaultDataStoreParameters(); |
106 |
store = (DefaultFeatureStore) dataManager.createStore(params); |
107 |
FeatureStoreProvider provider = new WFSStoreProvider(params, store);
|
108 |
|
109 |
assertEquals(provider.getFeatureCount(), 0);
|
110 |
|
111 |
FeatureSet set; |
112 |
// FeatureType type = store.getDefaultFeatureType();
|
113 |
set = store.getFeatureSet(); |
114 |
|
115 |
System.out.println("Feature count: " + set.getSize()); |
116 |
Iterator it = set.iterator();
|
117 |
// Iterator ftIt;
|
118 |
// FeatureAttributeDescriptor desc;
|
119 |
|
120 |
int i = 0; |
121 |
Feature feature; |
122 |
while (it.hasNext()) {
|
123 |
// ftIt = type.iterator();
|
124 |
|
125 |
System.out.println("====================================="); |
126 |
System.out.println("Feature " + i + ": "); |
127 |
System.out.println("-------------------------------------"); |
128 |
feature = (Feature) it.next(); |
129 |
Geometry geom = (Geometry) feature.getDefaultGeometry(); // .getGeometries().get(0);
|
130 |
|
131 |
FeatureType ft = feature.getType(); |
132 |
FeatureAttributeDescriptor[] atts = ft.getAttributeDescriptors();
|
133 |
int len = atts.length;
|
134 |
FeatureAttributeDescriptor att; |
135 |
for (int j=0; j<len; j++) { |
136 |
att = ft.getAttributeDescriptor(j); |
137 |
String value = ""; |
138 |
if (feature.get(j) !=null){ |
139 |
value = feature.get(j).toString(); |
140 |
} |
141 |
System.out.println("ATT: " + att.getName() + "; VAL = " + value); |
142 |
} |
143 |
System.out.println("-------------------------------------"); |
144 |
if (geom != null){ |
145 |
Envelope env = geom.getEnvelope(); |
146 |
System.out.println("GEOM BB: " |
147 |
+ env.getMinimum(0)
|
148 |
+ ", " + env.getMinimum(1) |
149 |
+ ", " + env.getMaximum(0) |
150 |
+ ", " + env.getMaximum(1)); |
151 |
} |
152 |
System.out.println("====================================="); |
153 |
i++; |
154 |
} |
155 |
set.dispose(); |
156 |
store.dispose(); |
157 |
} catch (ValidateDataParametersException e) {
|
158 |
// TODO Auto-generated catch block
|
159 |
e.printStackTrace(); |
160 |
fail(); |
161 |
} catch (InitializeException e) {
|
162 |
// TODO Auto-generated catch block
|
163 |
e.printStackTrace(); |
164 |
fail(); |
165 |
} catch (ProviderNotRegisteredException e) {
|
166 |
// TODO Auto-generated catch block
|
167 |
e.printStackTrace(); |
168 |
fail(); |
169 |
} catch (DataException e) {
|
170 |
// TODO Auto-generated catch block
|
171 |
e.printStackTrace(); |
172 |
fail(); |
173 |
} |
174 |
|
175 |
} |
176 |
|
177 |
/*
|
178 |
* (non-Javadoc)
|
179 |
*
|
180 |
* @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer()
|
181 |
*/
|
182 |
public boolean hasExplorer() { |
183 |
return true; |
184 |
} |
185 |
|
186 |
/* (non-Javadoc)
|
187 |
* @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#usesResources()
|
188 |
*/
|
189 |
public boolean usesResources() { |
190 |
// TODO Auto-generated method stub
|
191 |
return false; |
192 |
} |
193 |
} |
194 |
|
195 |
|