Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.geocoding / src-test / org / gvsig / normalization / operations / TestFilterString.java @ 32479

History | View | Annotate | Download (4.59 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.IOException;
32
import java.util.ArrayList;
33
import java.util.List;
34

    
35
import org.gvsig.fmap.dal.exception.DataException;
36
import org.gvsig.fmap.dal.feature.FeatureStore;
37
import org.gvsig.normalization.algorithm.NormalizationAlgorithm;
38
import org.gvsig.normalization.algorithm.impl.DefaultNormalizationAlgorithm;
39
import org.gvsig.normalization.impl.DefaultNormalizationLibrary;
40
import org.gvsig.normalization.impl.NormalizationTransform;
41
import org.gvsig.normalization.pattern.NormalizationPattern;
42
import org.gvsig.normalization.pattern.impl.DefaultNormalizationPattern;
43
import org.gvsig.tools.library.Library;
44
import org.gvsig.tools.persistence.PersistenceException;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

    
48
/**
49
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
50
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicent Sanjaime Calvet</a>
51
 */
52
public class TestFilterString extends
53
                org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase {
54

    
55
        private static final Logger log = LoggerFactory
56
                        .getLogger(TestFilterString.class);
57

    
58
        @Override
59
        protected void doSetUp() throws Exception {
60
                Library normlib = new DefaultNormalizationLibrary();
61
                normlib.initialize();
62
                normlib.postInitialize();
63
        }
64

    
65
        /**
66
         * @throws IOException
67
         * @throws PersistenceException
68
         * @throws DataException
69
         * 
70
         */
71
        public void testTransformFeatureStore() throws Exception {
72

    
73
                // store
74
                List<String> chains = new ArrayList<String>();
75
                chains.add(",XXX;9393;33.25;337.22E2;1/1/8");
76
                FeatureStore store = null;
77

    
78
                // Pattern
79
                File filePattern = new File(
80
                                "resources-test/normalization/PATNORM_TEST.xml");
81
                assertTrue(filePattern.exists());
82
                assertNotNull(filePattern);
83
                NormalizationPattern pat = parserPat(filePattern);
84
                assertNotNull(pat);
85

    
86
                // Algorithm
87
                NormalizationAlgorithm algorithm = new DefaultNormalizationAlgorithm(
88
                                pat);
89

    
90
                // Normalization transform
91
                NormalizationTransform transform = new NormalizationTransform();
92
                transform.initialize(store, pat, 0, algorithm);
93

    
94
                // Add transform
95
                store.getTransforms().add(transform);
96

    
97
                //        
98
                //
99
                //                
100
                // int nFields = -1;
101
                // long nRows = -1;
102
                // String val00 = null;
103
                // String val01 = null;
104
                // String val02 = null;
105
                // String val03 = null;
106
                // String val04 = null;
107
                // String val05 = null;
108
                //
109
                // try {
110
                // test.open(outputFile);
111
                // nFields = test.getFieldCount();
112
                // nRows = test.getRowCount();
113
                // val00 = test.getFieldValue(0, 0).toString().trim();
114
                // val01 = test.getFieldValue(0, 1).toString().trim();
115
                // val02 = test.getFieldValue(0, 2).toString().trim();
116
                // val03 = test.getFieldValue(0, 3).toString().trim();
117
                // val04 = test.getFieldValue(0, 4).toString().trim();
118
                // val05 = test.getFieldValue(0, 5).toString().trim();
119
                //
120
                // test.close();
121
                // } catch (Exception e) {
122
                // e.printStackTrace();
123
                // }
124
                //
125
                // assertEquals(nFields, 6);
126
                // assertEquals(nRows, 1);
127
                //
128
                // assertEquals(val00, "");
129
                // assertEquals(val01, "XXX");
130
                // assertEquals(val02, "9393");
131
                // assertEquals(val03, "0.0");
132
                // assertEquals(val04, "33722.0");
133
                // assertEquals(val05, "01-ene-0008");
134

    
135
                log.debug("Test finished");
136
        }
137

    
138
        /**
139
         * 
140
         * @param f
141
         * @return
142
         * @throws PersistenceException
143
         * @throws IOException
144
         */
145
        private NormalizationPattern parserPat(File f) throws Exception {
146

    
147
                NormalizationPattern pat = new DefaultNormalizationPattern();
148
                ((DefaultNormalizationPattern) pat).loadFromXML(f);
149
                return pat;
150
        }
151

    
152
}