Debian Codegraph @

dojox/data/tests/stores/CsvStore.js

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