Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGeocoding / src-test / org / gvsig / normalization / operations / TestMarshall.java @ 32307

History | View | Annotate | Download (3.69 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.IOException;
33
import java.io.UnsupportedEncodingException;
34

    
35
import junit.framework.TestCase;
36

    
37
import org.apache.log4j.Logger;
38
import org.exolab.castor.xml.MarshalException;
39
import org.exolab.castor.xml.ValidationException;
40
import org.gvsig.normalization.patterns.Element;
41
import org.gvsig.normalization.patterns.NormalizationPattern;
42

    
43
import com.iver.andami.PluginServices;
44
import com.iver.cit.gvsig.fmap.layers.XMLException;
45

    
46
public class TestMarshall extends TestCase {
47

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

    
50
        public void testMarshallUnmarshall() throws MarshalException,
51
                        ValidationException, XMLException, IOException {
52

    
53
                log.info("testMarshallUnmarshall. start test");
54
                NormalizationPattern pat = new NormalizationPattern();
55
                NormalizationPattern pat3 = new NormalizationPattern();
56
                File file = new File(
57
                                "src-test/org/gvsig/normalization/operations/testdata/patSplitChain.xml");
58

    
59
                // PARSER
60

    
61
                pat.loadFromXML(file);
62

    
63
                assertEquals(11, pat.getElements().size());
64
                assertEquals(0, pat.getNofirstrows());
65

    
66
                Element elem1 = (Element) pat.getElements().get(0);
67

    
68
                assertNotNull(elem1);
69
                assertEquals("NewField", elem1.getFieldname());
70

    
71
                // SERIALIZER
72
                File ftemp = File.createTempFile("temp", "txt");
73
                pat.saveToXML(ftemp);
74

    
75
                // PARSER
76

    
77
                assertNotNull(ftemp);
78

    
79
                pat3.loadFromXML(ftemp);
80

    
81
                Element elem2 = (Element) pat3.getElements().get(0);
82

    
83
                assertNotNull(elem2);
84

    
85
                assertEquals(elem1.getImportfield(), elem2.getImportfield());
86
                assertEquals(elem1.getFieldwidth(), elem2.getFieldwidth());
87
                assertEquals(elem1.getFieldname(), elem2.getFieldname());
88
                assertEquals(elem1.getInfieldseparators().getDecimalseparator(), elem2
89
                                .getInfieldseparators().getDecimalseparator());
90

    
91
        }
92

    
93
        public void testUnmarshall() throws MarshalException,
94
                        FileNotFoundException, UnsupportedEncodingException,
95
                        ValidationException, XMLException {
96

    
97
                log.info("testUnmarshall. start test");
98
                File file = new File(
99
                                "src-test/org/gvsig/normalization/operations/testdata/patSplitChain.xml");
100
                // Marshal the person object
101
                NormalizationPattern pat = new NormalizationPattern();
102
                pat.loadFromXML(file);
103

    
104
                log.info("pattern loaded");
105
                // results
106
                assertEquals(11, pat.getElements().size());
107
                assertEquals(0, ((Element) pat.getElements().get(3)).getFieldwidth());
108
                assertEquals(true, ((Element) pat.getElements().get(2))
109
                                .getImportfield());
110
                assertEquals(true, ((Element) pat.getElements().get(4))
111
                                .getFieldseparator().getSemicolonsep());
112

    
113
                log.info("testMarshallUnmarshall. test finished");
114
        }
115

    
116
}