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