1 if(!dojo._hasResource["dojox.data.tests.stores.KeyValueStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.data.tests.stores.KeyValueStore"] = true;
3 dojo.provide("dojox.data.tests.stores.KeyValueStore");
4 dojo.require("dojox.data.KeyValueStore");
5 dojo.require("dojo.data.api.Read");
6 dojo.require("dojo.data.api.Identity");
8 dojox.data.tests.stores.KeyValueStore.getDatasource = function(type){
10 // A simple helper function for getting the sample data used in each of the tests.
12 // A simple helper function for getting the sample data used in each of the tests.
15 var filepath = "stores/properties.js";
17 dataSource.url = dojo.moduleUrl("dojox.data.tests", filepath).toString();
19 // When running tests in Rhino, xhrGet is not available,
20 // so we have the file data in the code below.
22 // Properties of December 1, 2007
23 keyData += '{ "year": "2007" },';
24 keyData += '{ "nmonth": "12" },';
25 keyData += '{ "month": "December" },';
26 keyData += '{ "nday": "1" },';
27 keyData += '{ "day": "Saturday" },';
28 keyData += '{ "dayOfYear": "335" },';
29 keyData += '{ "weekOfYear": "48" }';
31 dataSource.data = keyData;
33 return dataSource; //Object
36 dojox.data.tests.stores.KeyValueStore.verifyItems = function(keyStore, items, attribute, compareArray){
38 // A helper function for validating that the items array is ordered
39 // the same as the compareArray
40 if(items.length != compareArray.length){ return false; }
41 for(var i = 0; i < items.length; i++){
42 if(!(keyStore.getValue(items[i], attribute) === compareArray[i])){
43 return false; //Boolean
46 return true; //Boolean
49 dojox.data.tests.stores.KeyValueStore.error = function(t, d, errData){
51 // The error callback function to be used for all of the tests.
53 console.log(errData[i]);
58 doh.register("dojox.data.tests.stores.KeyValueStore",
60 function testReadAPI_fetch_all(t){
62 // Simple test of a basic fetch on KeyValueStore.
64 // Simple test of a basic fetch on KeyValueStore.
66 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/properties.js");
67 var keyStore = new dojox.data.KeyValueStore(args);
69 var d = new doh.Deferred();
70 function completedAll(items){
71 t.assertTrue((items.length === 7));
76 keyStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
79 function testReadAPI_fetch_all_withEmptyStringField(t){
81 // Simple test of a basic fetch on KeyValueStore.
83 // Simple test of a basic fetch on KeyValueStore.
85 var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
86 var keyStore = new dojox.data.KeyValueStore(args);
88 var d = new doh.Deferred();
89 function completedAll(items){
90 t.assertTrue((items.length === 7));
95 keyStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
98 function testReadAPI_fetch_one(t){
100 // Simple test of a basic fetch on KeyValueStore of a single item.
102 // Simple test of a basic fetch on KeyValueStore of a single item.
104 var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
105 var keyStore = new dojox.data.KeyValueStore(args);
107 var d = new doh.Deferred();
108 function onComplete(items, request){
109 t.is(1, items.length);
112 keyStore.fetch({ query: {key: "year"},
113 onComplete: onComplete,
114 onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)
118 function testReadAPI_fetch_Multiple(t){
120 // Simple test of a basic fetch on KeyValueStore of a single item.
122 // Simple test of a basic fetch on KeyValueStore of a single item.
124 var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
125 var keyStore = new dojox.data.KeyValueStore(args);
127 var d = new doh.Deferred();
129 var done = [false, false];
131 function onCompleteOne(items, request){
133 t.is(1, items.length);
134 if(done[0] && done[1]){
139 function onCompleteTwo(items, request){
141 t.is(1, items.length);
142 if(done[0] && done[1]){
149 keyStore.fetch({ query: {key: "year"},
150 onComplete: onCompleteOne,
151 onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)
153 keyStore.fetch({ query: {key: "month"},
154 onComplete: onCompleteTwo,
155 onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)
167 function testReadAPI_fetch_MultipleMixed(t){
169 // Simple test of a basic fetch on KeyValueStore of a single item.
171 // Simple test of a basic fetch on KeyValueStore of a single item.
173 var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
174 var keyStore = new dojox.data.KeyValueStore(args);
176 var d = new doh.Deferred();
178 var done = [false, false];
179 function onComplete(items, request){
181 t.is(1, items.length);
182 if(done[0] && done[1]){
187 function onItem(item){
189 t.assertTrue(item !== null);
190 t.is('year', keyStore.getValue(item,"key"));
191 t.is(2007, keyStore.getValue(item,"value"));
192 t.is(2007, keyStore.getValue(item,"year"));
193 if(done[0] && done[1]){
198 keyStore.fetch({ query: {key: "day"},
199 onComplete: onComplete,
200 onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)
203 keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
206 function testReadAPI_fetch_all_streaming(t){
208 // Simple test of a basic fetch on KeyValueStore.
210 // Simple test of a basic fetch on KeyValueStore.
212 var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
213 var keyStore = new dojox.data.KeyValueStore(args);
215 var d = new doh.Deferred();
218 function onBegin(size, requestObj){
219 t.assertTrue(size === 7);
221 function onItem(item, requestObj){
222 t.assertTrue(keyStore.isItem(item));
225 function onComplete(items, request){
232 keyStore.fetch({ onBegin: onBegin,
234 onComplete: onComplete,
235 onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)
239 function testReadAPI_fetch_paging(t){
241 // Test of multiple fetches on a single result. Paging, if you will.
243 // Test of multiple fetches on a single result. Paging, if you will.
245 var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
246 var keyStore = new dojox.data.KeyValueStore(args);
248 var d = new doh.Deferred();
249 function dumpFirstFetch(items, request){
250 t.is(5, items.length);
253 request.onComplete = dumpSecondFetch;
254 keyStore.fetch(request);
257 function dumpSecondFetch(items, request){
258 t.is(1, items.length);
261 request.onComplete = dumpThirdFetch;
262 keyStore.fetch(request);
265 function dumpThirdFetch(items, request){
266 t.is(5, items.length);
269 request.onComplete = dumpFourthFetch;
270 keyStore.fetch(request);
273 function dumpFourthFetch(items, request){
274 t.is(5, items.length);
277 request.onComplete = dumpFifthFetch;
278 keyStore.fetch(request);
281 function dumpFifthFetch(items, request){
282 t.is(0, items.length);
285 request.onComplete = dumpSixthFetch;
286 keyStore.fetch(request);
289 function dumpSixthFetch(items, request){
290 t.is(5, items.length);
294 function completed(items, request){
295 t.is(7, items.length);
298 request.onComplete = dumpFirstFetch;
299 keyStore.fetch(request);
302 keyStore.fetch({onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
306 function testReadAPI_getLabel(t){
308 // Simple test of the getLabel function against a store set that has a label defined.
310 // Simple test of the getLabel function against a store set that has a label defined.
312 var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
313 var keyStore = new dojox.data.KeyValueStore(args);
315 var d = new doh.Deferred();
316 function onComplete(items, request){
317 t.assertEqual(items.length, 1);
318 var label = keyStore.getLabel(items[0]);
319 t.assertTrue(label !== null);
320 t.assertEqual("year", label);
323 keyStore.fetch({ query: {key: "year"},
324 onComplete: onComplete,
325 onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)
329 function testReadAPI_getLabelAttributes(t){
331 // Simple test of the getLabelAttributes function against a store set that has a label defined.
333 // Simple test of the getLabelAttributes function against a store set that has a label defined.
335 var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
336 var keyStore = new dojox.data.KeyValueStore(args);
338 var d = new doh.Deferred();
339 function onComplete(items, request){
340 t.assertEqual(items.length, 1);
341 var labelList = keyStore.getLabelAttributes(items[0]);
342 t.assertTrue(dojo.isArray(labelList));
343 t.assertEqual("key", labelList[0]);
346 keyStore.fetch({ query: {key: "year"},
347 onComplete: onComplete,
348 onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)
352 function testReadAPI_getValue(t){
354 // Simple test of the getValue function of the store.
356 // Simple test of the getValue function of the store.
358 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
359 var keyStore = new dojox.data.KeyValueStore(args);
361 var d = new doh.Deferred();
362 function onItem(item){
363 t.assertTrue(item !== null);
364 t.is("nday", keyStore.getValue(item,"key"));
365 t.is(1, keyStore.getValue(item,"value"));
366 t.is(1, keyStore.getValue(item,"nday"));
369 keyStore.fetchItemByIdentity({identity: "nday", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
372 function testReadAPI_getValue_2(t){
374 // Simple test of the getValue function of the store.
376 // Simple test of the getValue function of the store.
378 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
379 var keyStore = new dojox.data.KeyValueStore(args);
381 var d = new doh.Deferred();
382 function onItem(item){
383 t.assertTrue(item !== null);
384 t.is("day", keyStore.getValue(item,"key"));
385 t.is("Saturday", keyStore.getValue(item,"value"));
386 t.is("Saturday", keyStore.getValue(item,"day"));
389 keyStore.fetchItemByIdentity({identity: "day", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
392 function testReadAPI_getValue_3(t){
394 // Simple test of the getValue function of the store.
396 // Simple test of the getValue function of the store.
398 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
399 var keyStore = new dojox.data.KeyValueStore(args);
401 var d = new doh.Deferred();
402 function onItem(item){
403 t.assertTrue(item !== null);
404 t.is("dayOfYear", keyStore.getValue(item,"key"));
405 t.is(335, keyStore.getValue(item,"value"));
406 t.is(335, keyStore.getValue(item,"dayOfYear"));
409 keyStore.fetchItemByIdentity({identity: "dayOfYear", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
412 function testReadAPI_getValue_4(t){
414 // Simple test of the getValue function of the store.
416 // Simple test of the getValue function of the store.
418 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
419 var keyStore = new dojox.data.KeyValueStore(args);
421 var d = new doh.Deferred();
422 function onItem(item){
423 t.assertTrue(item !== null);
424 t.is("weekOfYear", keyStore.getValue(item,"key"));
425 t.is(48, keyStore.getValue(item,"value"));
426 t.is(48, keyStore.getValue(item,"weekOfYear"));
429 keyStore.fetchItemByIdentity({identity: "weekOfYear", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
432 function testReadAPI_getValues(t){
434 // Simple test of the getValues function of the store.
436 // Simple test of the getValues function of the store.
438 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
439 var keyStore = new dojox.data.KeyValueStore(args);
441 var d = new doh.Deferred();
442 function onItem(item){
443 t.assertTrue(item !== null);
444 var names = keyStore.getValues(item,"year");
445 t.assertTrue(dojo.isArray(names));
446 t.is(1, names.length);
447 t.is(2007, names[0]);
450 keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
453 function testIdentityAPI_fetchItemByIdentity(t){
455 // Simple test of the fetchItemByIdentity function of the store.
457 // Simple test of the fetchItemByIdentity function of the store.
459 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
460 var keyStore = new dojox.data.KeyValueStore(args);
462 var d = new doh.Deferred();
463 function onItem(item){
464 t.assertTrue(item !== null);
467 keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
471 function testIdentityAPI_fetchItemByIdentity_bad1(t){
473 // Simple test of the fetchItemByIdentity function of the store.
475 // Simple test of the fetchItemByIdentity function of the store.
477 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
478 var keyStore = new dojox.data.KeyValueStore(args);
480 var d = new doh.Deferred();
481 function onItem(item){
482 t.assertTrue(item === null);
485 keyStore.fetchItemByIdentity({identity: "y3ar", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
488 function testIdentityAPI_fetchItemByIdentity_bad2(t){
490 // Simple test of the fetchItemByIdentity function of the store.
492 // Simple test of the fetchItemByIdentity function of the store.
494 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
495 var keyStore = new dojox.data.KeyValueStore(args);
496 var d = new doh.Deferred();
497 function onItem(item){
498 t.assertTrue(item === null);
501 keyStore.fetchItemByIdentity({identity: "-1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
504 function testIdentityAPI_fetchItemByIdentity_bad3(t){
506 // Simple test of the fetchItemByIdentity function of the store.
508 // Simple test of the fetchItemByIdentity function of the store.
510 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
511 var keyStore = new dojox.data.KeyValueStore(args);
512 var d = new doh.Deferred();
513 function onItem(item){
514 t.assertTrue(item === null);
517 keyStore.fetchItemByIdentity({identity: "999999", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
520 function testIdentityAPI_getIdentity(t){
522 // Simple test of the fetchItemByIdentity function of the store.
524 // Simple test of the fetchItemByIdentity function of the store.
526 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
527 var keyStore = new dojox.data.KeyValueStore(args);
529 var d = new doh.Deferred();
530 function completed(items, request){
531 t.is(7, items.length);
532 t.is(keyStore.getIdentity(items[0]), 'year');
533 t.is(keyStore.getIdentity(items[1]), 'nmonth');
534 t.is(keyStore.getIdentity(items[2]), 'month');
535 t.is(keyStore.getIdentity(items[3]), 'nday');
536 t.is(keyStore.getIdentity(items[4]), 'day');
537 t.is(keyStore.getIdentity(items[5]), 'dayOfYear');
538 t.is(keyStore.getIdentity(items[6]), 'weekOfYear');
543 keyStore.fetch({ onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
546 function testIdentityAPI_getIdentityAttributes(t){
548 // Simple test of the getIdentityAttributes
550 // Simple test of the fetchItemByIdentity function of the store.
552 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
553 var keyStore = new dojox.data.KeyValueStore(args);
555 var d = new doh.Deferred();
556 function onItem(item){
557 t.assertTrue(keyStore.isItem(item));
558 t.assertEqual("key", keyStore.getIdentityAttributes(item));
561 keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
564 function testReadAPI_isItem(t){
566 // Simple test of the isItem function of the store
568 // Simple test of the isItem function of the store
570 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
571 var keyStore = new dojox.data.KeyValueStore(args);
573 var d = new doh.Deferred();
574 function onItem(item){
575 t.assertTrue(keyStore.isItem(item));
576 t.assertTrue(!keyStore.isItem({}));
577 t.assertTrue(!keyStore.isItem({ item: "not an item" }));
578 t.assertTrue(!keyStore.isItem("not an item"));
579 t.assertTrue(!keyStore.isItem(["not an item"]));
582 keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
585 function testReadAPI_hasAttribute(t){
587 // Simple test of the hasAttribute function of the store
589 // Simple test of the hasAttribute function of the store
591 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
592 var keyStore = new dojox.data.KeyValueStore(args);
594 var d = new doh.Deferred();
595 function onItem(item){
596 t.assertTrue(item !== null);
597 t.assertTrue(keyStore.hasAttribute(item, "key"));
598 t.assertTrue(keyStore.hasAttribute(item, "value"));
599 t.assertTrue(keyStore.hasAttribute(item, "year"));
600 t.assertTrue(!keyStore.hasAttribute(item, "Year"));
601 t.assertTrue(!keyStore.hasAttribute(item, "Nothing"));
602 t.assertTrue(!keyStore.hasAttribute(item, "Title"));
604 //Test that null attributes throw an exception
607 keyStore.hasAttribute(item, null);
611 t.assertTrue(passed);
614 keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
617 function testReadAPI_containsValue(t){
619 // Simple test of the containsValue function of the store
621 // Simple test of the containsValue function of the store
623 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
624 var keyStore = new dojox.data.KeyValueStore(args);
626 var d = new doh.Deferred();
627 function onItem(item){
628 t.assertTrue(item !== null);
629 t.assertTrue(keyStore.containsValue(item, "year", "2007"));
630 t.assertTrue(keyStore.containsValue(item, "value", "2007"));
631 t.assertTrue(keyStore.containsValue(item, "key", "year"));
632 t.assertTrue(!keyStore.containsValue(item, "Title", "Alien2"));
633 t.assertTrue(!keyStore.containsValue(item, "Year", "1979 "));
634 t.assertTrue(!keyStore.containsValue(item, "Title", null));
636 //Test that null attributes throw an exception
639 keyStore.containsValue(item, null, "foo");
643 t.assertTrue(passed);
646 keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
649 function testReadAPI_getAttributes(t){
651 // Simple test of the getAttributes function of the store
653 // Simple test of the getAttributes function of the store
655 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
656 var keyStore = new dojox.data.KeyValueStore(args);
658 var d = new doh.Deferred();
659 function onItem(item){
660 t.assertTrue(item !== null);
661 t.assertTrue(keyStore.isItem(item));
663 var attributes = keyStore.getAttributes(item);
664 t.is(3, attributes.length);
665 for(var i = 0; i < attributes.length; i++){
666 t.assertTrue((attributes[i] === "year" || attributes[i] === "value" || attributes[i] === "key"));
670 keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
674 function testReadAPI_getAttributes_onlyTwo(t){
676 // Simple test of the getAttributes function of the store
678 // Simple test of the getAttributes function of the store
680 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
681 var keyStore = new dojox.data.KeyValueStore(args);
683 var d = new doh.Deferred();
684 function onItem(item){
685 // Test an item that does not have all of the attributes
686 t.assertTrue(item !== null);
687 t.assertTrue(keyStore.isItem(item));
689 var attributes = keyStore.getAttributes(item);
690 t.assertTrue(attributes.length === 3);
691 t.assertTrue(attributes[0] === "key");
692 t.assertTrue(attributes[1] === "value");
693 t.assertTrue(attributes[2] === "nmonth");
696 keyStore.fetchItemByIdentity({identity: "nmonth", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
700 function testReadAPI_getFeatures(t){
702 // Simple test of the getFeatures function of the store
704 // Simple test of the getFeatures function of the store
706 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
707 var keyStore = new dojox.data.KeyValueStore(args);
709 var features = keyStore.getFeatures();
712 t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Identity"));
715 t.assertTrue(count === 2);
717 function testReadAPI_fetch_patternMatch0(t){
719 // Function to test pattern matching of everything starting with lowercase e
721 // Function to test pattern matching of everything starting with lowercase e
723 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
724 var keyStore = new dojox.data.KeyValueStore(args);
726 var d = new doh.Deferred();
727 function completed(items, request){
728 t.is(2, items.length);
729 var valueArray = [ "nmonth", "month"];
730 t.assertTrue(dojox.data.tests.stores.KeyValueStore.verifyItems(keyStore, items, "key", valueArray));
734 keyStore.fetch({query: {key: "*month"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
737 function testReadAPI_fetch_patternMatch1(t){
739 // Function to test pattern matching of everything with $ in it.
741 // Function to test pattern matching of everything with $ in it.
743 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv");
744 var keyStore = new dojox.data.KeyValueStore(args);
746 var d = new doh.Deferred();
747 function completed(items, request){
748 t.assertTrue(items.length === 2);
749 var valueArray = [ "1", "Saturday"];
750 t.assertTrue(dojox.data.tests.stores.KeyValueStore.verifyItems(keyStore, items, "value", valueArray));
754 keyStore.fetch({query: {key: "*day"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
757 function testReadAPI_fetch_patternMatch2(t){
759 // Function to test exact pattern match
761 // Function to test exact pattern match
763 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv");
764 var keyStore = new dojox.data.KeyValueStore(args);
766 var d = new doh.Deferred();
767 function completed(items, request){
768 t.is(2, items.length);
769 t.assertTrue(keyStore.getValue(items[0], "value") === "12");
770 t.assertTrue(keyStore.getValue(items[0], "key") === "nmonth");
771 t.assertTrue(keyStore.getValue(items[1], "value") === "1");
772 t.assertTrue(keyStore.getValue(items[1], "key") === "nday");
776 keyStore.fetch({query: {value: "1*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
779 function testReadAPI_fetch_patternMatch_caseInsensitive(t){
781 // Function to test exact pattern match with case insensitivity set.
783 // Function to test exact pattern match with case insensitivity set.
785 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv");
786 var keyStore = new dojox.data.KeyValueStore(args);
788 var d = new doh.Deferred();
789 function completed(items, request){
790 t.is(1, items.length);
791 t.assertTrue(keyStore.getValue(items[0], "value") === "December");
795 keyStore.fetch({query: {key: "MONth"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
798 function testReadAPI_fetch_patternMatch_caseSensitive(t){
800 // Function to test exact pattern match with case insensitivity set.
802 // Function to test exact pattern match with case insensitivity set.
804 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv");
805 var keyStore = new dojox.data.KeyValueStore(args);
807 var d = new doh.Deferred();
808 function completed(items, request){
809 t.is(0, items.length);
813 keyStore.fetch({query: {value: "DECEMberO"}, queryOptions: {ignoreCase: false}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
816 function testReadAPI_fetch_sortAlphabetic(t){
818 // Function to test sorting alphabetic ordering.
820 // Function to test sorting alphabetic ordering.
822 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv");
823 var keyStore = new dojox.data.KeyValueStore(args);
825 var d = new doh.Deferred();
826 function completed(items, request){
827 //Output should be in this order...
828 var orderedArray = [ "day", "dayOfYear", "month", "nday", "nmonth", "weekOfYear", "year" ];
829 t.is(7, items.length);
830 t.assertTrue(dojox.data.tests.stores.KeyValueStore.verifyItems(keyStore, items, "key", orderedArray));
834 var sortAttributes = [{attribute: "key"}];
835 keyStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
838 function testReadAPI_fetch_sortAlphabeticDescending(t){
840 // Function to test sorting alphabetic ordering in descending mode.
842 // Function to test sorting alphabetic ordering in descending mode.
844 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv");
845 var keyStore = new dojox.data.KeyValueStore(args);
847 var d = new doh.Deferred();
848 function completed(items, request){
849 //Output should be in this order...
850 var orderedArray = [ "year", "weekOfYear", "nmonth", "nday", "month", "dayOfYear", "day" ];
851 t.is(7, items.length);
852 t.assertTrue(dojox.data.tests.stores.KeyValueStore.verifyItems(keyStore, items, "key", orderedArray));
856 var sortAttributes = [{attribute: "key", descending: true}];
857 keyStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
860 function testReadAPI_fetch_sortMultiple(t){
862 // Function to test sorting on multiple attributes.
864 // Function to test sorting on multiple attributes.
866 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv");
867 var keyStore = new dojox.data.KeyValueStore(args);
869 var d = new doh.Deferred();
870 function completed(items, request){
871 var orderedArray1 = [ "123abc",
879 "jfq4@#!$!@Rf14r14i5u",
882 var orderedArray0 = [ "day", "dayOfYear", "month", "nday", "nmonth", "weekOfYear", "year" ];
883 var orderedArray1 = [ "Saturday", "335", "December", "1", "12", "48", "2007" ];
884 t.is(7, items.length);
885 t.assertTrue(dojox.data.tests.stores.KeyValueStore.verifyItems(keyStore, items, "key", orderedArray0));
886 t.assertTrue(dojox.data.tests.stores.KeyValueStore.verifyItems(keyStore, items, "value", orderedArray1));
890 var sortAttributes = [{ attribute: "key"}, { attribute: "value", descending: true}];
891 keyStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
894 function testReadAPI_fetch_sortMultipleSpecialComparator(t){
896 // Function to test sorting on multiple attributes with a custom comparator.
898 // Function to test sorting on multiple attributes with a custom comparator.
900 var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
901 var keyStore = new dojox.data.KeyValueStore(args);
903 keyStore.comparatorMap = {};
904 keyStore.comparatorMap["key"] = function(a,b){
906 // We want to sort keys alphabetical by the last character in the string
907 function lastChar(name){
908 if(typeof name === "undefined"){ return undefined; }
910 return name.slice(name.length-1); // Grab the last character in the string.
912 var lastCharA = lastChar(a);
913 var lastCharB = lastChar(b);
914 if(lastCharA > lastCharB || typeof lastCharA === "undefined"){
916 }else if(lastCharA < lastCharB || typeof lastCharB === "undefined"){
922 var sortAttributes = [{attribute: "key", descending: true}, { attribute: "value", descending: true}];
924 var d = new doh.Deferred();
925 function completed(items, findResult){
926 var orderedArray = [5,4,0,3,2,1,6];
927 var orderedArray = [ "day", "nday", "weekOfYear", "dayOfYear", "year", "month", "nmonth" ];
928 t.assertTrue(items.length === 7);
930 for(var i = 0; i < items.length; i++){
931 if(!(keyStore.getIdentity(items[i]) === orderedArray[i])){
936 t.assertTrue(passed);
940 keyStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
943 function testReadAPI_functionConformance(t){
945 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
947 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
949 var testStore = new dojox.data.KeyValueStore(dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv"));
950 var readApi = new dojo.data.api.Read();
954 if(i.toString().charAt(0) !== '_')
956 var member = readApi[i];
957 //Check that all the 'Read' defined functions exist on the test store.
958 if(typeof member === "function"){
959 console.log("Looking at function: [" + i + "]");
960 var testStoreMember = testStore[i];
961 if(!(typeof testStoreMember === "function")){
962 console.log("Problem with function: [" + i + "]. Got value: " + testStoreMember);
969 t.assertTrue(passed);
971 function testIdentityAPI_functionConformance(t){
973 // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
975 // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
977 var testStore = new dojox.data.KeyValueStore(dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv"));
978 var identityApi = new dojo.data.api.Identity();
981 for(i in identityApi){
982 if(i.toString().charAt(0) !== '_')
984 var member = identityApi[i];
985 //Check that all the 'Read' defined functions exist on the test store.
986 if(typeof member === "function"){
987 console.log("Looking at function: [" + i + "]");
988 var testStoreMember = testStore[i];
989 if(!(typeof testStoreMember === "function")){
996 t.assertTrue(passed);