]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/data/tests/stores/CsvStore.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojox / data / tests / stores / CsvStore.js
1 if(!dojo._hasResource["dojox.data.tests.stores.CsvStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.data.tests.stores.CsvStore"] = true;
3 dojo.provide("dojox.data.tests.stores.CsvStore");
4 dojo.require("dojox.data.CsvStore");
5 dojo.require("dojo.data.api.Read");
6 dojo.require("dojo.data.api.Identity");
7
8 dojox.data.tests.stores.CsvStore.getDatasource = function(filepath){
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         if(dojo.isBrowser){
16                 dataSource.url = dojo.moduleUrl("dojox.data.tests", filepath).toString();            
17         }else{
18                 // When running tests in Rhino, xhrGet is not available,
19                 // so we have the file data in the code below.
20                 switch(filepath){
21                         case "stores/movies.csv":
22                                 var csvData = "";
23                                 csvData += "Title, Year, Producer\n";
24                                 csvData += "City of God, 2002, Katia Lund\n";
25                                 csvData += "Rain,, Christine Jeffs\n";
26                                 csvData += "2001: A Space Odyssey, 1968, Stanley Kubrick\n";
27                                 csvData += '"This is a ""fake"" movie title", 1957, Sidney Lumet\n';
28                                 csvData += "Alien, 1979   , Ridley Scott\n";
29                                 csvData += '"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott\n';
30                                 csvData += '"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"\n';
31                                 break;
32                         case "stores/movies2.csv":
33                                 var csvData = "";
34                                 csvData += "Title, Year, Producer\n";
35                                 csvData += "City of God, 2002, Katia Lund\n";
36                                 csvData += "Rain,\"\", Christine Jeffs\n";
37                                 csvData += "2001: A Space Odyssey, 1968, Stanley Kubrick\n";
38                                 csvData += '"This is a ""fake"" movie title", 1957, Sidney Lumet\n';
39                                 csvData += "Alien, 1979   , Ridley Scott\n";
40                                 csvData += '"The Sequel to ""Dances With Wolves.""", 1982, Ridley Scott\n';
41                                 csvData += '"Caine Mutiny, The", 1954, "Dymtryk ""the King"", Edward"\n';
42                                 break;
43                         case "stores/books.csv":
44                                 var csvData = "";
45                                 csvData += "Title, Author\n";
46                                 csvData += "The Transparent Society, David Brin\n";
47                                 csvData += "The First Measured Century, Theodore Caplow\n";
48                                 csvData += "Maps in a Mirror, Orson Scott Card\n";
49                                 csvData += "Princess Smartypants, Babette Cole\n";
50                                 csvData += "Carfree Cities, Crawford J.H.\n";
51                                 csvData += "Down and Out in the Magic Kingdom, Cory Doctorow\n";
52                                 csvData += "Tax Shift, Alan Thein Durning\n";
53                                 csvData += "The Sneetches and other stories, Dr. Seuss\n";
54                                 csvData += "News from Tartary, Peter Fleming\n";
55                                 break;
56                         case "stores/patterns.csv":
57                                 var csvData = "";
58                                 csvData += "uniqueId, value\n";
59                                 csvData += "9, jfq4@#!$!@Rf14r14i5u\n";
60                                 csvData += "6, BaBaMaSaRa***Foo\n";
61                                 csvData += "2, bar*foo\n";
62                                 csvData += "8, 123abc\n";
63                                 csvData += "4, bit$Bite\n";
64                                 csvData += "3, 123abc\n";
65                                 csvData += "10, 123abcdefg\n";
66                                 csvData += "1, foo*bar\n";
67                                 csvData += "7, \n";
68                                 csvData += "5, 123abc\n"
69                                 break;
70                 }
71                 dataSource.data = csvData;
72         }
73         return dataSource; //Object
74 }
75
76 dojox.data.tests.stores.CsvStore.verifyItems = function(csvStore, items, attribute, compareArray){
77         //  summary:
78         //              A helper function for validating that the items array is ordered
79         //              the same as the compareArray
80         if(items.length != compareArray.length){ return false; }
81         for(var i = 0; i < items.length; i++){
82                 if(!(csvStore.getValue(items[i], attribute) === compareArray[i])){
83                         return false; //Boolean
84                 }
85         }
86         return true; //Boolean
87 }
88
89 dojox.data.tests.stores.CsvStore.error = function(t, d, errData){
90         //  summary:
91         //              The error callback function to be used for all of the tests.
92         for (i in errData) {
93                 console.log(errData[i]);
94         }
95         d.errback(errData);     
96 }
97
98 doh.register("dojox.data.tests.stores.CsvStore", 
99         [
100                 function testReadAPI_fetch_all(t){
101                         //      summary: 
102                         //              Simple test of a basic fetch on CsvStore.
103                         //      description:
104                         //              Simple test of a basic fetch on CsvStore.
105                         
106                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
107                         var csvStore = new dojox.data.CsvStore(args);
108                         
109                         var d = new doh.Deferred();
110                 function completedAll(items){
111                                 t.assertTrue((items.length === 7));
112                                 d.callback(true);
113                         }
114
115                         //Get everything...
116                         csvStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
117                         return d; //Object
118                 },
119                 function testReadAPI_fetch_all_withEmptyStringField(t){
120                         //      summary: 
121                         //              Simple test of a basic fetch on CsvStore.
122                         //      description:
123                         //              Simple test of a basic fetch on CsvStore.
124                         
125                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies2.csv");
126                         var csvStore = new dojox.data.CsvStore(args);
127                         
128                         var d = new doh.Deferred();
129                 function completedAll(items){
130                                 t.assertTrue((items.length === 7));
131                                 d.callback(true);
132                         }
133
134                         //Get everything...
135                         csvStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
136                         return d; //Object
137                 },
138                 function testReadAPI_fetch_one(t){
139                         //      summary: 
140                         //              Simple test of a basic fetch on CsvStore of a single item.
141                         //      description:
142                         //              Simple test of a basic fetch on CsvStore of a single item.
143
144                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
145                         var csvStore = new dojox.data.CsvStore(args);
146                         
147                         var d = new doh.Deferred();
148                         function onComplete(items, request){
149                                 t.is(1, items.length);
150                                 d.callback(true);
151                         }
152                         csvStore.fetch({        query: {Title: "*Sequel*"}, 
153                                                                 onComplete: onComplete, 
154                                                                 onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
155                                                         });
156                         return d; //Object
157                 },
158                 function testReadAPI_fetch_Multiple(t){
159                         //      summary: 
160                         //              Simple test of a basic fetch on CsvStore of a single item.
161                         //      description:
162                         //              Simple test of a basic fetch on CsvStore of a single item.
163
164                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
165                         var csvStore = new dojox.data.CsvStore(args);
166                         
167                         var d = new doh.Deferred();
168
169                         var done = [false, false];
170
171                         function onCompleteOne(items, request){
172                                 done[0] = true;
173                                 t.is(1, items.length);
174                                 if(done[0] && done[1]){
175                                         d.callback(true);
176                                 }
177                         }
178                         
179                         function onCompleteTwo(items, request){
180                                 done[1] = true;
181                                 t.is(1, items.length);
182                                 if(done[0] && done[1]){
183                                         d.callback(true);
184                                 }
185                         }
186                         
187                         try
188                         {
189                                 csvStore.fetch({        query: {Title: "*Sequel*"}, 
190                                                                         onComplete: onCompleteOne, 
191                                                                         onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
192                                                                 });
193                                 csvStore.fetch({        query: {Title: "2001:*"}, 
194                                                                         onComplete: onCompleteTwo, 
195                                                                         onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
196                                                                 });
197                         }
198                         catch(e)
199                         {
200                                 for (i in e) {
201                                         console.log(e[i]);
202                                 }
203                         }
204
205                         return d; //Object
206                 },
207                 function testReadAPI_fetch_MultipleMixed(t){
208                         //      summary: 
209                         //              Simple test of a basic fetch on CsvStore of a single item.
210                         //      description:
211                         //              Simple test of a basic fetch on CsvStore of a single item.
212
213                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
214                         var csvStore = new dojox.data.CsvStore(args);
215                         
216                         var d = new doh.Deferred();
217
218                         var done = [false, false];
219                         function onComplete(items, request){
220                                 done[0] = true;
221                                 t.is(1, items.length);
222                                 if(done[0] && done[1]){
223                                         d.callback(true);
224                                 }
225                         }
226                         
227                         function onItem(item){
228                                 done[1] = true;
229                                 t.assertTrue(item !== null);
230                                 t.is('Dymtryk "the King", Edward', csvStore.getValue(item,"Producer"));
231                                 t.is('Caine Mutiny, The', csvStore.getValue(item,"Title"));
232                                 if(done[0] && done[1]){
233                                         d.callback(true);
234                                 }
235                         }
236
237                         csvStore.fetch({        query: {Title: "*Sequel*"}, 
238                                                                 onComplete: onComplete, 
239                                                                 onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
240                                                         });
241                         
242                         csvStore.fetchItemByIdentity({identity: "6", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
243                         return d; //Object
244                 },
245                 function testReadAPI_fetch_all_streaming(t){
246                         //      summary: 
247                         //              Simple test of a basic fetch on CsvStore.
248                         //      description:
249                         //              Simple test of a basic fetch on CsvStore.
250
251                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
252                         var csvStore = new dojox.data.CsvStore(args);
253
254                         var d = new doh.Deferred();
255                         count = 0;
256
257                         function onBegin(size, requestObj){
258                                 t.assertTrue(size === 7);
259                         }
260                         function onItem(item, requestObj){
261                                 t.assertTrue(csvStore.isItem(item));
262                                 count++;
263                         }
264                         function onComplete(items, request){
265                                 t.is(7, count);
266                                 t.is(null, items);
267                             d.callback(true);
268                         }
269
270                         //Get everything...
271                         csvStore.fetch({        onBegin: onBegin,
272                                                                 onItem: onItem, 
273                                                                 onComplete: onComplete,
274                                                                 onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
275                                                         });
276                         return d; //Object
277                 },
278                 function testReadAPI_fetch_paging(t){
279                          //     summary: 
280                          //             Test of multiple fetches on a single result.  Paging, if you will.
281                          //     description:
282                          //             Test of multiple fetches on a single result.  Paging, if you will.
283
284                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
285                         var csvStore = new dojox.data.CsvStore(args);
286                         
287                         var d = new doh.Deferred();
288                         function dumpFirstFetch(items, request){
289                                 t.is(5, items.length);
290                                 request.start = 3;
291                                 request.count = 1;
292                                 request.onComplete = dumpSecondFetch;
293                                 csvStore.fetch(request);
294                         }
295
296                         function dumpSecondFetch(items, request){
297                                 t.is(1, items.length);
298                                 request.start = 0;
299                                 request.count = 5;
300                                 request.onComplete = dumpThirdFetch;
301                                 csvStore.fetch(request);
302                         }
303
304                         function dumpThirdFetch(items, request){
305                                 t.is(5, items.length);
306                                 request.start = 2;
307                                 request.count = 20;
308                                 request.onComplete = dumpFourthFetch;
309                                 csvStore.fetch(request);
310                         }
311
312                         function dumpFourthFetch(items, request){
313                                 t.is(5, items.length);
314                                 request.start = 9;
315                                 request.count = 100;
316                                 request.onComplete = dumpFifthFetch;
317                                 csvStore.fetch(request);
318                         }
319
320                         function dumpFifthFetch(items, request){
321                                 t.is(0, items.length);
322                                 request.start = 2;
323                                 request.count = 20;
324                                 request.onComplete = dumpSixthFetch;
325                                 csvStore.fetch(request);
326                         }
327
328                         function dumpSixthFetch(items, request){
329                                 t.is(5, items.length);
330                             d.callback(true);
331                         }
332
333                         function completed(items, request){
334                                 t.is(7, items.length);
335                                 request.start = 1;
336                                 request.count = 5;
337                                 request.onComplete = dumpFirstFetch;
338                                 csvStore.fetch(request);
339                         }
340
341                         csvStore.fetch({onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
342                         return d; //Object
343
344                 },
345                 
346                 function testReadAPI_getLabel(t){
347                         //      summary: 
348                         //              Simple test of the getLabel function against a store set that has a label defined.
349                         //      description:
350                         //              Simple test of the getLabel function against a store set that has a label defined.
351
352                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
353                         args.label = "Title";
354                         var csvStore = new dojox.data.CsvStore(args);
355                         
356                         var d = new doh.Deferred();
357                         function onComplete(items, request){
358                                 t.assertEqual(items.length, 1);
359                                 var label = csvStore.getLabel(items[0]);
360                                 t.assertTrue(label !== null);
361                                 t.assertEqual("The Sequel to \"Dances With Wolves.\"", label);
362                                 d.callback(true);
363                         }
364                         csvStore.fetch({        query: {Title: "*Sequel*"}, 
365                                                                 onComplete: onComplete, 
366                                                                 onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
367                                                         });
368                         return d;
369                 },
370                 function testReadAPI_getLabelAttributes(t){
371                         //      summary: 
372                         //              Simple test of the getLabelAttributes function against a store set that has a label defined.
373                         //      description:
374                         //              Simple test of the getLabelAttributes function against a store set that has a label defined.
375
376                          var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
377                          args.label = "Title";
378                          var csvStore = new dojox.data.CsvStore(args);
379                         
380                         var d = new doh.Deferred();
381                         function onComplete(items, request){
382                                 t.assertEqual(items.length, 1);
383                                 var labelList = csvStore.getLabelAttributes(items[0]);
384                                 t.assertTrue(dojo.isArray(labelList));
385                                 t.assertEqual("Title", labelList[0]);
386                                 d.callback(true);
387                         }
388                         csvStore.fetch({        query: {Title: "*Sequel*"}, 
389                                                                 onComplete: onComplete, 
390                                                                 onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)
391                                                         });
392                         return d;
393                 },
394                 function testReadAPI_getValue(t){
395                         //      summary: 
396                         //              Simple test of the getValue function of the store.
397                         //      description:
398                         //              Simple test of the getValue function of the store.
399
400                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
401                         var csvStore = new dojox.data.CsvStore(args);
402
403                         var d = new doh.Deferred();
404                         function onItem(item){
405                                 t.assertTrue(item !== null);
406                                 t.is('Dymtryk "the King", Edward', csvStore.getValue(item,"Producer"));
407                                 t.is('Caine Mutiny, The', csvStore.getValue(item,"Title"));
408                                 d.callback(true);       
409                         }
410                         csvStore.fetchItemByIdentity({identity: "6", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
411                         return d;
412                 },      
413                 function testReadAPI_getValue_2(t){
414                         //      summary: 
415                         //              Simple test of the getValue function of the store.
416                         //      description:
417                         //              Simple test of the getValue function of the store.
418
419                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
420                         var csvStore = new dojox.data.CsvStore(args);
421
422                         var d = new doh.Deferred();
423                         function onItem(item){
424                                 t.assertTrue(item !== null);
425                                 t.is("City of God", csvStore.getValue(item,"Title"));
426                                 t.is("2002", csvStore.getValue(item,"Year"));
427                                 d.callback(true);       
428                         }
429             csvStore.fetchItemByIdentity({identity: "0", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
430                         return d;
431                 },      
432                 function testReadAPI_getValue_3(t){
433                         //      summary: 
434                         //              Simple test of the getValue function of the store.
435                         //      description:
436                         //              Simple test of the getValue function of the store.
437
438                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
439                         var csvStore = new dojox.data.CsvStore(args);
440
441                         var d = new doh.Deferred();
442                         function onItem(item){
443                                 t.assertTrue(item !== null);
444                                 t.is("1979", csvStore.getValue(item,"Year"));
445                                 t.is("Alien", csvStore.getValue(item,"Title"));
446                                 d.callback(true);       
447                         }
448                         csvStore.fetchItemByIdentity({identity: "4", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
449                         return d;
450                 },      
451                 function testReadAPI_getValue_4(t){
452                         //      summary: 
453                         //              Simple test of the getValue function of the store.
454                         //      description:
455                         //              Simple test of the getValue function of the store.
456
457                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
458                         var csvStore = new dojox.data.CsvStore(args);
459
460                         var d = new doh.Deferred();
461                         function onItem(item){
462                                 t.assertTrue(item !== null);
463                                 t.is("2001: A Space Odyssey", csvStore.getValue(item,"Title"));
464                                 t.is("Stanley Kubrick", csvStore.getValue(item,"Producer"));
465                                 d.callback(true);       
466                         }
467                         csvStore.fetchItemByIdentity({identity: "2", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
468                         return d;
469                 },      
470
471                 function testReadAPI_getValues(t){
472                         //      summary: 
473                         //              Simple test of the getValues function of the store.
474                         //      description:
475                         //              Simple test of the getValues function of the store.
476
477                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
478                         var csvStore = new dojox.data.CsvStore(args);
479
480                         var d = new doh.Deferred();
481                         function onItem(item){
482                                 t.assertTrue(item !== null);
483                                 var names = csvStore.getValues(item,"Title");
484                                 t.assertTrue(dojo.isArray(names));
485                                 t.is(1, names.length);
486                                 t.is("Rain", names[0]);
487                                 d.callback(true);       
488                         }
489                         csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
490                         return d;
491                 },
492                 function testIdentityAPI_fetchItemByIdentity(t){
493                         //      summary: 
494                         //              Simple test of the fetchItemByIdentity function of the store.
495                         //      description:
496                         //              Simple test of the fetchItemByIdentity function of the store.
497                         
498                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
499                         var csvStore = new dojox.data.CsvStore(args);
500                         
501                         var d = new doh.Deferred();
502                         function onItem(item){
503                                 t.assertTrue(item !== null);
504                                 d.callback(true);       
505                         }
506                         csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
507                         return d;
508                 },
509
510                 function testIdentityAPI_fetchItemByIdentity_bad1(t){
511                         //      summary: 
512                         //              Simple test of the fetchItemByIdentity function of the store.
513                         //      description:
514                         //              Simple test of the fetchItemByIdentity function of the store.
515                         
516                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
517                         var csvStore = new dojox.data.CsvStore(args);
518                         
519                         var d = new doh.Deferred();
520                         function onItem(item){
521                                 t.assertTrue(item === null);
522                                 d.callback(true);       
523                         }
524                         csvStore.fetchItemByIdentity({identity: "7", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
525                         return d;
526                 },
527                 function testIdentityAPI_fetchItemByIdentity_bad2(t){
528                         //      summary: 
529                         //              Simple test of the fetchItemByIdentity function of the store.
530                         //      description:
531                         //              Simple test of the fetchItemByIdentity function of the store.
532                         
533                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
534                         var csvStore = new dojox.data.CsvStore(args);
535                         var d = new doh.Deferred();
536                         function onItem(item){
537                                 t.assertTrue(item === null);
538                                 d.callback(true);       
539                         }
540                         csvStore.fetchItemByIdentity({identity: "-1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
541                         return d;
542                 },
543                 function testIdentityAPI_fetchItemByIdentity_bad3(t){
544                         //      summary: 
545                         //              Simple test of the fetchItemByIdentity function of the store.
546                         //      description:
547                         //              Simple test of the fetchItemByIdentity function of the store.
548                         
549                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
550                         var csvStore = new dojox.data.CsvStore(args);
551                         var d = new doh.Deferred();
552                         function onItem(item){
553                                 t.assertTrue(item === null);
554                                 d.callback(true);       
555                         }
556                         csvStore.fetchItemByIdentity({identity: "999999", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
557                         return d;
558                 },
559                 function testIdentityAPI_getIdentity(t){
560                         //      summary: 
561                         //              Simple test of the fetchItemByIdentity function of the store.
562                         //      description:
563                         //              Simple test of the fetchItemByIdentity function of the store.
564                         
565                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
566                         var csvStore = new dojox.data.CsvStore(args);
567                         
568                         var d = new doh.Deferred();
569                         function completed(items, request){
570                                 t.is(7, items.length);
571                                 var passed = true;
572                                 for(var i = 0; i < items.length; i++){
573                                         if(!(csvStore.getIdentity(items[i]) === i)){
574                                                 passed=false;
575                                                 break;
576                                         }
577                                 }
578                                 t.assertTrue(passed);
579                                 d.callback(true);
580                         }
581                         
582                         //Get everything...
583                         csvStore.fetch({ onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
584                         return d; //Object
585                 },
586                 function testIdentityAPI_getIdentityAttributes(t){
587                         //      summary: 
588                         //              Simple test of the getIdentityAttributes
589                         //      description:
590                         //              Simple test of the fetchItemByIdentity function of the store.
591                         
592                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
593                         var csvStore = new dojox.data.CsvStore(args);
594
595                         var d = new doh.Deferred();
596                         function onItem(item){
597                                 t.assertTrue(csvStore.isItem(item));
598                                 t.assertEqual(null, csvStore.getIdentityAttributes(item)); 
599                                 d.callback(true);       
600                         }
601                         csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
602                         return d;
603                 },
604                 function testReadAPI_isItem(t){
605                         //      summary: 
606                         //              Simple test of the isItem function of the store
607                         //      description:
608                         //              Simple test of the isItem function of the store
609
610                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
611                         var csvStore = new dojox.data.CsvStore(args);
612
613                         var d = new doh.Deferred();
614                         function onItem(item){
615                                 t.assertTrue(csvStore.isItem(item));
616                                 t.assertTrue(!csvStore.isItem({}));
617                                 t.assertTrue(!csvStore.isItem({ item: "not an item" }));
618                                 t.assertTrue(!csvStore.isItem("not an item"));
619                                 t.assertTrue(!csvStore.isItem(["not an item"]));
620                                 d.callback(true);       
621                         }
622                         csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
623                         return d;
624                 },
625                 function testReadAPI_hasAttribute(t){
626                         //      summary: 
627                         //              Simple test of the hasAttribute function of the store
628                         //      description:
629                         //              Simple test of the hasAttribute function of the store
630
631                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
632                         var csvStore = new dojox.data.CsvStore(args);
633
634                         var d = new doh.Deferred();
635                         function onItem(item){
636                                 t.assertTrue(item !== null);
637                                 t.assertTrue(csvStore.hasAttribute(item, "Title"));
638                                 t.assertTrue(csvStore.hasAttribute(item, "Producer"));
639                                 t.assertTrue(!csvStore.hasAttribute(item, "Year"));
640                                 t.assertTrue(!csvStore.hasAttribute(item, "Nothing"));
641                                 t.assertTrue(!csvStore.hasAttribute(item, "title"));
642
643                                 //Test that null attributes throw an exception
644                                 var passed = false;
645                                 try{
646                                         csvStore.hasAttribute(item, null);
647                                 }catch (e){
648                                         passed = true;
649                                 }
650                                 t.assertTrue(passed);
651                                 d.callback(true);       
652                         }
653                         csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
654                         return d;
655                 },
656                 function testReadAPI_containsValue(t){
657                         //      summary: 
658                         //              Simple test of the containsValue function of the store
659                         //      description:
660                         //              Simple test of the containsValue function of the store
661
662                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
663                         var csvStore = new dojox.data.CsvStore(args);
664                         
665                         var d = new doh.Deferred();
666                         function onItem(item){
667                                 t.assertTrue(item !== null);
668                                 t.assertTrue(csvStore.containsValue(item, "Title", "Alien"));
669                                 t.assertTrue(csvStore.containsValue(item, "Year", "1979"));
670                                 t.assertTrue(csvStore.containsValue(item, "Producer", "Ridley Scott"));
671                                 t.assertTrue(!csvStore.containsValue(item, "Title", "Alien2"));
672                                 t.assertTrue(!csvStore.containsValue(item, "Year", "1979   "));
673                                 t.assertTrue(!csvStore.containsValue(item, "Title", null));
674
675                                 //Test that null attributes throw an exception
676                                 var passed = false;
677                                 try{
678                                         csvStore.containsValue(item, null, "foo");
679                                 }catch (e){
680                                         passed = true;
681                                 }
682                                 t.assertTrue(passed);
683                                 d.callback(true);       
684                         }
685                         csvStore.fetchItemByIdentity({identity: "4", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
686                         return d;
687                 },
688                 function testReadAPI_getAttributes(t){
689                         //      summary: 
690                         //              Simple test of the getAttributes function of the store
691                         //      description:
692                         //              Simple test of the getAttributes function of the store
693
694                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
695                         var csvStore = new dojox.data.CsvStore(args);
696
697                         var d = new doh.Deferred();
698                         function onItem(item){
699                                 t.assertTrue(item !== null);
700                                 t.assertTrue(csvStore.isItem(item));
701
702                                 var attributes = csvStore.getAttributes(item);
703                                 t.is(3, attributes.length);
704                                 for(var i = 0; i < attributes.length; i++){
705                                         t.assertTrue((attributes[i] === "Title" || attributes[i] === "Year" || attributes[i] === "Producer"));
706                                 }
707                                 d.callback(true);       
708                         }
709                         csvStore.fetchItemByIdentity({identity: "4", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
710                         return d;
711                 },
712
713                 function testReadAPI_getAttributes_onlyTwo(t){
714                         //      summary: 
715                         //              Simple test of the getAttributes function of the store
716                         //      description:
717                         //              Simple test of the getAttributes function of the store
718
719                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
720                         var csvStore = new dojox.data.CsvStore(args);
721
722                         var d = new doh.Deferred();
723                         function onItem(item){
724                                 // Test an item that does not have all of the attributes
725                                 t.assertTrue(item !== null);
726                                 t.assertTrue(csvStore.isItem(item));
727
728                                 var attributes = csvStore.getAttributes(item);
729                                 t.assertTrue(attributes.length === 2);
730                                 t.assertTrue(attributes[0] === "Title");
731                                 t.assertTrue(attributes[1] === "Producer");
732                                 d.callback(true);       
733                         }
734                         csvStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
735                         return d;
736                 },
737
738                 function testReadAPI_getFeatures(t){
739                         //      summary: 
740                         //              Simple test of the getFeatures function of the store
741                         //      description:
742                         //              Simple test of the getFeatures function of the store
743
744                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
745                         var csvStore = new dojox.data.CsvStore(args);
746
747                         var features = csvStore.getFeatures(); 
748                         var count = 0;
749                         for(i in features){
750                                 t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Identity"));
751                                 count++;
752                         }
753                         t.assertTrue(count === 2);
754                 },
755                 function testReadAPI_fetch_patternMatch0(t){
756                         //      summary: 
757                         //              Function to test pattern matching of everything starting with lowercase e
758                         //      description:
759                         //              Function to test pattern matching of everything starting with lowercase e
760
761                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
762                         var csvStore = new dojox.data.CsvStore(args);
763
764                         var d = new doh.Deferred();
765                         function completed(items, request){
766                                 t.is(2, items.length);
767                                 var valueArray = [ "Alien", "The Sequel to \"Dances With Wolves.\""];
768                                 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "Title", valueArray));
769                                 d.callback(true);
770                         }
771                         
772                         csvStore.fetch({query: {Producer: "* Scott"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
773                         return d; //Object
774                 },
775                 function testReadAPI_fetch_patternMatch1(t){
776                         //      summary: 
777                         //              Function to test pattern matching of everything with $ in it.
778                         //      description:
779                         //              Function to test pattern matching of everything with $ in it.
780                         
781                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
782                         var csvStore = new dojox.data.CsvStore(args);
783                         
784                         var d = new doh.Deferred();
785                         function completed(items, request){
786                                 t.assertTrue(items.length === 2);
787                                 var valueArray = [ "jfq4@#!$!@Rf14r14i5u", "bit$Bite"];
788                                 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", valueArray));
789                                 d.callback(true);
790                         }
791                         
792                         csvStore.fetch({query: {value: "*$*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
793                         return d; //Object
794                 },
795                 function testReadAPI_fetch_patternMatch2(t){
796                         //      summary: 
797                         //              Function to test exact pattern match
798                         //      description:
799                         //              Function to test exact pattern match
800                         
801                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
802                         var csvStore = new dojox.data.CsvStore(args);
803                         
804                         var d = new doh.Deferred();
805                         function completed(items, request){
806                                 t.is(1, items.length);
807                                 t.assertTrue(csvStore.getValue(items[0], "value") === "bar*foo");
808                                 d.callback(true);
809                         }
810                         
811                         csvStore.fetch({query: {value: "bar\*foo"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
812                         return d; //Object
813                 },
814                 function testReadAPI_fetch_patternMatch_caseInsensitive(t){
815                         //      summary: 
816                         //              Function to test exact pattern match with case insensitivity set.
817                         //      description:
818                         //              Function to test exact pattern match with case insensitivity set.
819                         
820                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
821                         var csvStore = new dojox.data.CsvStore(args);
822                         
823                         var d = new doh.Deferred();
824                         function completed(items, request){
825                                 t.is(1, items.length);
826                                 t.assertTrue(csvStore.getValue(items[0], "value") === "bar*foo");
827                                 d.callback(true);
828                         }
829                         
830                         csvStore.fetch({query: {value: "BAR\\*foo"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
831                         return d; //Object
832                 },
833                 function testReadAPI_fetch_patternMatch_caseSensitive(t){
834                         //      summary: 
835                         //              Function to test exact pattern match with case insensitivity set.
836                         //      description:
837                         //              Function to test exact pattern match with case insensitivity set.
838                         
839                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
840                         var csvStore = new dojox.data.CsvStore(args);
841                         
842                         var d = new doh.Deferred();
843                         function completed(items, request){
844                                 t.is(0, items.length);
845                                 d.callback(true);
846                         }
847                         
848                         csvStore.fetch({query: {value: "BAR\\*foo"}, queryOptions: {ignoreCase: false}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
849                         return d; //Object
850                 },
851                 function testReadAPI_fetch_sortNumeric(t){
852                         //      summary: 
853                         //              Function to test sorting numerically.
854                         //      description:
855                         //              Function to test sorting numerically.
856                         
857                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
858                         var csvStore = new dojox.data.CsvStore(args);
859
860                         var d = new doh.Deferred();
861                         function completed(items, request){
862                                 t.assertTrue(items.length === 10);
863                                 // TODO: CsvStore treats everything like a string, so these numbers will be sorted lexicographically.
864                                 var orderedArray = [ "1", "10", "2", "3", "4", "5", "6", "7", "8", "9" ];
865                                 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray));
866                                 d.callback(true);
867                         }
868
869                         var sortAttributes = [{attribute: "uniqueId"}];
870                         csvStore.fetch({onComplete: completed, 
871                                                         onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d),
872                                                         sort: sortAttributes});
873                         return d; //Object
874                 },
875                 function testReadAPI_fetch_sortNumericDescending(t){
876                         //      summary: 
877                         //              Function to test sorting numerically.
878                         //      description:
879                         //              Function to test sorting numerically.
880
881                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
882                         var csvStore = new dojox.data.CsvStore(args);
883                         
884                         var d = new doh.Deferred();
885                         function completed(items, request){
886                                 t.is(10, items.length);
887                                 // TODO: CsvStore treats everything like a string, so these numbers will be sorted lexicographically.
888                                 var orderedArray = [ "9", "8", "7", "6", "5", "4", "3", "2", "10", "1" ];
889                                 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray));
890                                 d.callback(true);
891                         }
892                         
893                         var sortAttributes = [{attribute: "uniqueId", descending: true}];
894                         csvStore.fetch({ sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
895                         return d; //Object
896                 },
897                 function testReadAPI_fetch_sortNumericWithCount(t){
898                         //      summary: 
899                         //              Function to test sorting numerically in descending order, returning only a specified number of them.
900                         //      description:
901                         //              Function to test sorting numerically in descending order, returning only a specified number of them.
902                 
903                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
904                         var csvStore = new dojox.data.CsvStore(args);
905                         
906                         var d = new doh.Deferred();
907                         function completed(items, request){
908                                 t.is(5, items.length);
909                                 // TODO: CsvStore treats everything like a string, so these numbers will be sorted lexicographically.
910                                 var orderedArray = [ "9", "8", "7", "6", "5" ];
911                                 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray));
912                                 d.callback(true);
913                         }
914                         
915                         var sortAttributes = [{attribute: "uniqueId", descending: true}];
916                         csvStore.fetch({sort: sortAttributes, 
917                                                         count: 5,
918                                                         onComplete: completed,
919                                                         onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
920                         return d; //Object
921                 },
922                 function testReadAPI_fetch_sortAlphabetic(t){
923                         //      summary: 
924                         //              Function to test sorting alphabetic ordering.
925                         //      description:
926                         //              Function to test sorting alphabetic ordering.
927                 
928                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
929                         var csvStore = new dojox.data.CsvStore(args);
930                         
931                         var d = new doh.Deferred();
932                         function completed(items, request){
933                                 //Output should be in this order...
934                                 var orderedArray = [    "123abc",
935                                                                                 "123abc",
936                                                                                 "123abc",
937                                                                                 "123abcdefg",
938                                                                                 "BaBaMaSaRa***Foo",
939                                                                                 "bar*foo",
940                                                                                 "bit$Bite",
941                                                                                 "foo*bar",
942                                                                                 "jfq4@#!$!@Rf14r14i5u",
943                                                                                 undefined
944                                         ];
945                                 t.is(10, items.length);
946                                 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", orderedArray));
947                                 d.callback(true);
948                         }
949                         
950                         var sortAttributes = [{attribute: "value"}];
951                         csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
952                         return d; //Object
953                 },
954                 function testReadAPI_fetch_sortAlphabeticDescending(t){
955                         //      summary: 
956                         //              Function to test sorting alphabetic ordering in descending mode.
957                         //      description:
958                         //              Function to test sorting alphabetic ordering in descending mode.
959                 
960                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
961                         var csvStore = new dojox.data.CsvStore(args);
962                         
963                         var d = new doh.Deferred();
964                         function completed(items, request){
965                                 //Output should be in this order...
966                                 var orderedArray = [    undefined,
967                                                                                 "jfq4@#!$!@Rf14r14i5u",
968                                                                                 "foo*bar",
969                                                                                 "bit$Bite",
970                                                                                 "bar*foo",
971                                                                                 "BaBaMaSaRa***Foo",
972                                                                                 "123abcdefg",
973                                                                                 "123abc",
974                                                                                 "123abc",
975                                                                                 "123abc"
976                                         ];
977                                 t.is(10, items.length);
978                                 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", orderedArray));
979                                 d.callback(true);
980                         }
981                         
982                         var sortAttributes = [{attribute: "value", descending: true}];
983                         csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
984                         return d; //Object
985                 },
986                 function testReadAPI_fetch_sortMultiple(t){
987                         //      summary: 
988                         //              Function to test sorting on multiple attributes.
989                         //      description:
990                         //              Function to test sorting on multiple attributes.
991                         
992                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/patterns.csv");
993                         var csvStore = new dojox.data.CsvStore(args);
994                 
995                         var d = new doh.Deferred();
996                         function completed(items, request){
997                                 var orderedArray0 = [ "8", "5", "3", "10", "6", "2", "4", "1", "9", "7" ];
998                                 var orderedArray1 = [   "123abc",
999                                                                                 "123abc",
1000                                                                                 "123abc",
1001                                                                                 "123abcdefg",
1002                                                                                 "BaBaMaSaRa***Foo",
1003                                                                                 "bar*foo",
1004                                                                                 "bit$Bite",
1005                                                                                 "foo*bar",
1006                                                                                 "jfq4@#!$!@Rf14r14i5u",
1007                                                                                 undefined
1008                                                                         ];
1009                                 t.is(10, items.length);
1010                                 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "uniqueId", orderedArray0));
1011                                 t.assertTrue(dojox.data.tests.stores.CsvStore.verifyItems(csvStore, items, "value", orderedArray1));
1012                                 d.callback(true);
1013                         }
1014                         
1015                         var sortAttributes = [{ attribute: "value"}, { attribute: "uniqueId", descending: true}];
1016                         csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
1017                         return d; //Object
1018                 },
1019                 function testReadAPI_fetch_sortMultipleSpecialComparator(t){
1020                         //      summary: 
1021                         //              Function to test sorting on multiple attributes with a custom comparator.
1022                         //      description:
1023                         //              Function to test sorting on multiple attributes with a custom comparator.
1024
1025                         var args = dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv");
1026                         var csvStore = new dojox.data.CsvStore(args);
1027                         
1028                         csvStore.comparatorMap = {};
1029                         csvStore.comparatorMap["Producer"] = function(a,b){ 
1030                                 var ret = 0;
1031                                 // We want to sort authors alphabetical by their last name
1032                                 function lastName(name){
1033                                         if(typeof name === "undefined"){ return undefined; }
1034                                         
1035                                         var matches = name.match(/\s*(\S+)$/); // Grab the last word in the string.
1036                                         return matches ? matches[1] : name; // Strings with only whitespace will not match.
1037                                 }
1038                                 var lastNameA = lastName(a);
1039                                 var lastNameB = lastName(b);
1040                                 if(lastNameA > lastNameB || typeof lastNameA === "undefined"){
1041                                         ret = 1;
1042                                 }else if(lastNameA < lastNameB || typeof lastNameB === "undefined"){
1043                                         ret = -1;
1044                                 }
1045                                 return ret;
1046                         };
1047                 
1048                         var sortAttributes = [{attribute: "Producer", descending: true}, { attribute: "Title", descending: true}];
1049                 
1050                         var d = new doh.Deferred();
1051                         function completed(items, findResult){
1052                                 var orderedArray = [5,4,0,3,2,1,6];
1053                                 t.assertTrue(items.length === 7);
1054                                 var passed = true;
1055                                 for(var i = 0; i < items.length; i++){
1056                                         if(!(csvStore.getIdentity(items[i]) === orderedArray[i])){
1057                                                 passed=false;
1058                                                 break;
1059                                         }
1060                                 }
1061                                 t.assertTrue(passed);
1062                                 d.callback(true);
1063                         }
1064                         
1065                         csvStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.CsvStore.error, t, d)});
1066                         return d; //Object
1067                 },
1068                 function testReadAPI_functionConformance(t){
1069                         //      summary: 
1070                         //              Simple test read API conformance.  Checks to see all declared functions are actual functions on the instances.
1071                         //      description:
1072                         //              Simple test read API conformance.  Checks to see all declared functions are actual functions on the instances.
1073
1074                         var testStore = new dojox.data.CsvStore(dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv"));
1075                         var readApi = new dojo.data.api.Read();
1076                         var passed = true;
1077
1078                         for(i in readApi){
1079                                 if(i.toString().charAt(0) !== '_')
1080                                 {
1081                                         var member = readApi[i];
1082                                         //Check that all the 'Read' defined functions exist on the test store.
1083                                         if(typeof member === "function"){
1084                                                 console.log("Looking at function: [" + i + "]");
1085                                                 var testStoreMember = testStore[i];
1086                                                 if(!(typeof testStoreMember === "function")){
1087                                                         console.log("Problem with function: [" + i + "].   Got value: " + testStoreMember);
1088                                                         passed = false;
1089                                                         break;
1090                                                 }
1091                                         }
1092                                 }
1093                         }
1094                         t.assertTrue(passed);
1095                 },
1096                 function testIdentityAPI_functionConformance(t){
1097                         //      summary: 
1098                         //              Simple test identity API conformance.  Checks to see all declared functions are actual functions on the instances.
1099                         //      description:
1100                         //              Simple test identity API conformance.  Checks to see all declared functions are actual functions on the instances.
1101
1102                         var testStore = new dojox.data.CsvStore(dojox.data.tests.stores.CsvStore.getDatasource("stores/movies.csv"));
1103                         var identityApi = new dojo.data.api.Identity();
1104                         var passed = true;
1105
1106                         for(i in identityApi){
1107                                 if(i.toString().charAt(0) !== '_')
1108                                 {
1109                                         var member = identityApi[i];
1110                                         //Check that all the 'Read' defined functions exist on the test store.
1111                                         if(typeof member === "function"){
1112                                                 console.log("Looking at function: [" + i + "]");
1113                                                 var testStoreMember = testStore[i];
1114                                                 if(!(typeof testStoreMember === "function")){
1115                                                         passed = false;
1116                                                         break;
1117                                                 }
1118                                         }
1119                                 }
1120                         }
1121                         t.assertTrue(passed);
1122                 }
1123         ]
1124 );
1125
1126
1127 }