]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/data/tests/stores/KeyValueStore.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojox / data / tests / stores / KeyValueStore.js
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");
7
8 dojox.data.tests.stores.KeyValueStore.getDatasource = function(type){
9         //  summary:
10         //              A simple helper function for getting the sample data used in each of the tests.
11         //  description:
12         //              A simple helper function for getting the sample data used in each of the tests.
13
14         var dataSource = {};
15         var filepath = "stores/properties.js";
16         if(dojo.isBrowser){
17                 dataSource.url = dojo.moduleUrl("dojox.data.tests", filepath).toString();            
18         }else{
19                 // When running tests in Rhino, xhrGet is not available,
20                 // so we have the file data in the code below.
21                 var keyData = "/*[";
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" }';
30                 keyData += ']*/';
31                 dataSource.data = keyData;
32         }
33         return dataSource; //Object
34 }
35
36 dojox.data.tests.stores.KeyValueStore.verifyItems = function(keyStore, items, attribute, compareArray){
37         //  summary:
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
44                 }
45         }
46         return true; //Boolean
47 }
48
49 dojox.data.tests.stores.KeyValueStore.error = function(t, d, errData){
50         //  summary:
51         //              The error callback function to be used for all of the tests.
52         for (i in errData) {
53                 console.log(errData[i]);
54         }
55         d.errback(errData);     
56 }
57
58 doh.register("dojox.data.tests.stores.KeyValueStore", 
59         [
60                 function testReadAPI_fetch_all(t){
61                         //      summary: 
62                         //              Simple test of a basic fetch on KeyValueStore.
63                         //      description:
64                         //              Simple test of a basic fetch on KeyValueStore.
65                         
66                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/properties.js");
67                         var keyStore = new dojox.data.KeyValueStore(args);
68                         
69                         var d = new doh.Deferred();
70                         function completedAll(items){
71                                 t.assertTrue((items.length === 7));
72                                 d.callback(true);
73                         }
74
75                         //Get everything...
76                         keyStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
77                         return d; //Object
78                 },
79                 function testReadAPI_fetch_all_withEmptyStringField(t){
80                         //      summary: 
81                         //              Simple test of a basic fetch on KeyValueStore.
82                         //      description:
83                         //              Simple test of a basic fetch on KeyValueStore.
84                         
85                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
86                         var keyStore = new dojox.data.KeyValueStore(args);
87                         
88                         var d = new doh.Deferred();
89                         function completedAll(items){
90                                 t.assertTrue((items.length === 7));
91                                 d.callback(true);
92                         }
93
94                         //Get everything...
95                         keyStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
96                         return d; //Object
97                 },
98                 function testReadAPI_fetch_one(t){
99                         //      summary: 
100                         //              Simple test of a basic fetch on KeyValueStore of a single item.
101                         //      description:
102                         //              Simple test of a basic fetch on KeyValueStore of a single item.
103
104                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
105                         var keyStore = new dojox.data.KeyValueStore(args);
106                         
107                         var d = new doh.Deferred();
108                         function onComplete(items, request){
109                                 t.is(1, items.length);
110                                 d.callback(true);
111                         }
112                         keyStore.fetch({        query: {key: "year"}, 
113                                                                 onComplete: onComplete, 
114                                                                 onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)
115                                                         });
116                         return d; //Object
117                 },
118                 function testReadAPI_fetch_Multiple(t){
119                         //      summary: 
120                         //              Simple test of a basic fetch on KeyValueStore of a single item.
121                         //      description:
122                         //              Simple test of a basic fetch on KeyValueStore of a single item.
123
124                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
125                         var keyStore = new dojox.data.KeyValueStore(args);
126                         
127                         var d = new doh.Deferred();
128
129                         var done = [false, false];
130
131                         function onCompleteOne(items, request){
132                                 done[0] = true;
133                                 t.is(1, items.length);
134                                 if(done[0] && done[1]){
135                                         d.callback(true);
136                                 }
137                         }
138                         
139                         function onCompleteTwo(items, request){
140                                 done[1] = true;
141                                 t.is(1, items.length);
142                                 if(done[0] && done[1]){
143                                         d.callback(true);
144                                 }
145                         }
146                         
147                         try
148                         {
149                                 keyStore.fetch({        query: {key: "year"}, 
150                                                                         onComplete: onCompleteOne, 
151                                                                         onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)
152                                                                 });
153                                 keyStore.fetch({        query: {key: "month"}, 
154                                                                         onComplete: onCompleteTwo, 
155                                                                         onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)
156                                                                 });
157                         }
158                         catch(e)
159                         {
160                                 for (i in e) {
161                                         console.log(e[i]);
162                                 }
163                         }
164
165                         return d; //Object
166                 },
167                 function testReadAPI_fetch_MultipleMixed(t){
168                         //      summary: 
169                         //              Simple test of a basic fetch on KeyValueStore of a single item.
170                         //      description:
171                         //              Simple test of a basic fetch on KeyValueStore of a single item.
172
173                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
174                         var keyStore = new dojox.data.KeyValueStore(args);
175                         
176                         var d = new doh.Deferred();
177
178                         var done = [false, false];
179                         function onComplete(items, request){
180                                 done[0] = true;
181                                 t.is(1, items.length);
182                                 if(done[0] && done[1]){
183                                         d.callback(true);
184                                 }
185                         }
186                         
187                         function onItem(item){
188                                 done[1] = true;
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]){
194                                         d.callback(true);
195                                 }
196                         }
197
198                         keyStore.fetch({        query: {key: "day"}, 
199                                                                 onComplete: onComplete, 
200                                                                 onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)
201                                                         });
202                         
203                         keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
204                         return d; //Object
205                 },
206                 function testReadAPI_fetch_all_streaming(t){
207                         //      summary: 
208                         //              Simple test of a basic fetch on KeyValueStore.
209                         //      description:
210                         //              Simple test of a basic fetch on KeyValueStore.
211
212                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
213                         var keyStore = new dojox.data.KeyValueStore(args);
214
215                         var d = new doh.Deferred();
216                         count = 0;
217
218                         function onBegin(size, requestObj){
219                                 t.assertTrue(size === 7);
220                         }
221                         function onItem(item, requestObj){
222                                 t.assertTrue(keyStore.isItem(item));
223                                 count++;
224                         }
225                         function onComplete(items, request){
226                                 t.is(7, count);
227                                 t.is(null, items);
228                             d.callback(true);
229                         }
230
231                         //Get everything...
232                         keyStore.fetch({        onBegin: onBegin,
233                                                                 onItem: onItem, 
234                                                                 onComplete: onComplete,
235                                                                 onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)
236                                                         });
237                         return d; //Object
238                 },
239                 function testReadAPI_fetch_paging(t){
240                          //     summary: 
241                          //             Test of multiple fetches on a single result.  Paging, if you will.
242                          //     description:
243                          //             Test of multiple fetches on a single result.  Paging, if you will.
244
245                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
246                         var keyStore = new dojox.data.KeyValueStore(args);
247                         
248                         var d = new doh.Deferred();
249                         function dumpFirstFetch(items, request){
250                                 t.is(5, items.length);
251                                 request.start = 3;
252                                 request.count = 1;
253                                 request.onComplete = dumpSecondFetch;
254                                 keyStore.fetch(request);
255                         }
256
257                         function dumpSecondFetch(items, request){
258                                 t.is(1, items.length);
259                                 request.start = 0;
260                                 request.count = 5;
261                                 request.onComplete = dumpThirdFetch;
262                                 keyStore.fetch(request);
263                         }
264
265                         function dumpThirdFetch(items, request){
266                                 t.is(5, items.length);
267                                 request.start = 2;
268                                 request.count = 20;
269                                 request.onComplete = dumpFourthFetch;
270                                 keyStore.fetch(request);
271                         }
272
273                         function dumpFourthFetch(items, request){
274                                 t.is(5, items.length);
275                                 request.start = 9;
276                                 request.count = 100;
277                                 request.onComplete = dumpFifthFetch;
278                                 keyStore.fetch(request);
279                         }
280
281                         function dumpFifthFetch(items, request){
282                                 t.is(0, items.length);
283                                 request.start = 2;
284                                 request.count = 20;
285                                 request.onComplete = dumpSixthFetch;
286                                 keyStore.fetch(request);
287                         }
288
289                         function dumpSixthFetch(items, request){
290                                 t.is(5, items.length);
291                             d.callback(true);
292                         }
293
294                         function completed(items, request){
295                                 t.is(7, items.length);
296                                 request.start = 1;
297                                 request.count = 5;
298                                 request.onComplete = dumpFirstFetch;
299                                 keyStore.fetch(request);
300                         }
301
302                         keyStore.fetch({onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
303                         return d; //Object
304                 },
305                 
306                 function testReadAPI_getLabel(t){
307                         //      summary: 
308                         //              Simple test of the getLabel function against a store set that has a label defined.
309                         //      description:
310                         //              Simple test of the getLabel function against a store set that has a label defined.
311
312                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
313                         var keyStore = new dojox.data.KeyValueStore(args);
314                         
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);
321                                 d.callback(true);
322                         }
323                         keyStore.fetch({        query: {key: "year"}, 
324                                                                 onComplete: onComplete, 
325                                                                 onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)
326                                                         });
327                         return d;
328                 },
329                 function testReadAPI_getLabelAttributes(t){
330                         //      summary: 
331                         //              Simple test of the getLabelAttributes function against a store set that has a label defined.
332                         //      description:
333                         //              Simple test of the getLabelAttributes function against a store set that has a label defined.
334
335                          var args = dojox.data.tests.stores.KeyValueStore.getDatasource();
336                          var keyStore = new dojox.data.KeyValueStore(args);
337                         
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]);
344                                 d.callback(true);
345                         }
346                         keyStore.fetch({        query: {key: "year"}, 
347                                                                 onComplete: onComplete, 
348                                                                 onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)
349                                                         });
350                         return d;
351                 },
352                 function testReadAPI_getValue(t){
353                         //      summary: 
354                         //              Simple test of the getValue function of the store.
355                         //      description:
356                         //              Simple test of the getValue function of the store.
357
358                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
359                         var keyStore = new dojox.data.KeyValueStore(args);
360
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"));
367                                 d.callback(true);       
368                         }
369                         keyStore.fetchItemByIdentity({identity: "nday", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
370                         return d;
371                 },      
372                 function testReadAPI_getValue_2(t){
373                         //      summary: 
374                         //              Simple test of the getValue function of the store.
375                         //      description:
376                         //              Simple test of the getValue function of the store.
377
378                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
379                         var keyStore = new dojox.data.KeyValueStore(args);
380
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"));
387                                 d.callback(true);       
388                         }
389             keyStore.fetchItemByIdentity({identity: "day", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
390                         return d;
391                 },      
392                 function testReadAPI_getValue_3(t){
393                         //      summary: 
394                         //              Simple test of the getValue function of the store.
395                         //      description:
396                         //              Simple test of the getValue function of the store.
397
398                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
399                         var keyStore = new dojox.data.KeyValueStore(args);
400
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"));
407                                 d.callback(true);       
408                         }
409                         keyStore.fetchItemByIdentity({identity: "dayOfYear", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
410                         return d;
411                 },      
412                 function testReadAPI_getValue_4(t){
413                         //      summary: 
414                         //              Simple test of the getValue function of the store.
415                         //      description:
416                         //              Simple test of the getValue function of the store.
417
418                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
419                         var keyStore = new dojox.data.KeyValueStore(args);
420
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"));
427                                 d.callback(true);       
428                         }
429                         keyStore.fetchItemByIdentity({identity: "weekOfYear", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
430                         return d;
431                 },
432                 function testReadAPI_getValues(t){
433                         //      summary: 
434                         //              Simple test of the getValues function of the store.
435                         //      description:
436                         //              Simple test of the getValues function of the store.
437
438                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
439                         var keyStore = new dojox.data.KeyValueStore(args);
440
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]);
448                                 d.callback(true);       
449                         }
450                         keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
451                         return d;
452                 },
453                 function testIdentityAPI_fetchItemByIdentity(t){
454                         //      summary: 
455                         //              Simple test of the fetchItemByIdentity function of the store.
456                         //      description:
457                         //              Simple test of the fetchItemByIdentity function of the store.
458                         
459                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
460                         var keyStore = new dojox.data.KeyValueStore(args);
461                         
462                         var d = new doh.Deferred();
463                         function onItem(item){
464                                 t.assertTrue(item !== null);
465                                 d.callback(true);       
466                         }
467                         keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
468                         return d;
469                 },
470
471                 function testIdentityAPI_fetchItemByIdentity_bad1(t){
472                         //      summary: 
473                         //              Simple test of the fetchItemByIdentity function of the store.
474                         //      description:
475                         //              Simple test of the fetchItemByIdentity function of the store.
476                         
477                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
478                         var keyStore = new dojox.data.KeyValueStore(args);
479                         
480                         var d = new doh.Deferred();
481                         function onItem(item){
482                                 t.assertTrue(item === null);
483                                 d.callback(true);       
484                         }
485                         keyStore.fetchItemByIdentity({identity: "y3ar", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
486                         return d;
487                 },
488                 function testIdentityAPI_fetchItemByIdentity_bad2(t){
489                         //      summary: 
490                         //              Simple test of the fetchItemByIdentity function of the store.
491                         //      description:
492                         //              Simple test of the fetchItemByIdentity function of the store.
493                         
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);
499                                 d.callback(true);       
500                         }
501                         keyStore.fetchItemByIdentity({identity: "-1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
502                         return d;
503                 },
504                 function testIdentityAPI_fetchItemByIdentity_bad3(t){
505                         //      summary: 
506                         //              Simple test of the fetchItemByIdentity function of the store.
507                         //      description:
508                         //              Simple test of the fetchItemByIdentity function of the store.
509                         
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);
515                                 d.callback(true);       
516                         }
517                         keyStore.fetchItemByIdentity({identity: "999999", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
518                         return d;
519                 },
520                 function testIdentityAPI_getIdentity(t){
521                         //      summary: 
522                         //              Simple test of the fetchItemByIdentity function of the store.
523                         //      description:
524                         //              Simple test of the fetchItemByIdentity function of the store.
525                         
526                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
527                         var keyStore = new dojox.data.KeyValueStore(args);
528                         
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');
539                                 d.callback(true);
540                         }
541                         
542                         //Get everything...
543                         keyStore.fetch({ onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
544                         return d; //Object
545                 },
546                 function testIdentityAPI_getIdentityAttributes(t){
547                         //      summary: 
548                         //              Simple test of the getIdentityAttributes
549                         //      description:
550                         //              Simple test of the fetchItemByIdentity function of the store.
551                         
552                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
553                         var keyStore = new dojox.data.KeyValueStore(args);
554
555                         var d = new doh.Deferred();
556                         function onItem(item){
557                                 t.assertTrue(keyStore.isItem(item));
558                                 t.assertEqual("key", keyStore.getIdentityAttributes(item)); 
559                                 d.callback(true);       
560                         }
561                         keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
562                         return d;
563                 },
564                 function testReadAPI_isItem(t){
565                         //      summary: 
566                         //              Simple test of the isItem function of the store
567                         //      description:
568                         //              Simple test of the isItem function of the store
569
570                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
571                         var keyStore = new dojox.data.KeyValueStore(args);
572
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"]));
580                                 d.callback(true);       
581                         }
582                         keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
583                         return d;
584                 },
585                 function testReadAPI_hasAttribute(t){
586                         //      summary: 
587                         //              Simple test of the hasAttribute function of the store
588                         //      description:
589                         //              Simple test of the hasAttribute function of the store
590
591                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
592                         var keyStore = new dojox.data.KeyValueStore(args);
593
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"));
603
604                                 //Test that null attributes throw an exception
605                                 var passed = false;
606                                 try{
607                                         keyStore.hasAttribute(item, null);
608                                 }catch (e){
609                                         passed = true;
610                                 }
611                                 t.assertTrue(passed);
612                                 d.callback(true);       
613                         }
614                         keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
615                         return d;
616                 },
617                 function testReadAPI_containsValue(t){
618                         //      summary:  
619                         //              Simple test of the containsValue function of the store
620                         //      description:
621                         //              Simple test of the containsValue function of the store
622
623                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
624                         var keyStore = new dojox.data.KeyValueStore(args);
625                         
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));
635
636                                 //Test that null attributes throw an exception
637                                 var passed = false;
638                                 try{
639                                         keyStore.containsValue(item, null, "foo");
640                                 }catch (e){
641                                         passed = true;
642                                 }
643                                 t.assertTrue(passed);
644                                 d.callback(true);       
645                         }
646                         keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
647                         return d;
648                 },
649                 function testReadAPI_getAttributes(t){
650                         //      summary: 
651                         //              Simple test of the getAttributes function of the store
652                         //      description:
653                         //              Simple test of the getAttributes function of the store
654
655                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
656                         var keyStore = new dojox.data.KeyValueStore(args);
657
658                         var d = new doh.Deferred();
659                         function onItem(item){
660                                 t.assertTrue(item !== null);
661                                 t.assertTrue(keyStore.isItem(item));
662
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"));
667                                 }
668                                 d.callback(true);       
669                         }
670                         keyStore.fetchItemByIdentity({identity: "year", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
671                         return d;
672                 },
673
674                 function testReadAPI_getAttributes_onlyTwo(t){
675                         //      summary: 
676                         //              Simple test of the getAttributes function of the store
677                         //      description:
678                         //              Simple test of the getAttributes function of the store
679
680                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
681                         var keyStore = new dojox.data.KeyValueStore(args);
682
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));
688
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");
694                                 d.callback(true);       
695                         }
696                         keyStore.fetchItemByIdentity({identity: "nmonth", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
697                         return d;
698                 },
699
700                 function testReadAPI_getFeatures(t){
701                         //      summary: 
702                         //              Simple test of the getFeatures function of the store
703                         //      description:
704                         //              Simple test of the getFeatures function of the store
705
706                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
707                         var keyStore = new dojox.data.KeyValueStore(args);
708
709                         var features = keyStore.getFeatures(); 
710                         var count = 0;
711                         for(i in features){
712                                 t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Identity"));
713                                 count++;
714                         }
715                         t.assertTrue(count === 2);
716                 },
717                 function testReadAPI_fetch_patternMatch0(t){
718                         //      summary: 
719                         //              Function to test pattern matching of everything starting with lowercase e
720                         //      description:
721                         //              Function to test pattern matching of everything starting with lowercase e
722
723                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
724                         var keyStore = new dojox.data.KeyValueStore(args);
725
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));
731                                 d.callback(true);
732                         }
733                         
734                         keyStore.fetch({query: {key: "*month"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
735                         return d; //Object
736                 },
737                 function testReadAPI_fetch_patternMatch1(t){
738                         //      summary: 
739                         //              Function to test pattern matching of everything with $ in it.
740                         //      description:
741                         //              Function to test pattern matching of everything with $ in it.
742                         
743                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv");
744                         var keyStore = new dojox.data.KeyValueStore(args);
745                         
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));
751                                 d.callback(true);
752                         }
753                         
754                         keyStore.fetch({query: {key: "*day"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
755                         return d; //Object
756                 },
757                 function testReadAPI_fetch_patternMatch2(t){
758                         //      summary: 
759                         //              Function to test exact pattern match
760                         //      description:
761                         //              Function to test exact pattern match
762                         
763                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv");
764                         var keyStore = new dojox.data.KeyValueStore(args);
765                         
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");
773                                 d.callback(true);
774                         }
775                         
776                         keyStore.fetch({query: {value: "1*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
777                         return d; //Object
778                 },
779                 function testReadAPI_fetch_patternMatch_caseInsensitive(t){
780                         //      summary: 
781                         //              Function to test exact pattern match with case insensitivity set.
782                         //      description:
783                         //              Function to test exact pattern match with case insensitivity set.
784                         
785                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv");
786                         var keyStore = new dojox.data.KeyValueStore(args);
787                         
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");
792                                 d.callback(true);
793                         }
794                         
795                         keyStore.fetch({query: {key: "MONth"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
796                         return d; //Object
797                 },
798                 function testReadAPI_fetch_patternMatch_caseSensitive(t){
799                         //      summary: 
800                         //              Function to test exact pattern match with case insensitivity set.
801                         //      description:
802                         //              Function to test exact pattern match with case insensitivity set.
803                         
804                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv");
805                         var keyStore = new dojox.data.KeyValueStore(args);
806                         
807                         var d = new doh.Deferred();
808                         function completed(items, request){
809                                 t.is(0, items.length);
810                                 d.callback(true);
811                         }
812                         
813                         keyStore.fetch({query: {value: "DECEMberO"}, queryOptions: {ignoreCase: false}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
814                         return d; //Object
815                 },
816                 function testReadAPI_fetch_sortAlphabetic(t){
817                         //      summary: 
818                         //              Function to test sorting alphabetic ordering.
819                         //      description:
820                         //              Function to test sorting alphabetic ordering.
821                 
822                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv");
823                         var keyStore = new dojox.data.KeyValueStore(args);
824                         
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));
831                                 d.callback(true);
832                         }
833                         
834                         var sortAttributes = [{attribute: "key"}];
835                         keyStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
836                         return d; //Object
837                 },
838                 function testReadAPI_fetch_sortAlphabeticDescending(t){
839                         //      summary: 
840                         //              Function to test sorting alphabetic ordering in descending mode.
841                         //      description:
842                         //              Function to test sorting alphabetic ordering in descending mode.
843                 
844                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv");
845                         var keyStore = new dojox.data.KeyValueStore(args);
846                         
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));
853                                 d.callback(true);
854                         }
855                         
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)});
858                         return d; //Object
859                 },
860                 function testReadAPI_fetch_sortMultiple(t){
861                         //      summary: 
862                         //              Function to test sorting on multiple attributes.
863                         //      description:
864                         //              Function to test sorting on multiple attributes.
865                         
866                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv");
867                         var keyStore = new dojox.data.KeyValueStore(args);
868                 
869                         var d = new doh.Deferred();
870                         function completed(items, request){
871                                 var orderedArray1 = [   "123abc",
872                                                                                 "123abc",
873                                                                                 "123abc",
874                                                                                 "123abcdefg",
875                                                                                 "BaBaMaSaRa***Foo",
876                                                                                 "bar*foo",
877                                                                                 "bit$Bite",
878                                                                                 "foo*bar",
879                                                                                 "jfq4@#!$!@Rf14r14i5u",
880                                                                                 undefined
881                                                                         ];
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));
887                                 d.callback(true);
888                         }
889                         
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)});
892                         return d; //Object
893                 },
894                 function testReadAPI_fetch_sortMultipleSpecialComparator(t){
895                         //      summary: 
896                         //              Function to test sorting on multiple attributes with a custom comparator.
897                         //      description:
898                         //              Function to test sorting on multiple attributes with a custom comparator.
899
900                         var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv");
901                         var keyStore = new dojox.data.KeyValueStore(args);
902                         
903                         keyStore.comparatorMap = {};
904                         keyStore.comparatorMap["key"] = function(a,b){ 
905                                 var ret = 0;
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; }
909                                         
910                                         return name.slice(name.length-1); // Grab the last character in the string.
911                                 }
912                                 var lastCharA = lastChar(a);
913                                 var lastCharB = lastChar(b);
914                                 if(lastCharA > lastCharB || typeof lastCharA === "undefined"){
915                                         ret = 1;
916                                 }else if(lastCharA < lastCharB || typeof lastCharB === "undefined"){
917                                         ret = -1;
918                                 }
919                                 return ret;
920                         };
921                 
922                         var sortAttributes = [{attribute: "key", descending: true}, { attribute: "value", descending: true}];
923                 
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);
929                                 var passed = true;
930                                 for(var i = 0; i < items.length; i++){
931                                         if(!(keyStore.getIdentity(items[i]) === orderedArray[i])){
932                                                 passed=false;
933                                                 break;
934                                         }
935                                 }
936                                 t.assertTrue(passed);
937                                 d.callback(true);
938                         }
939                         
940                         keyStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)});
941                         return d; //Object
942                 },
943                 function testReadAPI_functionConformance(t){
944                         //      summary: 
945                         //              Simple test read API conformance.  Checks to see all declared functions are actual functions on the instances.
946                         //      description:
947                         //              Simple test read API conformance.  Checks to see all declared functions are actual functions on the instances.
948
949                         var testStore = new dojox.data.KeyValueStore(dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv"));
950                         var readApi = new dojo.data.api.Read();
951                         var passed = true;
952
953                         for(i in readApi){
954                                 if(i.toString().charAt(0) !== '_')
955                                 {
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);
963                                                         passed = false;
964                                                         break;
965                                                 }
966                                         }
967                                 }
968                         }
969                         t.assertTrue(passed);
970                 },
971                 function testIdentityAPI_functionConformance(t){
972                         //      summary: 
973                         //              Simple test identity API conformance.  Checks to see all declared functions are actual functions on the instances.
974                         //      description:
975                         //              Simple test identity API conformance.  Checks to see all declared functions are actual functions on the instances.
976
977                         var testStore = new dojox.data.KeyValueStore(dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv"));
978                         var identityApi = new dojo.data.api.Identity();
979                         var passed = true;
980
981                         for(i in identityApi){
982                                 if(i.toString().charAt(0) !== '_')
983                                 {
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")){
990                                                         passed = false;
991                                                         break;
992                                                 }
993                                         }
994                                 }
995                         }
996                         t.assertTrue(passed);
997                 }
998         ]
999 );
1000
1001
1002 }