svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.geocoding / src-test / org / gvsig / normalization / patterns / TestCreateNewPattern.java @ 32479
History | View | Annotate | Download (6.09 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 Prodevelop S.L. main development
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.normalization.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 |
} |