root / trunk / libraries / libGeocoding / src-test / org / gvsig / normalization / patterns / TestPersistence.java @ 23012
History | View | Annotate | Download (4.39 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.patterns; |
29 |
|
30 |
import java.io.FileNotFoundException; |
31 |
import java.io.FileReader; |
32 |
import java.io.FileWriter; |
33 |
import java.io.IOException; |
34 |
import java.util.ArrayList; |
35 |
import java.util.List; |
36 |
|
37 |
import junit.framework.TestCase; |
38 |
|
39 |
import org.gvsig.tools.storage.IStorage; |
40 |
import org.gvsig.tools.storage.StorageXML; |
41 |
|
42 |
/**
|
43 |
*
|
44 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
45 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
46 |
*
|
47 |
*/
|
48 |
public class TestPersistence extends TestCase { |
49 |
|
50 |
// private static final Logger log = PluginServices.getLogger();
|
51 |
|
52 |
public void testParseXML() { |
53 |
|
54 |
Patternnormalization pat = new Patternnormalization();
|
55 |
pat.setPatternname("pruebaParseXML.xml");
|
56 |
pat.setPatternurl("c:\\pruebaParseXML.xml");
|
57 |
pat.setNofirstrows(0);
|
58 |
|
59 |
List elems = new ArrayList(); |
60 |
|
61 |
Element elem1 = new Element(); |
62 |
elem1.setFieldname("campo1");
|
63 |
|
64 |
Fieldtype tipo = new Fieldtype();
|
65 |
Stringvalue strval = new Stringvalue();
|
66 |
strval.setStringvaluewidth(50);
|
67 |
tipo.setStringvalue(strval); |
68 |
elem1.setFieldtype(tipo); |
69 |
|
70 |
elem1.setFieldwidth(30);
|
71 |
|
72 |
Fieldseparator fsep = new Fieldseparator();
|
73 |
fsep.setSemicolonsep(true);
|
74 |
fsep.setJoinsep(false);
|
75 |
elem1.setFieldseparator(fsep); |
76 |
|
77 |
Infieldseparators infsep = new Infieldseparators();
|
78 |
infsep.setThousandseparator(",");
|
79 |
infsep.setDecimalseparator(".");
|
80 |
infsep.setTextseparator("\"");
|
81 |
elem1.setInfieldseparators(infsep); |
82 |
|
83 |
elem1.setImportfield(true);
|
84 |
|
85 |
elems.add(elem1); |
86 |
|
87 |
Element elem2 = new Element(); |
88 |
elem2.setFieldname("campo2");
|
89 |
|
90 |
Fieldtype tipo2 = new Fieldtype();
|
91 |
Stringvalue strval2 = new Stringvalue();
|
92 |
strval2.setStringvaluewidth(50);
|
93 |
tipo2.setStringvalue(strval2); |
94 |
elem2.setFieldtype(tipo2); |
95 |
|
96 |
elem2.setFieldwidth(30);
|
97 |
|
98 |
Fieldseparator fsep2 = new Fieldseparator();
|
99 |
fsep2.setSemicolonsep(true);
|
100 |
fsep2.setJoinsep(false);
|
101 |
elem2.setFieldseparator(fsep2); |
102 |
|
103 |
Infieldseparators infsep2 = new Infieldseparators();
|
104 |
infsep2.setThousandseparator(",");
|
105 |
infsep2.setDecimalseparator(".");
|
106 |
infsep2.setTextseparator("\"");
|
107 |
elem2.setInfieldseparators(infsep2); |
108 |
|
109 |
elem2.setImportfield(true);
|
110 |
|
111 |
elems.add(elem2); |
112 |
|
113 |
pat.setElements(elems); |
114 |
|
115 |
IStorage storage = new StorageXML();
|
116 |
FileWriter writer = null; |
117 |
|
118 |
pat.getstate(storage); |
119 |
try {
|
120 |
writer = new FileWriter(pat.getPatternurl()); |
121 |
storage.dump(writer); |
122 |
writer.close(); |
123 |
} catch (IOException e) { |
124 |
// TODO Auto-generated catch block
|
125 |
e.printStackTrace(); |
126 |
} |
127 |
|
128 |
} |
129 |
|
130 |
public void testLoadXML() { |
131 |
|
132 |
Patternnormalization pat = new Patternnormalization();
|
133 |
IStorage storage = new StorageXML();
|
134 |
FileReader reader = null; |
135 |
|
136 |
try {
|
137 |
reader = new FileReader("c:\\pruebaParseXML.xml"); |
138 |
storage.load(reader); |
139 |
pat.setstate(storage); |
140 |
} catch (FileNotFoundException e) { |
141 |
// TODO Auto-generated catch block
|
142 |
e.printStackTrace(); |
143 |
} catch (ClassNotFoundException e) { |
144 |
// TODO Auto-generated catch block
|
145 |
e.printStackTrace(); |
146 |
} |
147 |
|
148 |
assertEquals(0, pat.getNofirstrows());
|
149 |
|
150 |
assertEquals("pruebaParseXML.xml", pat.getPatternname());
|
151 |
assertEquals("c:\\pruebaParseXML.xml", pat.getPatternurl());
|
152 |
assertEquals(0, pat.getNofirstrows());
|
153 |
|
154 |
Element elem0 = ((Element)pat.getElements().get(0)); |
155 |
|
156 |
assertEquals("campo1", elem0.getFieldname());
|
157 |
assertEquals(true, elem0.getImportfield());
|
158 |
} |
159 |
} |