Statistics
| Revision:

root / trunk / libraries / libGeocoding / src-test / org / gvsig / normalization / operations / TestNormalizeTableAlterTable.java @ 23012

History | View | Annotate | Download (5.03 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 development
26
 */
27

    
28
package org.gvsig.normalization.operations;
29

    
30
import java.io.File;
31
import java.io.FileReader;
32

    
33
import junit.framework.TestCase;
34

    
35
import org.apache.log4j.Logger;
36
import org.gvsig.normalization.patterns.Patternnormalization;
37
import org.gvsig.tools.storage.IStorage;
38
import org.gvsig.tools.storage.StorageXML;
39

    
40
import com.hardcode.gdbms.driver.exceptions.CloseDriverException;
41
import com.hardcode.gdbms.engine.data.file.FileDataSource;
42
import com.hardcode.gdbms.engine.data.file.FileDataSourceFactory;
43
import com.hardcode.gdbms.engine.data.file.FileSourceInfo;
44
import com.iver.andami.PluginServices;
45
import com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver;
46
import com.iver.cit.gvsig.fmap.edition.EditableAdapter;
47
import com.iver.cit.gvsig.fmap.edition.EditionEvent;
48
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
49

    
50
/**
51
 * 
52
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
53
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
54
 * 
55
 */
56

    
57
public class TestNormalizeTableAlterTable extends TestCase {
58

    
59
        private static final Logger log = PluginServices.getLogger();
60
        Patternnormalization pat = new Patternnormalization();
61
        File dbfFile = new File(
62
                        "src-test/org/gvsig/normalization/operations/testdata/pro.dbf");
63
        File patFile = new File(
64
                        "src-test/org/gvsig/normalization/operations/testdata/normAlterTable.xml");
65

    
66
        EditableAdapter source = new EditableAdapter();
67
        DBFDriver driver = null;
68
        FileDataSource fiDatSource = null;
69

    
70
        // TODO
71

    
72
        public void setUp() {
73
                try {
74
                        IStorage storage = new StorageXML();
75
                        FileReader red = new FileReader(patFile);
76
                        
77
                        storage.load(red);
78
                        pat.setstate(storage);
79
                        //pat = (Patternnormalization) Patternnormalization.unmarshal(red);
80
                } catch (Exception e) {
81
                        log.error("Error parsing the xml pattern", e);
82
                }
83
                try {
84
                        driver = new DBFDriver();
85
                        driver.open(dbfFile);
86

    
87
                        fiDatSource = FileDataSourceFactory.newInstance();
88
                        fiDatSource.setDriver(driver);
89
                        String path = dbfFile.getAbsolutePath();
90
                        String na = dbfFile.getName();
91
                        FileSourceInfo fsi = new FileSourceInfo();
92
                        fsi.file = path;
93
                        fsi.name = na;
94
                        fiDatSource.setSourceInfo(fsi);
95

    
96
                        SelectableDataSource selDaSource = new SelectableDataSource(
97
                                        fiDatSource);
98

    
99
                        source.setOriginalDataSource(selDaSource);
100
                        source.startEdition(EditionEvent.GRAPHIC);
101

    
102
                } catch (Exception e) {
103
                        log.error("Reading the driver", e);
104
                }
105
        }
106

    
107
        public void testNormalizeTableAlterTable() {
108
                TableNormalization norm = new TableNormalization(source, 5, pat);
109
                norm.preProcess();
110
                try {
111
                        for (int i = 0; i < source.getRowCount(); i++) {
112

    
113
                                norm.fillRow(i);
114

    
115
                        }
116
                } catch (Exception e) {
117
                        log.error("Normalizing", e);
118
                }
119
                norm.postProcess();
120

    
121
                System.out.println("Fin");
122

    
123
                String val09 = null;
124
                String val06 = null;
125
                String val17 = null;
126
                String val27 = null;
127
                String val29 = null;
128
                String val210 = null;
129

    
130
                int nFields = 0;
131
                long nRows = 0;
132

    
133
                try {
134

    
135
                        // int fields = driver.getFieldCount();
136
                        // long rows = driver.getRowCount();
137

    
138
                        SelectableDataSource sds = source.getRecordset();
139
                        nFields = sds.getFieldCount();
140
                        nRows = sds.getRowCount();
141

    
142
                        val09 = sds.getFieldValue(0, 9).toString().trim();
143
                        val06 = sds.getFieldValue(0, 6).toString().trim();
144
                        val17 = sds.getFieldValue(1, 7).toString().trim();
145
                        val27 = sds.getFieldValue(2, 7).toString().trim();
146
                        val29 = sds.getFieldValue(2, 9).toString().trim();
147
                        val210 = sds.getFieldValue(2, 10).toString().trim();
148

    
149
                } catch (Exception e) {
150
                        e.printStackTrace();
151
                }
152

    
153
                assertEquals(nFields, 11);
154
                assertEquals(nRows, 3);
155

    
156
                assertEquals(val09, "35.5");
157
                assertEquals(val06, "23030");
158
                assertEquals(val17, "743690");
159
                assertEquals(val27, "700347");
160
                assertEquals(val29, "26.0");
161
                assertEquals(val210, "12/11/2006");
162

    
163
        }
164

    
165
        public void tearDown() {
166
                try {
167
                        driver.close();
168

    
169
                        log.info("TEST FINISHED");
170
                } catch (CloseDriverException e) {
171
                        log.error("Clossing the driver");
172
                        e.printStackTrace();
173
                }
174
        }
175

    
176
}