Debian Codegraph @

dojox/data/tests/stores/AppStore.js

raw symbols SCIP
1 dojo.provide("dojox.data.tests.stores.AppStore");
2 dojo.require("dojox.data.AppStore");
3 dojo.require("dojo.data.api.Read");
4 dojo.require("dojo.data.api.Write");
5 dojo.require("dojo.data.api.Identity");
6
7 dojox.data.tests.stores.AppStore.getStore = function(preventCache){
8 preventCache = preventCache?true:false;
9 return new dojox.data.AppStore({url: dojo.moduleUrl('dojox.atom.tests.widget', 'samplefeedEdit.xml').toString(), urlPreventCache: preventCache});
10 };
11
12 doh.register("dojox.data.tests.stores.AppStore",
13 [
14 function testReadAPI_fetch_all(t){
15 // summary:
16 // Simple test of fetching all items
17 // description:
18 // Simple test of fetching all items
19 var store = dojox.data.tests.stores.AppStore.getStore();
20
21 var d = new doh.Deferred();
22 function onComplete(items, request){
23 t.assertEqual(8, items.length);
24 d.callback(true);
25 }
26 function onError(error, request){
27 d.errback(error);
28 }
29 store.fetch({query:{title:"*"}, onComplete: onComplete, onError: onError});
30 return d; //Object
31 },
32 function testReadAPI_fetch_all_preventCache(t){
33 // summary:
34 // Simple test of fetching all items
35 // description:
36 // Simple test of fetching all items
37 var store = dojox.data.tests.stores.AppStore.getStore(true);
38
39 var d = new doh.Deferred();
40 function onComplete(items, request){
41 t.assertEqual(8, items.length);
42 d.callback(true);
43 }
44 function onError(error, request){
45 d.errback(error);
46 }
47 store.fetch({query:{title:"*"}, onComplete: onComplete, onError: onError});
48 return d; //Object
49 },
50 function testReadAPI_fetch_one(t){
51 // summary:
52 // Simple test of fetching one item
53 // description:
54 // Simple test of fetching one item
55 var store = dojox.data.tests.stores.AppStore.getStore();
56
57 var d = new doh.Deferred();
58 function onComplete(items, request){
59 t.assertEqual(1, items.length);
60 d.callback(true);
61 }
62 function onError(error, request){
63 d.errback(error);
64 }
65 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
66 return d; //Object
67 },
68 function testReadAPI_fetch_paging(t){
69 // summary:
70 // Simple test of paging
71 // description:
72 // Simple test of paging
73 var store = dojox.data.tests.stores.AppStore.getStore();
74
75 var d = new doh.Deferred();
76
77 function dumpFifthFetch(items, request){
78 t.assertEqual(0, items.length);
79 d.callback(true);
80 }
81
82 function dumpFourthFetch(items, request){
83 t.assertEqual(6, items.length);
84 request.start = 9;
85 request.count = 100;
86 request.onComplete = dumpFifthFetch;
87 store.fetch(request);
88 }
89
90 function dumpThirdFetch(items, request){
91 t.assertEqual(5, items.length);
92 request.start = 2;
93 request.count = 20;
94 request.onComplete = dumpFourthFetch;
95 store.fetch(request);
96 }
97
98 function dumpSecondFetch(items, request){
99 t.assertEqual(1, items.length);
100 request.start = 0;
101 request.count = 5;
102 request.onComplete = dumpThirdFetch;
103 store.fetch(request);
104 }
105
106 function dumpFirstFetch(items, request){
107 t.assertEqual(5, items.length);
108 request.start = 3;
109 request.count = 1;
110 request.onComplete = dumpSecondFetch;
111 store.fetch(request);
112 }
113
114 function completed(items, request){
115 t.assertEqual(8, items.length);
116 request.start = 1;
117 request.count = 5;
118 request.onComplete = dumpFirstFetch;
119 store.fetch(request);
120 }
121
122 function error(errData, request){
123 d.errback(errData);
124 }
125
126 store.fetch({onComplete: completed, onError: error});
127 return d; //Object
128 },
129 function testReadAPI_fetch_pattern0(t){
130 // summary:
131 // Simple test of fetching one item with ? pattern match
132 // description:
133 // Simple test of fetching one item with ? pattern match
134 var store = dojox.data.tests.stores.AppStore.getStore();
135 var d = new doh.Deferred();
136 function onComplete(items, request){
137 t.assertEqual(1, items.length);
138 d.callback(true);
139 }
140 function onError(error, request){
141 d.errback(error);
142 }
143 store.fetch({query:{title:"?est Editable Entry #1"}, onComplete: onComplete, onError: onError});
144 return d; //Object
145 },
146 function testReadAPI_fetch_pattern1(t){
147 // summary:
148 // Simple test of fetching one item with * pattern match
149 // description:
150 // Simple test of fetching one item with * pattern match
151 var store = dojox.data.tests.stores.AppStore.getStore();
152 var d = new doh.Deferred();
153 function onComplete(items, request){
154 t.assertEqual(8, items.length);
155 d.callback(true);
156 }
157 function onError(error, request){
158 d.errback(error);
159 }
160 store.fetch({query:{title:"*Test*"}, onComplete: onComplete, onError: onError});
161 return d; //Object
162 },
163 function testReadAPI_fetch_pattern_caseInsensitive(t){
164 // summary:
165 // Simple test of fetching one item with * pattern match case insensitive
166 // description:
167 // Simple test of fetching one item with * pattern match case insensitive
168 var store = dojox.data.tests.stores.AppStore.getStore();
169 var d = new doh.Deferred();
170 function onComplete(items, request){
171 t.assertEqual(8, items.length);
172 d.callback(true);
173 }
174 function onError(error, request){
175 d.errback(error);
176 }
177 store.fetch({query:{title:"*test*"}, queryOptions: {ignoreCase: true}, onComplete: onComplete, onError: onError});
178 return d; //Object
179 },
180
181 function testReadAPI_getLabel(t){
182 // summary:
183 // Simple test of the getLabel function against a store set that has a label defined.
184 // description:
185 // Simple test of the getLabel function against a store set that has a label defined.
186
187 var store = dojox.data.tests.stores.AppStore.getStore();
188
189 var d = new doh.Deferred();
190 function onComplete(items, request){
191 t.assertEqual(items.length, 1);
192 var label = store.getLabel(items[0]);
193 t.assertTrue(label !== null);
194 t.assertEqual("Test Editable Entry #1", label);
195 d.callback(true);
196 }
197 function onError(error, request){
198 d.errback(error);
199 }
200 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
201 return d;
202 },
203 function testReadAPI_getLabelAttributes(t){
204 // summary:
205 // Simple test of the getLabelAttributes function against a store set that has a label defined.
206 // description:
207 // Simple test of the getLabelAttributes function against a store set that has a label defined.
208
209 var store = dojox.data.tests.stores.AppStore.getStore();
210
211 var d = new doh.Deferred();
212 function onComplete(items, request){
213 t.assertEqual(items.length, 1);
214 var labelList = store.getLabelAttributes(items[0]);
215 t.assertTrue(dojo.isArray(labelList));
216 t.assertEqual("title", labelList[0]);
217 d.callback(true);
218 }
219 function onError(error, request){
220 d.errback(error);
221 }
222 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
223 return d;
224 },
225
226 function testReadAPI_getValue(t){
227 // summary:
228 // Simple test of the getValue API
229 // description:
230 // Simple test of the getValue API
231 var store = dojox.data.tests.stores.AppStore.getStore();
232
233 var d = new doh.Deferred();
234 function onComplete(items, request){
235 t.assertEqual(1, items.length);
236 var item = items[0];
237 t.assertTrue(store.hasAttribute(item,"id"));
238 t.assertEqual(store.getValue(item,"id"), "http://example.com/samplefeedEdit.xml/entry/10");
239 d.callback(true);
240 }
241 function onError(error, request){
242 d.errback(error);
243 }
244 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
245 return d; //Object
246 },
247 function testReadAPI_getValues(t){
248 // summary:
249 // Simple test of the getValues API
250 // description:
251 // Simple test of the getValues API
252 var store = dojox.data.tests.stores.AppStore.getStore();
253
254 var d = new doh.Deferred();
255 function onComplete(items, request){
256 t.assertEqual(1, items.length);
257 var item = items[0];
258 t.assertTrue(store.hasAttribute(item,"id"));
259 var values = store.getValues(item,"id");
260 t.assertEqual(1,values.length);
261 t.assertEqual(values[0], "http://example.com/samplefeedEdit.xml/entry/10");
262 d.callback(true);
263 }
264 function onError(error, request){
265 d.errback(error);
266 }
267 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
268 return d; //Object
269 },
270 function testReadAPI_isItem(t){
271 // summary:
272 // Simple test of the isItem API
273 // description:
274 // Simple test of the isItem API
275 var store = dojox.data.tests.stores.AppStore.getStore();
276
277 var d = new doh.Deferred();
278 function onComplete(items, request){
279 t.assertEqual(1, items.length);
280 var item = items[0];
281 t.assertTrue(store.isItem(item));
282 t.assertTrue(!store.isItem({}));
283 t.assertTrue(!store.isItem("Foo"));
284 t.assertTrue(!store.isItem(1));
285 d.callback(true);
286 }
287 function onError(error, request){
288 d.errback(error);
289 }
290 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
291 return d; //Object
292 },
293 function testReadAPI_isItem_multistore(t){
294 // summary:
295 // Simple test of the isItem API across multiple store instances.
296 // description:
297 // Simple test of the isItem API across multiple store instances.
298 var store1 = dojox.data.tests.stores.AppStore.getStore();
299 var store2 = dojox.data.tests.stores.AppStore.getStore();
300
301 var d = new doh.Deferred();
302
303 function onError(error, request){
304 d.errback(error);
305 }
306
307 function onComplete1(items, request){
308 t.assertEqual(1, items.length);
309 var item1 = items[0];
310 t.assertTrue(store1.isItem(item1));
311
312 function onComplete2(items, request){
313 t.assertEqual(1, items.length);
314 var item2 = items[0];
315 t.assertTrue(store2.isItem(item2));
316 t.assertTrue(!store1.isItem(item2));
317 t.assertTrue(!store2.isItem(item1));
318 d.callback(true);
319 }
320 store2.fetch({query:{title:"Test Entry #1"}, onComplete: onComplete2, onError: onError});
321 }
322 store1.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete1, onError: onError});
323 return d; //Object
324 },
325 function testReadAPI_hasAttribute(t){
326 // summary:
327 // Simple test of the hasAttribute API
328 // description:
329 // Simple test of the hasAttribute API
330 var store = dojox.data.tests.stores.AppStore.getStore();
331
332 var d = new doh.Deferred();
333
334 function onError(error, request){
335 d.errback(error);
336 }
337
338 function onComplete(items, request){
339 t.assertEqual(1, items.length);
340 var item = items[0];
341 t.assertTrue(store.hasAttribute(item,"title"));
342 t.assertTrue(store.hasAttribute(item,"summary"));
343 t.assertTrue(!store.hasAttribute(item,"bob"));
344 d.callback(true);
345 }
346 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
347 return d; //Object
348 },
349 function testReadAPI_containsValue(t){
350 // summary:
351 // Simple test of the containsValue API
352 // description:
353 // Simple test of the containsValue API
354 var store = dojox.data.tests.stores.AppStore.getStore();
355
356 var d = new doh.Deferred();
357 function onComplete(items, request){
358 t.assertEqual(1, items.length);
359 var item = items[0];
360 t.assertTrue(store.containsValue(item,"title", "Test Editable Entry #1"));
361 t.assertTrue(!store.containsValue(item,"title", "bob"));
362 d.callback(true);
363 }
364 function onError(error, request){
365 d.errback(error);
366 }
367 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
368 return d; //Object
369 },
370 function testReadAPI_sortDescending(t){
371 // summary:
372 // Simple test of the sorting API in descending order.
373 // description:
374 // Simple test of the sorting API in descending order.
375 var store = dojox.data.tests.stores.AppStore.getStore();
376
377 //Comparison is done as a string type (toString comparison), so the order won't be numeric
378 //So have to compare in 'alphabetic' order.
379 var order = [ "Test Entry #6",
380 "Test Entry #5",
381 "Test Entry #4",
382 "Test Entry #3",
383 "Test Entry #2",
384 "Test Entry #1",
385 "Test Editable Entry #2",
386 "Test Editable Entry #1"];
387
388 var d = new doh.Deferred();
389 function onComplete(items, request){
390 t.assertEqual(8, items.length);
391
392 for(var i = 0; i < items.length; i++){
393 t.assertEqual(order[i], store.getValue(items[i],"title"));
394 }
395 d.callback(true);
396 }
397 function onError(error, request){
398 d.errback(error);
399 }
400
401 var sortAttributes = [{attribute: "title", descending: true}];
402 store.fetch({query:{title:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
403 return d; //Object
404 },
405 function testReadAPI_sortAscending(t){
406 // summary:
407 // Simple test of the sorting API in ascending order.
408 // description:
409 // Simple test of the sorting API in ascending order.
410 var store = dojox.data.tests.stores.AppStore.getStore();
411
412 //Comparison is done as a string type (toString comparison), so the order won't be numeric
413 //So have to compare in 'alphabetic' order.
414 var order = [ "Test Editable Entry #1",
415 "Test Editable Entry #2",
416 "Test Entry #1",
417 "Test Entry #2",
418 "Test Entry #3",
419 "Test Entry #4",
420 "Test Entry #5",
421 "Test Entry #6"];
422
423 var d = new doh.Deferred();
424 function onComplete(items, request){
425 t.assertEqual(8, items.length);
426 var itemId = 1;
427 for(var i = 0; i < items.length; i++){
428 t.assertEqual(order[i], store.getValue(items[i],"title"));
429 }
430 d.callback(true);
431 }
432 function onError(error, request){
433 d.errback(error);
434 }
435
436 var sortAttributes = [{attribute: "title"}];
437 store.fetch({query:{title:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError});
438 return d; //Object
439 },
440 function testReadAPI_isItemLoaded(t){
441 // summary:
442 // Simple test of the isItemLoaded API
443 // description:
444 // Simple test of the isItemLoaded API
445 var store = dojox.data.tests.stores.AppStore.getStore();
446
447 var d = new doh.Deferred();
448 function onComplete(items, request){
449 t.assertEqual(1, items.length);
450 var item = items[0];
451 t.assertTrue(store.isItemLoaded(item));
452 d.callback(true);
453 }
454 function onError(error, request){
455 d.errback(error);
456 }
457 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
458 return d; //Object
459 },
460 function testReadAPI_getFeatures(t){
461 // summary:
462 // Simple test of the getFeatures function of the store
463 // description:
464 // Simple test of the getFeatures function of the store
465
466 var store = dojox.data.tests.stores.AppStore.getStore();
467 var features = store.getFeatures();
468 var count = 0;
469 for(var i in features){
470 t.assertTrue(( i === "dojo.data.api.Read" || i === "dojo.data.api.Write" || i === "dojo.data.api.Identity"));
471 count++;
472 }
473 t.assertEqual(3, count);
474 },
475 function testReadAPI_getAttributes(t){
476 // summary:
477 // Simple test of the getAttributes API
478 // description:
479 // Simple test of the getAttributes API
480 var store = dojox.data.tests.stores.AppStore.getStore();
481
482 var d = new doh.Deferred();
483 function onComplete(items, request){
484 t.assertEqual(1, items.length);
485 var item = items[0];
486 var attributes = store.getAttributes(item);
487 t.assertEqual(6,attributes.length);
488 d.callback(true);
489 }
490 function onError(error, request){
491 d.errback(error);
492 }
493 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
494 return d; //Object
495 },
496 function testWriteAPI_newItem(t){
497 // summary:
498 // Simple test of the newItem API
499 // description:
500 // Simple test of the newItem API
501 var store = dojox.data.tests.stores.AppStore.getStore();
502
503 store.newItem({title: "New entry", id: "12345", content: "This is test content", author: {name:"Bob"}});
504
505 var d = new doh.Deferred();
506 function onComplete(items, request){
507 t.assertEqual(1, items.length);
508 var item = items[0];
509 t.assertTrue(store.containsValue(item,"title", "New entry"));
510 t.assertTrue(store.containsValue(item, "content", "This is test content"));
511 d.callback(true);
512 }
513 function onError(error, request) {
514 d.errback(error);
515 }
516 store.fetch({query:{title:"New entry"}, onComplete: onComplete, onError: onError});
517 return d; //Object
518 },
519 function testWriteAPI_newItemInCallback(t){
520 // summary:
521 // Simple test of the newItem API
522 // description:
523 // Simple test of the newItem API
524 var store = dojox.data.tests.stores.AppStore.getStore();
525
526 store.newItem({title: "New entry", id: "12345", content: "This is test content", author: {name:"Bob"}});
527
528 var d = new doh.Deferred();
529
530 function onError(error, request){
531 d.errback(error);
532 }
533
534 function onComplete(items, request){
535 t.assertEqual(1, items.length);
536 var item = items[0];
537 t.assertTrue(store.containsValue(item,"title", "New entry"));
538 t.assertTrue(store.containsValue(item, "content", "This is test content"));
539
540 store.newItem({title: "New entry2", id: "12346", content: "This is test content", author: [{name:"Bob"}]});
541
542 function onComplete1(items, request){
543 t.assertEqual(1, items.length);
544 var item = items[0];
545 t.assertTrue(store.containsValue(item, "title", "New entry2"));
546 d.callback(true);
547 }
548
549 store.fetch({query:{title:"New entry2"}, onComplete: onComplete1, onError: onError});
550 }
551 store.fetch({query:{title:"New entry"}, onComplete: onComplete, onError: onError});
552 return d; //Object
553 },
554 function testWriteAPI_deleteItem(t){
555 // summary:
556 // Simple test of the deleteItem API
557 // description:
558 // Simple test of the deleteItem API
559 var store = dojox.data.tests.stores.AppStore.getStore();
560
561 var d = new doh.Deferred();
562
563 function onError(error, request){
564 d.errback(error);
565 }
566
567 function onComplete(items, request){
568 t.assertEqual(1, items.length);
569 var item = items[0];
570 t.assertTrue(store.containsValue(item,"title", "Test Editable Entry #1"));
571 store.deleteItem(item);
572
573 function onComplete1(items, request){
574 t.assertEqual(0, items.length);
575 d.callback(true);
576 }
577 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete1, onError: onError});
578 }
579 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
580 return d; //Object
581 },
582 function testWriteAPI_setValue(t){
583 // summary:
584 // Simple test of the setValue API
585 // description:
586 // Simple test of the setValue API
587 var store = dojox.data.tests.stores.AppStore.getStore();
588
589 var d = new doh.Deferred();
590 function onComplete(items, request){
591 t.assertEqual(1, items.length);
592 var item = items[0];
593 t.assertTrue(store.containsValue(item,"title", "Test Editable Entry #1"));
594 store.setValue(item, "title", "Edited title");
595 t.assertEqual(store.getValue(item,"title"), "Edited title");
596 d.callback(true);
597 }
598 function onError(error, request){
599 d.errback(error);
600 }
601 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
602 return d; //Object
603 },
604 function testWriteAPI_setValues(t){
605 // summary:
606 // Simple test of the setValues API
607 // description:
608 // Simple test of the setValues API
609 var store = dojox.data.tests.stores.AppStore.getStore();
610
611 var d = new doh.Deferred();
612 function onComplete(items, request){
613 t.assertEqual(1, items.length);
614 var item = items[0];
615 t.assertTrue(store.containsValue(item,"title", "Test Editable Entry #1"));
616 store.setValues(item, "author", [{name: "John"}, {name: "Bill", email:"[email protected]", uri:"http://example.com/bill"}]);
617 var values = store.getValues(item,"author");
618 t.assertEqual(values[0].name, "John");
619 t.assertEqual(values[1].name, "Bill");
620 t.assertEqual(values[1].email, "[email protected]");
621 t.assertEqual(values[1].uri, "http://example.com/bill");
622 d.callback(true);
623 }
624 function onError(error, request){
625 d.errback(error);
626 }
627 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
628 return d; //Object
629 },
630 function testWriteAPI_unsetAttribute(t){
631 // summary:
632 // Simple test of the unsetAttribute API
633 // description:
634 // Simple test of the unsetAttribute API
635 var store = dojox.data.tests.stores.AppStore.getStore();
636
637 var d = new doh.Deferred();
638 function onComplete(items, request){
639 t.assertEqual(1, items.length);
640 var item = items[0];
641 t.assertTrue(store.containsValue(item,"title", "Test Editable Entry #1"));
642 store.unsetAttribute(item,"title");
643 t.assertTrue(!store.hasAttribute(item,"title"));
644 t.assertTrue(store.isDirty(item));
645 d.callback(true);
646 }
647 function onError(error, request) {
648 d.errback(error);
649 }
650 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
651 return d; //Object
652 },
653 function testWriteAPI_isDirty(t){
654 // summary:
655 // Simple test of the isDirty API
656 // description:
657 // Simple test of the isDirty API
658 var store = dojox.data.tests.stores.AppStore.getStore();
659
660 var d = new doh.Deferred();
661 function onComplete(items, request){
662 t.assertEqual(1, items.length);
663 var item = items[0];
664 t.assertTrue(store.containsValue(item,"title", "Test Editable Entry #1"));
665 store.setValue(item, "title", "Edited title");
666 t.assertEqual(store.getValue(item,"title"), "Edited title");
667 t.assertTrue(store.isDirty(item));
668 d.callback(true);
669 }
670 function onError(error, request){
671 d.errback(error);
672 }
673 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
674 return d; //Object
675 },
676 function testWriteAPI_revert(t){
677 // summary:
678 // Simple test of the isDirty API
679 // description:
680 // Simple test of the isDirty API
681 var store = dojox.data.tests.stores.AppStore.getStore();
682
683 var d = new doh.Deferred();
684 function onError(error, request){
685 d.errback(error);
686 }
687 function onComplete(items, request){
688 t.assertEqual(1, items.length);
689 var item = items[0];
690 t.assertTrue(store.containsValue(item,"title", "Test Editable Entry #1"));
691 t.assertTrue(!store.isDirty(item));
692 store.setValue(item, "title", "Edited title");
693 t.assertEqual(store.getValue(item,"title"), "Edited title");
694 t.assertTrue(store.isDirty(item));
695 store.revert();
696
697 //Fetch again to see if it reset the state.
698 function onComplete1(items, request){
699 t.assertEqual(1, items.length);
700 var item = items[0];
701 t.assertTrue(store.containsValue(item,"title", "Test Editable Entry #1"));
702 d.callback(true);
703 }
704 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete1, onError: onError});
705 }
706 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
707 return d; //Object
708 },
709 function testWriteAPI_revert2(t){
710 // summary:
711 // Simple test of the revert API
712 // description:
713 // Simple test of the revert API
714 var store = dojox.data.tests.stores.AppStore.getStore();
715
716 var d = new doh.Deferred();
717 function onError(error, request){
718 d.errback(error);
719 }
720 function onComplete(items, request){
721 t.assertEqual(1, items.length);
722 var item = items[0];
723 t.assertTrue(store.containsValue(item,"title", "Test Editable Entry #1"));
724 store.deleteItem(item);
725
726 function onComplete1(items, request){
727 t.assertEqual(7, items.length);
728 store.newItem({title: "New entry", id: "12345", content: "This is test content", author: {name:"Bob"}});
729
730 function onComplete2(items, request){
731 t.assertEqual(1, items.length);
732 store.revert();
733
734 function onComplete3(items, request){
735 t.assertEqual(0, items.length);
736 d.callback(true);
737 }
738 store.fetch({query:{title:"New entry"}, onComplete: onComplete3, onError: onError});
739 }
740 store.fetch({query:{title:"New entry"}, onComplete: onComplete2, onError: onError});
741 }
742 store.fetch({query:{title:"*"}, onComplete: onComplete1, onError: onError});
743 }
744 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
745 return d; //Object
746 },
747
748 function testReadAPI_getIdentity(t){
749 // summary:
750 // Simple test of fetching the identity of an item.
751 // description:
752 // Simple test of fetching the identity of an item.
753 var store = dojox.data.tests.stores.AppStore.getStore();
754
755 var d = new doh.Deferred();
756 function onComplete(items, request){
757 t.assertEqual(1, items.length);
758 var id = store.getIdentity(items[0]);
759 t.assertEqual("http://example.com/samplefeedEdit.xml/entry/10",id);
760 d.callback(true);
761 }
762 function onError(error, request){
763 d.errback(error);
764 }
765 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
766 return d; //Object
767 },
768
769 function testReadAPI_getIdentityAttributes(t){
770 // summary:
771 // Simple test of fetching the identity attributes off an item,
772 // description:
773 // Simple test of fetching the identity attributes off an item,
774 var store = dojox.data.tests.stores.AppStore.getStore();
775
776 var d = new doh.Deferred();
777 function onComplete(items, request){
778 t.assertEqual(1, items.length);
779 var idAttrs = store.getIdentityAttributes(items[0]);
780 t.assertEqual(1, idAttrs.length);
781 t.assertEqual("id", idAttrs[0]);
782 d.callback(true);
783 }
784 function onError(error, request){
785 d.errback(error);
786 }
787 store.fetch({query:{title:"Test Editable Entry #1"}, onComplete: onComplete, onError: onError});
788 return d; //Object
789 },
790
791 function testReadAPI_fetchItemByIdentity(t){
792 // summary:
793 // Simple test of fetching one atom item through its identity
794 // description:
795 // Simple test of fetching one atom item through its identity
796 var store = dojox.data.tests.stores.AppStore.getStore();
797
798 var d = new doh.Deferred();
799 function onItem(item, request) {
800 var id = store.getIdentity(item);
801 t.assertEqual("http://example.com/samplefeedEdit.xml/entry/10",id);
802 d.callback(true);
803 }
804 function onError(error, request){
805 d.errback(error);
806 }
807 store.fetchItemByIdentity({identity: "http://example.com/samplefeedEdit.xml/entry/10", onItem: onItem, onError: onError});
808 return d; //Object
809 },
810
811 function testReadAPI_fetchItemByIdentity_fails(t){
812 // summary:
813 // Simple test of fetching one atom item through its identity fails correctly on no id match
814 // description:
815 // Simple test of fetching one atom item through its identity fails correctly on no id match
816 var store = dojox.data.tests.stores.AppStore.getStore();
817
818 var d = new doh.Deferred();
819 function onItem(item, request){
820 t.assertTrue(item === null);
821 d.callback(true);
822 }
823 function onError(error, request){
824 d.errback(error);
825 }
826 store.fetchItemByIdentity({identity: "http://example.com/samplefeedEdit.xml/entry/10/none", onItem: onItem, onError: onError});
827 return d; //Object
828 },
829
830 function testReadAPI_functionConformance(t){
831 // summary:
832 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
833 // description:
834 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
835 var testStore = dojox.data.tests.stores.AppStore.getStore();
836 var readApi = new dojo.data.api.Read();
837 var passed = true;
838
839 for(var i in readApi){
840 var member = readApi[i];
841 //Check that all the 'Read' defined functions exist on the test store.
842 if(typeof member === "function"){
843 var testStoreMember = testStore[i];
844 if(!(typeof testStoreMember === "function")){
845 console.log("Problem with function: [" + i + "]");
846 passed = false;
847 break;
848 }
849 }
850 }
851 t.assertTrue(passed);
852 },
853 function testWriteAPI_functionConformance(t){
854 // summary:
855 // Simple test write API conformance. Checks to see all declared functions are actual functions on the instances.
856 // description:
857 // Simple test write API conformance. Checks to see all declared functions are actual functions on the instances.
858 var testStore = dojox.data.tests.stores.AppStore.getStore();
859 var writeApi = new dojo.data.api.Write();
860 var passed = true;
861
862 for(var i in writeApi){
863 var member = writeApi[i];
864 //Check that all the 'Write' defined functions exist on the test store.
865 if(typeof member === "function"){
866 var testStoreMember = testStore[i];
867 if(!(typeof testStoreMember === "function")){
868 passed = false;
869 break;
870 }
871 }
872 }
873 t.assertTrue(passed);
874 },
875 function testIdentityAPI_functionConformance(t){
876 // summary:
877 // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
878 // description:
879 // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
880 var testStore = dojox.data.tests.stores.AppStore.getStore();
881 var identityApi = new dojo.data.api.Identity();
882 var passed = true;
883
884 for(var i in identityApi){
885 var member = identityApi[i];
886 //Check that all the 'Write' defined functions exist on the test store.
887 if(typeof member === "function"){
888 var testStoreMember = testStore[i];
889 if(!(typeof testStoreMember === "function")){
890 passed = false;
891 break;
892 }
893 }
894 }
895 t.assertTrue(passed);
896 }
897 ]
898 );