root / trunk / libraries / libGeocoding / src-test / org / gvsig / normalization / operations / TestNormalizeTableJoinTable.java @ 23012
History | View | Annotate | Download (5.32 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 |
|
34 |
import junit.framework.TestCase; |
35 |
|
36 |
import org.apache.log4j.Logger; |
37 |
import org.gvsig.normalization.patterns.Patternnormalization; |
38 |
import org.gvsig.tools.storage.IStorage; |
39 |
import org.gvsig.tools.storage.StorageXML; |
40 |
|
41 |
import com.hardcode.gdbms.driver.exceptions.CloseDriverException; |
42 |
import com.hardcode.gdbms.engine.data.file.FileDataSource; |
43 |
import com.hardcode.gdbms.engine.data.file.FileDataSourceFactory; |
44 |
import com.hardcode.gdbms.engine.data.file.FileSourceInfo; |
45 |
import com.iver.andami.PluginServices; |
46 |
import com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver; |
47 |
import com.iver.cit.gvsig.fmap.edition.EditableAdapter; |
48 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
49 |
|
50 |
/**
|
51 |
*
|
52 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
53 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
54 |
*
|
55 |
*/
|
56 |
public class TestNormalizeTableJoinTable extends TestCase { |
57 |
|
58 |
private static final Logger log = PluginServices.getLogger(); |
59 |
Patternnormalization pat = new Patternnormalization();
|
60 |
File dbfFile = new File( |
61 |
"src-test/org/gvsig/normalization/operations/testdata/pro.dbf");
|
62 |
File patFile = new File( |
63 |
"src-test/org/gvsig/normalization/operations/testdata/normAlterTable.xml");
|
64 |
File outputFile;
|
65 |
EditableAdapter source = new EditableAdapter();
|
66 |
String[] joinNames = { "PROVINCIA", "COUNT" }; |
67 |
DBFDriver test = null;
|
68 |
|
69 |
public void setUp() { |
70 |
try {
|
71 |
IStorage storage = new StorageXML();
|
72 |
FileReader red = new FileReader(patFile); |
73 |
|
74 |
|
75 |
storage.load(red); |
76 |
pat.setstate(storage); |
77 |
|
78 |
//pat = (Patternnormalization) Patternnormalization.unmarshal(red);
|
79 |
} catch (Exception e) { |
80 |
log.error("Error parsing the xml pattern", e);
|
81 |
} |
82 |
|
83 |
try {
|
84 |
test = new DBFDriver();
|
85 |
test.open(dbfFile); |
86 |
|
87 |
FileDataSource fildas = FileDataSourceFactory.newInstance(); |
88 |
fildas.setDriver(test); |
89 |
String path = dbfFile.getAbsolutePath();
|
90 |
String na = dbfFile.getName();
|
91 |
FileSourceInfo fsi = new FileSourceInfo();
|
92 |
fsi.file = path; |
93 |
fsi.name = na; |
94 |
fildas.setSourceInfo(fsi); |
95 |
|
96 |
SelectableDataSource sds = new SelectableDataSource(fildas);
|
97 |
|
98 |
source.setOriginalDataSource(sds); |
99 |
|
100 |
} catch (Exception e) { |
101 |
log.error("Reading the driver", e);
|
102 |
} |
103 |
|
104 |
} |
105 |
|
106 |
public void testNormalizeTableJoinTable() { |
107 |
|
108 |
try {
|
109 |
outputFile = File.createTempFile("jointable", ".dbf"); |
110 |
|
111 |
JoinedTableNormalization norm = new JoinedTableNormalization(
|
112 |
source, 5, pat, joinNames, outputFile);
|
113 |
norm.preProcess(); |
114 |
try {
|
115 |
for (int i = 0; i < source.getRowCount(); i++) { |
116 |
|
117 |
norm.fillRow(i); |
118 |
|
119 |
} |
120 |
} catch (Exception e) { |
121 |
log.error("Normalizing", e);
|
122 |
} |
123 |
norm.postProcess(); |
124 |
|
125 |
// asserts
|
126 |
|
127 |
DBFDriver test = new DBFDriver();
|
128 |
int nFields = -1; |
129 |
long nRows = -1; |
130 |
String val02 = null; |
131 |
String val03 = null; |
132 |
String val04 = null; |
133 |
String val05 = null; |
134 |
String val06 = null; |
135 |
String val12 = null; |
136 |
String val15 = null; |
137 |
String val26 = null; |
138 |
|
139 |
try {
|
140 |
test.open(outputFile); |
141 |
nFields = test.getFieldCount(); |
142 |
nRows = test.getRowCount(); |
143 |
val02 = test.getFieldValue(0, 2).toString().trim(); |
144 |
val03 = test.getFieldValue(0, 3).toString().trim(); |
145 |
val04 = test.getFieldValue(0, 4).toString().trim(); |
146 |
val05 = test.getFieldValue(0, 5).toString().trim(); |
147 |
val06 = test.getFieldValue(0, 6).toString().trim(); |
148 |
val12 = test.getFieldValue(1, 2).toString().trim(); |
149 |
val15 = test.getFieldValue(1, 5).toString().trim(); |
150 |
val26 = test.getFieldValue(2, 6).toString().trim(); |
151 |
|
152 |
} catch (Exception e) { |
153 |
e.printStackTrace(); |
154 |
} |
155 |
|
156 |
assertEquals(nFields, 7);
|
157 |
assertEquals(nRows, 3);
|
158 |
|
159 |
assertEquals(val02, "23030");
|
160 |
assertEquals(val03, "697096");
|
161 |
assertEquals(val04, "4364444");
|
162 |
assertEquals(val05, "35.5");
|
163 |
assertEquals(val06, "01/07/2007");
|
164 |
|
165 |
assertEquals(val12, "23030");
|
166 |
assertEquals(val15, "100.8");
|
167 |
|
168 |
assertEquals(val26, "12/11/2006");
|
169 |
|
170 |
outputFile.delete(); |
171 |
|
172 |
} catch (IOException e1) { |
173 |
log.error("Creating the temp file", e1);
|
174 |
} |
175 |
} |
176 |
|
177 |
public void tearDown() { |
178 |
try {
|
179 |
test.close(); |
180 |
log.info("TEST FINISHED");
|
181 |
} catch (CloseDriverException e) {
|
182 |
log.error("Clossing the driver", e);
|
183 |
} |
184 |
} |
185 |
} |