root / trunk / extensions / extNormalization / src-test / org / gvsig / normalization / operations / TestNormalizeStringsFromFile.java @ 22975
History | View | Annotate | Download (4.04 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. main development
|
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.CloseDriverException; |
43 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
44 |
import com.iver.andami.PluginServices; |
45 |
import com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver; |
46 |
|
47 |
/**
|
48 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
49 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
50 |
*/
|
51 |
|
52 |
public class TestNormalizeStringsFromFile extends TestCase { |
53 |
|
54 |
private static final Logger log = PluginServices.getLogger(); |
55 |
Patternnormalization pat = new Patternnormalization();
|
56 |
ArrayList<String> chains = new ArrayList<String>(); |
57 |
File file;
|
58 |
DBFDriver test = null;
|
59 |
|
60 |
public void setUp() { |
61 |
|
62 |
File f = new File( |
63 |
"src-test/org/gvsig/normalization/operations/testdata/normFile.xml");
|
64 |
try {
|
65 |
IStorage storage = new StorageXML();
|
66 |
FileReader red = new FileReader(f); |
67 |
storage.load(red); |
68 |
pat.setstate(storage); |
69 |
//pat = (Patternnormalization) Patternnormalization.unmarshal(red);
|
70 |
} catch (Exception e) { |
71 |
log.error("Error parsing the xml pattern", e);
|
72 |
} |
73 |
chains.add("TEST1;TEST2;TEST3");
|
74 |
chains.add("TEST4;TEST5;TEST6");
|
75 |
chains.add("TEST7;TEST8;TEST9");
|
76 |
} |
77 |
|
78 |
public void testNormalizeStringsFromFile() { |
79 |
|
80 |
try {
|
81 |
file = File.createTempFile("temp", ".dbf"); |
82 |
|
83 |
StringListNormalization norm = new StringListNormalization(pat,
|
84 |
chains, file); |
85 |
norm.preProcess(); |
86 |
for (int i = 0; i < chains.size(); i++) { |
87 |
try {
|
88 |
norm.fillRow(i); |
89 |
} catch (ReadDriverException e) {
|
90 |
e.printStackTrace(); |
91 |
} |
92 |
} |
93 |
norm.postProcess(); |
94 |
|
95 |
// Asserts
|
96 |
test = new DBFDriver();
|
97 |
int nFields = -1; |
98 |
long nRows = -1; |
99 |
String val00 = null; |
100 |
String val01 = null; |
101 |
String val10 = null; |
102 |
String val11 = null; |
103 |
try {
|
104 |
test.open(file); |
105 |
nFields = test.getFieldCount(); |
106 |
nRows = test.getRowCount(); |
107 |
val00 = test.getFieldValue(0, 0).toString().trim(); |
108 |
val01 = test.getFieldValue(0, 1).toString().trim(); |
109 |
val10 = test.getFieldValue(1, 0).toString().trim(); |
110 |
val11 = test.getFieldValue(1, 1).toString().trim(); |
111 |
test.close(); |
112 |
} catch (Exception e) { |
113 |
e.printStackTrace(); |
114 |
} |
115 |
|
116 |
assertEquals(nFields, 2);
|
117 |
assertEquals(nRows, 3);
|
118 |
|
119 |
assertEquals(val00, "TEST1");
|
120 |
assertEquals(val10, "TEST4");
|
121 |
assertEquals(val01, "TEST2;TEST3");
|
122 |
assertEquals(val11, "TEST5;TEST6");
|
123 |
|
124 |
file.delete(); |
125 |
|
126 |
} catch (IOException e1) { |
127 |
log.error("Creating the temp file", e1);
|
128 |
} |
129 |
|
130 |
} |
131 |
|
132 |
public void tearDown() { |
133 |
try {
|
134 |
test.close(); |
135 |
log.info("TEST FINISHED");
|
136 |
} catch (CloseDriverException e) {
|
137 |
log.error("Clossing the driver");
|
138 |
e.printStackTrace(); |
139 |
} |
140 |
} |
141 |
|
142 |
} |