root / trunk / extensions / extNormalization / src-test / org / gvsig / normalization / operations / TestFilterString.java @ 22975
History | View | Annotate | Download (4 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.util.ArrayList; |
34 |
|
35 |
import junit.framework.TestCase; |
36 |
|
37 |
import org.apache.log4j.Logger; |
38 |
import org.gvsig.patterns.normalization.Patternnormalization; |
39 |
import org.gvsig.tools.storage.IStorage; |
40 |
import org.gvsig.tools.storage.StorageXML; |
41 |
|
42 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
43 |
import com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver; |
44 |
|
45 |
/**
|
46 |
*
|
47 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
48 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
49 |
*
|
50 |
*/
|
51 |
public class TestFilterString extends TestCase { |
52 |
|
53 |
private static final Logger log = Logger.getLogger(TestFilterString.class); |
54 |
|
55 |
public void testFilterString() { |
56 |
|
57 |
log.info("TestFilterString: start the test");
|
58 |
|
59 |
ArrayList<String> chains = new ArrayList<String>(); |
60 |
chains.add(",XXX;9393;33.25;337.22;1/1/8");
|
61 |
|
62 |
File fPat = new File( |
63 |
"src-test/org/gvsig/normalization/operations/testdata/PATNORM_TEST.xml");
|
64 |
|
65 |
assertNotNull(fPat); |
66 |
|
67 |
Patternnormalization pat = parserPat(fPat); |
68 |
assertNotNull(pat); |
69 |
|
70 |
File outputFile = null; |
71 |
try {
|
72 |
outputFile = File.createTempFile("filters", ".dbf"); |
73 |
} catch (IOException e1) { |
74 |
e1.printStackTrace(); |
75 |
} |
76 |
|
77 |
// Normalization
|
78 |
StringListNormalization norm = new StringListNormalization(pat, chains,
|
79 |
outputFile); |
80 |
|
81 |
norm.preProcess(); |
82 |
for (int i = 0; i < chains.size(); i++) { |
83 |
try {
|
84 |
norm.fillRow(i); |
85 |
} catch (ReadDriverException e) {
|
86 |
e.printStackTrace(); |
87 |
} |
88 |
} |
89 |
norm.postProcess(); |
90 |
|
91 |
DBFDriver test = new DBFDriver();
|
92 |
int nFields = -1; |
93 |
long nRows = -1; |
94 |
String val00 = null; |
95 |
String val01 = null; |
96 |
String val02 = null; |
97 |
String val03 = null; |
98 |
String val04 = null; |
99 |
String val05 = null; |
100 |
|
101 |
try {
|
102 |
test.open(outputFile); |
103 |
nFields = test.getFieldCount(); |
104 |
nRows = test.getRowCount(); |
105 |
val00 = test.getFieldValue(0, 0).toString().trim(); |
106 |
val01 = test.getFieldValue(0, 1).toString().trim(); |
107 |
val02 = test.getFieldValue(0, 2).toString().trim(); |
108 |
val03 = test.getFieldValue(0, 3).toString().trim(); |
109 |
val04 = test.getFieldValue(0, 4).toString().trim(); |
110 |
val05 = test.getFieldValue(0, 5).toString().trim(); |
111 |
|
112 |
test.close(); |
113 |
} catch (Exception e) { |
114 |
e.printStackTrace(); |
115 |
} |
116 |
|
117 |
assertEquals(nFields, 6);
|
118 |
assertEquals(nRows, 1);
|
119 |
|
120 |
assertEquals(val00, "");
|
121 |
assertEquals(val01, "XXX");
|
122 |
assertEquals(val02, "9393");
|
123 |
assertEquals(val03, "0.0");
|
124 |
assertEquals(val04, "337.22");
|
125 |
assertEquals(val05, "01-ene-0008");
|
126 |
|
127 |
log.info("TestFilterString: test finished");
|
128 |
} |
129 |
|
130 |
private Patternnormalization parserPat(File f) { |
131 |
Patternnormalization pat = new Patternnormalization();
|
132 |
IStorage storage = new StorageXML();
|
133 |
try {
|
134 |
FileReader red = new FileReader(f); |
135 |
storage.load(red); |
136 |
pat.setstate(storage); |
137 |
} catch (Exception e) { |
138 |
e.printStackTrace(); |
139 |
} |
140 |
return pat;
|
141 |
} |
142 |
|
143 |
} |