root / trunk / libraries / libGeocoding / src-test / org / gvsig / normalization / operations / TestMarshall.java @ 23012
History | View | Annotate | Download (4.83 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 developer
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.normalization.operations; |
29 |
|
30 |
import java.io.File; |
31 |
import java.io.FileNotFoundException; |
32 |
import java.io.FileReader; |
33 |
import java.io.FileWriter; |
34 |
import java.io.IOException; |
35 |
|
36 |
import junit.framework.TestCase; |
37 |
|
38 |
import org.apache.log4j.Logger; |
39 |
import org.gvsig.normalization.patterns.Element; |
40 |
import org.gvsig.normalization.patterns.Patternnormalization; |
41 |
import org.gvsig.tools.storage.IStorage; |
42 |
import org.gvsig.tools.storage.StorageXML; |
43 |
|
44 |
import com.iver.andami.PluginServices; |
45 |
|
46 |
public class TestMarshall extends TestCase { |
47 |
|
48 |
private static final Logger log = PluginServices.getLogger(); |
49 |
|
50 |
public void testMarshallUnmarshall() { |
51 |
|
52 |
log.info("testMarshallUnmarshall. start test");
|
53 |
Patternnormalization pat = new Patternnormalization();
|
54 |
Patternnormalization pat3 = new Patternnormalization();
|
55 |
File file = new File( |
56 |
"src-test/org/gvsig/normalization/operations/testdata/patSplitChain.xml");
|
57 |
|
58 |
FileReader reader = null; |
59 |
IStorage storage = new StorageXML();
|
60 |
|
61 |
Element elem1 = null; |
62 |
|
63 |
// PARSER
|
64 |
try {
|
65 |
reader = new FileReader(file); |
66 |
storage.load(reader); |
67 |
pat.setstate(storage); |
68 |
|
69 |
assertEquals(11, pat.getElements().size());
|
70 |
assertEquals(0, pat.getNofirstrows());
|
71 |
|
72 |
elem1 = (Element) pat.getElements().get(0); |
73 |
|
74 |
assertNotNull(elem1); |
75 |
assertEquals("NewField", elem1.getFieldname());
|
76 |
|
77 |
} catch (FileNotFoundException e) { |
78 |
log.error("Parsing and serializing the pattern", e);
|
79 |
} catch (ClassNotFoundException e) { |
80 |
log.error("Parsing and serializing the pattern", e);
|
81 |
} |
82 |
|
83 |
// SERIALIZER
|
84 |
IStorage storage2 = new StorageXML();
|
85 |
pat.getstate(storage2); |
86 |
File ftemp = null; |
87 |
try {
|
88 |
//ftemp = File.createTempFile("tem", "txt");
|
89 |
ftemp = new File("C:\\000.txt"); |
90 |
FileWriter writer2 = new FileWriter(ftemp); |
91 |
storage2.dump(writer2); |
92 |
writer2.close(); |
93 |
} catch (IOException e) { |
94 |
log.error("Parsing and serializing the pattern", e);
|
95 |
} |
96 |
|
97 |
// PARSER
|
98 |
IStorage storage3 = new StorageXML();
|
99 |
FileReader reader3;
|
100 |
try {
|
101 |
assertNotNull(ftemp); |
102 |
reader3 = new FileReader(ftemp); |
103 |
storage3.load(reader3); |
104 |
pat3.setstate(storage3); |
105 |
|
106 |
Element elem2 = (Element) pat3.getElements().get(0); |
107 |
|
108 |
assertNotNull(elem2); |
109 |
|
110 |
assertEquals(elem1.getImportfield(), elem2.getImportfield()); |
111 |
assertEquals(elem1.getFieldwidth(), elem2.getFieldwidth()); |
112 |
assertEquals(elem1.getFieldname(), elem2.getFieldname()); |
113 |
assertEquals(elem1.getInfieldseparators().getDecimalseparator(), |
114 |
elem2.getInfieldseparators().getDecimalseparator()); |
115 |
|
116 |
} catch (FileNotFoundException e) { |
117 |
log.error("Parsing and serializing the pattern", e);
|
118 |
} catch (ClassNotFoundException e) { |
119 |
log.error("Parsing and serializing the pattern", e);
|
120 |
} |
121 |
} |
122 |
|
123 |
public void testUnmarshall() { |
124 |
|
125 |
log.info("testUnmarshall. start test");
|
126 |
// Create a Reader to the file to unmarshall from
|
127 |
FileReader reader = null; |
128 |
try {
|
129 |
reader = new FileReader( |
130 |
"src-test/org/gvsig/normalization/operations/testdata/patSplitChain.xml");
|
131 |
assertNotNull(reader); |
132 |
} catch (FileNotFoundException e) { |
133 |
log.error("File not found");
|
134 |
e.printStackTrace(); |
135 |
} |
136 |
|
137 |
// Marshal the person object
|
138 |
Patternnormalization pat = new Patternnormalization();
|
139 |
IStorage storage = new StorageXML();
|
140 |
try {
|
141 |
storage.load(reader); |
142 |
pat.setstate(storage); |
143 |
assertNotNull(pat); |
144 |
} catch (Exception e) { |
145 |
log.error("Unmarshall the pattern");
|
146 |
e.printStackTrace(); |
147 |
} |
148 |
log.info("pattern loaded");
|
149 |
// results
|
150 |
assertEquals(11, pat.getElements().size());
|
151 |
assertEquals(0, ((Element) pat.getElements().get(3)).getFieldwidth()); |
152 |
assertEquals(true, ((Element) pat.getElements().get(2)) |
153 |
.getImportfield()); |
154 |
assertEquals(true, ((Element) pat.getElements().get(4)) |
155 |
.getFieldseparator().getSemicolonsep()); |
156 |
|
157 |
log.info("testMarshallUnmarshall. test finished");
|
158 |
} |
159 |
|
160 |
} |