Debian Codegraph @

dojox/data/tests/stores/FileStore.js

raw symbols SCIP
1 dojo.provide("dojox.data.tests.stores.FileStore");
2 dojo.require("dojox.data.FileStore");
3 dojo.require("dojo.data.api.Read");
4 dojo.require("dojo.data.api.Identity");
5
6
7 dojox.data.tests.stores.FileStore.getGeoStore = function(){
8 return new dojox.data.FileStore({url: require.toUrl("dojox/data/tests/stores/filestore_dojoxdatageo.php").toString(), pathAsQueryParam: true});
9 };
10
11
12 doh.register("dojox.data.tests.stores.FileStore",
13 [
14 /***************************************
15 dojo.data.api.Read API
16 ***************************************/
17 {
18 name: "testReadAPI_fetch_all",
19 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
20 runTest: function(t) {
21 // summary:
22 // Simple test of fetching all xml items through an XML element called isbn
23 // description:
24 // Simple test of fetching all xml items through an XML element called isbn
25 var store = dojox.data.tests.stores.FileStore.getGeoStore();
26
27 var d = new doh.Deferred();
28 function onComplete(items, request) {
29 t.assertEqual(49, items.length);
30 d.callback(true);
31 }
32 function onError(error, request) {
33 d.errback(error);
34 }
35 store.fetch({query:{name:"*"}, queryOptions: {deep: true}, onComplete: onComplete, onError: onError});
36 return d; //Object
37 }
38 },
39 {
40 name: "testReadAPI_fetch_one",
41 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
42 runTest: function(t) {
43 // summary:
44 // Simple test of fetching one xml items through an XML element called isbn
45 // description:
46 // Simple test of fetching one xml items through an XML element called isbn
47 var store = dojox.data.tests.stores.FileStore.getGeoStore();
48
49 var d = new doh.Deferred();
50 function onComplete(items, request) {
51 t.assertEqual(1, items.length);
52 d.callback(true);
53 }
54 function onError(error, request) {
55 d.errback(error);
56 }
57 store.fetch({query:{name:"Commonwealth of Australia"}, onComplete: onComplete, onError: onError});
58 return d; //Object
59 }
60 },
61 {
62 name: "testReadAPI_fetch_paging",
63 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
64 runTest: function(t) {
65 // summary:
66 // Simple test of fetching a series of pages
67 // description:
68 // Simple test of fetching a series of pages
69 var store = dojox.data.tests.stores.FileStore.getGeoStore();
70
71 var d = new doh.Deferred();
72
73 function dumpSixthFetch(items, request){
74 t.assertEqual(20, items.length);
75 d.callback(true);
76 }
77
78 function dumpFifthFetch(items, request){
79 t.assertEqual(40, items.length);
80 request.start = 2;
81 request.count = 20;
82 request.onComplete = dumpSixthFetch;
83 store.fetch(request);
84 }
85
86 function dumpFourthFetch(items, request){
87 t.assertEqual(20, items.length);
88 request.start = 9;
89 request.count = 100;
90 request.onComplete = dumpFifthFetch;
91 store.fetch(request);
92 }
93
94 function dumpThirdFetch(items, request){
95 t.assertEqual(5, items.length);
96 request.start = 2;
97 request.count = 20;
98 request.onComplete = dumpFourthFetch;
99 store.fetch(request);
100 }
101
102 function dumpSecondFetch(items, request){
103 t.assertEqual(1, items.length);
104 request.start = 0;
105 request.count = 5;
106 request.onComplete = dumpThirdFetch;
107 store.fetch(request);
108 }
109
110 function dumpFirstFetch(items, request){
111 t.assertEqual(5, items.length);
112 request.start = 3;
113 request.count = 1;
114 request.onComplete = dumpSecondFetch;
115 store.fetch(request);
116 }
117
118 function completed(items, request){
119 t.assertEqual(49, items.length);
120 request.start = 1;
121 request.count = 5;
122 request.onComplete = dumpFirstFetch;
123 store.fetch(request);
124 }
125
126 function error(errData, request){
127 d.errback(errData);
128 }
129
130 store.fetch({queryOptions: {deep:true}, onComplete: completed, onError: error});
131 return d; //Object
132 }
133 },
134 {
135 name: "testReadAPI_fetch_pattern0",
136 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
137 runTest: function(t) {
138 // summary:
139 // Simple test of fetching a few files based on wildcarded name
140 // description:
141 // Simple test of fetching a few files based on wildcarded name
142 var store = dojox.data.tests.stores.FileStore.getGeoStore();
143 var d = new doh.Deferred();
144 function onComplete(items, request) {
145 t.assertEqual(3, items.length);
146 d.callback(true);
147 }
148 function onError(error, request) {
149 d.errback(error);
150 }
151 store.fetch({query:{name:"C*"}, onComplete: onComplete, onError: onError});
152 return d; //Object
153 }
154 },
155 {
156 name: "testReadAPI_fetch_pattern1",
157 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
158 runTest: function(t) {
159 // summary:
160 // Simple test of fetching a one files based on wildcarded name
161 // description:
162 // Simple test of fetching a one file based on wildcarded name
163 var store = dojox.data.tests.stores.FileStore.getGeoStore();
164 var d = new doh.Deferred();
165 function onComplete(items, request) {
166 t.assertEqual(1, items.length);
167 d.callback(true);
168 }
169 function onError(error, request) {
170 d.errback(error);
171 }
172 store.fetch({query:{name:"?ussia"}, onComplete: onComplete, onError: onError});
173 return d; //Object
174 }
175 },
176 {
177 name: "testReadAPI_fetch_pattern_caseInsensitive",
178 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
179 runTest: function(t) {
180 // summary:
181 // Simple test of fetching one file item case insensitively
182 // description:
183 // Simple test of fetching one file item case insensitively
184 var store = dojox.data.tests.stores.FileStore.getGeoStore();
185 var d = new doh.Deferred();
186 function onComplete(items, request) {
187 t.assertEqual(1, items.length);
188 d.callback(true);
189 }
190 function onError(error, request) {
191 d.errback(error);
192 }
193 store.fetch({query:{name:"germany"}, queryOptions: {ignoreCase: true}, onComplete: onComplete, onError: onError});
194 return d; //Object
195 }
196 },
197 {
198 name: "testReadAPI_fetch_pattern_caseSensitive",
199 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
200 runTest: function(t) {
201 // summary:
202 // Simple test of fetching one file item case sensitively
203 // description:
204 // Simple test of fetching one file item case sensitively
205 var store = dojox.data.tests.stores.FileStore.getGeoStore();
206 var d = new doh.Deferred();
207 function onComplete(items, request) {
208 t.assertEqual(1, items.length);
209 d.callback(true);
210 }
211 function onError(error, request) {
212 d.errback(error);
213 }
214 store.fetch({query:{name:"Germany"}, queryOptions: {ignoreCase: false}, onComplete: onComplete, onError: onError});
215 return d; //Object
216 }
217 },
218 {
219 name: "testReadAPI_getLabel",
220 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
221 runTest: function(t) {
222 // summary:
223 // Simple test of the getLabel function against a store
224 // description:
225 // Simple test of the getLabel function against a store
226
227 var store = dojox.data.tests.stores.FileStore.getGeoStore();
228
229 var d = new doh.Deferred();
230 function onComplete(items, request){
231 t.assertEqual(items.length, 1);
232 var label = store.getLabel(items[0]);
233 t.assertTrue(label !== null);
234 t.assertEqual("China", label);
235 d.callback(true);
236 }
237 function onError(error, request) {
238 d.errback(error);
239 }
240 store.fetch({query:{name:"China"}, onComplete: onComplete, onError: onError});
241 return d;
242 }
243 },
244 {
245 name: "testReadAPI_getLabelAttributes",
246 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
247 runTest: function(t) {
248 // summary:
249 // Simple test of the getLabelAttributes function against a store set that has a label defined.
250 // description:
251 // Simple test of the getLabelAttributes function against a store set that has a label defined.
252
253 var store = dojox.data.tests.stores.FileStore.getGeoStore();
254
255 var d = new doh.Deferred();
256 function onComplete(items, request){
257 t.assertEqual(items.length, 1);
258 var labelList = store.getLabelAttributes(items[0]);
259 t.assertTrue(labelList !== null);
260 t.assertEqual("name", labelList[0]);
261 d.callback(true);
262 }
263 function onError(error, request) {
264 d.errback(error);
265 }
266 store.fetch({query:{name:"China"}, onComplete: onComplete, onError: onError});
267 return d;
268 }
269 },
270 {
271 name: "testReadAPI_getValue",
272 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
273 runTest: function(t) {
274 // summary:
275 // Simple test of the getValue API
276 // description:
277 // Simple test of the getValue API
278 var store = dojox.data.tests.stores.FileStore.getGeoStore();
279
280 var d = new doh.Deferred();
281 function onComplete(items, request) {
282 t.assertEqual(1, items.length);
283 var item = items[0];
284 t.assertTrue(store.hasAttribute(item,"name"));
285 t.assertEqual(store.getValue(item,"name"), "Guadalajara");
286 d.callback(true);
287 }
288 function onError(error, request) {
289 d.errback(error);
290 }
291 store.fetch({query:{name:"Guadalajara"}, queryOptions: {deep: true}, onComplete: onComplete, onError: onError});
292 return d; //Object
293 }
294 },
295 {
296 name: "testReadAPI_getValues",
297 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
298 runTest: function(t) {
299 // summary:
300 // Simple test of the getValues API
301 // description:
302 // Simple test of the getValues API
303 var store = dojox.data.tests.stores.FileStore.getGeoStore();
304
305 var d = new doh.Deferred();
306 function onComplete(items, request) {
307 t.assertEqual(1, items.length);
308 var item = items[0];
309 t.assertTrue(store.hasAttribute(item,"name"));
310 var values = store.getValues(item,"name");
311 t.assertEqual(1,values.length);
312 t.assertEqual("Guadalajara", values[0]);
313 d.callback(true);
314 }
315 function onError(error, request) {
316 d.errback(error);
317 }
318 store.fetch({query:{name:"Guadalajara"}, queryOptions: {deep: true}, onComplete: onComplete, onError: onError});
319 return d; //Object
320 }
321 },
322 {
323 name: "testReadAPI_isItem",
324 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
325 runTest: function(t) {
326 // summary:
327 // Simple test of the isItem API
328 // description:
329 // Simple test of the isItem API
330 var store = dojox.data.tests.stores.FileStore.getGeoStore();
331
332 var d = new doh.Deferred();
333 function onComplete(items, request) {
334 t.assertEqual(1, items.length);
335 var item = items[0];
336 t.assertTrue(store.isItem(item));
337 t.assertTrue(!store.isItem({}));
338 t.assertTrue(!store.isItem("Foo"));
339 t.assertTrue(!store.isItem(1));
340 d.callback(true);
341 }
342 function onError(error, request) {
343 d.errback(error);
344 }
345 store.fetch({query:{name:"Guadalajara"}, queryOptions: {deep: true}, onComplete: onComplete, onError: onError});
346 return d; //Object
347 }
348 },
349 {
350 name: "testReadAPI_isItem_multistore",
351 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
352 runTest: function(t) {
353 // summary:
354 // Simple test of the isItem API across multiple store instances.
355 // description:
356 // Simple test of the isItem API across multiple store instances.
357 var store1 = dojox.data.tests.stores.FileStore.getGeoStore();
358 var store2 = dojox.data.tests.stores.FileStore.getGeoStore();
359
360 var d = new doh.Deferred();
361
362 function onError(error, request) {
363 d.errback(error);
364 }
365
366 function onComplete1(items, request) {
367 t.assertEqual(1, items.length);
368 var item1 = items[0];
369 t.assertTrue(store1.isItem(item1));
370
371 function onComplete2(items, request) {
372 t.assertEqual(1, items.length);
373 var item2 = items[0];
374 t.assertTrue(store2.isItem(item2));
375 t.assertTrue(!store1.isItem(item2));
376 t.assertTrue(!store2.isItem(item1));
377 d.callback(true);
378 }
379 store2.fetch({query:{name:"Guadalajara"}, queryOptions: {deep: true}, onComplete: onComplete2, onError: onError});
380 }
381 store1.fetch({query:{name:"China"}, onComplete: onComplete1, onError: onError});
382 return d; //Object
383 }
384 },
385 {
386 name: "testReadAPI_hasAttribute",
387 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
388 runTest: function(t) {
389 // summary:
390 // Simple test of the hasAttribute API
391 // description:
392 // Simple test of the hasAttribute API
393 var store = dojox.data.tests.stores.FileStore.getGeoStore();
394
395 var d = new doh.Deferred();
396 function onComplete(items, request) {
397 t.assertEqual(1, items.length);
398 var item = items[0];
399 t.assertTrue(store.hasAttribute(item,"name"));
400 t.assertTrue(!store.hasAttribute(item,"bob"));
401 d.callback(true);
402 }
403 function onError(error, request) {
404 d.errback(error);
405 }
406 store.fetch({query:{name:"China"}, onComplete: onComplete, onError: onError});
407 return d; //Object
408 }
409 },
410 {
411 name: "testReadAPI_containsValue",
412 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
413 runTest: function(t) {
414 // summary:
415 // Simple test of the containsValue API
416 // description:
417 // Simple test of the containsValue API
418 var store = dojox.data.tests.stores.FileStore.getGeoStore();
419
420 var d = new doh.Deferred();
421 function onComplete(items, request) {
422 t.assertEqual(1, items.length);
423 var item = items[0];
424 t.assertTrue(store.containsValue(item,"name", "China"));
425 t.assertTrue(!store.containsValue(item,"name", "bob"));
426 d.callback(true);
427 }
428 function onError(error, request) {
429 d.errback(error);
430 }
431 store.fetch({query:{name:"China"}, onComplete: onComplete, onError: onError});
432 return d; //Object
433 }
434 },
435 {
436 name: "testReadAPI_sortDescending",
437 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
438 runTest: function(t) {
439 // summary:
440 // Simple test of the sorting API in descending order.
441 // description:
442 // Simple test of the sorting API in descending order.
443 var store = dojox.data.tests.stores.FileStore.getGeoStore();
444
445 //Comparison is done as a string type (toString comparison), so the order won't be numeric
446 //So have to compare in 'alphabetic' order.
447 var order = ["root.json","United States of America","Sudan","Spain","Russia","Mongolia","Mexico","Kenya","Italy","India","Germany","France","Egypt","Commonwealth of Australia","China","Canada","Brazil","Argentina"];
448
449 var d = new doh.Deferred();
450 function onComplete(items, request) {
451 t.assertEqual(18, items.length);
452 for(var i = 0; i < items.length; i++){
453 t.assertEqual(order[i], store.getValue(items[i],"name").toString());
454 }
455 d.callback(true);
456 }
457 function onError(error, request) {
458 d.errback(error);
459 }
460
461 var sortAttributes = [{attribute: "name", descending: true}];
462 store.fetch({query:{name:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
463 return d; //Object
464 }
465 },
466 {
467 name: "testReadAPI_sortAscending",
468 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
469 runTest: function(t) {
470 // summary:
471 // Simple test of the sorting API in ascending order.
472 // description:
473 // Simple test of the sorting API in ascending order.
474 var store = dojox.data.tests.stores.FileStore.getGeoStore();
475
476 //Comparison is done as a string type (toString comparison), so the order won't be numeric
477 //So have to compare in 'alphabetic' order.
478
479 var order = ["root.json","United States of America","Sudan","Spain","Russia","Mongolia","Mexico","Kenya","Italy","India","Germany","France","Egypt","Commonwealth of Australia","China","Canada","Brazil","Argentina"].reverse();
480
481 var d = new doh.Deferred();
482 function onComplete(items, request) {
483 t.assertEqual(18, items.length);
484 for(var i = 0; i < items.length; i++){
485 t.assertEqual(order[i], store.getValue(items[i],"name").toString());
486 }
487 d.callback(true);
488 }
489 function onError(error, request) {
490 d.errback(error);
491 }
492
493 var sortAttributes = [{attribute: "name"}];
494 store.fetch({query:{name:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
495 return d; //Object
496 }
497 },
498 {
499 name: "testReadAPI_isItemLoaded",
500 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
501 runTest: function(t) {
502 // summary:
503 // Simple test of the isItemLoaded API
504 // description:
505 // Simple test of the isItemLoaded API
506 var store = dojox.data.tests.stores.FileStore.getGeoStore();
507
508 var d = new doh.Deferred();
509 function onComplete(items, request) {
510 t.assertEqual(1, items.length);
511 var item = items[0];
512 t.assertTrue(store.isItemLoaded(item));
513 d.callback(true);
514 }
515 function onError(error, request) {
516 d.errback(error);
517 }
518 store.fetch({query:{name:"China"}, onComplete: onComplete, onError: onError});
519 return d; //Object
520 }
521 },
522 function testReadAPI_getFeatures(t){
523 // summary:
524 // Simple test of the getFeatures function of the store
525 // description:
526 // Simple test of the getFeatures function of the store
527
528 var store = dojox.data.tests.stores.FileStore.getGeoStore();
529 var features = store.getFeatures();
530 var count = 0;
531 var i;
532 for(i in features){
533 t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Identity"));
534 count++;
535 }
536 t.assertEqual(2, count);
537 },
538 {
539 name: "testReadAPI_getAttributes",
540 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
541 runTest: function(t) {
542 // summary:
543 // Simple test of the getAttributes API
544 // description:
545 // Simple test of the getAttributes API
546 var store = dojox.data.tests.stores.FileStore.getGeoStore();
547
548 var d = new doh.Deferred();
549 function onComplete(items, request) {
550 t.assertEqual(1, items.length);
551 var item = items[0];
552 var attributes = store.getAttributes(item);
553 t.assertEqual(7,attributes.length);
554 for(var i=0; i<attributes.length; i++){
555 t.assertTrue((attributes[i] === "children" || attributes[i] === "directory" || attributes[i] === "name" || attributes[i] === "path" || attributes[i] === "modified" || attributes[i] === "size" || attributes[i] === "parentDir"));
556 }
557 d.callback(true);
558 }
559 function onError(error, request) {
560 d.errback(error);
561 }
562 store.fetch({query:{name:"China"}, onComplete: onComplete, onError: onError});
563 return d; //Object
564 }
565 },
566 function testReadAPI_functionConformance(t){
567 // summary:
568 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
569 // description:
570 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
571
572 var testStore = dojox.data.tests.stores.FileStore.getGeoStore();
573 var readApi = new dojo.data.api.Read();
574 var passed = true;
575
576 var i;
577 for(i in readApi){
578 var member = readApi[i];
579 //Check that all the 'Read' defined functions exist on the test store.
580 if(typeof member === "function"){
581 var testStoreMember = testStore[i];
582 if(!(typeof testStoreMember === "function")){
583 console.log("Problem with function: [" + i + "]");
584 passed = false;
585 break;
586 }
587 }
588 }
589 t.assertTrue(passed);
590 },
591
592 /***************************************
593 dojo.data.api.Identity API
594 ***************************************/
595 {
596 name: "testIdentityAPI_getIdentity",
597 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
598 runTest: function(t) {
599 // summary:
600 // Simple test of the getAttributes API
601 // description:
602 // Simple test of the getAttributes API
603 var store = dojox.data.tests.stores.FileStore.getGeoStore();
604
605 var d = new doh.Deferred();
606 function onComplete(items, request) {
607 t.assertEqual(1, items.length);
608 var item = items[0];
609 t.assertEqual("./Argentina",store.getIdentity(item));
610 d.callback(true);
611 }
612 function onError(error, request) {
613 d.errback(error);
614 }
615 store.fetch({query:{name:"Argentina"}, onComplete: onComplete, onError: onError});
616 return d; //Object
617 }
618 },
619 {
620 name: "testIdentityAPI_getIdentityAttributes",
621 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
622 runTest: function(t) {
623 // summary:
624 // Simple test of the getAttributes API
625 // description:
626 // Simple test of the getAttributes API
627 var store = dojox.data.tests.stores.FileStore.getGeoStore();
628
629 var d = new doh.Deferred();
630 function onComplete(items, request) {
631 t.assertEqual(1, items.length);
632 var item = items[0];
633 //Should have none, as it's not a public attribute.
634 var attributes = store.getIdentityAttributes(item);
635 t.assertEqual(1, attributes.length);
636 t.assertEqual("path", attributes[0]);
637 d.callback(true);
638 }
639 function onError(error, request) {
640 d.errback(error);
641 }
642 store.fetch({query:{name:"Argentina"}, onComplete: onComplete, onError: onError});
643 return d; //Object
644 }
645 },
646 {
647 name: "testIdentityAPI_fetchItemByIdentity",
648 timeout: 10000, //10 seconds. Lots of server calls, expect network delay
649 runTest: function(t) {
650 // summary:
651 // Simple test of the fetchItemByIdentity API
652 // description:
653 // Simple test of the fetchItemByIdentity API
654 var store = dojox.data.tests.stores.FileStore.getGeoStore();
655
656 var d = new doh.Deferred();
657 function onItem(item, request) {
658 t.assertTrue(item !== null);
659 t.assertTrue(store.isItem(item));
660 t.assertEqual("Argentina", store.getValue(item, "name"));
661 d.callback(true);
662 }
663 function onError(error, request) {
664 d.errback(error);
665 }
666 store.fetchItemByIdentity({identity: "./Argentina", onItem: onItem, onError: onError});
667 return d; //Object
668 }
669 },
670 function testIdentityAPI_functionConformance(t){
671 // summary:
672 // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
673 // description:
674 // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
675
676 var testStore = dojox.data.tests.stores.FileStore.getGeoStore();
677 var identityApi = new dojo.data.api.Identity();
678 var passed = true;
679
680 var i;
681 for(i in identityApi){
682 var member = identityApi[i];
683 //Check that all the 'Read' defined functions exist on the test store.
684 if(typeof member === "function"){
685 var testStoreMember = testStore[i];
686 if(!(typeof testStoreMember === "function")){
687 console.log("Problem with function: [" + i + "]");
688 passed = false;
689 break;
690 }
691 }
692 }
693 t.assertTrue(passed);
694 }
695 ]
696 );
697