Debian Codegraph @

dojox/data/tests/stores/OpmlStore.js

raw symbols SCIP
1 dojo.provide("dojox.data.tests.stores.OpmlStore");
2 dojo.require("dojox.data.OpmlStore");
3 dojo.require("dojo.data.api.Read");
4 dojo.require("dojo.data.api.Identity");
5
6 dojox.data.tests.stores.OpmlStore.getDatasource = function(filepath){
7 // summary:
8 // A simple helper function for getting the sample data used in each of the tests.
9 // description:
10 // A simple helper function for getting the sample data used in each of the tests.
11
12 var dataSource = {};
13 if(dojo.isBrowser){
14 dataSource.url = require.toUrl("dojox/data/tests/" + filepath).toString();
15 }else{
16 // When running tests in Rhino, xhrGet is not available,
17 // so we have the file data in the code below.
18 switch(filepath){
19 case "stores/geography.xml":
20 var opmlData = "";
21 opmlData += '<?xml version="1.0" encoding="ISO-8859-1"?>\n';
22 opmlData += ' <opml version="1.0">\n';
23 opmlData += ' <head>\n';
24 opmlData += ' <title>geography.opml</title>\n';
25 opmlData += ' <dateCreated>2006-11-10</dateCreated>\n';
26 opmlData += ' <dateModified>2006-11-13</dateModified>\n';
27 opmlData += ' <ownerName>Magellan, Ferdinand</ownerName>\n';
28 opmlData += ' </head>\n';
29 opmlData += ' <body>\n';
30 opmlData += ' <outline text="Africa" type="continent">\n';
31 opmlData += ' <outline text="Egypt" type="country"/>\n';
32 opmlData += ' <outline text="Kenya" type="country">\n';
33 opmlData += ' <outline text="Nairobi" type="city"/>\n';
34 opmlData += ' <outline text="Mombasa" type="city"/>\n';
35 opmlData += ' </outline>\n';
36 opmlData += ' <outline text="Sudan" type="country">\n';
37 opmlData += ' <outline text="Khartoum" type="city"/>\n';
38 opmlData += ' </outline>\n';
39 opmlData += ' </outline>\n';
40 opmlData += ' <outline text="Asia" type="continent">\n';
41 opmlData += ' <outline text="China" type="country"/>\n';
42 opmlData += ' <outline text="India" type="country"/>\n';
43 opmlData += ' <outline text="Russia" type="country"/>\n';
44 opmlData += ' <outline text="Mongolia" type="country"/>\n';
45 opmlData += ' </outline>\n';
46 opmlData += ' <outline text="Australia" type="continent" population="21 million">\n';
47 opmlData += ' <outline text="Australia" type="country" population="21 million"/>\n';
48 opmlData += ' </outline>\n';
49 opmlData += ' <outline text="Europe" type="continent">\n';
50 opmlData += ' <outline text="Germany" type="country"/>\n';
51 opmlData += ' <outline text="France" type="country"/>\n';
52 opmlData += ' <outline text="Spain" type="country"/>\n';
53 opmlData += ' <outline text="Italy" type="country"/>\n';
54 opmlData += ' </outline>\n';
55 opmlData += ' <outline text="North America" type="continent">\n';
56 opmlData += ' <outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km">\n';
57 opmlData += ' <outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC"/>\n';
58 opmlData += ' <outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC"/>\n';
59 opmlData += ' </outline>\n';
60 opmlData += ' <outline text="Canada" type="country" population="33 million" area="9,984,670 sq km">\n';
61 opmlData += ' <outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC"/>\n';
62 opmlData += ' <outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC"/>\n';
63 opmlData += ' </outline>\n';
64 opmlData += ' <outline text="United States of America" type="country"/>\n';
65 opmlData += ' </outline>\n';
66 opmlData += ' <outline text="South America" type="continent">\n';
67 opmlData += ' <outline text="Brazil" type="country" population="186 million"/>\n';
68 opmlData += ' <outline text="Argentina" type="country" population="40 million"/>\n';
69 opmlData += ' </outline>\n';
70 opmlData += ' </body>\n';
71 opmlData += ' </opml>\n';
72 break;
73 case "stores/geography_withspeciallabel.xml":
74 var opmlData = "";
75 opmlData += '<?xml version="1.0" encoding="ISO-8859-1"?>\n';
76 opmlData += '<opml version="1.0">\n';
77 opmlData += ' <head>\n';
78 opmlData += ' <title>geography.opml</title>\n';
79 opmlData += ' <dateCreated>2006-11-10</dateCreated>\n';
80 opmlData += ' <dateModified>2006-11-13</dateModified>\n';
81 opmlData += ' <ownerName>Magellan, Ferdinand</ownerName>\n';
82 opmlData += ' </head>\n';
83 opmlData += ' <body>\n';
84 opmlData += ' <outline text="Africa" type="continent" label="Continent/Africa">\n';
85 opmlData += ' <outline text="Egypt" type="country" label="Country/Egypt"/>\n';
86 opmlData += ' <outline text="Kenya" type="country" label="Country/Kenya">\n';
87 opmlData += ' <outline text="Nairobi" type="city" label="City/Nairobi"/>\n';
88 opmlData += ' <outline text="Mombasa" type="city" label="City/Mombasa"/>\n';
89 opmlData += ' </outline>\n';
90 opmlData += ' <outline text="Sudan" type="country" label="Country/Sudan">\n';
91 opmlData += ' <outline text="Khartoum" type="city" label="City/Khartoum"/>\n';
92 opmlData += ' </outline>\n';
93 opmlData += ' </outline>\n';
94 opmlData += ' <outline text="Asia" type="continent" label="Continent/Asia">\n';
95 opmlData += ' <outline text="China" type="country" label="Country/China"/>\n';
96 opmlData += ' <outline text="India" type="country" label="Country/India"/>\n';
97 opmlData += ' <outline text="Russia" type="country" label="Country/Russia"/>\n';
98 opmlData += ' <outline text="Mongolia" type="country" label="Country/Mongolia"/>\n';
99 opmlData += ' </outline>\n';
100 opmlData += ' <outline text="Australia" type="continent" population="21 million" label="Continent/Australia">\n';
101 opmlData += ' <outline text="Australia" type="country" population="21 million" label="Country/Australia"/>\n';
102 opmlData += ' </outline>\n';
103 opmlData += ' <outline text="Europe" type="continent" label="Contintent/Europe">\n';
104 opmlData += ' <outline text="Germany" type="country" label="Country/Germany"/>\n';
105 opmlData += ' <outline text="France" type="country" label="Country/France"/>\n';
106 opmlData += ' <outline text="Spain" type="country" label="Country/Spain"/>\n';
107 opmlData += ' <outline text="Italy" type="country" label="Country/Italy"/>\n';
108 opmlData += ' </outline>\n';
109 opmlData += ' <outline text="North America" type="continent" label="Continent/North America">\n';
110 opmlData += ' <outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km" label="Country/Mexico">\n';
111 opmlData += ' <outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC" label="City/Mexico City"/>\n';
112 opmlData += ' <outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC" label="City/Guadalajara"/>\n';
113 opmlData += ' </outline>\n';
114 opmlData += ' <outline text="Canada" type="country" population="33 million" area="9,984,670 sq km" label="Country/Canada">\n';
115 opmlData += ' <outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC" label="City/Ottawa"/>\n';
116 opmlData += ' <outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC" label="City/Toronto"/>\n';
117 opmlData += ' </outline>\n';
118 opmlData += ' <outline text="United States of America" type="country" label="Country/United States of America"/>\n';
119 opmlData += ' </outline>\n';
120 opmlData += ' <outline text="South America" type="continent" label="Continent/South America">\n';
121 opmlData += ' <outline text="Brazil" type="country" population="186 million" label="Country/Brazil"/>\n';
122 opmlData += ' <outline text="Argentina" type="country" population="40 million" label="Country/Argentina"/>\n';
123 opmlData += ' </outline>\n';
124 opmlData += ' </body>\n';
125 opmlData += '</opml>\n';
126 break;
127 }
128 dataSource.data = opmlData;
129 }
130 return dataSource; //Object
131 };
132
133 dojox.data.tests.stores.OpmlStore.verifyItems = function(opmlStore, items, attribute, compareArray){
134 // summary:
135 // A helper function for validating that the items array is ordered
136 // the same as the compareArray
137 if(items.length != compareArray.length){ return false; }
138 for(var i = 0; i < items.length; i++){
139 if(!(opmlStore.getValue(items[i], attribute) === compareArray[i])){
140 return false; //Boolean
141 }
142 }
143 return true; //Boolean
144 };
145
146 dojox.data.tests.stores.OpmlStore.error = function(t, d, errData){
147 // summary:
148 // The error callback function to be used for all of the tests.
149 d.errback(errData);
150 };
151
152 doh.register("dojox.data.tests.stores.OpmlStore",
153 [
154 function testReadAPI_fetch_all(t){
155 // summary:
156 // Simple test of a basic fetch on OpmlStore.
157 // description:
158 // Simple test of a basic fetch on OpmlStore.
159
160 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
161 var opmlStore = new dojox.data.OpmlStore(args);
162
163 var d = new doh.Deferred();
164 function completedAll(items){
165 t.is(6, items.length);
166 d.callback(true);
167 }
168
169 //Get everything...
170 opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
171 return d; //Object
172 },
173 function testReadAPI_fetch_one(t){
174 // summary:
175 // Simple test of a basic fetch on OpmlStore of a single item.
176 // description:
177 // Simple test of a basic fetch on OpmlStore of a single item.
178
179 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
180 var opmlStore = new dojox.data.OpmlStore(args);
181
182 var d = new doh.Deferred();
183 function onComplete(items, request){
184 t.is(1, items.length);
185 d.callback(true);
186 }
187 opmlStore.fetch({ query: {text: "Asia"},
188 onComplete: onComplete,
189 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
190 });
191 return d; //Object
192 },
193
194 function testReadAPI_fetch_one_Multiple(t){
195 // summary:
196 // Simple test of a basic fetch on OpmlStore of a single item.
197 // description:
198 // Simple test of a basic fetch on OpmlStore of a single item.
199
200 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
201 var opmlStore = new dojox.data.OpmlStore(args);
202
203 var d = new doh.Deferred();
204 var done = [false,false];
205 function onCompleteOne(items, request){
206 done[0] = true;
207 t.is(1, items.length);
208 if(done[0] && done[1]){
209 d.callback(true);
210 }
211 }
212 function onCompleteTwo(items, request){
213 done[1] = true;
214 t.is(1, items.length);
215 if(done[0] && done[1]){
216 d.callback(true);
217 }
218 }
219
220 opmlStore.fetch({ query: {text: "Asia"},
221 onComplete: onCompleteOne,
222 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
223 });
224
225 opmlStore.fetch({ query: {text: "North America"},
226 onComplete: onCompleteTwo,
227 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
228 });
229
230 return d; //Object
231 },
232
233 function testReadAPI_fetch_one_MultipleMixed(t){
234 // summary:
235 // Simple test of a basic fetch on OpmlStore of a single item mixing two fetch types.
236 // description:
237 // Simple test of a basic fetch on Cpmltore of a single item mixing two fetch types.
238
239 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
240 var opmlStore = new dojox.data.OpmlStore(args);
241
242 var d = new doh.Deferred();
243
244 var done = [false, false];
245 function onComplete(items, request){
246 done[0] = true;
247 t.is(1, items.length);
248 console.log("Found item: " + opmlStore.getValue(items[0],"text") + " with identity: " + opmlStore.getIdentity(items[0]));
249 t.is(0, opmlStore.getIdentity(items[0]));
250 if(done[0] && done[1]){
251 d.callback(true);
252 }
253 }
254
255 function onItem(item){
256 done[1] = true;
257 t.assertTrue(item !== null);
258 console.log("Found item: " + opmlStore.getValue(item,"text"));
259 t.is('Egypt', opmlStore.getValue(item,"text")); //Should be the second node parsed, ergo id 1, first node is id 0.
260 t.is(1, opmlStore.getIdentity(item));
261 if(done[0] && done[1]){
262 d.callback(true);
263 }
264 }
265
266 opmlStore.fetch({ query: {text: "Africa"},
267 onComplete: onComplete,
268 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
269 });
270
271 opmlStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
272
273 return d; //Object
274 },
275
276 function testReadAPI_fetch_one_deep(t){
277 // summary:
278 // Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
279 // description:
280 // Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
281
282 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
283 var opmlStore = new dojox.data.OpmlStore(args);
284
285 var d = new doh.Deferred();
286 function onComplete(items, request){
287 t.is(1, items.length);
288 d.callback(true);
289 }
290 opmlStore.fetch({ query: {text: "Mexico City"},
291 queryOptions: {deep:true},
292 onComplete: onComplete,
293 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
294 });
295 return d; //Object
296 },
297
298 function testReadAPI_fetch_one_deep_off(t){
299 // summary:
300 // Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
301 // description:
302 // Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
303
304 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
305 var opmlStore = new dojox.data.OpmlStore(args);
306
307 var d = new doh.Deferred();
308 function onComplete(items, request){
309 //Nothing should be found.
310 t.is(0, items.length);
311 d.callback(true);
312 }
313 opmlStore.fetch({ query: {text: "Mexico City"},
314 onComplete: onComplete,
315 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
316 });
317 return d; //Object
318 },
319
320 function testReadAPI_fetch_all_streaming(t){
321 // summary:
322 // Simple test of a basic fetch on OpmlStore.
323 // description:
324 // Simple test of a basic fetch on OpmlStore.
325
326 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
327 var opmlStore = new dojox.data.OpmlStore(args);
328
329 var d = new doh.Deferred();
330 count = 0;
331
332 function onBegin(size, requestObj){
333 t.is(6, size);
334 }
335 function onItem(item, requestObj){
336 t.assertTrue(opmlStore.isItem(item));
337 count++;
338 }
339 function onComplete(items, request){
340 t.is(6, count);
341 t.is(null, items);
342 d.callback(true);
343 }
344
345 //Get everything...
346 opmlStore.fetch({ onBegin: onBegin,
347 onItem: onItem,
348 onComplete: onComplete,
349 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
350 });
351 return d; //Object
352 },
353 function testReadAPI_fetch_paging(t){
354 // summary:
355 // Test of multiple fetches on a single result. Paging, if you will.
356 // description:
357 // Test of multiple fetches on a single result. Paging, if you will.
358
359 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
360 var opmlStore = new dojox.data.OpmlStore(args);
361
362 var d = new doh.Deferred();
363 function dumpFirstFetch(items, request){
364 t.is(5, items.length);
365 request.start = 3;
366 request.count = 1;
367 request.onComplete = dumpSecondFetch;
368 opmlStore.fetch(request);
369 }
370
371 function dumpSecondFetch(items, request){
372 t.is(1, items.length);
373 request.start = 0;
374 request.count = 5;
375 request.onComplete = dumpThirdFetch;
376 opmlStore.fetch(request);
377 }
378
379 function dumpThirdFetch(items, request){
380 t.is(5, items.length);
381 request.start = 2;
382 request.count = 20;
383 request.onComplete = dumpFourthFetch;
384 opmlStore.fetch(request);
385 }
386
387 function dumpFourthFetch(items, request){
388 t.is(4, items.length);
389 request.start = 9;
390 request.count = 100;
391 request.onComplete = dumpFifthFetch;
392 opmlStore.fetch(request);
393 }
394
395 function dumpFifthFetch(items, request){
396 t.is(0, items.length);
397 request.start = 2;
398 request.count = 20;
399 request.onComplete = dumpSixthFetch;
400 opmlStore.fetch(request);
401 }
402
403 function dumpSixthFetch(items, request){
404 t.is(4, items.length);
405 d.callback(true);
406 }
407
408 function completed(items, request){
409 t.is(6, items.length);
410 request.start = 1;
411 request.count = 5;
412 request.onComplete = dumpFirstFetch;
413 opmlStore.fetch(request);
414 }
415
416 opmlStore.fetch({onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
417 return d; //Object
418
419 },
420 function testReadAPI_getLabel(t){
421 // summary:
422 // Simple test of the getLabel function against a store set that has a label defined.
423 // description:
424 // Simple test of the getLabel function against a store set that has a label defined.
425
426 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
427 var opmlStore = new dojox.data.OpmlStore(args);
428
429 var d = new doh.Deferred();
430 function onComplete(items, request){
431 t.assertEqual(items.length, 1);
432 var label = opmlStore.getLabel(items[0]);
433 t.assertTrue(label !== null);
434 t.assertEqual("Asia", label);
435 d.callback(true);
436 }
437 opmlStore.fetch({ query: {text: "Asia"},
438 onComplete: onComplete,
439 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
440 });
441 return d;
442 },
443 function testReadAPI_getLabelAttributes(t){
444 // summary:
445 // Simple test of the getLabelAttributes function against a store set that has a label defined.
446 // description:
447 // Simple test of the getLabelAttributes function against a store set that has a label defined.
448
449 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
450 var opmlStore = new dojox.data.OpmlStore(args);
451
452 var d = new doh.Deferred();
453 function onComplete(items, request){
454 t.assertEqual(items.length, 1);
455 var labelList = opmlStore.getLabelAttributes(items[0]);
456 t.assertTrue(dojo.isArray(labelList));
457 t.assertEqual("text", labelList[0]);
458 d.callback(true);
459 }
460 opmlStore.fetch({ query: {text: "Asia"},
461 onComplete: onComplete,
462 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
463 });
464 return d;
465 },
466
467 function testReadAPI_getLabel_nondefault(t){
468 // summary:
469 // Simple test of the getLabel function against a store set that has a label defined.
470 // description:
471 // Simple test of the getLabel function against a store set that has a label defined.
472
473 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography_withspeciallabel.xml");
474 args.label="label";
475 var opmlStore = new dojox.data.OpmlStore(args);
476
477 var d = new doh.Deferred();
478 function onComplete(items, request){
479 t.assertEqual(items.length, 1);
480 var label = opmlStore.getLabel(items[0]);
481 t.assertTrue(label !== null);
482 t.assertEqual("Continent/Asia", label);
483 d.callback(true);
484 }
485 opmlStore.fetch({ query: {text: "Asia"},
486 onComplete: onComplete,
487 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
488 });
489 return d;
490 },
491 function testReadAPI_getLabelAttributes_nondefault(t){
492 // summary:
493 // Simple test of the getLabelAttributes function against a store set that has a label defined.
494 // description:
495 // Simple test of the getLabelAttributes function against a store set that has a label defined.
496
497 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography_withspeciallabel.xml");
498 args.label="label";
499 var opmlStore = new dojox.data.OpmlStore(args);
500
501 var d = new doh.Deferred();
502 function onComplete(items, request){
503 t.assertEqual(items.length, 1);
504 var labelList = opmlStore.getLabelAttributes(items[0]);
505 t.assertTrue(dojo.isArray(labelList));
506 t.assertEqual("label", labelList[0]);
507 d.callback(true);
508 }
509 opmlStore.fetch({ query: {text: "Asia"},
510 onComplete: onComplete,
511 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
512 });
513 return d;
514 },
515
516 function testReadAPI_getValue(t){
517 // summary:
518 // Simple test of the getValue function of the store.
519 // description:
520 // Simple test of the getValue function of the store.
521
522 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
523 var opmlStore = new dojox.data.OpmlStore(args);
524
525 var d = new doh.Deferred();
526 function completedAll(items){
527 t.is(6, items.length);
528
529 t.is("Africa", opmlStore.getValue(items[0],"text"));
530 t.is("Asia", opmlStore.getValue(items[1],"text"));
531 t.is("Australia", opmlStore.getValue(items[2],"text"));
532 t.is("Europe", opmlStore.getValue(items[3],"text"));
533 t.is("North America", opmlStore.getValue(items[4],"text"));
534 t.is("South America", opmlStore.getValue(items[5],"text"));
535
536 t.is("continent", opmlStore.getValue(items[1],"type"));
537 t.is("21 million", opmlStore.getValue(items[2],"population"));
538
539 var firstChild = opmlStore.getValue(items[4],"children");
540 t.assertTrue(opmlStore.isItem(firstChild));
541 t.is("Mexico", opmlStore.getValue(firstChild,"text"));
542 t.is("country", opmlStore.getValue(firstChild,"type"));
543 t.is("108 million", opmlStore.getValue(firstChild,"population"));
544 t.is("1,972,550 sq km", opmlStore.getValue(firstChild,"area"));
545
546 firstChild = opmlStore.getValue(firstChild,"children");
547 t.assertTrue(opmlStore.isItem(firstChild));
548 t.is("Mexico City", opmlStore.getValue(firstChild,"text"));
549 t.is("city", opmlStore.getValue(firstChild,"type"));
550 t.is("19 million", opmlStore.getValue(firstChild,"population"));
551 t.is("-6 UTC", opmlStore.getValue(firstChild,"timezone"));
552
553 d.callback(true);
554 }
555
556 //Get everything...
557 opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
558 return d; //Object
559 },
560 function testReadAPI_getValues(t){
561 // summary:
562 // Simple test of the getValues function of the store.
563 // description:
564 // Simple test of the getValues function of the store.
565
566 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
567 var opmlStore = new dojox.data.OpmlStore(args);
568
569 var d = new doh.Deferred();
570 function completed(items){
571 t.is(1, items.length);
572
573 var children = opmlStore.getValues(items[0],"children");
574 t.is(3, children.length);
575 for(var i=0; i<children.length; i++){
576 t.assertTrue(opmlStore.isItem(children[i]));
577 }
578
579 t.is("Mexico", opmlStore.getValues(children[0],"text")[0]);
580 t.is("country", opmlStore.getValues(children[0],"type")[0]);
581 t.is("108 million", opmlStore.getValues(children[0],"population")[0]);
582 t.is("1,972,550 sq km", opmlStore.getValues(children[0],"area")[0]);
583
584 t.is("Canada", opmlStore.getValues(children[1],"text")[0]);
585 t.is("country", opmlStore.getValues(children[1],"type")[0]);
586
587 children = opmlStore.getValues(children[1],"children");
588 t.is(2, children.length);
589 for(var i=0; i<children.length; i++){
590 t.assertTrue(opmlStore.isItem(children[i]));
591 }
592 t.is("Ottawa", opmlStore.getValues(children[0],"text")[0]);
593 t.is("Toronto", opmlStore.getValues(children[1],"text")[0]);
594
595 d.callback(true);
596 }
597
598 //Get one item...
599 opmlStore.fetch({ query: {text: "North America"},
600 onComplete: completed,
601 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
602 return d; //Object
603 },
604 function testReadAPI_isItem(t){
605 // summary:
606 // Simple test of the isItem function of the store
607 // description:
608 // Simple test of the isItem function of the store
609
610 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
611 var opmlStore = new dojox.data.OpmlStore(args);
612
613 var d = new doh.Deferred();
614 function completedAll(items){
615 t.is(6, items.length);
616 for(var i=0; i<6; i++){
617 t.assertTrue(opmlStore.isItem(items[i]));
618 }
619 t.assertTrue(!opmlStore.isItem({}));
620 t.assertTrue(!opmlStore.isItem({ item: "not an item" }));
621 t.assertTrue(!opmlStore.isItem("not an item"));
622 t.assertTrue(!opmlStore.isItem(["not an item"]));
623
624 d.callback(true);
625 }
626
627 //Get everything...
628 opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
629 return d; //Object
630 },
631 function testReadAPI_hasAttribute(t){
632 // summary:
633 // Simple test of the hasAttribute function of the store
634 // description:
635 // Simple test of the hasAttribute function of the store
636
637 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
638 var opmlStore = new dojox.data.OpmlStore(args);
639
640 var d = new doh.Deferred();
641 function onComplete(items){
642 t.is(1, items.length);
643 t.assertTrue(items[0] !== null);
644 t.assertTrue(opmlStore.hasAttribute(items[0], "text"));
645 t.assertTrue(opmlStore.hasAttribute(items[0], "type"));
646 t.assertTrue(!opmlStore.hasAttribute(items[0], "population"));
647 t.assertTrue(!opmlStore.hasAttribute(items[0], "Nothing"));
648 t.assertTrue(!opmlStore.hasAttribute(items[0], "Text"));
649
650 //Test that null attributes throw an exception
651 var passed = false;
652 try{
653 opmlStore.hasAttribute(items[0], null);
654 }catch (e){
655 passed = true;
656 }
657 t.assertTrue(passed);
658
659 d.callback(true);
660 }
661
662 //Get one item...
663 opmlStore.fetch({ query: {text: "Asia"},
664 onComplete: onComplete,
665 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
666 });
667 return d; //Object
668 },
669 function testReadAPI_containsValue(t){
670 // summary:
671 // Simple test of the containsValue function of the store
672 // description:
673 // Simple test of the containsValue function of the store
674
675 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
676 var opmlStore = new dojox.data.OpmlStore(args);
677
678 var d = new doh.Deferred();
679 function onComplete(items){
680 t.is(1, items.length);
681 t.assertTrue(items[0] !== null);
682 t.assertTrue(opmlStore.containsValue(items[0], "text", "North America"));
683 t.assertTrue(opmlStore.containsValue(items[0], "type", "continent"));
684 t.assertTrue(!opmlStore.containsValue(items[0], "text", "America"));
685 t.assertTrue(!opmlStore.containsValue(items[0], "Type", "continent"));
686 t.assertTrue(!opmlStore.containsValue(items[0], "text", null));
687
688 var children = opmlStore.getValues(items[0], "children");
689 t.assertTrue(opmlStore.containsValue(items[0], "children", children[0]));
690 t.assertTrue(opmlStore.containsValue(items[0], "children", children[1]));
691 t.assertTrue(opmlStore.containsValue(items[0], "children", children[2]));
692
693 //Test that null attributes throw an exception
694 var passed = false;
695 try{
696 opmlStore.containsValue(items[0], null, "foo");
697 }catch (e){
698 passed = true;
699 }
700 t.assertTrue(passed);
701
702 d.callback(true);
703 }
704
705 //Get one item...
706 opmlStore.fetch({ query: {text: "North America"},
707 onComplete: onComplete,
708 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
709 });
710 return d; //Object
711 },
712 function testReadAPI_getAttributes(t){
713 // summary:
714 // Simple test of the getAttributes function of the store
715 // description:
716 // Simple test of the getAttributes function of the store
717
718 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
719 var opmlStore = new dojox.data.OpmlStore(args);
720
721 var d = new doh.Deferred();
722 function onComplete(items){
723 t.is(6, items.length);
724 t.assertTrue(opmlStore.isItem(items[0]));
725
726 var attributes = opmlStore.getAttributes(items[0]);
727 t.is(3, attributes.length);
728 for(var i = 0; i < attributes.length; i++){
729 t.assertTrue((attributes[i] === "text" || attributes[i] === "type" || attributes[i] === "children"));
730 }
731
732 d.callback(true);
733 }
734
735 //Get everything...
736 opmlStore.fetch({ onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
737 return d; //Object
738 },
739 function testReadAPI_getFeatures(t){
740 // summary:
741 // Simple test of the getFeatures function of the store
742 // description:
743 // Simple test of the getFeatures function of the store
744
745 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
746 var opmlStore = new dojox.data.OpmlStore(args);
747
748 var features = opmlStore.getFeatures();
749 var count = 0;
750 for(i in features){
751 t.assertTrue((i === "dojo.data.api.Read") || (i === "dojo.data.api.Identity"));
752 count++;
753 }
754 t.assertTrue(count === 2);
755 },
756 function testReadAPI_fetch_patternMatch0(t){
757 // summary:
758 // Function to test pattern matching of everything starting with Capital A
759 // description:
760 // Function to test pattern matching of everything starting with Capital A
761
762 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
763 var opmlStore = new dojox.data.OpmlStore(args);
764
765 var d = new doh.Deferred();
766 function completed(items, request){
767 t.is(3, items.length);
768 var valueArray = [ "Africa", "Asia", "Australia"];
769 t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", valueArray));
770 d.callback(true);
771 }
772
773 opmlStore.fetch({query: {text: "A*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
774 return d; //Object
775 },
776 function testReadAPI_fetch_patternMatch1(t){
777 // summary:
778 // Function to test pattern matching of everything with America in it.
779 // description:
780 // Function to test pattern matching of everything with America in it.
781
782 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
783 var opmlStore = new dojox.data.OpmlStore(args);
784
785 var d = new doh.Deferred();
786 function completed(items, request){
787 t.assertTrue(items.length === 2);
788 var valueArray = [ "North America", "South America"];
789 t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", valueArray));
790 d.callback(true);
791 }
792
793 opmlStore.fetch({query: {text: "*America*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
794 return d; //Object
795 },
796 function testReadAPI_fetch_patternMatch2(t){
797 // summary:
798 // Function to test exact pattern match
799 // description:
800 // Function to test exact pattern match
801
802 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
803 var opmlStore = new dojox.data.OpmlStore(args);
804
805 var d = new doh.Deferred();
806 function completed(items, request){
807 t.is(1, items.length);
808 t.assertTrue(opmlStore.getValue(items[0], "text") === "Europe");
809 d.callback(true);
810 }
811
812 opmlStore.fetch({query: {text: "Europe"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
813 return d; //Object
814 },
815 function testReadAPI_fetch_patternMatch_caseInsensitive(t){
816 // summary:
817 // Function to test exact pattern match with case insensitivity set.
818 // description:
819 // Function to test exact pattern match with case insensitivity set.
820
821 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
822 var opmlStore = new dojox.data.OpmlStore(args);
823
824 var d = new doh.Deferred();
825 function completed(items, request){
826 t.is(1, items.length);
827 t.assertTrue(opmlStore.getValue(items[0], "text") === "Asia");
828 d.callback(true);
829 }
830
831 opmlStore.fetch({query: {text: "asia"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
832 return d; //Object
833 },
834 function testReadAPI_fetch_patternMatch_caseSensitive(t){
835 // summary:
836 // Function to test exact pattern match with case sensitivity set.
837 // description:
838 // Function to test exact pattern match with case sensitivity set.
839
840 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
841 var opmlStore = new dojox.data.OpmlStore(args);
842
843 var d = new doh.Deferred();
844 function completed(items, request){
845 t.is(0, items.length);
846 d.callback(true);
847 }
848
849 opmlStore.fetch({query: {text: "ASIA"}, queryOptions: {ignoreCase: false}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
850 return d; //Object
851 },
852 function testReadAPI_fetch_sortAlphabetic(t){
853 // summary:
854 // Function to test sorting alphabetic ordering.
855 // description:
856 // Function to test sorting alphabetic ordering.
857
858 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
859 var opmlStore = new dojox.data.OpmlStore(args);
860
861 var d = new doh.Deferred();
862 function completed(items, request){
863 //Output should be in this order...
864 var orderedArray = [ "Africa", "Asia", "Australia", "Europe", "North America", "South America"];
865 t.is(6, items.length);
866 t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
867 d.callback(true);
868 }
869
870 var sortAttributes = [{attribute: "text"}];
871 opmlStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
872 return d; //Object
873 },
874 function testReadAPI_fetch_sortAlphabeticDescending(t){
875 // summary:
876 // Function to test sorting alphabetic ordering in descending mode.
877 // description:
878 // Function to test sorting alphabetic ordering in descending mode.
879
880 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
881 var opmlStore = new dojox.data.OpmlStore(args);
882
883 var d = new doh.Deferred();
884 function completed(items, request){
885 //Output should be in this order...
886 var orderedArray = [ "South America", "North America", "Europe", "Australia", "Asia", "Africa"
887 ];
888 t.is(6, items.length);
889 t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
890 d.callback(true);
891 }
892
893 var sortAttributes = [{attribute: "text", descending: true}];
894 opmlStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
895 return d; //Object
896 },
897 function testReadAPI_fetch_sortAlphabeticWithCount(t){
898 // summary:
899 // Function to test sorting numerically in descending order, returning only a specified number of them.
900 // description:
901 // Function to test sorting numerically in descending order, returning only a specified number of them.
902
903 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
904 var opmlStore = new dojox.data.OpmlStore(args);
905
906 var d = new doh.Deferred();
907 function completed(items, request){
908 //Output should be in this order...
909 var orderedArray = [ "South America", "North America", "Europe", "Australia"
910 ];
911 t.is(4, items.length);
912 t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
913 d.callback(true);
914 }
915
916 var sortAttributes = [{attribute: "text", descending: true}];
917 opmlStore.fetch({sort: sortAttributes,
918 count: 4,
919 onComplete: completed,
920 onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
921 return d; //Object
922 },
923 function testReadAPI_functionConformance(t){
924 // summary:
925 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
926 // description:
927 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
928
929 var testStore = new dojox.data.OpmlStore(dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"));
930 var readApi = new dojo.data.api.Read();
931 var passed = true;
932
933 for(i in readApi){
934 if(i.toString().charAt(0) !== '_')
935 {
936 var member = readApi[i];
937 //Check that all the 'Read' defined functions exist on the test store.
938 if(typeof member === "function"){
939 var testStoreMember = testStore[i];
940 if(!(typeof testStoreMember === "function")){
941 passed = false;
942 break;
943 }
944 }
945 }
946 }
947 t.assertTrue(passed);
948 },
949 function testIdentityAPI_fetchItemByIdentity(t){
950 // summary:
951 // Simple test of the fetchItemByIdentity function of the store.
952 // description:
953 // Simple test of the fetchItemByIdentity function of the store.
954
955 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
956 var opmlStore = new dojox.data.OpmlStore(args);
957
958 var d = new doh.Deferred();
959 function onItem(item){
960 t.assertTrue(item !== null);
961 d.callback(true);
962 }
963 opmlStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
964 return d;
965 },
966
967 function testIdentityAPI_fetchItemByIdentity_bad1(t){
968 // summary:
969 // Simple test of the fetchItemByIdentity function of the store.
970 // description:
971 // Simple test of the fetchItemByIdentity function of the store.
972
973 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
974 var opmlStore = new dojox.data.OpmlStore(args);
975
976 var d = new doh.Deferred();
977 function onItem(item){
978 t.assertTrue(item === null);
979 d.callback(true);
980 }
981 opmlStore.fetchItemByIdentity({identity: "200", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
982 return d;
983 },
984 function testIdentityAPI_fetchItemByIdentity_bad2(t){
985 // summary:
986 // Simple test of the fetchItemByIdentity function of the store.
987 // description:
988 // Simple test of the fetchItemByIdentity function of the store.
989
990 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
991 var opmlStore = new dojox.data.OpmlStore(args);
992 var d = new doh.Deferred();
993 function onItem(item){
994 t.assertTrue(item === null);
995 d.callback(true);
996 }
997 opmlStore.fetchItemByIdentity({identity: "-1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
998 return d;
999 },
1000 function testIdentityAPI_fetchItemByIdentity_bad3(t){
1001 // summary:
1002 // Simple test of the fetchItemByIdentity function of the store.
1003 // description:
1004 // Simple test of the fetchItemByIdentity function of the store.
1005
1006 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
1007 var opmlStore = new dojox.data.OpmlStore(args);
1008 var d = new doh.Deferred();
1009 function onItem(item){
1010 t.assertTrue(item === null);
1011 d.callback(true);
1012 }
1013 opmlStore.fetchItemByIdentity({identity: "999999", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
1014 return d;
1015 },
1016 function testIdentityAPI_getIdentity(t){
1017 // summary:
1018 // Simple test of the fetchItemByIdentity function of the store.
1019 // description:
1020 // Simple test of the fetchItemByIdentity function of the store.
1021
1022 var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
1023 var opmlStore = new dojox.data.OpmlStore(args);
1024
1025 var d = new doh.Deferred();
1026 function completed(items, request){
1027 var passed = true;
1028 for(var i = 0; i < items.length; i++){
1029 console.log("Identity is: " + opmlStore.getIdentity(items[i]) + " count is : "+ i);
1030 if(!(opmlStore.getIdentity(items[i]) == i)){
1031 passed=false;
1032 break;
1033 }
1034 }
1035 t.assertTrue(passed);
1036 d.callback(true);
1037 }
1038
1039 //Get everything...
1040 opmlStore.fetch({ onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d), queryOptions: {deep: true}});
1041 return d; //Object
1042 },
1043 function testIdentityAPI_functionConformance(t){
1044 // summary:
1045 // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
1046 // description:
1047 // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
1048
1049 var testStore = new dojox.data.OpmlStore(dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"));
1050 var identityApi = new dojo.data.api.Identity();
1051 var passed = true;
1052
1053 for(i in identityApi){
1054 if(i.toString().charAt(0) !== '_')
1055 {
1056 var member = identityApi[i];
1057 //Check that all the 'Read' defined functions exist on the test store.
1058 if(typeof member === "function"){
1059 console.log("Looking at function: [" + i + "]");
1060 var testStoreMember = testStore[i];
1061 if(!(typeof testStoreMember === "function")){
1062 passed = false;
1063 break;
1064 }
1065 }
1066 }
1067 }
1068 t.assertTrue(passed);
1069 }
1070 ]
1071 );
1072