svn-gvsig-desktop / trunk / libraries / libIverUtiles / src-test / com / iver / utiles / TestXMLEntity.java @ 10595
History | View | Annotate | Download (8.33 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: TestXMLEntity.java 10595 2007-03-02 13:24:53Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.2 2007-03-02 13:24:53 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.1 2007/03/02 13:23:50 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.1 2006/08/29 06:18:17 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
*
|
56 |
*/
|
57 |
package com.iver.utiles; |
58 |
|
59 |
import java.io.File; |
60 |
import java.io.FileNotFoundException; |
61 |
import java.io.FileReader; |
62 |
|
63 |
import org.exolab.castor.xml.MarshalException; |
64 |
import org.exolab.castor.xml.ValidationException; |
65 |
|
66 |
import junit.framework.TestCase; |
67 |
|
68 |
import com.iver.utiles.xmlEntity.generate.XmlTag; |
69 |
|
70 |
public class TestXMLEntity extends TestCase { |
71 |
private XMLEntity x1, x2, x3, x4;
|
72 |
private XMLEntity gvp1;
|
73 |
private XMLEntity gvp2;
|
74 |
|
75 |
public void setUp() { |
76 |
x1 = new XMLEntity();
|
77 |
x2 = new XMLEntity();
|
78 |
x3 = new XMLEntity();
|
79 |
|
80 |
|
81 |
final Object obj1 = new XMLEntity(); |
82 |
final Object obj2 = new XMLEntity(); |
83 |
final Object obj3 = "StringClass"; |
84 |
|
85 |
|
86 |
x1.putProperty("boolean1", false); |
87 |
x1.putProperty("boolean2", true); |
88 |
|
89 |
x1.putProperty("integer1", Integer.parseInt("123")); |
90 |
x1.putProperty("integer2", Integer.parseInt("321")); |
91 |
|
92 |
x1.putProperty("long1", Long.parseLong("123123")); |
93 |
x1.putProperty("long2", Long.parseLong("321321")); |
94 |
|
95 |
x1.putProperty("float1", Float.parseFloat("1234.1234")); |
96 |
x1.putProperty("float2", Float.parseFloat("4321.4321")); |
97 |
|
98 |
x1.putProperty("double1", Double.parseDouble("12341234.12341234")); |
99 |
x1.putProperty("double2", Double.parseDouble("43214321.43214321")); |
100 |
|
101 |
x1.putProperty("string1", "String1"); |
102 |
x1.putProperty("string2", "String2"); |
103 |
|
104 |
x1.putProperty("object1", obj1);
|
105 |
x1.putProperty("object2", obj2);
|
106 |
|
107 |
|
108 |
//----- x1 == x2
|
109 |
x2.putProperty("boolean1", false); |
110 |
x2.putProperty("boolean2", true); |
111 |
|
112 |
x2.putProperty("integer1", Integer.parseInt("123")); |
113 |
x2.putProperty("integer2", Integer.parseInt("321")); |
114 |
|
115 |
x2.putProperty("long1", Long.parseLong("123123")); |
116 |
x2.putProperty("long2", Long.parseLong("321321")); |
117 |
|
118 |
x2.putProperty("float1", Float.parseFloat("1234.1234")); |
119 |
x2.putProperty("float2", Float.parseFloat("4321.4321")); |
120 |
|
121 |
x2.putProperty("double1", Double.parseDouble("12341234.12341234")); |
122 |
x2.putProperty("double2", Double.parseDouble("43214321.43214321")); |
123 |
|
124 |
x2.putProperty("string1", "String1"); |
125 |
x2.putProperty("string2", "String2"); |
126 |
|
127 |
x2.putProperty("object1", obj1);
|
128 |
x2.putProperty("object2", obj2);
|
129 |
|
130 |
|
131 |
//----- x1 != x3
|
132 |
|
133 |
x3.putProperty("boolean1", false); |
134 |
x3.putProperty("boolean2", true); |
135 |
|
136 |
x3.putProperty("integer1", Integer.parseInt("123")); |
137 |
x3.putProperty("integer2", Integer.parseInt("321")); |
138 |
|
139 |
x3.putProperty("long1", Long.parseLong("123123")); |
140 |
x3.putProperty("long2", Long.parseLong("321321")); |
141 |
|
142 |
x3.putProperty("float1", Float.parseFloat("1234.1234")); |
143 |
x3.putProperty("float2", Float.parseFloat("4321.4321")); |
144 |
|
145 |
x3.putProperty("double1", Double.parseDouble("12341234.12341234")); |
146 |
x3.putProperty("double2", Double.parseDouble("43214321.43214324")); |
147 |
|
148 |
x3.putProperty("string1", "String1"); |
149 |
x3.putProperty("string2", "String2"); |
150 |
|
151 |
x3.putProperty("object1", obj1);
|
152 |
x3.putProperty("object2", obj3);
|
153 |
|
154 |
|
155 |
XmlTag tag; |
156 |
try {
|
157 |
tag = (XmlTag) XmlTag.unmarshal( |
158 |
new FileReader(new File("testdata/ISymbol+SpatialIndex+GraduatedSymbol.gvp"))); |
159 |
gvp1 = new XMLEntity(tag);
|
160 |
|
161 |
tag = (XmlTag) XmlTag.unmarshal( |
162 |
new FileReader(new File("testdata/ISymbol+SpatialIndex+GraduatedSymbol.gvp"))); |
163 |
gvp2 = new XMLEntity(tag);
|
164 |
} catch (Exception e) { |
165 |
// TODO Auto-generated catch block
|
166 |
e.printStackTrace(); |
167 |
} |
168 |
|
169 |
|
170 |
|
171 |
} |
172 |
|
173 |
public void testEquality() { |
174 |
assertEquals(x1, x2); |
175 |
|
176 |
assertFalse(x1.equals(x3)); |
177 |
assertFalse(x2.equals(x3)); |
178 |
} |
179 |
|
180 |
|
181 |
public void testHash() { |
182 |
final int x1Hash = x1.toHashCode(); |
183 |
final int x2Hash = x2.toHashCode(); |
184 |
final int x3Hash = x3.toHashCode(); |
185 |
|
186 |
assertTrue("x1 should be equals to x2", x1Hash == x2Hash);
|
187 |
assertTrue("x1 should be distinct to x3", x1Hash != x3Hash);
|
188 |
} |
189 |
|
190 |
public void testSkippedProperties() { |
191 |
x1.putProperty("skipped1", true, false); |
192 |
x1.putProperty("skipped2", 1, false); |
193 |
x1.putProperty("skipped3", 1D, false); |
194 |
x1.putProperty("skipped4", 1F, false); |
195 |
x1.putProperty("skipped5", 1L, false); |
196 |
x1.putProperty("skipped6", "bla bla", false); |
197 |
|
198 |
x2.putProperty("skipped1", false, false); |
199 |
x2.putProperty("skipped2", 2, false); |
200 |
x2.putProperty("skipped3", 2D, false); |
201 |
x2.putProperty("skipped4", 2F, false); |
202 |
x2.putProperty("skipped5", 2L, false); |
203 |
x2.putProperty("skipped6", "bla bla bleitor", false); |
204 |
|
205 |
x3.putProperty("skipped1", false, false); |
206 |
x3.putProperty("skipped2", 2, false); |
207 |
x3.putProperty("skipped3", 2D, false); |
208 |
x3.putProperty("skipped4", 2F, false); |
209 |
x3.putProperty("skipped5", 2L, false); |
210 |
x3.putProperty("skipped6", "bla bla bleitor", false); |
211 |
|
212 |
|
213 |
|
214 |
final int x1Hash = x1.toHashCode(); |
215 |
final int x2Hash = x2.toHashCode(); |
216 |
final int x3Hash = x3.toHashCode(); |
217 |
|
218 |
assertTrue("x1 should be equals to x2", x1Hash == x2Hash);
|
219 |
assertTrue("x1 should be distinct to x3", x1Hash != x3Hash);
|
220 |
assertTrue("x2 should be distinct to x3", x2Hash != x3Hash);
|
221 |
|
222 |
x1.remove("skipped1");
|
223 |
x1.remove("skipped2");
|
224 |
x1.remove("skipped3");
|
225 |
x1.remove("skipped4");
|
226 |
x1.remove("skipped5");
|
227 |
x1.remove("skipped6");
|
228 |
|
229 |
x2.remove("skipped1");
|
230 |
x2.remove("skipped2");
|
231 |
x2.remove("skipped3");
|
232 |
x2.remove("skipped4");
|
233 |
x2.remove("skipped5");
|
234 |
x2.remove("skipped6");
|
235 |
|
236 |
x3.remove("skipped1");
|
237 |
x3.remove("skipped2");
|
238 |
x3.remove("skipped3");
|
239 |
x3.remove("skipped4");
|
240 |
x3.remove("skipped5");
|
241 |
x3.remove("skipped6");
|
242 |
} |
243 |
|
244 |
public void testNonSkippedProperties() { |
245 |
x1.putProperty("skipped1", true, true); |
246 |
x1.putProperty("skipped2", 1, true); |
247 |
x1.putProperty("skipped3", 1D, true); |
248 |
x1.putProperty("skipped4", 1F, true); |
249 |
x1.putProperty("skipped5", 1L, true); |
250 |
x1.putProperty("skipped6", "bla bla", true); |
251 |
|
252 |
x3.putProperty("skipped1", false, true); |
253 |
x3.putProperty("skipped2", 2, true); |
254 |
x3.putProperty("skipped3", 2D, true); |
255 |
x3.putProperty("skipped4", 2F, true); |
256 |
x3.putProperty("skipped5", 2L, true); |
257 |
x3.putProperty("skipped6", "bla bla bleitor", true); |
258 |
|
259 |
x2.putProperty("skipped1", false, true); |
260 |
x2.putProperty("skipped2", 2, true); |
261 |
x2.putProperty("skipped3", 2D, true); |
262 |
x2.putProperty("skipped4", 2F, true); |
263 |
x2.putProperty("skipped5", 2L, true); |
264 |
x2.putProperty("skipped6", "bla bla bleitor", true); |
265 |
|
266 |
final int x1Hash = x1.toHashCode(); |
267 |
final int x2Hash = x2.toHashCode(); |
268 |
final int x3Hash = x3.toHashCode(); |
269 |
|
270 |
assertFalse("x1 should be distinct to x2", x1Hash == x2Hash);
|
271 |
assertFalse("x1 should be distinct to x3", x1Hash == x3Hash);
|
272 |
assertFalse("x2 should be distinct to x3", x2Hash == x3Hash);
|
273 |
|
274 |
x1.remove("skipped1");
|
275 |
x1.remove("skipped2");
|
276 |
x1.remove("skipped3");
|
277 |
x1.remove("skipped4");
|
278 |
x1.remove("skipped5");
|
279 |
x1.remove("skipped6");
|
280 |
|
281 |
x2.remove("skipped1");
|
282 |
x2.remove("skipped2");
|
283 |
x2.remove("skipped3");
|
284 |
x2.remove("skipped4");
|
285 |
x2.remove("skipped5");
|
286 |
x2.remove("skipped6");
|
287 |
|
288 |
x3.remove("skipped1");
|
289 |
x3.remove("skipped2");
|
290 |
x3.remove("skipped3");
|
291 |
x3.remove("skipped4");
|
292 |
x3.remove("skipped5");
|
293 |
x3.remove("skipped6");
|
294 |
|
295 |
testHash(); |
296 |
testEquality(); |
297 |
} |
298 |
|
299 |
public void testEquivalentProjects() { |
300 |
final int x1Hash = gvp1.toHashCode(); |
301 |
final int x2Hash = gvp2.toHashCode(); |
302 |
|
303 |
assertTrue("x1 should be equals to x2", x1Hash == x2Hash);
|
304 |
|
305 |
|
306 |
|
307 |
} |
308 |
} |