Revision 23012

View differences:

trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/patterns/AllTests.java
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.patterns;
29

  
30
import junit.framework.Test;
31
import junit.framework.TestSuite;
32

  
33
/**
34
 * 
35
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
36
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
37
 * 
38
 */
39

  
40
public class AllTests {
41

  
42
	public static Test suite() {
43
		TestSuite suite = new TestSuite(
44
				"Test for org.gvsig.normalization.patterns");
45
		// $JUnit-BEGIN$
46
		suite.addTestSuite(TestPersistence.class);
47

  
48
		// $JUnit-END$
49
		return suite;
50
	}
51

  
52
}
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/patterns/TestPersistence.java
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.patterns;
29

  
30
import java.io.FileNotFoundException;
31
import java.io.FileReader;
32
import java.io.FileWriter;
33
import java.io.IOException;
34
import java.util.ArrayList;
35
import java.util.List;
36

  
37
import junit.framework.TestCase;
38

  
39
import org.gvsig.tools.storage.IStorage;
40
import org.gvsig.tools.storage.StorageXML;
41

  
42
/**
43
 * 
44
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
45
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
46
 * 
47
 */
48
public class TestPersistence extends TestCase {
49

  
50
	// private static final Logger log = PluginServices.getLogger();
51

  
52
	public void testParseXML() {
53

  
54
		Patternnormalization pat = new Patternnormalization();
55
		pat.setPatternname("pruebaParseXML.xml");
56
		pat.setPatternurl("c:\\pruebaParseXML.xml");
57
		pat.setNofirstrows(0);
58

  
59
		List elems = new ArrayList();
60

  
61
		Element elem1 = new Element();
62
		elem1.setFieldname("campo1");
63

  
64
		Fieldtype tipo = new Fieldtype();
65
		Stringvalue strval = new Stringvalue();
66
		strval.setStringvaluewidth(50);
67
		tipo.setStringvalue(strval);
68
		elem1.setFieldtype(tipo);
69

  
70
		elem1.setFieldwidth(30);
71

  
72
		Fieldseparator fsep = new Fieldseparator();
73
		fsep.setSemicolonsep(true);
74
		fsep.setJoinsep(false);
75
		elem1.setFieldseparator(fsep);
76

  
77
		Infieldseparators infsep = new Infieldseparators();
78
		infsep.setThousandseparator(",");
79
		infsep.setDecimalseparator(".");
80
		infsep.setTextseparator("\"");
81
		elem1.setInfieldseparators(infsep);
82

  
83
		elem1.setImportfield(true);
84

  
85
		elems.add(elem1);
86

  
87
		Element elem2 = new Element();
88
		elem2.setFieldname("campo2");
89

  
90
		Fieldtype tipo2 = new Fieldtype();
91
		Stringvalue strval2 = new Stringvalue();
92
		strval2.setStringvaluewidth(50);
93
		tipo2.setStringvalue(strval2);
94
		elem2.setFieldtype(tipo2);
95

  
96
		elem2.setFieldwidth(30);
97

  
98
		Fieldseparator fsep2 = new Fieldseparator();
99
		fsep2.setSemicolonsep(true);
100
		fsep2.setJoinsep(false);
101
		elem2.setFieldseparator(fsep2);
102

  
103
		Infieldseparators infsep2 = new Infieldseparators();
104
		infsep2.setThousandseparator(",");
105
		infsep2.setDecimalseparator(".");
106
		infsep2.setTextseparator("\"");
107
		elem2.setInfieldseparators(infsep2);
108

  
109
		elem2.setImportfield(true);
110

  
111
		elems.add(elem2);
112

  
113
		pat.setElements(elems);
114

  
115
		IStorage storage = new StorageXML();
116
		FileWriter writer = null;
117

  
118
		pat.getstate(storage);
119
		try {
120
			writer = new FileWriter(pat.getPatternurl());
121
			storage.dump(writer);
122
			writer.close();
123
		} catch (IOException e) {
124
			// TODO Auto-generated catch block
125
			e.printStackTrace();
126
		}
127

  
128
	}
129

  
130
	public void testLoadXML() {
131

  
132
		Patternnormalization pat = new Patternnormalization();
133
		IStorage storage = new StorageXML();
134
		FileReader reader = null;
135

  
136
		try {
137
			reader = new FileReader("c:\\pruebaParseXML.xml");
138
			storage.load(reader);
139
			pat.setstate(storage);
140
		} catch (FileNotFoundException e) {
141
			// TODO Auto-generated catch block
142
			e.printStackTrace();
143
		} catch (ClassNotFoundException e) {
144
			// TODO Auto-generated catch block
145
			e.printStackTrace();
146
		}
147

  
148
		assertEquals(0, pat.getNofirstrows());
149
		
150
		assertEquals("pruebaParseXML.xml", pat.getPatternname());
151
		assertEquals("c:\\pruebaParseXML.xml", pat.getPatternurl());
152
		assertEquals(0, pat.getNofirstrows());
153
		
154
		Element elem0 = ((Element)pat.getElements().get(0));
155
		
156
		assertEquals("campo1", elem0.getFieldname());
157
		assertEquals(true, elem0.getImportfield());
158
	}
159
}
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/AllTests.java
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 junit.framework.Test;
31
import junit.framework.TestSuite;
32

  
33
/**
34
 * 
35
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
36
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
37
 * 
38
 */
39
public class AllTests {
40

  
41
	public static Test suite() {
42
		TestSuite suite = new TestSuite(
43
				"Test for org.gvsig.normalization.operations");
44
		// $JUnit-BEGIN$
45
		
46
		suite.addTestSuite(TestMarshall.class);
47
		suite.addTestSuite(TestFilterString.class);
48
		suite.addTestSuite(TestNormAlgorithm.class);
49
		
50
		// Norm Strings from file
51
		suite.addTestSuite(TestCreateNewPattern.class);
52
		
53

  
54
		// Norm Strings from file
55
		suite.addTestSuite(TestNormalizeStringsFromFile.class);
56
		suite.addTestSuite(TestAllTypeData.class);
57

  
58
		// Norm Strings from table
59
		suite.addTestSuite(TestNormalizeTableAlterTable.class);
60
		suite.addTestSuite(TestNormalizeTableJoinTable.class);
61

  
62
		// $JUnit-END$
63
		return suite;
64
	}
65

  
66
}
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestCreateNewPattern.java
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.text.DecimalFormatSymbols;
31
import java.util.ArrayList;
32
import java.util.List;
33
import java.util.Locale;
34

  
35
import junit.framework.TestCase;
36

  
37
import org.gvsig.normalization.patterns.Decimalvalue;
38
import org.gvsig.normalization.patterns.Element;
39
import org.gvsig.normalization.patterns.Fieldseparator;
40
import org.gvsig.normalization.patterns.Fieldtype;
41
import org.gvsig.normalization.patterns.Infieldseparators;
42
import org.gvsig.normalization.patterns.Patternnormalization;
43
import org.gvsig.normalization.patterns.Stringvalue;
44

  
45
/*
46
 * This test validates a new pattern generated
47
 * 
48
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
49
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
50
 */
51
public class TestCreateNewPattern extends TestCase {
52

  
53
	public void getUp() {
54
	}
55

  
56
	public void testCreateNewPattern() {
57
		// Create object
58
		Patternnormalization pat = new Patternnormalization();
59

  
60
		// Field Separators
61
		Fieldseparator filsep1 = new Fieldseparator();
62

  
63
		filsep1.setSemicolonsep(true);
64
		filsep1.setJoinsep(false);
65
		filsep1.setColonsep(false);
66
		filsep1.setSpacesep(false);
67
		filsep1.setTabsep(false);
68

  
69
		// Field Separators
70
		Fieldseparator filsep2 = new Fieldseparator();
71

  
72
		filsep2.setSemicolonsep(true);
73
		filsep2.setJoinsep(false);
74
		filsep2.setColonsep(false);
75
		filsep2.setSpacesep(false);
76
		filsep2.setTabsep(false);
77

  
78
		// In Field Separators
79
		Locale loc = Locale.getDefault();
80
		DecimalFormatSymbols dfs = new DecimalFormatSymbols(loc);
81
		Infieldseparators infilsep1 = new Infieldseparators();
82

  
83
		infilsep1.setDecimalseparator(Character.toString(dfs
84
				.getDecimalSeparator()));
85
		infilsep1.setTextseparator("\"");
86
		infilsep1.setThousandseparator(Character.toString(dfs
87
				.getGroupingSeparator()));
88

  
89
		// In Field Separators
90

  
91
		Infieldseparators infilsep2 = new Infieldseparators();
92

  
93
		infilsep2.setDecimalseparator(Character.toString(dfs
94
				.getDecimalSeparator()));
95
		infilsep2.setTextseparator("\"");
96
		infilsep2.setThousandseparator(Character.toString(dfs
97
				.getGroupingSeparator()));
98

  
99
		// Main attributes
100
		pat.setPatternname("thePattern");
101
		pat.setPatternurl("c:\\patterns\\thePattern.xml");
102
		pat.setNofirstrows(0);
103

  
104
		// Create the first Address Element ////////////////////
105
		List elems = new ArrayList();
106
		Element elem1 = new Element();
107

  
108
		// Field Name
109
		elem1.setFieldname("StringField");
110

  
111
		elem1.setFieldseparator(filsep1);
112

  
113
		elem1.setInfieldseparators(infilsep1);
114

  
115
		// Field type
116
		Fieldtype newtype = new Fieldtype();
117
		Stringvalue strval = new Stringvalue();
118
		strval.setStringvaluewidth(50);
119
		newtype.setStringvalue(strval);
120

  
121
		elem1.setFieldtype(newtype);
122
		elem1.setFieldwidth(0);
123
		elem1.setImportfield(true);
124

  
125
		elems.add(elem1);
126

  
127
		// Create the second Address Element ////////////////////
128

  
129
		Element elem2 = new Element();
130

  
131
		// Field Name
132
		elem2.setFieldname("DecimalField");
133

  
134
		elem2.setFieldseparator(filsep2);
135

  
136
		elem2.setInfieldseparators(infilsep2);
137

  
138
		// Field type
139
		Fieldtype newtype2 = new Fieldtype();
140
		Decimalvalue decval = new Decimalvalue();
141
		decval.setDecimalvalueint(5);
142
		decval.setDecimalvaluedec(5);
143
		newtype2.setDecimalvalue(decval);
144

  
145
		elem2.setFieldtype(newtype2);
146
		elem2.setFieldwidth(0);
147
		elem2.setImportfield(true);
148

  
149
		elems.add(elem2);
150

  
151
		pat.setElements(elems);
152
		System.out.println("load pattern");
153

  
154
		assertNotNull(pat);
155
		assertNotNull(elem1);
156
		assertNotNull(elem2);
157
		assertEquals(((Element) pat.getElements().get(0)).getImportfield(),
158
				true);
159
		assertEquals(((Element) pat.getElements().get(0)).getFieldwidth(), 0);
160
		assertEquals(((Stringvalue)((Element) pat.getElements().get(0)).getFieldtype()
161
				.getStringvalue()).getStringvaluewidth(), 50);
162
		assertEquals(((Element) pat.getElements().get(0)).getFieldseparator()
163
				.getSemicolonsep(), true);
164
		assertEquals(((Element) pat.getElements().get(1)).getImportfield(),
165
				true);
166
		assertEquals(((Element) pat.getElements().get(1)).getFieldwidth(), 0);
167
		assertEquals(((Element) pat.getElements().get(1)).getFieldtype()
168
				.getDecimalvalue().getDecimalvaluedec(), 5);
169
		assertEquals(((Element) pat.getElements().get(1)).getFieldseparator()
170
				.getSemicolonsep(), true);
171

  
172
	}
173

  
174
	public void tearDown() {
175
	}
176

  
177
}
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestFilterString.java
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.FileReader;
32
import java.io.IOException;
33
import java.util.ArrayList;
34

  
35
import junit.framework.TestCase;
36

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

  
42
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
43
import com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver;
44

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

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

  
55
	public void testFilterString() {
56

  
57
		log.info("TestFilterString: start the test");
58

  
59
		ArrayList<String> chains = new ArrayList<String>();
60
		chains.add(",XXX;9393;33.25;337.22;1/1/8");
61

  
62
		File fPat = new File(
63
				"src-test/org/gvsig/normalization/operations/testdata/PATNORM_TEST.xml");
64

  
65
		assertNotNull(fPat);
66

  
67
		Patternnormalization pat = parserPat(fPat);
68
		assertNotNull(pat);
69

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

  
77
		// Normalization
78
		StringListNormalization norm = new StringListNormalization(pat, chains,
79
				outputFile);
80

  
81
		norm.preProcess();
82
		for (int i = 0; i < chains.size(); i++) {
83
			try {
84
				norm.fillRow(i);
85
			} catch (ReadDriverException e) {
86
				e.printStackTrace();
87
			}
88
		}
89
		norm.postProcess();
90

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

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

  
112
			test.close();
113
		} catch (Exception e) {
114
			e.printStackTrace();
115
		}
116

  
117
		assertEquals(nFields, 6);
118
		assertEquals(nRows, 1);
119

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

  
127
		log.info("TestFilterString: test finished");
128
	}
129

  
130
	private Patternnormalization parserPat(File f) {
131
		Patternnormalization pat = new Patternnormalization();
132
		IStorage storage = new StorageXML();
133
		try {
134
			FileReader red = new FileReader(f);
135
			storage.load(red);
136
			pat.setstate(storage);
137
		} catch (Exception e) {
138
			e.printStackTrace();
139
		}
140
		return pat;
141
	}
142

  
143
}
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestNormalizeStringsFromFile.java
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
import java.io.IOException;
33
import java.util.ArrayList;
34

  
35
import junit.framework.TestCase;
36

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

  
42
import com.hardcode.gdbms.driver.exceptions.CloseDriverException;
43
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
44
import com.iver.andami.PluginServices;
45
import com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver;
46

  
47
/**
48
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
49
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
50
 */
51

  
52
public class TestNormalizeStringsFromFile extends TestCase {
53

  
54
	private static final Logger log = PluginServices.getLogger();
55
	Patternnormalization pat = new Patternnormalization();
56
	ArrayList<String> chains = new ArrayList<String>();
57
	File file;
58
	DBFDriver test = null;
59

  
60
	public void setUp() {
61

  
62
		File f = new File(
63
				"src-test/org/gvsig/normalization/operations/testdata/normFile.xml");
64
		try {
65
			IStorage storage = new StorageXML();
66
			FileReader red = new FileReader(f);
67
			storage.load(red);
68
			pat.setstate(storage);
69
			//pat = (Patternnormalization) Patternnormalization.unmarshal(red);
70
		} catch (Exception e) {
71
			log.error("Error parsing the xml pattern", e);
72
		}
73
		chains.add("TEST1;TEST2;TEST3");
74
		chains.add("TEST4;TEST5;TEST6");
75
		chains.add("TEST7;TEST8;TEST9");
76
	}
77

  
78
	public void testNormalizeStringsFromFile() {
79

  
80
		try {
81
			file = File.createTempFile("temp", ".dbf");
82

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

  
95
			// Asserts
96
			test = new DBFDriver();
97
			int nFields = -1;
98
			long nRows = -1;
99
			String val00 = null;
100
			String val01 = null;
101
			String val10 = null;
102
			String val11 = null;
103
			try {
104
				test.open(file);
105
				nFields = test.getFieldCount();
106
				nRows = test.getRowCount();
107
				val00 = test.getFieldValue(0, 0).toString().trim();
108
				val01 = test.getFieldValue(0, 1).toString().trim();
109
				val10 = test.getFieldValue(1, 0).toString().trim();
110
				val11 = test.getFieldValue(1, 1).toString().trim();
111
				test.close();
112
			} catch (Exception e) {
113
				e.printStackTrace();
114
			}
115

  
116
			assertEquals(nFields, 2);
117
			assertEquals(nRows, 3);
118

  
119
			assertEquals(val00, "TEST1");
120
			assertEquals(val10, "TEST4");
121
			assertEquals(val01, "TEST2;TEST3");
122
			assertEquals(val11, "TEST5;TEST6");
123

  
124
			file.delete();
125

  
126
		} catch (IOException e1) {
127
			log.error("Creating the temp file", e1);
128
		}
129

  
130
	}
131

  
132
	public void tearDown() {
133
		try {
134
			test.close();
135
			log.info("TEST FINISHED");
136
		} catch (CloseDriverException e) {
137
			log.error("Clossing the driver");
138
			e.printStackTrace();
139
		}
140
	}
141

  
142
}
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestNormalizeTableJoinTable.java
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
import java.io.IOException;
33

  
34
import junit.framework.TestCase;
35

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

  
41
import com.hardcode.gdbms.driver.exceptions.CloseDriverException;
42
import com.hardcode.gdbms.engine.data.file.FileDataSource;
43
import com.hardcode.gdbms.engine.data.file.FileDataSourceFactory;
44
import com.hardcode.gdbms.engine.data.file.FileSourceInfo;
45
import com.iver.andami.PluginServices;
46
import com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver;
47
import com.iver.cit.gvsig.fmap.edition.EditableAdapter;
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
public class TestNormalizeTableJoinTable extends TestCase {
57

  
58
	private static final Logger log = PluginServices.getLogger();
59
	Patternnormalization pat = new Patternnormalization();
60
	File dbfFile = new File(
61
			"src-test/org/gvsig/normalization/operations/testdata/pro.dbf");
62
	File patFile = new File(
63
			"src-test/org/gvsig/normalization/operations/testdata/normAlterTable.xml");
64
	File outputFile;
65
	EditableAdapter source = new EditableAdapter();
66
	String[] joinNames = { "PROVINCIA", "COUNT" };
67
	DBFDriver test = null;
68

  
69
	public void setUp() {
70
		try {
71
			IStorage storage = new StorageXML();
72
			FileReader red = new FileReader(patFile);
73

  
74
			
75
			storage.load(red);
76
			pat.setstate(storage);
77

  
78
			//pat = (Patternnormalization) Patternnormalization.unmarshal(red);
79
		} catch (Exception e) {
80
			log.error("Error parsing the xml pattern", e);
81
		}
82

  
83
		try {
84
			test = new DBFDriver();
85
			test.open(dbfFile);
86

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

  
96
			SelectableDataSource sds = new SelectableDataSource(fildas);
97

  
98
			source.setOriginalDataSource(sds);
99

  
100
		} catch (Exception e) {
101
			log.error("Reading the driver", e);
102
		}
103

  
104
	}
105

  
106
	public void testNormalizeTableJoinTable() {
107

  
108
		try {
109
			outputFile = File.createTempFile("jointable", ".dbf");
110

  
111
			JoinedTableNormalization norm = new JoinedTableNormalization(
112
					source, 5, pat, joinNames, outputFile);
113
			norm.preProcess();
114
			try {
115
				for (int i = 0; i < source.getRowCount(); i++) {
116

  
117
					norm.fillRow(i);
118

  
119
				}
120
			} catch (Exception e) {
121
				log.error("Normalizing", e);
122
			}
123
			norm.postProcess();
124

  
125
			// asserts
126

  
127
			DBFDriver test = new DBFDriver();
128
			int nFields = -1;
129
			long nRows = -1;
130
			String val02 = null;
131
			String val03 = null;
132
			String val04 = null;
133
			String val05 = null;
134
			String val06 = null;
135
			String val12 = null;
136
			String val15 = null;
137
			String val26 = null;
138

  
139
			try {
140
				test.open(outputFile);
141
				nFields = test.getFieldCount();
142
				nRows = test.getRowCount();
143
				val02 = test.getFieldValue(0, 2).toString().trim();
144
				val03 = test.getFieldValue(0, 3).toString().trim();
145
				val04 = test.getFieldValue(0, 4).toString().trim();
146
				val05 = test.getFieldValue(0, 5).toString().trim();
147
				val06 = test.getFieldValue(0, 6).toString().trim();
148
				val12 = test.getFieldValue(1, 2).toString().trim();
149
				val15 = test.getFieldValue(1, 5).toString().trim();
150
				val26 = test.getFieldValue(2, 6).toString().trim();
151

  
152
			} catch (Exception e) {
153
				e.printStackTrace();
154
			}
155

  
156
			assertEquals(nFields, 7);
157
			assertEquals(nRows, 3);
158

  
159
			assertEquals(val02, "23030");
160
			assertEquals(val03, "697096");
161
			assertEquals(val04, "4364444");
162
			assertEquals(val05, "35.5");
163
			assertEquals(val06, "01/07/2007");
164

  
165
			assertEquals(val12, "23030");
166
			assertEquals(val15, "100.8");
167

  
168
			assertEquals(val26, "12/11/2006");
169

  
170
			outputFile.delete();
171

  
172
		} catch (IOException e1) {
173
			log.error("Creating the temp file", e1);
174
		}
175
	}
176

  
177
	public void tearDown() {
178
		try {
179
			test.close();
180
			log.info("TEST FINISHED");
181
		} catch (CloseDriverException e) {
182
			log.error("Clossing the driver", e);
183
		}
184
	}
185
}
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestNormAlgorithm.java
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
import java.util.List;
33

  
34
import junit.framework.TestCase;
35

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

  
41
public class TestNormAlgorithm extends TestCase {
42

  
43
	private static final Logger log = Logger.getLogger(TestNormAlgorithm.class);
44

  
45
	public void setUp() {
46
	}
47

  
48
	public void testSplitChain() {
49

  
50
		log.info("TestNormAlgorithm. Test splits strings");
51

  
52
		log.info("SubTest 1");
53
		String c1 = ";aaa,,bbb;;;ccc/ddd@eee##;";
54

  
55
		File f1 = new File(
56
				"src-test/org/gvsig/normalization/operations/testdata/patSplitChain.xml");
57
		assertNotNull(f1);
58

  
59
		List<String> r1 = parser(f1, c1);
60
		assertNotNull(r1);
61

  
62
		assertEquals("", (String) r1.get(0));
63
		assertEquals("aaa", (String) r1.get(1));
64
		assertEquals("", (String) r1.get(2));
65
		assertEquals("bbb", (String) r1.get(3));
66
		assertEquals("", (String) r1.get(4));
67
		assertEquals("", (String) r1.get(5));
68
		assertEquals("ccc", (String) r1.get(6));
69
		assertEquals("ddd", (String) r1.get(7));
70
		assertEquals("eee", (String) r1.get(8));
71
		assertEquals("", (String) r1.get(9));
72
		assertEquals(";", (String) r1.get(10));
73

  
74
		log.info("SubTest 2.");
75
		String c2 = "aaa bbb ccc ddd,76 %";
76

  
77
		File f2 = new File(
78
				"src-test/org/gvsig/normalization/operations/testdata/patSplitChain2.xml");
79
		assertNotNull(f2);
80

  
81
		List<String> r2 = parser(f2, c2);
82
		assertNotNull(r2);
83

  
84
		assertEquals("aaa", (String) r2.get(0));
85
		assertEquals("bbb", (String) r2.get(1));
86
		assertEquals("ccc", (String) r2.get(2));
87
		assertEquals("ddd", (String) r2.get(3));
88
		assertEquals("76", (String) r2.get(4));
89
		assertEquals("%", (String) r2.get(5));
90

  
91
		log.info("SubTest 3.");
92
		String c3 = "Av;Germanias;25;3;Moncada;Valencia";
93

  
94
		File f3 = new File(
95
				"src-test/org/gvsig/normalization/operations/testdata/patSplitChain3.xml");
96
		assertNotNull(f3);
97

  
98
		List<String> r3 = parser(f3, c3);
99
		assertNotNull(r3);
100

  
101
		assertEquals("Av", (String) r3.get(0));
102
		assertEquals("Germanias", (String) r3.get(1));
103
		assertEquals(25, Integer.parseInt((String) r3.get(2)));
104
		assertEquals(3, Integer.parseInt((String) r3.get(3)));
105
		assertEquals("Moncada", (String) r3.get(4));
106
		assertEquals("Valencia", (String) r3.get(5));
107

  
108
		log.info("SubTest 4.");
109
		String c4 = "Av. Germanias      15  2   Moncada   Valencia    ";
110

  
111
		File f4 = new File(
112
				"src-test/org/gvsig/normalization/operations/testdata/patSplitChain4.xml");
113
		assertNotNull(f4);
114

  
115
		List<String> r4 = parser(f4, c4);
116
		assertNotNull(r4);
117

  
118
		assertEquals("Av.", ((String) r4.get(0)).trim());
119
		assertEquals("Germanias", ((String) r4.get(1)).trim());
120
		assertEquals(15, Integer.parseInt(((String) r4.get(2)).trim()));
121
		assertEquals(2, Integer.parseInt(((String) r4.get(3)).trim()));
122
		assertEquals("Moncada", ((String) r4.get(4)).trim());
123
		assertEquals("Valencia", ((String) r4.get(5)).trim());
124

  
125
		log.info("SubTest 5.");
126
		String c5 = "Av;;Germanias;15;;2;Moncada;Valencia";
127

  
128
		File f5 = new File(
129
				"src-test/org/gvsig/normalization/operations/testdata/patSplitChain5.xml");
130
		assertNotNull(f5);
131

  
132
		List<String> r5 = parser(f5, c5);
133
		assertNotNull(r5);
134

  
135
		assertEquals("Av", (String) r5.get(0));
136
		assertEquals("Germanias", (String) r5.get(1));
137
		assertEquals(15, Integer.parseInt((String) r5.get(2)));
138
		assertEquals(2, Integer.parseInt((String) r5.get(3)));
139
		assertEquals("Moncada", (String) r5.get(4));
140
		assertEquals("Valencia", (String) r5.get(5));
141

  
142
		log.info("SubTest 6.");
143
		String c6 = "Av. Germanias 15-2 Moncada (Valencia)";
144

  
145
		File f6 = new File(
146
				"src-test/org/gvsig/normalization/operations/testdata/patSplitChain6.xml");
147
		assertNotNull(f6);
148

  
149
		List<String> r6 = parser(f6, c6);
150
		assertNotNull(r6);
151

  
152
		assertEquals("Av.", ((String) r6.get(0)).trim());
153
		assertEquals("Germanias", ((String) r6.get(1)).trim());
154
		assertEquals(15, Integer.parseInt(((String) r6.get(2)).trim()));
155
		assertEquals(2, Integer.parseInt(((String) r6.get(3)).trim()));
156
		assertEquals("Moncada", ((String) r6.get(4)).trim());
157
		assertEquals("Valencia", ((String) r6.get(5)).trim());
158

  
159
		log.info("SubTest 7.");
160
		String c7 = "Juana Aguirre;Piedras;No 623;Piso2;Dto.4;C1070AAM;Capital Federal;ARGENTINA";
161

  
162
		File f7 = new File(
163
				"src-test/org/gvsig/normalization/operations/testdata/patSplitChain7.xml");
164
		assertNotNull(f7);
165

  
166
		List<String> r7 = parser(f7, c7);
167
		assertNotNull(r7);
168

  
169
		assertEquals("Juana Aguirre", ((String) r7.get(0)).trim());
170
		assertEquals("Piedras", ((String) r7.get(1)).trim());
171
		assertEquals("No 623", ((String) r7.get(2)).trim());
172
		assertEquals("Piso2", ((String) r7.get(3)).trim());
173
		assertEquals("Dto.4", ((String) r7.get(4)).trim());
174
		assertEquals("C1070AAM", ((String) r7.get(5)).trim());
175
		assertEquals("Capital Federal", ((String) r7.get(6)).trim());
176
		assertEquals("ARGENTINA", ((String) r7.get(7)).trim());
177

  
178
		log.info("SubTest 8.");
179
		String c8 = "5.548\t5478.254\t0.24578457\t256.21450045";
180

  
181
		File f8 = new File(
182
				"src-test/org/gvsig/normalization/operations/testdata/patSplitChain8.xml");
183
		assertNotNull(f8);
184

  
185
		List<String> r8 = parser(f8, c8);
186
		assertNotNull(r8);
187

  
188
		assertEquals(5.548, Double.parseDouble(((String) r8.get(0)).trim()));
189
		assertEquals(5478.254, Double.parseDouble(((String) r8.get(1)).trim()));
190
		assertEquals(0.24578457, Double
191
				.parseDouble(((String) r8.get(2)).trim()));
192
		assertEquals(256.21450045, Double.parseDouble(((String) r8.get(3))
193
				.trim()));
194

  
195
		log.info("TestNormAlgorithm. Test finished");
196
	}
197

  
198
	public void testSplitFixed() {
199

  
200
		log.info("TestNormAlgorithm. Test tokens fixed");
201

  
202
		String chain = "esto;/es;;; una_prueba;  de un/   split de una cadena_de texto";
203

  
204
		int parts = 4;
205
		boolean join = true;
206
		String[] separators = { " " };
207
		List<String> result = NormAlgorithm.splitChainBySeparators(chain,
208
				parts, separators, join);
209
		log.info("Cadena inicial: " + chain);
210
		for (int i = 0; i < result.size(); i++) {
211
			log.info("Subcadena" + i + ": " + (String) result.get(i));
212
		}
213
		assertEquals("esto;/es;;;", result.get(0));
214
		assertEquals("una_prueba;", result.get(1));
215
		assertEquals("de", result.get(2));
216
		assertEquals("un/   split de una cadena_de texto", result.get(3));
217

  
218
		log.info("TestNormAlgorithm. Test tokens fixed finished");
219

  
220
	}
221

  
222
	public void testSplitSeparators() {
223

  
224
		log.info("TestNormAlgorithm. Test tokens with separators");
225

  
226
		String chain = "esto;/es;;; una_prueba;  de un/   split de una cadena_de texto";
227

  
228
		int parts = 4;
229
		boolean join = true;
230
		String[] separators = { " " };
231
		List<String> result = NormAlgorithm.splitChainBySeparators(chain,
232
				parts, separators, join);
233
		System.out.println("Cadena inicial: " + chain);
234
		for (int i = 0; i < result.size(); i++) {
235
			System.out.println("Subcadena" + i + ": " + (String) result.get(i));
236
		}
237
		assertEquals("esto;/es;;;", result.get(0));
238
		assertEquals("una_prueba;", result.get(1));
239
		assertEquals("de", result.get(2));
240
		assertEquals("un/   split de una cadena_de texto", result.get(3));
241

  
242
		log.info("TestNormAlgorithm. Test tokens with separators finished");
243

  
244
	}
245

  
246
	private List<String> parser(File f, String chain) {
247
		Patternnormalization pat = new Patternnormalization();
248
		IStorage storage = new StorageXML();
249

  
250
		try {
251
			FileReader reader = new FileReader(f);
252
			storage.load(reader);
253
			pat.setstate(storage);			
254
		} catch (Exception e) {
255
			e.printStackTrace();
256
		}
257
		NormAlgorithm na = new NormAlgorithm(pat);
258

  
259
		List<String> result = na.splitChain(chain);
260
		return result;
261

  
262
	}
263

  
264
}
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestMarshall.java
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.FileWriter;
34
import java.io.IOException;
35

  
36
import junit.framework.TestCase;
37

  
38
import org.apache.log4j.Logger;
39
import org.gvsig.normalization.patterns.Element;
40
import org.gvsig.normalization.patterns.Patternnormalization;
41
import org.gvsig.tools.storage.IStorage;
42
import org.gvsig.tools.storage.StorageXML;
43

  
44
import com.iver.andami.PluginServices;
45

  
46
public class TestMarshall extends TestCase {
47

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

  
50
	public void testMarshallUnmarshall() {
51

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

  
58
		FileReader reader = null;
59
		IStorage storage = new StorageXML();
60

  
61
		Element elem1 = null;
62

  
63
		// PARSER
64
		try {
65
			reader = new FileReader(file);
66
			storage.load(reader);
67
			pat.setstate(storage);
68

  
69
			assertEquals(11, pat.getElements().size());
70
			assertEquals(0, pat.getNofirstrows());
71

  
72
			elem1 = (Element) pat.getElements().get(0);
73

  
74
			assertNotNull(elem1);
75
			assertEquals("NewField", elem1.getFieldname());
76

  
77
		} catch (FileNotFoundException e) {
78
			log.error("Parsing and serializing the pattern", e);
79
		} catch (ClassNotFoundException e) {
80
			log.error("Parsing and serializing the pattern", e);
81
		}
82

  
83
		// SERIALIZER
84
		IStorage storage2 = new StorageXML();
85
		pat.getstate(storage2);
86
		File ftemp = null;
87
		try {
88
			//ftemp = File.createTempFile("tem", "txt");
89
			ftemp = new File("C:\\000.txt");
90
			FileWriter writer2 = new FileWriter(ftemp);
91
			storage2.dump(writer2);
92
			writer2.close();
93
		} catch (IOException e) {
94
			log.error("Parsing and serializing the pattern", e);
95
		}
96

  
97
		// PARSER
98
		IStorage storage3 = new StorageXML();
99
		FileReader reader3;
100
		try {
101
			assertNotNull(ftemp);
102
			reader3 = new FileReader(ftemp);
103
			storage3.load(reader3);
104
			pat3.setstate(storage3);
105

  
106
			Element elem2 = (Element) pat3.getElements().get(0);
107

  
108
			assertNotNull(elem2);
109

  
110
			assertEquals(elem1.getImportfield(), elem2.getImportfield());
111
			assertEquals(elem1.getFieldwidth(), elem2.getFieldwidth());
112
			assertEquals(elem1.getFieldname(), elem2.getFieldname());
113
			assertEquals(elem1.getInfieldseparators().getDecimalseparator(),
114
					elem2.getInfieldseparators().getDecimalseparator());
115

  
116
		} catch (FileNotFoundException e) {
117
			log.error("Parsing and serializing the pattern", e);
118
		} catch (ClassNotFoundException e) {
119
			log.error("Parsing and serializing the pattern", e);
120
		}
121
	}
122

  
123
	public void testUnmarshall() {
124

  
125
		log.info("testUnmarshall. start test");
126
		// Create a Reader to the file to unmarshall from
127
		FileReader reader = null;
128
		try {
129
			reader = new FileReader(
130
					"src-test/org/gvsig/normalization/operations/testdata/patSplitChain.xml");
131
			assertNotNull(reader);
132
		} catch (FileNotFoundException e) {
133
			log.error("File not found");
134
			e.printStackTrace();
135
		}
136

  
137
		// Marshal the person object
138
		Patternnormalization pat = new Patternnormalization();
139
		IStorage storage = new StorageXML();
140
		try {
141
			storage.load(reader);
142
			pat.setstate(storage);
143
			assertNotNull(pat);
144
		} catch (Exception e) {
145
			log.error("Unmarshall the pattern");
146
			e.printStackTrace();
147
		}
148
		log.info("pattern loaded");
149
		// results
150
		assertEquals(11, pat.getElements().size());
151
		assertEquals(0, ((Element) pat.getElements().get(3)).getFieldwidth());
152
		assertEquals(true, ((Element) pat.getElements().get(2))
153
				.getImportfield());
154
		assertEquals(true, ((Element) pat.getElements().get(4))
155
				.getFieldseparator().getSemicolonsep());
156

  
157
		log.info("testMarshallUnmarshall. test finished");
158
	}
159

  
160
}
trunk/libraries/libGeocoding/src-test/org/gvsig/normalization/operations/TestAllTypeData.java
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.FileReader;
32
import java.io.IOException;
33
import java.util.ArrayList;
34

  
35
import junit.framework.TestCase;
36

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

  
42
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
43
import com.iver.andami.PluginServices;
44
import com.iver.cit.gvsig.fmap.drivers.dbf.DBFDriver;
45

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

  
54
	private static final Logger log = PluginServices.getLogger();
55
	Patternnormalization pat = new Patternnormalization();
56
	ArrayList<String> chains = new ArrayList<String>();
57
	File file;
58

  
59
	public void setUp() {
60
		File f = new File(
61
				"src-test/org/gvsig/normalization/operations/testdata/pattotal.xml");
62
		IStorage storage = new StorageXML();
63
		try {
64
			FileReader red = new FileReader(f);
65
			storage.load(red);
66
			pat.setstate(storage);
67
		} catch (Exception e) {
68
			log.error("Error parsing the xml pattern", e);
69
		}
70

  
71
		chains.add("Javier#-7;-0.2578&01/10/2007&02/09&02-78");
72
		chains.add("Javier#-7;-0.2578&01/10/2007&02/09&02-78");
73
		chains.add("v");
74
		chains.add("");
75
		chains.add("Javier#-7;-0.2578&01/10/2007&02/09&02-78");
76
		chains.add("Javier#-7;-0.2578&01/10/2007&02/09&02-78");
77
	}
78

  
79
	public void testAllTypeData() {
80

  
81
		try {
82
			file = File.createTempFile("alltype", ".dbf");
83

  
84
			StringListNormalization norm = new StringListNormalization(pat,
85
					chains, file);
86
			norm.preProcess();
87
			for (int i = 0; i < chains.size(); i++) {
88
				try {
89
					norm.fillRow(i);
90
				} catch (ReadDriverException e) {
91
					e.printStackTrace();
92
				}
93
			}
94
			norm.postProcess();
95

  
96
			DBFDriver test = new DBFDriver();
97
			int nFields = -1;
98
			long nRows = -1;
99
			String val01 = null;
100
			String val03 = null;
101
			String val10 = null;
102
			String val30 = null;
103
			String val52 = null;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff