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