root / trunk / libraries / libGeocoding / src-test / org / gvsig / normalization / operations / TestAllTypeData.java @ 23012
History | View | Annotate | Download (4.13 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.normalization.patterns.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.andami.PluginServices; |
44 |
import com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver; |
45 |
|
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 TestAllTypeData 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 |
|
59 |
public void setUp() { |
60 |
File f = new File( |
61 |
"src-test/org/gvsig/normalization/operations/testdata/pattotal.xml");
|
62 |
IStorage storage = new StorageXML();
|
63 |
try {
|
64 |
FileReader red = new FileReader(f); |
65 |
storage.load(red); |
66 |
pat.setstate(storage); |
67 |
} catch (Exception e) { |
68 |
log.error("Error parsing the xml pattern", e);
|
69 |
} |
70 |
|
71 |
chains.add("Javier#-7;-0.2578&01/10/2007&02/09&02-78");
|
72 |
chains.add("Javier#-7;-0.2578&01/10/2007&02/09&02-78");
|
73 |
chains.add("v");
|
74 |
chains.add("");
|
75 |
chains.add("Javier#-7;-0.2578&01/10/2007&02/09&02-78");
|
76 |
chains.add("Javier#-7;-0.2578&01/10/2007&02/09&02-78");
|
77 |
} |
78 |
|
79 |
public void testAllTypeData() { |
80 |
|
81 |
try {
|
82 |
file = File.createTempFile("alltype", ".dbf"); |
83 |
|
84 |
StringListNormalization norm = new StringListNormalization(pat,
|
85 |
chains, file); |
86 |
norm.preProcess(); |
87 |
for (int i = 0; i < chains.size(); i++) { |
88 |
try {
|
89 |
norm.fillRow(i); |
90 |
} catch (ReadDriverException e) {
|
91 |
e.printStackTrace(); |
92 |
} |
93 |
} |
94 |
norm.postProcess(); |
95 |
|
96 |
DBFDriver test = new DBFDriver();
|
97 |
int nFields = -1; |
98 |
long nRows = -1; |
99 |
String val01 = null; |
100 |
String val03 = null; |
101 |
String val10 = null; |
102 |
String val30 = null; |
103 |
String val52 = null; |
104 |
try {
|
105 |
test.open(file); |
106 |
nFields = test.getFieldCount(); |
107 |
nRows = test.getRowCount(); |
108 |
val01 = test.getFieldValue(0, 1).toString().trim(); |
109 |
val03 = test.getFieldValue(0, 3).toString().trim(); |
110 |
val10 = test.getFieldValue(1, 0).toString().trim(); |
111 |
val30 = test.getFieldValue(3, 0).toString().trim(); |
112 |
val52 = test.getFieldValue(5, 2).toString().trim(); |
113 |
test.close(); |
114 |
} catch (Exception e) { |
115 |
e.printStackTrace(); |
116 |
} |
117 |
|
118 |
assertEquals(nFields, 6);
|
119 |
assertEquals(nRows, 6);
|
120 |
|
121 |
log.info(val01); |
122 |
log.info(val03); |
123 |
log.info(val10); |
124 |
log.info(val30); |
125 |
log.info(val52); |
126 |
|
127 |
assertEquals(val01, "-7");
|
128 |
assertEquals(val03, "01-oct-2007");
|
129 |
assertEquals(val10, "Javier");
|
130 |
assertEquals(val30, "");
|
131 |
assertEquals(val52, "-2578.0");
|
132 |
|
133 |
file.delete(); |
134 |
|
135 |
} catch (IOException e1) { |
136 |
// TODO Auto-generated catch block
|
137 |
e1.printStackTrace(); |
138 |
} |
139 |
|
140 |
} |
141 |
|
142 |
public void tearDown() { |
143 |
log.info("TEST FINISHED");
|
144 |
} |
145 |
|
146 |
} |