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