Revision 32479

View differences:

branches/v2_0_0_prep/libraries/org.gvsig.geocoding/src-test/org/gvsig/normalization/AllTests.java
1
/**
2
 * 
3
 */
4
package org.gvsig.normalization;
5

  
6
import junit.framework.Test;
7
import junit.framework.TestCase;
8
import junit.framework.TestSuite;
9

  
10

  
11

  
12
/**
13
 * @author jorge
14
 *
15
 */
16
public class AllTests  extends TestCase{
17
	public static Test suite() {
18
		TestSuite suite = new TestSuite("Test for Normalization");
19
		//$JUnit-BEGIN$
20
		suite.addTest(org.gvsig.normalization.operations.AllTests.suite());
21
		suite.addTest(org.gvsig.normalization.patterns.AllTests.suite());
22
		//$JUnit-END$
23
		return suite;
24
	}
25
}
0 26

  
branches/v2_0_0_prep/libraries/org.gvsig.geocoding/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.File;
31
import java.io.FileOutputStream;
32
import java.util.ArrayList;
33
import java.util.List;
34

  
35
import junit.framework.TestCase;
36

  
37
import org.gvsig.fmap.dal.DALFileLibrary;
38
import org.gvsig.fmap.dal.DALLibrary;
39
import org.gvsig.fmap.dal.store.shp.SHPLibrary;
40
import org.gvsig.normalization.pattern.Element;
41
import org.gvsig.normalization.pattern.Fieldseparator;
42
import org.gvsig.normalization.pattern.Fieldtype;
43
import org.gvsig.normalization.pattern.Infieldseparators;
44
import org.gvsig.normalization.pattern.NormalizationPattern;
45
import org.gvsig.normalization.pattern.Stringvalue;
46
import org.gvsig.normalization.pattern.impl.DefaultElement;
47
import org.gvsig.normalization.pattern.impl.DefaultFieldseparator;
48
import org.gvsig.normalization.pattern.impl.DefaultFieldtype;
49
import org.gvsig.normalization.pattern.impl.DefaultInfieldseparators;
50
import org.gvsig.normalization.pattern.impl.DefaultNormalizationPattern;
51
import org.gvsig.normalization.pattern.impl.DefaultStringvalue;
52
import org.gvsig.tools.ToolsLibrary;
53
import org.gvsig.tools.library.Library;
54
import org.gvsig.utils.XMLEntity;
55
import org.gvsig.utils.XMLException;
56
import org.slf4j.Logger;
57
import org.slf4j.LoggerFactory;
58

  
59
/**
60
 * test persistence
61
 * 
62
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
63
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
64
 * 
65
 */
66
public class TestPersistence extends TestCase {
67

  
68
	private static final Logger log = LoggerFactory
69
			.getLogger(TestPersistence.class);
70

  
71
	/**
72
	 * Constructor
73
	 */
74
	public TestPersistence() {
75

  
76
		ToolsLibrary tools = new ToolsLibrary();
77
		tools.initialize();
78
		tools.postInitialize();
79

  
80
		Library dlib = new DALLibrary();
81
		dlib.initialize();
82
		dlib.postInitialize();
83

  
84
		Library libFile = new DALFileLibrary();
85
		libFile.initialize();
86
		libFile.postInitialize();
87

  
88
		Library shpLib = new SHPLibrary();
89
		shpLib.initialize();
90
		shpLib.postInitialize();
91
	}
92

  
93
	public void setUp() {
94

  
95
	}
96

  
97
	public void testSerializing() throws XMLException {
98

  
99
		NormalizationPattern pat = new DefaultNormalizationPattern();
100
		pat.setPatternname("pruebaParseXML.xml");
101
		pat.setNofirstrows(0);
102

  
103
		List<Element> elems = new ArrayList<Element>();
104

  
105
		Element elem1 = new DefaultElement();
106
		elem1.setFieldname("campo1");
107

  
108
		Fieldtype tipo = new DefaultFieldtype();
109
		Stringvalue strval = new DefaultStringvalue();
110
		strval.setStringvaluewidth(50);
111
		tipo.setStringvalue(strval);
112
		elem1.setFieldtype(tipo);
113

  
114
		elem1.setFieldwidth(30);
115

  
116
		Fieldseparator fsep = new DefaultFieldseparator();
117
		fsep.setSemicolonsep(true);
118
		fsep.setJoinsep(false);
119
		elem1.setFieldseparator(fsep);
120

  
121
		Infieldseparators infsep = new DefaultInfieldseparators();
122
		infsep.setThousandseparator(",");
123
		infsep.setDecimalseparator(".");
124
		infsep.setTextseparator("\"");
125
		elem1.setInfieldseparators(infsep);
126

  
127
		elem1.setImportfield(true);
128

  
129
		elems.add(elem1);
130

  
131
		Element elem2 = new DefaultElement();
132
		elem2.setFieldname("campo2");
133

  
134
		Fieldtype tipo2 = new DefaultFieldtype();
135
		Stringvalue strval2 = new DefaultStringvalue();
136
		strval2.setStringvaluewidth(50);
137
		tipo2.setStringvalue(strval2);
138
		elem2.setFieldtype(tipo2);
139

  
140
		elem2.setFieldwidth(30);
141

  
142
		Fieldseparator fsep2 = new DefaultFieldseparator();
143
		fsep2.setSemicolonsep(true);
144
		fsep2.setJoinsep(false);
145
		elem2.setFieldseparator(fsep2);
146

  
147
		Infieldseparators infsep2 = new DefaultInfieldseparators();
148
		infsep2.setThousandseparator(",");
149
		infsep2.setDecimalseparator(".");
150
		infsep2.setTextseparator("\"");
151
		elem2.setInfieldseparators(infsep2);
152

  
153
		elem2.setImportfield(true);
154

  
155
		elems.add(elem2);
156

  
157
		pat.setElements(elems);
158

  
159
		XMLEntity xml = pat.getXMLEntity();
160
		assertNotNull(xml);
161
	}
162

  
163
	public void testParsing() throws XMLException {
164

  
165
		NormalizationPattern pat = new DefaultNormalizationPattern();
166
		pat.setPatternname("pruebaParseXML.xml");
167
		pat.setNofirstrows(0);
168

  
169
		List<Element> elems = new ArrayList<Element>();
170

  
171
		Element elem1 = new DefaultElement();
172
		elem1.setFieldname("campo1");
173

  
174
		Fieldtype tipo = new DefaultFieldtype();
175
		Stringvalue strval = new DefaultStringvalue();
176
		strval.setStringvaluewidth(50);
177
		tipo.setStringvalue(strval);
178
		elem1.setFieldtype(tipo);
179

  
180
		elem1.setFieldwidth(30);
181

  
182
		Fieldseparator fsep = new DefaultFieldseparator();
183
		fsep.setSemicolonsep(true);
184
		fsep.setJoinsep(false);
185
		elem1.setFieldseparator(fsep);
186

  
187
		Infieldseparators infsep = new DefaultInfieldseparators();
188
		infsep.setThousandseparator(",");
189
		infsep.setDecimalseparator(".");
190
		infsep.setTextseparator("\"");
191
		elem1.setInfieldseparators(infsep);
192

  
193
		elem1.setImportfield(true);
194

  
195
		elems.add(elem1);
196

  
197
		Element elem2 = new DefaultElement();
198
		elem2.setFieldname("campo2");
199

  
200
		Fieldtype tipo2 = new DefaultFieldtype();
201
		Stringvalue strval2 = new DefaultStringvalue();
202
		strval2.setStringvaluewidth(50);
203
		tipo2.setStringvalue(strval2);
204
		elem2.setFieldtype(tipo2);
205

  
206
		elem2.setFieldwidth(30);
207

  
208
		Fieldseparator fsep2 = new DefaultFieldseparator();
209
		fsep2.setSemicolonsep(true);
210
		fsep2.setJoinsep(false);
211
		elem2.setFieldseparator(fsep2);
212

  
213
		Infieldseparators infsep2 = new DefaultInfieldseparators();
214
		infsep2.setThousandseparator(",");
215
		infsep2.setDecimalseparator(".");
216
		infsep2.setTextseparator("\"");
217
		elem2.setInfieldseparators(infsep2);
218

  
219
		elem2.setImportfield(true);
220

  
221
		elems.add(elem2);
222

  
223
		pat.setElements(elems);
224

  
225
		XMLEntity xml = pat.getXMLEntity();
226

  
227
		// pat 2
228
		NormalizationPattern pat2 = new DefaultNormalizationPattern();
229
		pat2.setXMLEntity(xml);
230

  
231
		assertEquals(0, pat2.getNofirstrows());
232

  
233
		assertEquals("pruebaParseXML.xml", pat2.getPatternname());
234
		assertEquals(0, pat2.getNofirstrows());
235

  
236
		Element elem0 = ((Element) pat2.getElements().get(0));
237

  
238
		assertEquals("campo1", elem0.getFieldname());
239
		assertEquals(true, elem0.getImportfield());
240
	}
241

  
242
	public void testParserSerializer() throws Exception {
243

  
244
		NormalizationPattern pat = new DefaultNormalizationPattern();
245

  
246
		File file = new File("./resources-test/normalization/patSplitChain.xml");
247

  
248
		assertTrue(file.exists());
249

  
250
		// PARSER
251
		((DefaultNormalizationPattern) pat).loadFromXML(file);
252

  
253
		assertNotNull(pat);
254
		assertEquals(11, pat.getElements().size());
255
		assertEquals(0, pat.getNofirstrows());
256

  
257
		Element elem1 = pat.getElements().get(0);
258

  
259
		assertNotNull(elem1);
260
		assertEquals("NewField", elem1.getFieldname());
261

  
262
		// SERIALIZER
263
		File ftemp = File.createTempFile("tem", "txt");
264
		FileOutputStream out2 = new FileOutputStream(ftemp);
265

  
266
		XMLEntity xml1 = pat.getXMLEntity();
267

  
268
		// PARSER
269
		NormalizationPattern pat3 = new DefaultNormalizationPattern();
270

  
271
		pat3.setXMLEntity(xml1);
272

  
273
		Element elem2 = (Element) pat3.getElements().get(0);
274

  
275
		assertNotNull(elem2);
276

  
277
		assertEquals(elem1.getImportfield(), elem2.getImportfield());
278
		assertEquals(elem1.getFieldwidth(), elem2.getFieldwidth());
279
		assertEquals(elem1.getFieldname(), elem2.getFieldname());
280
		assertEquals(elem1.getInfieldseparators().getDecimalseparator(), elem2
281
				.getInfieldseparators().getDecimalseparator());
282

  
283
		ftemp.delete();
284
		log.debug("Test finished.....");
285

  
286
	}
287
}
0 288

  
branches/v2_0_0_prep/libraries/org.gvsig.geocoding/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
 * Patterns tests
35
 * 
36
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
37
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
38
 * 
39
 */
40

  
41
public class AllTests {
42

  
43
	public static Test suite() {
44
		TestSuite suite = new TestSuite(
45
				"Test for org.gvsig.normalization.patterns");
46
		// $JUnit-BEGIN$
47
		suite.addTestSuite(TestPersistence.class);
48
		suite.addTestSuite(TestCreateNewPattern.class);
49
		// $JUnit-END$
50
		return suite;
51
	}
52

  
53
}
0 54

  
branches/v2_0_0_prep/libraries/org.gvsig.geocoding/src-test/org/gvsig/normalization/patterns/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.patterns;
29

  
30
import java.text.DecimalFormatSymbols;
31
import java.util.ArrayList;
32
import java.util.List;
33
import java.util.Locale;
34

  
35
import org.gvsig.normalization.impl.DefaultNormalizationLibrary;
36
import org.gvsig.normalization.pattern.Decimalvalue;
37
import org.gvsig.normalization.pattern.Element;
38
import org.gvsig.normalization.pattern.Fieldseparator;
39
import org.gvsig.normalization.pattern.Fieldtype;
40
import org.gvsig.normalization.pattern.Infieldseparators;
41
import org.gvsig.normalization.pattern.NormalizationPattern;
42
import org.gvsig.normalization.pattern.Stringvalue;
43
import org.gvsig.normalization.pattern.impl.DefaultDecimalvalue;
44
import org.gvsig.normalization.pattern.impl.DefaultElement;
45
import org.gvsig.normalization.pattern.impl.DefaultFieldseparator;
46
import org.gvsig.normalization.pattern.impl.DefaultFieldtype;
47
import org.gvsig.normalization.pattern.impl.DefaultInfieldseparators;
48
import org.gvsig.normalization.pattern.impl.DefaultNormalizationPattern;
49
import org.gvsig.normalization.pattern.impl.DefaultStringvalue;
50
import org.gvsig.tools.library.Library;
51

  
52
import junit.framework.TestCase;
53

  
54

  
55

  
56
/*
57
 * This test validates a new pattern generated
58
 * 
59
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
60
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
61
 */
62
public class TestCreateNewPattern extends org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase {
63

  
64

  
65
	@Override
66
	protected void doSetUp() throws Exception {
67
		Library normlib = new DefaultNormalizationLibrary();
68
		normlib.initialize();
69
		normlib.postInitialize();
70
	}
71

  
72
	public void testCreateNewPattern() {
73
		// Create object
74
		NormalizationPattern pat = new DefaultNormalizationPattern();
75

  
76
		// Field Separators
77
		Fieldseparator filsep1 = new DefaultFieldseparator();
78

  
79
		filsep1.setSemicolonsep(true);
80
		filsep1.setJoinsep(false);
81
		filsep1.setColonsep(false);
82
		filsep1.setSpacesep(false);
83
		filsep1.setTabsep(false);
84

  
85
		// Field Separators
86
		Fieldseparator filsep2 = new DefaultFieldseparator();
87

  
88
		filsep2.setSemicolonsep(true);
89
		filsep2.setJoinsep(false);
90
		filsep2.setColonsep(false);
91
		filsep2.setSpacesep(false);
92
		filsep2.setTabsep(false);
93

  
94
		// In Field Separators
95
		Locale loc = Locale.getDefault();
96
		DecimalFormatSymbols dfs = new DecimalFormatSymbols(loc);
97
		Infieldseparators infilsep1 = new DefaultInfieldseparators();
98

  
99
		infilsep1.setDecimalseparator(Character.toString(dfs
100
				.getDecimalSeparator()));
101
		infilsep1.setTextseparator("\"");
102
		infilsep1.setThousandseparator(Character.toString(dfs
103
				.getGroupingSeparator()));
104

  
105
		// In Field Separators
106

  
107
		Infieldseparators infilsep2 = new DefaultInfieldseparators();
108

  
109
		infilsep2.setDecimalseparator(Character.toString(dfs
110
				.getDecimalSeparator()));
111
		infilsep2.setTextseparator("\"");
112
		infilsep2.setThousandseparator(Character.toString(dfs
113
				.getGroupingSeparator()));
114

  
115
		// Main attributes
116
		pat.setPatternname("thePattern");
117
		pat.setNofirstrows(0);
118

  
119
		// Create the first Address Element ////////////////////
120
		List<Element> elems = new ArrayList<Element>();
121
		Element elem1 = new DefaultElement();
122

  
123
		// Field Name
124
		elem1.setFieldname("StringField");
125

  
126
		elem1.setFieldseparator(filsep1);
127

  
128
		elem1.setInfieldseparators(infilsep1);
129

  
130
		// Field type
131
		Fieldtype newtype = new DefaultFieldtype();
132
		Stringvalue strval = new DefaultStringvalue();
133
		strval.setStringvaluewidth(50);
134
		newtype.setStringvalue(strval);
135

  
136
		elem1.setFieldtype(newtype);
137
		elem1.setFieldwidth(0);
138
		elem1.setImportfield(true);
139

  
140
		elems.add(elem1);
141

  
142
		// Create the second Address Element ////////////////////
143

  
144
		Element elem2 = new DefaultElement();
145

  
146
		// Field Name
147
		elem2.setFieldname("DecimalField");
148

  
149
		elem2.setFieldseparator(filsep2);
150

  
151
		elem2.setInfieldseparators(infilsep2);
152

  
153
		// Field type
154
		Fieldtype newtype2 = new DefaultFieldtype();
155
		Decimalvalue decval = new DefaultDecimalvalue();
156
		decval.setDecimalvalueint(5);
157
		decval.setDecimalvaluedec(5);
158
		newtype2.setDecimalvalue(decval);
159

  
160
		elem2.setFieldtype(newtype2);
161
		elem2.setFieldwidth(0);
162
		elem2.setImportfield(true);
163

  
164
		elems.add(elem2);
165

  
166
		pat.setElements(elems);
167
		System.out.println("load pattern");
168

  
169
		assertNotNull(pat);
170
		assertNotNull(elem1);
171
		assertNotNull(elem2);
172
		assertEquals(((Element) pat.getElements().get(0)).getImportfield(),
173
				true);
174
		assertEquals(((Element) pat.getElements().get(0)).getFieldwidth(), 0);
175
		assertEquals(((Stringvalue) ((Element) pat.getElements().get(0))
176
				.getFieldtype().getStringvalue()).getStringvaluewidth(), 50);
177
		assertEquals(((Element) pat.getElements().get(0)).getFieldseparator()
178
				.getSemicolonsep(), true);
179
		assertEquals(((Element) pat.getElements().get(1)).getImportfield(),
180
				true);
181
		assertEquals(((Element) pat.getElements().get(1)).getFieldwidth(), 0);
182
		assertEquals(((Element) pat.getElements().get(1)).getFieldtype()
183
				.getDecimalvalue().getDecimalvaluedec(), 5);
184
		assertEquals(((Element) pat.getElements().get(1)).getFieldseparator()
185
				.getSemicolonsep(), true);
186

  
187
	}
188

  
189
	public void tearDown() {
190
	}
191

  
192
}
0 193

  
branches/v2_0_0_prep/libraries/org.gvsig.geocoding/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 org.gvsig.normalization.patterns.TestCreateNewPattern;
31

  
32
import junit.framework.Test;
33
import junit.framework.TestCase;
34
import junit.framework.TestSuite;
35

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

  
44
	public static Test suite() {
45
		TestSuite suite = new TestSuite(
46
				"Test for org.gvsig.normalization.operations");
47
		// $JUnit-BEGIN$
48
		
49
		
50
		suite.addTestSuite(TestFilterString.class);
51
		suite.addTestSuite(TestNormAlgorithm.class);		
52

  
53
		// Norm Strings from file
54
		suite.addTestSuite(TestNormalizeFeatureData.class);
55

  
56

  
57
		// $JUnit-END$
58
		return suite;
59
	}
60

  
61
}
0 62

  
branches/v2_0_0_prep/libraries/org.gvsig.geocoding/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.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
}
0 153

  
branches/v2_0_0_prep/libraries/org.gvsig.geocoding/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.FileInputStream;
32
import java.io.IOException;
33
import java.util.List;
34

  
35
import org.gvsig.normalization.algorithm.NormalizationAlgorithm;
36
import org.gvsig.normalization.algorithm.impl.DefaultNormalizationAlgorithm;
37
import org.gvsig.normalization.impl.DefaultNormalizationLibrary;
38
import org.gvsig.normalization.pattern.NormalizationPattern;
39
import org.gvsig.normalization.pattern.impl.DefaultNormalizationPattern;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.library.Library;
42
import org.gvsig.tools.persistence.PersistenceException;
43
import org.gvsig.tools.persistence.PersistenceManager;
44
import org.gvsig.tools.persistence.PersistentState;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

  
48
public class TestNormAlgorithm extends org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase {
49

  
50
	private static final Logger log = LoggerFactory
51
			.getLogger(TestNormAlgorithm.class);
52

  
53
	@Override
54
	protected void doSetUp() throws Exception {
55
		Library normlib = new DefaultNormalizationLibrary();
56
		normlib.initialize();
57
		normlib.postInitialize();
58
	}
59

  
60
	/**
61
	 * 
62
	 * @throws Exception 
63
	 */
64
	public void testSplitChain() throws Exception {
65

  
66
		log.debug("TestNormAlgorithm. Test splits strings");
67

  
68
		log.debug("SubTest 1");
69
		String c1 = ";aaa,,bbb;;;ccc/ddd@eee##;";
70

  
71
		File f1 = new File(
72
				"resources-test/normalization/patSplitChain.xml");
73

  
74
		assertTrue(f1.exists());
75
		assertNotNull(f1);
76

  
77
		List<String> r1 = parser(f1, c1);
78
		assertNotNull(r1);
79

  
80
		assertEquals("", (String) r1.get(0));
81
		assertEquals("aaa", (String) r1.get(1));
82
		assertEquals("", (String) r1.get(2));
83
		assertEquals("bbb", (String) r1.get(3));
84
		assertEquals("", (String) r1.get(4));
85
		assertEquals("", (String) r1.get(5));
86
		assertEquals("ccc", (String) r1.get(6));
87
		assertEquals("ddd", (String) r1.get(7));
88
		assertEquals("eee", (String) r1.get(8));
89
		assertEquals("", (String) r1.get(9));
90
		assertEquals(";", (String) r1.get(10));
91

  
92
		log.debug("SubTest 2.");
93
		String c2 = "aaa bbb ccc ddd,76 %";
94

  
95
		File f2 = new File(
96
				"resources-test/normalization/patSplitChain2.xml");
97
		assertTrue(f2.exists());
98
		assertNotNull(f2);
99

  
100
		List<String> r2 = parser(f2, c2);
101
		assertNotNull(r2);
102

  
103
		assertEquals("aaa", (String) r2.get(0));
104
		assertEquals("bbb", (String) r2.get(1));
105
		assertEquals("ccc", (String) r2.get(2));
106
		assertEquals("ddd", (String) r2.get(3));
107
		assertEquals("76", (String) r2.get(4));
108
		assertEquals("%", (String) r2.get(5));
109

  
110
		log.debug("SubTest 3.");
111
		String c3 = "Av;Germanias;25;3;Moncada;Valencia";
112

  
113
		File f3 = new File(
114
				"resources-test/normalization/testdata/patSplitChain3.xml");
115
		assertTrue(f3.exists());
116
		assertNotNull(f3);
117

  
118
		List<String> r3 = parser(f3, c3);
119
		assertNotNull(r3);
120

  
121
		assertEquals("Av", (String) r3.get(0));
122
		assertEquals("Germanias", (String) r3.get(1));
123
		assertEquals(25, Integer.parseInt((String) r3.get(2)));
124
		assertEquals(3, Integer.parseInt((String) r3.get(3)));
125
		assertEquals("Moncada", (String) r3.get(4));
126
		assertEquals("Valencia", (String) r3.get(5));
127

  
128
		log.debug("SubTest 4.");
129
		String c4 = "Av. Germanias      15  2   Moncada   Valencia    ";
130

  
131
		File f4 = new File(
132
				"resources-test/normalization/patSplitChain4.xml");
133
		assertTrue(f4.exists());
134
		assertNotNull(f4);
135

  
136
		List<String> r4 = parser(f4, c4);
137
		assertNotNull(r4);
138

  
139
		assertEquals("Av.", ((String) r4.get(0)).trim());
140
		assertEquals("Germanias", ((String) r4.get(1)).trim());
141
		assertEquals(15, Integer.parseInt(((String) r4.get(2)).trim()));
142
		assertEquals(2, Integer.parseInt(((String) r4.get(3)).trim()));
143
		assertEquals("Moncada", ((String) r4.get(4)).trim());
144
		assertEquals("Valencia", ((String) r4.get(5)).trim());
145

  
146
		log.debug("SubTest 5.");
147
		String c5 = "Av;,;Germanias;15;;2;Moncada;Valencia";
148

  
149
		File f5 = new File(
150
				"resources-test/normalization/patSplitChain5.xml");
151
		assertTrue(f5.exists());
152
		assertNotNull(f5);
153

  
154
		List<String> r5 = parser(f5, c5);
155
		assertNotNull(r5);
156

  
157
		assertEquals("Av", (String) r5.get(0));
158
		assertEquals("Germanias", (String) r5.get(1));
159
		assertEquals(15, Integer.parseInt((String) r5.get(2)));
160
		assertEquals(2, Integer.parseInt((String) r5.get(3)));
161
		assertEquals("Moncada", (String) r5.get(4));
162
		assertEquals("Valencia", (String) r5.get(5));
163

  
164
		log.debug("SubTest 6.");
165
		String c6 = "Av. Germanias 15-2 Moncada (Valencia)";
166

  
167
		File f6 = new File(
168
				"resources-test/normalization/patSplitChain6.xml");
169
		assertTrue(f6.exists());
170
		assertNotNull(f6);
171

  
172
		List<String> r6 = parser(f6, c6);
173
		assertNotNull(r6);
174

  
175
		assertEquals("Av.", ((String) r6.get(0)).trim());
176
		assertEquals("Germanias", ((String) r6.get(1)).trim());
177
		assertEquals(15, Integer.parseInt(((String) r6.get(2)).trim()));
178
		assertEquals(2, Integer.parseInt(((String) r6.get(3)).trim()));
179
		assertEquals("Moncada", ((String) r6.get(4)).trim());
180
		assertEquals("Valencia", ((String) r6.get(5)).trim());
181

  
182
		log.debug("SubTest 7.");
183
		String c7 = "Juana Aguirre;Piedras;No 623;Piso2;Dto.4;C1070AAM;Capital Federal;ARGENTINA";
184

  
185
		File f7 = new File(
186
				"resources-test/normalization/patSplitChain7.xml");
187
		assertTrue(f7.exists());
188
		assertNotNull(f7);
189

  
190
		List<String> r7 = parser(f7, c7);
191
		assertNotNull(r7);
192

  
193
		assertEquals("Juana Aguirre", ((String) r7.get(0)).trim());
194
		assertEquals("Piedras", ((String) r7.get(1)).trim());
195
		assertEquals("No 623", ((String) r7.get(2)).trim());
196
		assertEquals("Piso2", ((String) r7.get(3)).trim());
197
		assertEquals("Dto.4", ((String) r7.get(4)).trim());
198
		assertEquals("C1070AAM", ((String) r7.get(5)).trim());
199
		assertEquals("Capital Federal", ((String) r7.get(6)).trim());
200
		assertEquals("ARGENTINA", ((String) r7.get(7)).trim());
201

  
202
		log.debug("SubTest 8.");
203
		String c8 = "5.548\t5478.254\t0.24578457\t256.21450045";
204

  
205
		File f8 = new File(
206
				"resources-test/normalization/patSplitChain8.xml");
207
		assertTrue(f8.exists());
208
		assertNotNull(f8);
209

  
210
		List<String> r8 = parser(f8, c8);
211
		assertNotNull(r8);
212

  
213
		assertEquals(5.548d, Double.parseDouble(((String) r8.get(0)).trim()), 0);
214
		assertEquals(5478.254, Double.parseDouble(((String) r8.get(1)).trim()),
215
				0);
216
		assertEquals(0.24578457, Double
217
				.parseDouble(((String) r8.get(2)).trim()), 0);
218
		assertEquals(256.21450045, Double.parseDouble(((String) r8.get(3))
219
				.trim()), 0);
220

  
221
		log.debug("TestNormAlgorithm. Test finished");
222
	}
223

  
224
	/**
225
	 * 
226
	 */
227
	public void testSplitFixed() {
228

  
229
		log.debug("TestNormAlgorithm. Test tokens fixed");
230

  
231
		String chain = "esto;/es;;; una_prueba;  de un/   split de una cadena_de texto";
232

  
233
		int parts = 4;
234
		boolean join = true;
235
		String[] separators = { " " };
236
		List<String> result = DefaultNormalizationAlgorithm
237
				.splitChainBySeparators(chain, parts, separators, join);
238
		log.debug("Cadena inicial: " + chain);
239
		for (int i = 0; i < result.size(); i++) {
240
			log.debug("Subcadena" + i + ": " + (String) result.get(i));
241
		}
242
		assertEquals("esto;/es;;;", result.get(0));
243
		assertEquals("una_prueba;", result.get(1));
244
		assertEquals("de", result.get(2));
245
		assertEquals("un/   split de una cadena_de texto", result.get(3));
246

  
247
		log.debug("TestNormAlgorithm. Test tokens fixed finished");
248

  
249
	}
250

  
251
	/**
252
	 * 
253
	 */
254
	public void testSplitSeparators() {
255

  
256
		log.debug("TestNormAlgorithm. Test tokens with separators");
257

  
258
		String chain = "esto;/es;;; una_prueba;  de un/   split de una cadena_de texto";
259

  
260
		int parts = 4;
261
		boolean join = true;
262
		String[] separators = { " " };
263
		List<String> result = DefaultNormalizationAlgorithm
264
				.splitChainBySeparators(chain, parts, separators, join);
265
		System.out.println("Cadena inicial: " + chain);
266
		for (int i = 0; i < result.size(); i++) {
267
			System.out.println("Subcadena" + i + ": " + (String) result.get(i));
268
		}
269
		assertEquals("esto;/es;;;", result.get(0));
270
		assertEquals("una_prueba;", result.get(1));
271
		assertEquals("de", result.get(2));
272
		assertEquals("un/   split de una cadena_de texto", result.get(3));
273

  
274
		log.debug("TestNormAlgorithm. Test tokens with separators finished");
275

  
276
	}
277

  
278
	/**
279
	 * 
280
	 * @param f
281
	 * @param chain
282
	 * @return
283
	 * @throws PersistenceException
284
	 * @throws IOException
285
	 */
286
	private List<String> parser(File f, String chain)
287
			throws Exception {
288

  
289
		
290

  
291
		NormalizationPattern pat = new DefaultNormalizationPattern();
292
		
293
		((DefaultNormalizationPattern)pat).loadFromXML(f);
294

  
295
		NormalizationAlgorithm na = new DefaultNormalizationAlgorithm(pat);
296

  
297
		List<String> result = na.splitChain(chain);
298
		return result;
299

  
300
	}
301

  
302
}
0 303

  
branches/v2_0_0_prep/libraries/org.gvsig.geocoding/src-test/org/gvsig/normalization/operations/TestNormalizeFeatureData.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.text.DecimalFormatSymbols;
32
import java.util.ArrayList;
33
import java.util.List;
34
import java.util.Locale;
35

  
36
import junit.framework.TestCase;
37

  
38
import org.gvsig.fmap.dal.DALFileLibrary;
39
import org.gvsig.fmap.dal.DALLibrary;
40
import org.gvsig.fmap.dal.DALLocator;
41
import org.gvsig.fmap.dal.DataManager;
42
import org.gvsig.fmap.dal.exception.DataException;
43
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
44
import org.gvsig.fmap.dal.feature.FeatureStore;
45
import org.gvsig.fmap.dal.feature.FeatureStoreTransform;
46
import org.gvsig.fmap.dal.feature.FeatureStoreTransforms;
47
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters;
48
import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider;
49
import org.gvsig.fmap.dal.store.shp.SHPLibrary;
50
import org.gvsig.normalization.NormalizationLocator;
51
import org.gvsig.normalization.algorithm.NormalizationAlgorithm;
52
import org.gvsig.normalization.algorithm.impl.DefaultNormalizationAlgorithm;
53
import org.gvsig.normalization.impl.DefaultNormalizationLibrary;
54
import org.gvsig.normalization.impl.NormalizationTransform;
55
import org.gvsig.normalization.pattern.Element;
56
import org.gvsig.normalization.pattern.Fieldseparator;
57
import org.gvsig.normalization.pattern.Fieldtype;
58
import org.gvsig.normalization.pattern.Infieldseparators;
59
import org.gvsig.normalization.pattern.NormalizationPattern;
60
import org.gvsig.normalization.pattern.Stringvalue;
61
import org.gvsig.normalization.pattern.impl.DefaultElement;
62
import org.gvsig.normalization.pattern.impl.DefaultFieldseparator;
63
import org.gvsig.normalization.pattern.impl.DefaultFieldtype;
64
import org.gvsig.normalization.pattern.impl.DefaultInfieldseparators;
65
import org.gvsig.normalization.pattern.impl.DefaultNormalizationPattern;
66
import org.gvsig.normalization.pattern.impl.DefaultStringvalue;
67
import org.gvsig.tools.ToolsLibrary;
68
import org.gvsig.tools.ToolsLocator;
69
import org.gvsig.tools.library.Library;
70
import org.slf4j.Logger;
71
import org.slf4j.LoggerFactory;
72

  
73
/**
74
 * 
75
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
76
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
77
 * 
78
 */
79
public class TestNormalizeFeatureData extends org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase {
80

  
81
	private static final Logger log = LoggerFactory
82
			.getLogger(TestNormalizeFeatureData.class);
83

  
84
	NormalizationPattern pat = null;
85
	File file = null;
86

  
87

  
88
	@Override
89
	protected void doSetUp() throws Exception {
90
		Library normlib = new DefaultNormalizationLibrary();
91
		normlib.initialize();
92
		normlib.postInitialize();
93
	}
94

  
95

  
96

  
97
	public void testNormalizationTransform()
98
			throws ValidateDataParametersException, DataException {
99

  
100
		DataManager manager = DALLocator.getDataManager();
101

  
102
		// PATTERN
103
		pat = getPattern();
104

  
105
		// DATASTORE
106
		file = new File("resources-test/normalization/pro.dbf");		
107
		assertTrue(file.exists());
108
		DBFStoreParameters params = (DBFStoreParameters) manager
109
				.createStoreParameters(DBFStoreProvider.NAME);
110
		params.setDBFFile(file);
111
		FeatureStore store = (FeatureStore) manager.createStore(params);
112

  
113
		// ALGORITHM
114
		
115
		NormalizationAlgorithm algorithm = new DefaultNormalizationAlgorithm(
116
				pat);
117

  
118
		// TRANSFORM
119
		NormalizationTransform transform = (NormalizationTransform) NormalizationLocator.getInstance().getNormalizer();
120
		
121
		transform.initialize(store, pat, 5, algorithm);
122
		// Add transform
123
		FeatureStoreTransforms trans = store.getTransforms();
124
		trans.add((FeatureStoreTransform)transform);
125

  
126
	}
127

  
128
	public void tearDown() {
129
		log.debug("TEST FINISHED");
130
	}
131

  
132
	private NormalizationPattern getPattern() {
133

  
134
		// Create object
135
		NormalizationPattern pat = new DefaultNormalizationPattern();
136

  
137
		// Field Separators
138
		Fieldseparator filsep1 = new DefaultFieldseparator();
139

  
140
		filsep1.setSemicolonsep(true);
141
		filsep1.setJoinsep(false);
142
		filsep1.setColonsep(false);
143
		filsep1.setSpacesep(false);
144
		filsep1.setTabsep(false);
145

  
146
		// Field Separators
147
		Fieldseparator filsep2 = new DefaultFieldseparator();
148

  
149
		filsep2.setSemicolonsep(true);
150
		filsep2.setJoinsep(false);
151
		filsep2.setColonsep(false);
152
		filsep2.setSpacesep(false);
153
		filsep2.setTabsep(false);
154

  
155
		// In Field Separators
156
		Locale loc = Locale.getDefault();
157
		DecimalFormatSymbols dfs = new DecimalFormatSymbols(loc);
158
		Infieldseparators infilsep1 = new DefaultInfieldseparators();
159

  
160
		infilsep1.setDecimalseparator(Character.toString(dfs
161
				.getDecimalSeparator()));
162
		infilsep1.setTextseparator("\"");
163
		infilsep1.setThousandseparator(Character.toString(dfs
164
				.getGroupingSeparator()));
165

  
166
		// In Field Separators
167

  
168
		Infieldseparators infilsep2 = new DefaultInfieldseparators();
169

  
170
		infilsep2.setDecimalseparator(Character.toString(dfs
171
				.getDecimalSeparator()));
172
		infilsep2.setTextseparator("\"");
173
		infilsep2.setThousandseparator(Character.toString(dfs
174
				.getGroupingSeparator()));
175

  
176
		// Main attributes
177
		pat.setPatternname("thePattern");
178
		pat.setNofirstrows(0);
179

  
180
		// Create the first Address Element ////////////////////
181
		List<Element> elems = new ArrayList<Element>();
182
		Element elem1 = new DefaultElement();
183

  
184
		// Field 1 Field 1 Field 1 Field 1
185
		elem1.setFieldname("campo1");
186

  
187
		elem1.setFieldseparator(filsep1);
188

  
189
		elem1.setInfieldseparators(infilsep1);
190

  
191
		// Field type
192
		Fieldtype newtype = new DefaultFieldtype();
193
		Stringvalue strval = new DefaultStringvalue();
194
		strval.setStringvaluewidth(50);
195
		newtype.setStringvalue(strval);
196

  
197
		elem1.setFieldtype(newtype);
198
		elem1.setFieldwidth(0);
199
		elem1.setImportfield(true);
200

  
201
		elems.add(elem1);
202

  
203
		// Create the second Address Element ////////////////////
204

  
205
		Element elem2 = new DefaultElement();
206

  
207
		// Field 2 Field 2 Field 2 Field 2
208
		elem2.setFieldname("campo2");
209

  
210
		elem2.setFieldseparator(filsep2);
211

  
212
		elem2.setInfieldseparators(infilsep2);
213

  
214
		// Field type
215
		Fieldtype newtype2 = new DefaultFieldtype();
216
		Stringvalue strval2 = new DefaultStringvalue();
217
		strval2.setStringvaluewidth(50);
218
		newtype2.setStringvalue(strval2);
219

  
220
		elem2.setFieldtype(newtype2);
221
		elem2.setFieldwidth(0);
222
		elem2.setImportfield(true);
223

  
224
		elems.add(elem2);
225

  
226
		pat.setElements(elems);
227

  
228
		return pat;
229
	}
230

  
231
}
0 232

  
branches/v2_0_0_prep/libraries/org.gvsig.geocoding/src-test/org/gvsig/geocoding/update/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.geocoding.update;
29

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

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

  
41
	public static Test suite() {
42
		TestSuite suite = new TestSuite(
43
				"Test for org.gvsig.geocoding.update");
44
		// $JUnit-BEGIN$		
45
		suite.addTestSuite(TestUpdateFeature.class);
46
		
47
		
48
		// $JUnit-END$
49
		return suite;
50
	}
51

  
52
}
0 53

  
branches/v2_0_0_prep/libraries/org.gvsig.geocoding/src-test/org/gvsig/geocoding/update/TestUpdateFeature.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):
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff