Statistics
| Revision:

root / trunk / extensions / extNormalization / src-test / org / gvsig / normalization / operations / TestMarshall.java @ 22825

History | View | Annotate | Download (3.93 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.StringReader;
34
import java.io.StringWriter;
35

    
36
import junit.framework.TestCase;
37

    
38
import org.apache.log4j.Logger;
39
import org.exolab.castor.xml.Unmarshaller;
40
import org.gvsig.geocoding.patterns.normalization.Addresselement;
41
import org.gvsig.geocoding.patterns.normalization.Patternnormalization;
42

    
43
import com.iver.andami.PluginServices;
44

    
45
public class TestMarshall extends TestCase {
46

    
47
        private static final Logger log = PluginServices.getLogger();
48

    
49
        public void testMarshallUnmarshall() {
50

    
51
                log.info("testMarshallUnmarshall. start test");
52
                Patternnormalization pat = null;
53
                File f = new File(
54
                                "src-test/org/gvsig/normalization/operations/testdata/patSplitChain.xml");
55

    
56
                FileReader red = null;
57

    
58
                try {
59
                        red = new FileReader(f);
60
                        pat = (Patternnormalization) Patternnormalization.unmarshal(red);
61

    
62
                        Addresselement al = pat.getAddresselements().getAddresselement()[0];
63
                        Addresselement elem = null;
64

    
65
                        assertNotNull(al);
66

    
67
                        StringWriter stw = new StringWriter();
68
                        al.marshal(stw);
69

    
70
                        elem = (Addresselement) Addresselement.unmarshal(new StringReader(
71
                                        stw.toString()));
72

    
73
                        assertNotNull(elem);
74
                        assertEquals(al.getImportfield(), elem.getImportfield());
75
                        assertEquals(al.getFieldwidth(), elem.getFieldwidth());
76
                        assertEquals(al.getNewfieldname(), elem.getNewfieldname());
77
                        assertEquals(al.getInfieldseparators().getDecimalseparator()
78
                                        .getValue(), elem.getInfieldseparators()
79
                                        .getDecimalseparator().getValue());
80

    
81
                } catch (Exception e) {
82
                        log.error("Parsing and serializing the pattern", e);
83
                        e.printStackTrace();
84
                }
85
                log.info("testMarshallUnmarshall. test finished");
86
        }
87

    
88
        public void testUnmarshall() {
89

    
90
                log.info("testUnmarshall. start test");
91
                // Create a Reader to the file to unmarshall from
92
                FileReader reader = null;
93
                try {
94
                        reader = new FileReader(
95
                                        "src-test/org/gvsig/normalization/operations/testdata/patSplitChain.xml");
96
                        assertNotNull(reader);
97
                } catch (FileNotFoundException e) {
98
                        log.error("File not found");
99
                        e.printStackTrace();
100
                }
101

    
102
                // Marshal the person object
103
                Patternnormalization pat = null;
104
                try {
105
                        pat = (Patternnormalization) Unmarshaller.unmarshal(
106
                                        Patternnormalization.class, reader);
107
                        assertNotNull(pat);
108
                } catch (Exception e) {
109
                        log.error("Unmarshall the pattern");
110
                        e.printStackTrace();
111
                }
112
                log.info("pattern loaded");
113
                // results
114
                assertEquals(11, pat.getAddresselements().getAddresselementCount());
115
                assertEquals(0, pat.getAddresselements().getAddresselement(3)
116
                                .getFieldwidth());
117
                assertEquals(true, pat.getAddresselements().getAddresselement(2)
118
                                .getImportfield());
119
                assertEquals(true, pat.getAddresselements().getAddresselement(4)
120
                                .getFieldseparator().getSemicolonsep());
121

    
122
                log.info("testMarshallUnmarshall. test finished");
123
        }
124

    
125
}