Statistics
| Revision:

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

History | View | Annotate | Download (4.1 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.FileNotFoundException;
32
import java.io.IOException;
33
import java.io.UnsupportedEncodingException;
34
import java.util.ArrayList;
35

    
36
import junit.framework.TestCase;
37

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

    
43
import com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver;
44
import com.iver.cit.gvsig.fmap.layers.XMLException;
45

    
46
/**
47
 * 
48
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
49
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicent Sanjaime Calvet</a>
50
 * 
51
 */
52
public class TestFilterString extends TestCase {
53

    
54
        private static final Logger log = Logger.getLogger(TestFilterString.class);
55

    
56
        public void testFilterString() throws MarshalException,
57
                        FileNotFoundException, UnsupportedEncodingException,
58
                        ValidationException, XMLException {
59

    
60
                log.info("TestFilterString: start the test");
61

    
62
                ArrayList<String> chains = new ArrayList<String>();
63
                chains.add(",XXX;9393;33.25;337.22;1/1/8");
64

    
65
                File fPat = new File(
66
                                "./src-test/org/gvsig/normalization/testdata/PATNORM_TEST.xml");
67

    
68
                assertNotNull(fPat);
69

    
70
                NormalizationPattern pat = parserPat(fPat);
71
                assertNotNull(pat);
72

    
73
                File outputFile = null;
74
                try {
75
                        outputFile = File.createTempFile("filters", ".dbf");
76
                } catch (IOException e1) {
77
                        e1.printStackTrace();
78
                }
79

    
80
                // Normalization
81
                StringListNormalization norm = new StringListNormalization(pat, chains,
82
                                outputFile);
83

    
84
                norm.preProcess();
85
                for (int i = 0; i < chains.size(); i++) {
86
                        try {
87
                                norm.fillRow(i);
88
                        } catch (Exception e) {
89
                                e.printStackTrace();
90
                        }
91
                }
92
                norm.postProcess();
93

    
94
                DBFDriver test = new DBFDriver();
95
                int nFields = -1;
96
                long nRows = -1;
97
                String val00 = null;
98
                String val01 = null;
99
                String val02 = null;
100
                String val03 = null;
101
                String val04 = null;
102
                String val05 = null;
103

    
104
                try {
105
                        test.open(outputFile);
106
                        nFields = test.getFieldCount();
107
                        nRows = test.getRowCount();
108
                        val00 = test.getFieldValue(0, 0).toString().trim();
109
                        val01 = test.getFieldValue(0, 1).toString().trim();
110
                        val02 = test.getFieldValue(0, 2).toString().trim();
111
                        val03 = test.getFieldValue(0, 3).toString().trim();
112
                        val04 = test.getFieldValue(0, 4).toString().trim();
113
                        val05 = test.getFieldValue(0, 5).toString().trim();
114

    
115
                        test.close();
116
                } catch (Exception e) {
117
                        e.printStackTrace();
118
                }
119

    
120
                assertEquals(nFields, 6);
121
                assertEquals(nRows, 1);
122

    
123
                assertEquals(val00, "");
124
                assertEquals(val01, "XXX");
125
                assertEquals(val02, "9393");
126
                assertEquals(val03, "0.0");
127
                assertEquals(val04, "337.22");
128
                assertEquals(val05, "01-ene-0008");
129

    
130
                log.info("TestFilterString: test finished");
131
        }
132

    
133
        private NormalizationPattern parserPat(File f) throws MarshalException,
134
                        FileNotFoundException, UnsupportedEncodingException,
135
                        ValidationException, XMLException {
136
                NormalizationPattern pat = new NormalizationPattern();
137
                pat.loadFromXML(f);
138
                return pat;
139
        }
140

    
141
}