svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libIverUtiles / src-test / com / iver / utiles / TestXMLEntity.java @ 28076
History | View | Annotate | Download (9.91 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 28076 2009-04-21 12:39:58Z cmartinez $
|
45 |
* $Log$
|
46 |
* Revision 1.7 2007-03-05 11:15:43 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.6 2007/03/05 10:03:12 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.5 2007/03/05 09:00:11 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.4 2007/03/02 13:35:56 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.3 2007/03/02 13:27:32 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.2 2007/03/02 13:24:53 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.1 2007/03/02 13:23:50 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.1 2006/08/29 06:18:17 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
*
|
71 |
*/
|
72 |
package com.iver.utiles; |
73 |
|
74 |
import java.io.File; |
75 |
import java.io.FileReader; |
76 |
|
77 |
import org.gvsig.tools.IverUtilesLibrary; |
78 |
import org.gvsig.tools.ToolsLibrary; |
79 |
import org.gvsig.tools.ToolsLocator; |
80 |
import org.gvsig.tools.locator.Library; |
81 |
|
82 |
import junit.framework.TestCase; |
83 |
|
84 |
import com.iver.utiles.xmlEntity.generate.XmlTag; |
85 |
|
86 |
public class TestXMLEntity extends TestCase { |
87 |
private XMLEntity x1, x2, x3, x4;
|
88 |
private XMLEntity gvp1;
|
89 |
private XMLEntity gvp2;
|
90 |
|
91 |
public void setUp() { |
92 |
Library toolsLib = new ToolsLibrary();
|
93 |
toolsLib.initialize(); |
94 |
|
95 |
Library utilsLib = new IverUtilesLibrary();
|
96 |
utilsLib.initialize(); |
97 |
|
98 |
toolsLib.postInitialize(); |
99 |
utilsLib.postInitialize(); |
100 |
|
101 |
|
102 |
x1 = new XMLEntity();
|
103 |
x2 = new XMLEntity();
|
104 |
x3 = new XMLEntity();
|
105 |
|
106 |
|
107 |
final Object obj1 = new XMLEntity(); |
108 |
final Object obj2 = new XMLEntity(); |
109 |
final Object obj3 = "StringClass"; |
110 |
|
111 |
|
112 |
x1.putProperty("boolean1", false); |
113 |
x1.putProperty("boolean2", true); |
114 |
|
115 |
x1.putProperty("integer1", Integer.parseInt("123")); |
116 |
x1.putProperty("integer2", Integer.parseInt("321")); |
117 |
|
118 |
x1.putProperty("long1", Long.parseLong("123123")); |
119 |
x1.putProperty("long2", Long.parseLong("321321")); |
120 |
|
121 |
x1.putProperty("float1", Float.parseFloat("1234.1234")); |
122 |
x1.putProperty("float2", Float.parseFloat("4321.4321")); |
123 |
|
124 |
x1.putProperty("double1", Double.parseDouble("12341234.12341234")); |
125 |
x1.putProperty("double2", Double.parseDouble("43214321.43214321")); |
126 |
|
127 |
x1.putProperty("string1", "String1"); |
128 |
x1.putProperty("string2", "String2"); |
129 |
|
130 |
x1.putProperty("object1", obj1);
|
131 |
x1.putProperty("object2", obj2);
|
132 |
|
133 |
|
134 |
//----- x1 == x2
|
135 |
x2.putProperty("boolean1", false); |
136 |
x2.putProperty("boolean2", true); |
137 |
|
138 |
x2.putProperty("integer1", Integer.parseInt("123")); |
139 |
x2.putProperty("integer2", Integer.parseInt("321")); |
140 |
|
141 |
x2.putProperty("long1", Long.parseLong("123123")); |
142 |
x2.putProperty("long2", Long.parseLong("321321")); |
143 |
|
144 |
x2.putProperty("float1", Float.parseFloat("1234.1234")); |
145 |
x2.putProperty("float2", Float.parseFloat("4321.4321")); |
146 |
|
147 |
x2.putProperty("double1", Double.parseDouble("12341234.12341234")); |
148 |
x2.putProperty("double2", Double.parseDouble("43214321.43214321")); |
149 |
|
150 |
x2.putProperty("string1", "String1"); |
151 |
x2.putProperty("string2", "String2"); |
152 |
|
153 |
x2.putProperty("object1", obj1);
|
154 |
x2.putProperty("object2", obj2);
|
155 |
|
156 |
|
157 |
//----- x1 != x3
|
158 |
|
159 |
x3.putProperty("boolean1", false); |
160 |
x3.putProperty("boolean2", true); |
161 |
|
162 |
x3.putProperty("integer1", Integer.parseInt("123")); |
163 |
x3.putProperty("integer2", Integer.parseInt("321")); |
164 |
|
165 |
x3.putProperty("long1", Long.parseLong("123123")); |
166 |
x3.putProperty("long2", Long.parseLong("321321")); |
167 |
|
168 |
x3.putProperty("float1", Float.parseFloat("1234.1234")); |
169 |
x3.putProperty("float2", Float.parseFloat("4321.4321")); |
170 |
|
171 |
x3.putProperty("double1", Double.parseDouble("12341234.12341234")); |
172 |
x3.putProperty("double2", Double.parseDouble("43214321.43214324")); |
173 |
|
174 |
x3.putProperty("string1", "String1"); |
175 |
x3.putProperty("string2", "String2"); |
176 |
|
177 |
x3.putProperty("object1", obj1);
|
178 |
x3.putProperty("object2", obj3);
|
179 |
|
180 |
|
181 |
XmlTag tag; |
182 |
try {
|
183 |
tag = (XmlTag) XmlTag.unmarshal( |
184 |
new FileReader(new File("testdata/sample.gvp"))); |
185 |
gvp1 = new XMLEntity(tag);
|
186 |
|
187 |
tag = (XmlTag) XmlTag.unmarshal( |
188 |
new FileReader(new File("testdata/sample2.gvp"))); |
189 |
gvp2 = new XMLEntity(tag);
|
190 |
} catch (Exception e) { |
191 |
// TODO Auto-generated catch block
|
192 |
e.printStackTrace(); |
193 |
} |
194 |
|
195 |
|
196 |
|
197 |
} |
198 |
|
199 |
public void testEquality() { |
200 |
assertEquals(x1, x2); |
201 |
|
202 |
assertFalse(x1.equals(x3)); |
203 |
assertFalse(x2.equals(x3)); |
204 |
} |
205 |
|
206 |
|
207 |
public void testHash() { |
208 |
final long x1Hash = x1.hash(); |
209 |
final long x2Hash = x2.hash(); |
210 |
final long x3Hash = x3.hash(); |
211 |
|
212 |
assertTrue("x1 should be equals to x2", x1Hash == x2Hash);
|
213 |
assertTrue("x1 should be distinct to x3", x1Hash != x3Hash);
|
214 |
} |
215 |
|
216 |
|
217 |
public void testSkippedProperties() { |
218 |
x1.putProperty("skipped1", true, false); |
219 |
x1.putProperty("skipped2", 1, false); |
220 |
x1.putProperty("skipped3", 1D, false); |
221 |
x1.putProperty("skipped4", 1F, false); |
222 |
x1.putProperty("skipped5", 1L, false); |
223 |
x1.putProperty("skipped6", "bla bla", false); |
224 |
|
225 |
x2.putProperty("skipped1", false, false); |
226 |
x2.putProperty("skipped2", 2, false); |
227 |
x2.putProperty("skipped3", 2D, false); |
228 |
x2.putProperty("skipped4", 2F, false); |
229 |
x2.putProperty("skipped5", 2L, false); |
230 |
x2.putProperty("skipped6", "bla bla bleitor", false); |
231 |
|
232 |
x3.putProperty("skipped1", false, false); |
233 |
x3.putProperty("skipped2", 2, false); |
234 |
x3.putProperty("skipped3", 2D, false); |
235 |
x3.putProperty("skipped4", 2F, false); |
236 |
x3.putProperty("skipped5", 2L, false); |
237 |
x3.putProperty("skipped6", "bla bla bleitor", false); |
238 |
|
239 |
|
240 |
|
241 |
final long x1Hash = x1.hash(); |
242 |
final long x2Hash = x2.hash(); |
243 |
final long x3Hash = x3.hash(); |
244 |
|
245 |
assertTrue("x1 should be equals to x2", x1Hash == x2Hash);
|
246 |
assertTrue("x1 should be distinct to x3", x1Hash != x3Hash);
|
247 |
assertTrue("x2 should be distinct to x3", x2Hash != x3Hash);
|
248 |
|
249 |
x1.remove("skipped1");
|
250 |
x1.remove("skipped2");
|
251 |
x1.remove("skipped3");
|
252 |
x1.remove("skipped4");
|
253 |
x1.remove("skipped5");
|
254 |
x1.remove("skipped6");
|
255 |
|
256 |
x2.remove("skipped1");
|
257 |
x2.remove("skipped2");
|
258 |
x2.remove("skipped3");
|
259 |
x2.remove("skipped4");
|
260 |
x2.remove("skipped5");
|
261 |
x2.remove("skipped6");
|
262 |
|
263 |
x3.remove("skipped1");
|
264 |
x3.remove("skipped2");
|
265 |
x3.remove("skipped3");
|
266 |
x3.remove("skipped4");
|
267 |
x3.remove("skipped5");
|
268 |
x3.remove("skipped6");
|
269 |
} |
270 |
|
271 |
|
272 |
|
273 |
public void testNonSkippedProperties() { |
274 |
x1.putProperty("non_skipped1", true, true); |
275 |
x1.putProperty("non_skipped2", 1, true); |
276 |
x1.putProperty("non_skipped3", 1D, true); |
277 |
x1.putProperty("non_skipped4", 1F, true); |
278 |
x1.putProperty("non_skipped5", 1L, true); |
279 |
x1.putProperty("non_skipped6", "bla bla", true); |
280 |
|
281 |
x3.putProperty("non_skipped1", false, true); |
282 |
x3.putProperty("non_skipped2", 2, true); |
283 |
x3.putProperty("non_skipped3", 2D, true); |
284 |
x3.putProperty("non_skipped4", 2F, true); |
285 |
x3.putProperty("non_skipped5", 2L, true); |
286 |
x3.putProperty("non_skipped6", "bla bla bleitor", true); |
287 |
|
288 |
x2.putProperty("non_skipped1", false, true); |
289 |
x2.putProperty("non_skipped2", 2, true); |
290 |
x2.putProperty("non_skipped3", 2D, true); |
291 |
x2.putProperty("non_skipped4", 2F, true); |
292 |
x2.putProperty("non_skipped5", 2L, true); |
293 |
x2.putProperty("non_skipped6", "bla bla bleitor", true); |
294 |
|
295 |
final long x1Hash = x1.hash(); |
296 |
final long x2Hash = x2.hash(); |
297 |
final long x3Hash = x3.hash(); |
298 |
|
299 |
assertFalse("x1 should be distinct to x2", x1Hash == x2Hash);
|
300 |
assertFalse("x1 should be distinct to x3", x1Hash == x3Hash);
|
301 |
assertFalse("x2 should be distinct to x3", x2Hash == x3Hash);
|
302 |
|
303 |
|
304 |
// restore the XMEntities to the initial state and ensure that
|
305 |
// passes the tests again
|
306 |
x1.remove("non_skipped1");
|
307 |
x1.remove("non_skipped2");
|
308 |
x1.remove("non_skipped3");
|
309 |
x1.remove("non_skipped4");
|
310 |
x1.remove("non_skipped5");
|
311 |
x1.remove("non_skipped6");
|
312 |
|
313 |
x2.remove("non_skipped1");
|
314 |
x2.remove("non_skipped2");
|
315 |
x2.remove("non_skipped3");
|
316 |
x2.remove("non_skipped4");
|
317 |
x2.remove("non_skipped5");
|
318 |
x2.remove("non_skipped6");
|
319 |
|
320 |
x3.remove("non_skipped1");
|
321 |
x3.remove("non_skipped2");
|
322 |
x3.remove("non_skipped3");
|
323 |
x3.remove("non_skipped4");
|
324 |
x3.remove("non_skipped5");
|
325 |
x3.remove("non_skipped6");
|
326 |
|
327 |
testHash(); |
328 |
testEquality(); |
329 |
} |
330 |
|
331 |
|
332 |
public void testEquivalentProjects() { |
333 |
final long x1Hash = gvp1.hash(); |
334 |
final long x2Hash = gvp2.hash(); |
335 |
|
336 |
assertTrue("x1 should be equals to x2", x1Hash == x2Hash);
|
337 |
} |
338 |
|
339 |
public void testBenchMark() { |
340 |
long t_ini, t_unmarshal, t_buildXMLEntity, t_computeHash ;
|
341 |
t_ini = System.currentTimeMillis();
|
342 |
XmlTag tag; |
343 |
try {
|
344 |
File f= new File("testdata/big.gvp"); |
345 |
tag = (XmlTag) XmlTag.unmarshal( |
346 |
new FileReader(f)); |
347 |
t_unmarshal = System.currentTimeMillis() - t_ini;
|
348 |
|
349 |
gvp1 = new XMLEntity(tag);
|
350 |
t_buildXMLEntity = System.currentTimeMillis() - t_unmarshal- t_ini;
|
351 |
|
352 |
long hash = gvp1.hash();
|
353 |
t_computeHash = System.currentTimeMillis() - t_buildXMLEntity- t_ini;
|
354 |
|
355 |
assertTrue("BenchMark ("+f.getAbsolutePath()+" "+f.length()/1024+"Kb):" + |
356 |
"\t-unmarshal time: "+t_unmarshal+" milliseconds\n" + |
357 |
"\t-build XMLEntity time: "+t_buildXMLEntity+" milliseconds\n" + |
358 |
"\t-compute hash time: "+t_computeHash+" milliseconds",t_computeHash < 500); |
359 |
|
360 |
} catch (Exception e) { |
361 |
// TODO Auto-generated catch block
|
362 |
e.printStackTrace(); |
363 |
} |
364 |
|
365 |
} |
366 |
} |