svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libGeocoding / src-test / org / gvsig / normalization / operations / TestFilterString.java @ 29385
History | View | Annotate | Download (5.47 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.io.FileReader; |
32 |
import java.io.IOException; |
33 |
import java.io.Reader; |
34 |
import java.util.ArrayList; |
35 |
import java.util.List; |
36 |
|
37 |
import junit.framework.TestCase; |
38 |
|
39 |
import org.gvsig.fmap.dal.DALFileLibrary; |
40 |
import org.gvsig.fmap.dal.DALLibrary; |
41 |
import org.gvsig.fmap.dal.exception.DataException; |
42 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
43 |
import org.gvsig.fmap.dal.store.shp.SHPLibrary; |
44 |
import org.gvsig.normalization.algorithm.NormalizationAlgorithm; |
45 |
import org.gvsig.normalization.algorithm.impl.DefaultNormalizationAlgorithm; |
46 |
import org.gvsig.normalization.impl.NormalizationTransform; |
47 |
import org.gvsig.normalization.pattern.Patternnormalization; |
48 |
import org.gvsig.normalization.pattern.impl.DefaultPatternnormalization; |
49 |
import org.gvsig.tools.ToolsLibrary; |
50 |
import org.gvsig.tools.ToolsLocator; |
51 |
import org.gvsig.tools.locator.Library; |
52 |
import org.gvsig.tools.persistence.PersistenceException; |
53 |
import org.gvsig.tools.persistence.PersistenceManager; |
54 |
import org.gvsig.tools.persistence.PersistentState; |
55 |
import org.gvsig.tools.persistence.xmlentity.XMLEntityManager; |
56 |
import org.slf4j.Logger; |
57 |
import org.slf4j.LoggerFactory; |
58 |
|
59 |
/**
|
60 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
61 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
62 |
*/
|
63 |
public class TestFilterString extends TestCase { |
64 |
|
65 |
private static final Logger log = LoggerFactory |
66 |
.getLogger(TestFilterString.class); |
67 |
|
68 |
/**
|
69 |
* Constructor
|
70 |
*/
|
71 |
public TestFilterString() {
|
72 |
ToolsLibrary tools = new ToolsLibrary();
|
73 |
tools.initialize(); |
74 |
ToolsLocator.registerPersistenceManager(XMLEntityManager.class); |
75 |
tools.postInitialize(); |
76 |
Library dlib = new DALLibrary();
|
77 |
dlib.initialize(); |
78 |
dlib.postInitialize(); |
79 |
Library libFile = new DALFileLibrary();
|
80 |
libFile.initialize(); |
81 |
libFile.postInitialize(); |
82 |
Library shpLib = new SHPLibrary();
|
83 |
shpLib.initialize(); |
84 |
shpLib.postInitialize(); |
85 |
} |
86 |
|
87 |
/**
|
88 |
* @throws IOException
|
89 |
* @throws PersistenceException
|
90 |
* @throws DataException
|
91 |
*
|
92 |
*/
|
93 |
public void testTransformFeatureStore() throws PersistenceException, |
94 |
IOException, DataException {
|
95 |
|
96 |
// store
|
97 |
List<String> chains = new ArrayList<String>(); |
98 |
chains.add(",XXX;9393;33.25;337.22E2;1/1/8");
|
99 |
FeatureStore store = null;
|
100 |
|
101 |
// Pattern
|
102 |
File filePattern = new File( |
103 |
"test-data/normalization/PATNORM_TEST.xml");
|
104 |
assertTrue(filePattern.exists()); |
105 |
assertNotNull(filePattern); |
106 |
Patternnormalization pat = parserPat(filePattern); |
107 |
assertNotNull(pat); |
108 |
|
109 |
// Algorithm
|
110 |
NormalizationAlgorithm algorithm = new DefaultNormalizationAlgorithm(
|
111 |
pat); |
112 |
|
113 |
// Normalization transform
|
114 |
NormalizationTransform transform = new NormalizationTransform();
|
115 |
transform.initialize(store, pat, 0, algorithm);
|
116 |
|
117 |
// Add transform
|
118 |
store.getTransforms().add(transform); |
119 |
|
120 |
//
|
121 |
//
|
122 |
//
|
123 |
// int nFields = -1;
|
124 |
// long nRows = -1;
|
125 |
// String val00 = null;
|
126 |
// String val01 = null;
|
127 |
// String val02 = null;
|
128 |
// String val03 = null;
|
129 |
// String val04 = null;
|
130 |
// String val05 = null;
|
131 |
//
|
132 |
// try {
|
133 |
// test.open(outputFile);
|
134 |
// nFields = test.getFieldCount();
|
135 |
// nRows = test.getRowCount();
|
136 |
// val00 = test.getFieldValue(0, 0).toString().trim();
|
137 |
// val01 = test.getFieldValue(0, 1).toString().trim();
|
138 |
// val02 = test.getFieldValue(0, 2).toString().trim();
|
139 |
// val03 = test.getFieldValue(0, 3).toString().trim();
|
140 |
// val04 = test.getFieldValue(0, 4).toString().trim();
|
141 |
// val05 = test.getFieldValue(0, 5).toString().trim();
|
142 |
//
|
143 |
// test.close();
|
144 |
// } catch (Exception e) {
|
145 |
// e.printStackTrace();
|
146 |
// }
|
147 |
//
|
148 |
// assertEquals(nFields, 6);
|
149 |
// assertEquals(nRows, 1);
|
150 |
//
|
151 |
// assertEquals(val00, "");
|
152 |
// assertEquals(val01, "XXX");
|
153 |
// assertEquals(val02, "9393");
|
154 |
// assertEquals(val03, "0.0");
|
155 |
// assertEquals(val04, "33722.0");
|
156 |
// assertEquals(val05, "01-ene-0008");
|
157 |
|
158 |
log.info("Test finished");
|
159 |
} |
160 |
|
161 |
/**
|
162 |
*
|
163 |
* @param f
|
164 |
* @return
|
165 |
* @throws PersistenceException
|
166 |
* @throws IOException
|
167 |
*/
|
168 |
private Patternnormalization parserPat(File f) throws PersistenceException, |
169 |
IOException {
|
170 |
|
171 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
172 |
Patternnormalization pat = new DefaultPatternnormalization();
|
173 |
Reader reader = new FileReader(f); |
174 |
PersistentState state3 = manager.loadState(reader); |
175 |
pat.loadFromState(state3); |
176 |
reader.close(); |
177 |
return pat;
|
178 |
} |
179 |
|
180 |
} |