svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.geocoding / src-test / org / gvsig / normalization / operations / TestNormalizeFeatureData.java @ 32479
History | View | Annotate | Download (7.21 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 |
* 2008 Prodevelop S.L vsanjaime programador
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.normalization.operations; |
29 |
|
30 |
import java.io.File; |
31 |
import java.text.DecimalFormatSymbols; |
32 |
import java.util.ArrayList; |
33 |
import java.util.List; |
34 |
import java.util.Locale; |
35 |
|
36 |
import junit.framework.TestCase; |
37 |
|
38 |
import org.gvsig.fmap.dal.DALFileLibrary; |
39 |
import org.gvsig.fmap.dal.DALLibrary; |
40 |
import org.gvsig.fmap.dal.DALLocator; |
41 |
import org.gvsig.fmap.dal.DataManager; |
42 |
import org.gvsig.fmap.dal.exception.DataException; |
43 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
44 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
45 |
import org.gvsig.fmap.dal.feature.FeatureStoreTransform; |
46 |
import org.gvsig.fmap.dal.feature.FeatureStoreTransforms; |
47 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters; |
48 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider; |
49 |
import org.gvsig.fmap.dal.store.shp.SHPLibrary; |
50 |
import org.gvsig.normalization.NormalizationLocator; |
51 |
import org.gvsig.normalization.algorithm.NormalizationAlgorithm; |
52 |
import org.gvsig.normalization.algorithm.impl.DefaultNormalizationAlgorithm; |
53 |
import org.gvsig.normalization.impl.DefaultNormalizationLibrary; |
54 |
import org.gvsig.normalization.impl.NormalizationTransform; |
55 |
import org.gvsig.normalization.pattern.Element; |
56 |
import org.gvsig.normalization.pattern.Fieldseparator; |
57 |
import org.gvsig.normalization.pattern.Fieldtype; |
58 |
import org.gvsig.normalization.pattern.Infieldseparators; |
59 |
import org.gvsig.normalization.pattern.NormalizationPattern; |
60 |
import org.gvsig.normalization.pattern.Stringvalue; |
61 |
import org.gvsig.normalization.pattern.impl.DefaultElement; |
62 |
import org.gvsig.normalization.pattern.impl.DefaultFieldseparator; |
63 |
import org.gvsig.normalization.pattern.impl.DefaultFieldtype; |
64 |
import org.gvsig.normalization.pattern.impl.DefaultInfieldseparators; |
65 |
import org.gvsig.normalization.pattern.impl.DefaultNormalizationPattern; |
66 |
import org.gvsig.normalization.pattern.impl.DefaultStringvalue; |
67 |
import org.gvsig.tools.ToolsLibrary; |
68 |
import org.gvsig.tools.ToolsLocator; |
69 |
import org.gvsig.tools.library.Library; |
70 |
import org.slf4j.Logger; |
71 |
import org.slf4j.LoggerFactory; |
72 |
|
73 |
/**
|
74 |
*
|
75 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
76 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
77 |
*
|
78 |
*/
|
79 |
public class TestNormalizeFeatureData extends org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase { |
80 |
|
81 |
private static final Logger log = LoggerFactory |
82 |
.getLogger(TestNormalizeFeatureData.class); |
83 |
|
84 |
NormalizationPattern pat = null;
|
85 |
File file = null; |
86 |
|
87 |
|
88 |
@Override
|
89 |
protected void doSetUp() throws Exception { |
90 |
Library normlib = new DefaultNormalizationLibrary();
|
91 |
normlib.initialize(); |
92 |
normlib.postInitialize(); |
93 |
} |
94 |
|
95 |
|
96 |
|
97 |
public void testNormalizationTransform() |
98 |
throws ValidateDataParametersException, DataException {
|
99 |
|
100 |
DataManager manager = DALLocator.getDataManager(); |
101 |
|
102 |
// PATTERN
|
103 |
pat = getPattern(); |
104 |
|
105 |
// DATASTORE
|
106 |
file = new File("resources-test/normalization/pro.dbf"); |
107 |
assertTrue(file.exists()); |
108 |
DBFStoreParameters params = (DBFStoreParameters) manager |
109 |
.createStoreParameters(DBFStoreProvider.NAME); |
110 |
params.setDBFFile(file); |
111 |
FeatureStore store = (FeatureStore) manager.createStore(params); |
112 |
|
113 |
// ALGORITHM
|
114 |
|
115 |
NormalizationAlgorithm algorithm = new DefaultNormalizationAlgorithm(
|
116 |
pat); |
117 |
|
118 |
// TRANSFORM
|
119 |
NormalizationTransform transform = (NormalizationTransform) NormalizationLocator.getInstance().getNormalizer(); |
120 |
|
121 |
transform.initialize(store, pat, 5, algorithm);
|
122 |
// Add transform
|
123 |
FeatureStoreTransforms trans = store.getTransforms(); |
124 |
trans.add((FeatureStoreTransform)transform); |
125 |
|
126 |
} |
127 |
|
128 |
public void tearDown() { |
129 |
log.debug("TEST FINISHED");
|
130 |
} |
131 |
|
132 |
private NormalizationPattern getPattern() {
|
133 |
|
134 |
// Create object
|
135 |
NormalizationPattern pat = new DefaultNormalizationPattern();
|
136 |
|
137 |
// Field Separators
|
138 |
Fieldseparator filsep1 = new DefaultFieldseparator();
|
139 |
|
140 |
filsep1.setSemicolonsep(true);
|
141 |
filsep1.setJoinsep(false);
|
142 |
filsep1.setColonsep(false);
|
143 |
filsep1.setSpacesep(false);
|
144 |
filsep1.setTabsep(false);
|
145 |
|
146 |
// Field Separators
|
147 |
Fieldseparator filsep2 = new DefaultFieldseparator();
|
148 |
|
149 |
filsep2.setSemicolonsep(true);
|
150 |
filsep2.setJoinsep(false);
|
151 |
filsep2.setColonsep(false);
|
152 |
filsep2.setSpacesep(false);
|
153 |
filsep2.setTabsep(false);
|
154 |
|
155 |
// In Field Separators
|
156 |
Locale loc = Locale.getDefault(); |
157 |
DecimalFormatSymbols dfs = new DecimalFormatSymbols(loc); |
158 |
Infieldseparators infilsep1 = new DefaultInfieldseparators();
|
159 |
|
160 |
infilsep1.setDecimalseparator(Character.toString(dfs
|
161 |
.getDecimalSeparator())); |
162 |
infilsep1.setTextseparator("\"");
|
163 |
infilsep1.setThousandseparator(Character.toString(dfs
|
164 |
.getGroupingSeparator())); |
165 |
|
166 |
// In Field Separators
|
167 |
|
168 |
Infieldseparators infilsep2 = new DefaultInfieldseparators();
|
169 |
|
170 |
infilsep2.setDecimalseparator(Character.toString(dfs
|
171 |
.getDecimalSeparator())); |
172 |
infilsep2.setTextseparator("\"");
|
173 |
infilsep2.setThousandseparator(Character.toString(dfs
|
174 |
.getGroupingSeparator())); |
175 |
|
176 |
// Main attributes
|
177 |
pat.setPatternname("thePattern");
|
178 |
pat.setNofirstrows(0);
|
179 |
|
180 |
// Create the first Address Element ////////////////////
|
181 |
List<Element> elems = new ArrayList<Element>(); |
182 |
Element elem1 = new DefaultElement(); |
183 |
|
184 |
// Field 1 Field 1 Field 1 Field 1
|
185 |
elem1.setFieldname("campo1");
|
186 |
|
187 |
elem1.setFieldseparator(filsep1); |
188 |
|
189 |
elem1.setInfieldseparators(infilsep1); |
190 |
|
191 |
// Field type
|
192 |
Fieldtype newtype = new DefaultFieldtype();
|
193 |
Stringvalue strval = new DefaultStringvalue();
|
194 |
strval.setStringvaluewidth(50);
|
195 |
newtype.setStringvalue(strval); |
196 |
|
197 |
elem1.setFieldtype(newtype); |
198 |
elem1.setFieldwidth(0);
|
199 |
elem1.setImportfield(true);
|
200 |
|
201 |
elems.add(elem1); |
202 |
|
203 |
// Create the second Address Element ////////////////////
|
204 |
|
205 |
Element elem2 = new DefaultElement(); |
206 |
|
207 |
// Field 2 Field 2 Field 2 Field 2
|
208 |
elem2.setFieldname("campo2");
|
209 |
|
210 |
elem2.setFieldseparator(filsep2); |
211 |
|
212 |
elem2.setInfieldseparators(infilsep2); |
213 |
|
214 |
// Field type
|
215 |
Fieldtype newtype2 = new DefaultFieldtype();
|
216 |
Stringvalue strval2 = new DefaultStringvalue();
|
217 |
strval2.setStringvaluewidth(50);
|
218 |
newtype2.setStringvalue(strval2); |
219 |
|
220 |
elem2.setFieldtype(newtype2); |
221 |
elem2.setFieldwidth(0);
|
222 |
elem2.setImportfield(true);
|
223 |
|
224 |
elems.add(elem2); |
225 |
|
226 |
pat.setElements(elems); |
227 |
|
228 |
return pat;
|
229 |
} |
230 |
|
231 |
} |