Debian Codegraph @

dojox/data/tests/stores/AtomReadStore.js

raw symbols SCIP
1 dojo.provide("dojox.data.tests.stores.AtomReadStore");
2 dojo.require("dojox.data.AtomReadStore");
3 dojo.require("dojo.data.api.Read");
4
5 dojox.data.tests.stores.AtomReadStore.getBlog1Store = function(){
6 return new dojox.data.AtomReadStore({url: require.toUrl("dojox/data/tests/stores/atom1.xml").toString()});
7 //return new dojox.data.AtomReadStore({url: "/sos/feeds/blog.php"});
8 };
9 /*
10 dojox.data.tests.stores.AtomReadStore.getBlog2Store = function(){
11 return new dojox.data.AtomReadStore({url: dojo.moduleUrl("dojox.data.tests", "stores/atom2.xml").toString()});
12 };
13 */
14 dojox.data.tests.stores.AtomReadStore.error = function(t, d, errData){
15 // summary:
16 // The error callback function to be used for all of the tests.
17
18 //console.log("In here.");
19 //console.trace();
20 d.errback(errData);
21 }
22
23 doh.register("dojox.data.tests.stores.AtomReadStore",
24 [
25 {
26 name: "ReadAPI: Fetch_One",
27 timeout: 5000, //1 second
28 runTest: function(t) {
29 // summary:
30 // Simple test of a basic fetch on AtomReadStore of a single item.
31 // description:
32 // Simple test of a basic fetch on AtomReadStore of a single item.
33
34 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
35
36 var d = new doh.Deferred();
37 function onComplete(items, request){
38 t.is(1, items.length);
39 d.callback(true);
40 }
41 atomStore.fetch({
42 query: {
43 },
44 count: 1,
45 onComplete: onComplete,
46 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, doh, d)
47 });
48 return d; //Object
49 }
50 },
51 {
52 name: "ReadAPI: Fetch_5_Streaming",
53 timeout: 5000, //1 second.
54 runTest: function(t) {
55 // summary:
56 // Simple test of a basic fetch on AtomReadStore.
57 // description:
58 // Simple test of a basic fetch on AtomReadStore.
59 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
60
61 var d = new doh.Deferred();
62 var count = 0;
63
64 function onItem(item, requestObj){
65 t.assertTrue(atomStore.isItem(item));
66 count++;
67 }
68 function onComplete(items, request){
69 t.is(5, count);
70
71 t.is(null, items);
72 d.callback(true);
73 }
74 //Get everything...
75 atomStore.fetch({
76 query: {
77 },
78 onBegin: null,
79 count: 5,
80 onItem: onItem,
81 onComplete: onComplete,
82 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
83 });
84 return d; //Object
85 }
86 },
87 {
88 name: "ReadAPI: Fetch_Paging",
89 timeout: 5000, //1 second.
90 runTest: function(t) {
91 // summary:
92 // Test of multiple fetches on a single result. Paging, if you will.
93 // description:
94 // Test of multiple fetches on a single result. Paging, if you will.
95
96 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
97 var d = new doh.Deferred();
98
99 function dumpFirstFetch(items, request){
100 t.is(5, items.length);
101 request.start = 3;
102 request.count = 1;
103 request.onComplete = dumpSecondFetch;
104 atomStore.fetch(request);
105 }
106
107 function dumpSecondFetch(items, request){
108 console.log("dumpSecondFetch: got "+items.length);
109 t.is(1, items.length);
110 request.start = 0;
111 request.count = 5;
112 request.onComplete = dumpThirdFetch;
113 atomStore.fetch(request);
114 }
115
116 function dumpThirdFetch(items, request){
117 console.log("dumpThirdFetch: got "+items.length);
118 t.is(5, items.length);
119 request.start = 2;
120 request.count = 18;
121 request.onComplete = dumpFourthFetch;
122 atomStore.fetch(request);
123 }
124
125 function dumpFourthFetch(items, request){
126 console.log("dumpFourthFetch: got "+items.length);
127 t.is(18, items.length);
128 request.start = 5;
129 request.count = 11;
130 request.onComplete = dumpFifthFetch;
131 atomStore.fetch(request);
132 }
133
134 function dumpFifthFetch(items, request){
135 console.log("dumpFifthFetch: got "+items.length);
136 t.is(11, items.length);
137 request.start = 4;
138 request.count = 16;
139 request.onComplete = dumpSixthFetch;
140 atomStore.fetch(request);
141 }
142
143 function dumpSixthFetch(items, request){
144 console.log("dumpSixthFetch: got "+items.length);
145 t.is(16, items.length);
146 d.callback(true);
147 }
148
149 function completed(items, request){
150 t.is(7, items.length);
151 request.start = 1;
152 request.count = 5;
153 request.onComplete = dumpFirstFetch;
154 atomStore.fetch(request);
155 }
156 atomStore.fetch({
157 query: {
158 },
159 count: 7,
160 onComplete: completed,
161 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
162 });
163 return d; //Object
164 }
165 },
166 {
167 name: "ReadAPI: getLabel",
168 timeout: 5000, //1 second.
169 runTest: function(t) {
170 // summary:
171 // Simple test of the getLabel function against a store set that has a label defined.
172 // description:
173 // Simple test of the getLabel function against a store set that has a label defined.
174
175 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
176
177 var d = new doh.Deferred();
178 function onComplete(items, request){
179 t.assertEqual(items.length, 1);
180 var label = atomStore.getLabel(items[0]);
181 t.assertTrue(label !== null);
182 d.callback(true);
183 }
184 atomStore.fetch({
185 query: {
186 },
187 count: 1,
188 onComplete: onComplete,
189 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
190 });
191 return d;
192 }
193 },
194 {
195 name: "ReadAPI: getLabelAttributes",
196 timeout: 5000, //1 second
197 runTest: function(t) {
198 // summary:
199 // Simple test of the getLabelAttributes function against a store set that has a label defined.
200 // description:
201 // Simple test of the getLabelAttributes function against a store set that has a label defined.
202
203 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
204
205 var d = new doh.Deferred();
206 function onComplete(items, request){
207 t.assertEqual(items.length, 1);
208 var labelList = atomStore.getLabelAttributes(items[0]);
209 t.assertTrue(dojo.isArray(labelList));
210 t.assertEqual("title", labelList[0]);
211 d.callback(true);
212 }
213 atomStore.fetch({
214 query: {
215 },
216 count: 1,
217 onComplete: onComplete,
218 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
219 });
220 return d;
221
222 }
223 },
224 {
225 name: "ReadAPI: getValue",
226 timeout: 5000, //1 second
227 runTest: function(t) {
228 // summary:
229 // Simple test of the getValue function of the store.
230 // description:
231 // Simple test of the getValue function of the store.
232 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
233
234 var d = new doh.Deferred();
235 function completedAll(items){
236 t.is(1, items.length);
237 t.assertTrue(atomStore.getValue(items[0], "summary") !== null);
238 t.assertTrue(atomStore.getValue(items[0], "content") !== null);
239 t.assertTrue(atomStore.getValue(items[0], "published") !== null);
240 t.assertTrue(atomStore.getValue(items[0], "updated") !== null);
241 console.log("typeof updated = "+typeof(atomStore.getValue(items[0], "updated")));
242 t.assertTrue(atomStore.getValue(items[0], "updated").getFullYear);
243 d.callback(true);
244 }
245
246 //Get one item and look at it.
247 atomStore.fetch({
248 query: {
249 },
250 count: 1,
251 onComplete: completedAll,
252 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)});
253 return d; //Object
254 }
255 },
256 {
257 name: "ReadAPI: getValue_Failure",
258 timeout: 5000, //1 second
259 runTest: function(t) {
260 // summary:
261 // Simple test of the getValue function of the store.
262 // description:
263 // Simple test of the getValue function of the store.
264 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
265 var passed = false;
266 try{
267 var value = atomStore.getValue("NotAnItem", "foo");
268 }catch(e){
269 passed = true;
270 }
271 t.assertTrue(passed);
272 }
273 },
274 {
275 name: "ReadAPI: getValues",
276 timeout: 5000, //1 second
277 runTest: function(t) {
278 // summary:
279 // Simple test of the getValue function of the store.
280 // description:
281 // Simple test of the getValue function of the store.
282 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
283
284 var d = new doh.Deferred();
285 function completedAll(items){
286 t.is(1, items.length);
287 var summary = atomStore.getValues(items[0], "summary");
288 t.assertTrue(dojo.isArray(summary));
289
290 var content = atomStore.getValues(items[0], "content");
291 t.assertTrue(dojo.isArray(content));
292
293 var published = atomStore.getValues(items[0], "published");
294 t.assertTrue(dojo.isArray(published));
295
296 var updated = atomStore.getValues(items[0], "updated");
297 t.assertTrue(dojo.isArray(updated));
298 d.callback(true);
299 }
300 //Get one item and look at it.
301 atomStore.fetch({
302 query: {
303 },
304 count: 1,
305 onComplete: completedAll,
306 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error,
307 t,
308 d)
309 });
310 return d; //Object
311 }
312 },
313 {
314 name: "ReadAPI: getValues_Failure",
315 timeout: 5000, //1 second
316 runTest: function(t) {
317 // summary:
318 // Simple test of the getValue function of the store.
319 // description:
320 // Simple test of the getValue function of the store.
321 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
322 var passed = false;
323 try{
324 var value = atomStore.getValues("NotAnItem", "foo");
325 }catch(e){
326 passed = true;
327 }
328 t.assertTrue(passed);
329 }
330 },
331 {
332 name: "ReadAPI: isItem",
333 timeout: 5000, //1 second
334 runTest: function(t) {
335 // summary:
336 // Simple test of the isItem function of the store
337 // description:
338 // Simple test of the isItem function of the store
339 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
340
341 var d = new doh.Deferred();
342 function completedAll(items){
343 t.is(5, items.length);
344 for(var i=0; i < items.length; i++){
345 t.assertTrue(atomStore.isItem(items[i]));
346 }
347 d.callback(true);
348 }
349
350 //Get everything...
351 atomStore.fetch({
352 query: {
353 },
354 count: 5,
355 onComplete: completedAll,
356 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
357 });
358 return d; //Object
359 }
360 },
361 {
362 name: "ReadAPI: hasAttribute",
363 timeout: 5000, //1 second
364 runTest: function(t) {
365 // summary:
366 // Simple test of the hasAttribute function of the store
367 // description:
368 // Simple test of the hasAttribute function of the store
369
370 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
371
372 var d = new doh.Deferred();
373 function onComplete(items){
374 t.is(1, items.length);
375 t.assertTrue(items[0] !== null);
376 var count = 0;
377 console.log("hasAttribute");
378 t.assertTrue(atomStore.hasAttribute(items[0], "author"));
379 t.assertTrue(atomStore.hasAttribute(items[0], "published"));
380 t.assertTrue(atomStore.hasAttribute(items[0], "updated"));
381 t.assertTrue(atomStore.hasAttribute(items[0], "category"));
382 t.assertTrue(atomStore.hasAttribute(items[0], "id"));
383 t.assertTrue(!atomStore.hasAttribute(items[0], "foo"));
384 t.assertTrue(!atomStore.hasAttribute(items[0], "bar"));
385
386
387 t.assertTrue(atomStore.hasAttribute(items[0], "summary"));
388 t.assertTrue(atomStore.hasAttribute(items[0], "content"));
389 t.assertTrue(atomStore.hasAttribute(items[0], "title"));
390
391
392 var summary = atomStore.getValue(items[0], "summary");
393 var content = atomStore.getValue(items[0], "content");
394 var title = atomStore.getValue(items[0], "title");
395
396 t.assertTrue(summary && summary.text && summary.type == "html");
397 t.assertTrue(content && content.text && content.type == "html");
398 t.assertTrue(title && title.text && title.type == "html");
399
400 //Test that null attributes throw an exception
401 try{
402 atomStore.hasAttribute(items[0], null);
403 t.assertTrue(false);
404 }catch (e){
405
406 }
407 d.callback(true);
408 }
409
410 //Get one item...
411 atomStore.fetch({
412 query: {
413 },
414 count: 1,
415 onComplete: onComplete,
416 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
417 });
418 return d; //Object
419 }
420 },
421 {
422 name: "ReadAPI: containsValue",
423 timeout: 5000, //1 second
424 runTest: function(t) {
425 // summary:
426 // Simple test of the containsValue function of the store
427 // description:
428 // Simple test of the containsValue function of the store
429
430 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
431
432 var d = new doh.Deferred();
433 function onComplete(items){
434 t.is(1, items.length);
435
436 t.assertTrue(atomStore.containsValue(items[0], "id","http://shaneosullivan.wordpress.com/2008/01/22/using-aol-hosted-dojo-with-your-custom-code/"));
437
438 d.callback(true);
439 }
440
441 //Get one item...
442 atomStore.fetch({
443 query: {
444 },
445 count: 1,
446 onComplete: onComplete,
447 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
448 });
449 return d; //Object
450 }
451 },
452 {
453 name: "ReadAPI: getAttributes",
454 timeout: 5000, //1 second
455 runTest: function(t) {
456 // summary:
457 // Simple test of the getAttributes function of the store
458 // description:
459 // Simple test of the getAttributes function of the store
460
461 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
462
463 var d = new doh.Deferred();
464 function onComplete(items){
465 t.is(1, items.length);
466 t.assertTrue(atomStore.isItem(items[0]));
467
468 var attributes = atomStore.getAttributes(items[0]);
469 console.log("getAttributes 4: "+attributes.length);
470 t.is(10, attributes.length);
471 d.callback(true);
472 }
473
474 //Get everything...
475 atomStore.fetch({
476 query: {
477 },
478 count: 1,
479 onComplete: onComplete,
480 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
481 });
482 return d; //Object
483 }
484 },
485 {
486 name: "ReadAPI: fetch_Category",
487 timeout: 5000, //1 second.
488 runTest: function(t) {
489 // summary:
490 // Retrieve items from the store by category
491 // description:
492 // Simple test of the getAttributes function of the store
493
494 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
495
496 var d = new doh.Deferred();
497 function onComplete(items){
498 t.is(2, items.length);
499 t.assertTrue(atomStore.isItem(items[0]));
500 t.assertTrue(atomStore.isItem(items[1]));
501
502 var categories = atomStore.getValues(items[0], "category");
503 t.assertTrue(dojo.some(categories, function(category){
504 return category.term == "aol";
505 }));
506 categories = atomStore.getValues(items[1], "category");
507 t.assertTrue(dojo.some(categories, function(category){
508 return category.term == "aol";
509 }));
510
511 d.callback(true);
512 }
513
514 //Get everything...
515 atomStore.fetch({
516 query: {
517 category: "aol"
518 },
519 onComplete: onComplete,
520 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
521 });
522 return d; //Object
523 }
524 },
525 {
526 name: "ReadAPI: fetch_byID",
527 timeout: 5000, //1 second.
528 runTest: function(t) {
529 // summary:
530 // Retrieve items from the store by category
531 // description:
532 // Simple test of the getAttributes function of the store
533
534 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
535
536 var d = new doh.Deferred();
537 function onComplete(items){
538 console.log("getById: items.length="+items.length)
539 t.is(1, items.length);
540 t.assertTrue(atomStore.isItem(items[0]));
541
542 var title = atomStore.getValue(items[0], "title");
543 console.log("getById: title.text="+title.text)
544 t.assertTrue(title.text == "Dojo Grid has landed");
545
546 d.callback(true);
547 }
548
549 //Get everything...
550 atomStore.fetch({
551 query: {
552 id: "http://shaneosullivan.wordpress.com/2007/10/05/dojo-grid-has-landed/"
553 },
554 onComplete: onComplete,
555 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
556 });
557 return d; //Object
558 }
559 },
560 {
561 name: "ReadAPI: fetch_alternate",
562 timeout: 5000, //1 second.
563 runTest: function(t) {
564 // summary:
565 // Retrieve items from the store by category
566 // description:
567 // Simple test of the getAttributes function of the store
568
569 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
570
571 var d = new doh.Deferred();
572 function onComplete(items){
573 t.is(1, items.length);
574 t.assertTrue(atomStore.isItem(items[0]));
575
576 var alternate = atomStore.getValue(items[0], "alternate");
577 t.assertEqual(alternate.href, "http://shaneosullivan.wordpress.com/2007/10/05/dojo-grid-has-landed/");
578
579 d.callback(true);
580 }
581
582 //Get everything...
583 atomStore.fetch({
584 query: {
585 id: "http://shaneosullivan.wordpress.com/2007/10/05/dojo-grid-has-landed/"
586 },
587 onComplete: onComplete,
588 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
589 });
590 return d; //Object
591 }
592 },
593 function testReadAPI_getFeatures(t){
594 // summary:
595 // Simple test of the getFeatures function of the store
596 // description:
597 // Simple test of the getFeatures function of the store
598
599 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
600
601 var features = atomStore.getFeatures();
602 var count = 0;
603 for(i in features){
604 t.assertTrue((i === "dojo.data.api.Read"));
605 count++;
606 }
607 t.assertTrue(count === 1);
608 },
609 function testReadAPI_functionConformance(t){
610 // summary:
611 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
612 // description:
613 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
614
615 var testStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
616 var readApi = new dojo.data.api.Read();
617 var passed = true;
618
619 for(i in readApi){
620 if(i.toString().charAt(0) !== '_')
621 {
622 var member = readApi[i];
623 //Check that all the 'Read' defined functions exist on the test store.
624 if(typeof member === "function"){
625 console.log("Looking at function: [" + i + "]");
626 var testStoreMember = testStore[i];
627 if(!(typeof testStoreMember === "function")){
628 console.log("Problem with function: [" + i + "]. Got value: " + testStoreMember);
629 passed = false;
630 break;
631 }
632 }
633 }
634 }
635 t.assertTrue(passed);
636 }
637 ]
638 );