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");
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"});
12 dojox.data.tests.stores.AtomReadStore.getBlog2Store = function(){
13 return new dojox.data.AtomReadStore({url: dojo.moduleUrl("dojox.data.tests", "stores/atom2.xml").toString()});
16 dojox.data.tests.stores.AtomReadStore.error = function(t, d, errData){
18 // The error callback function to be used for all of the tests.
19 //console.log("In here.");
24 doh.register("dojox.data.tests.stores.AtomReadStore",
27 name: "ReadAPI: Fetch_One",
28 timeout: 5000, //1 second
29 runTest: function(t) {
31 // Simple test of a basic fetch on AtomReadStore of a single item.
33 // Simple test of a basic fetch on AtomReadStore of a single item.
35 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
37 var d = new doh.Deferred();
38 function onComplete(items, request){
39 t.is(1, items.length);
46 onComplete: onComplete,
47 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, doh, d)
53 name: "ReadAPI: Fetch_5_Streaming",
54 timeout: 5000, //1 second.
55 runTest: function(t) {
57 // Simple test of a basic fetch on AtomReadStore.
59 // Simple test of a basic fetch on AtomReadStore.
60 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
62 var d = new doh.Deferred();
65 function onItem(item, requestObj){
66 t.assertTrue(atomStore.isItem(item));
69 function onComplete(items, request){
82 onComplete: onComplete,
83 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
89 name: "ReadAPI: Fetch_Paging",
90 timeout: 5000, //1 second.
91 runTest: function(t) {
93 // Test of multiple fetches on a single result. Paging, if you will.
95 // Test of multiple fetches on a single result. Paging, if you will.
97 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
98 var d = new doh.Deferred();
100 function dumpFirstFetch(items, request){
101 t.is(5, items.length);
104 request.onComplete = dumpSecondFetch;
105 atomStore.fetch(request);
108 function dumpSecondFetch(items, request){
109 console.log("dumpSecondFetch: got "+items.length);
110 t.is(1, items.length);
113 request.onComplete = dumpThirdFetch;
114 atomStore.fetch(request);
117 function dumpThirdFetch(items, request){
118 console.log("dumpThirdFetch: got "+items.length);
119 t.is(5, items.length);
122 request.onComplete = dumpFourthFetch;
123 atomStore.fetch(request);
126 function dumpFourthFetch(items, request){
127 console.log("dumpFourthFetch: got "+items.length);
128 t.is(18, items.length);
131 request.onComplete = dumpFifthFetch;
132 atomStore.fetch(request);
135 function dumpFifthFetch(items, request){
136 console.log("dumpFifthFetch: got "+items.length);
137 t.is(11, items.length);
140 request.onComplete = dumpSixthFetch;
141 atomStore.fetch(request);
144 function dumpSixthFetch(items, request){
145 console.log("dumpSixthFetch: got "+items.length);
146 t.is(16, items.length);
150 function completed(items, request){
151 t.is(7, items.length);
154 request.onComplete = dumpFirstFetch;
155 atomStore.fetch(request);
161 onComplete: completed,
162 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
168 name: "ReadAPI: getLabel",
169 timeout: 5000, //1 second.
170 runTest: function(t) {
172 // Simple test of the getLabel function against a store set that has a label defined.
174 // Simple test of the getLabel function against a store set that has a label defined.
176 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
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);
189 onComplete: onComplete,
190 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
196 name: "ReadAPI: getLabelAttributes",
197 timeout: 5000, //1 second
198 runTest: function(t) {
200 // Simple test of the getLabelAttributes function against a store set that has a label defined.
202 // Simple test of the getLabelAttributes function against a store set that has a label defined.
204 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
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]);
218 onComplete: onComplete,
219 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
226 name: "ReadAPI: getValue",
227 timeout: 5000, //1 second
228 runTest: function(t) {
230 // Simple test of the getValue function of the store.
232 // Simple test of the getValue function of the store.
233 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
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);
247 //Get one item and look at it.
252 onComplete: completedAll,
253 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)});
258 name: "ReadAPI: getValue_Failure",
259 timeout: 5000, //1 second
260 runTest: function(t) {
262 // Simple test of the getValue function of the store.
264 // Simple test of the getValue function of the store.
265 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
268 var value = store.getValue("NotAnItem", foo);
272 t.assertTrue(passed);
276 name: "ReadAPI: getValues",
277 timeout: 5000, //1 second
278 runTest: function(t) {
280 // Simple test of the getValue function of the store.
282 // Simple test of the getValue function of the store.
283 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
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));
291 var content = atomStore.getValues(items[0], "content");
292 t.assertTrue(dojo.isArray(content));
294 var published = atomStore.getValues(items[0], "published");
295 t.assertTrue(dojo.isArray(published));
297 var updated = atomStore.getValues(items[0], "updated");
298 t.assertTrue(dojo.isArray(updated));
301 //Get one item and look at it.
306 onComplete: completedAll,
307 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error,
315 name: "ReadAPI: getValues_Failure",
316 timeout: 5000, //1 second
317 runTest: function(t) {
319 // Simple test of the getValue function of the store.
321 // Simple test of the getValue function of the store.
322 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
325 var value = store.getValues("NotAnItem", foo);
329 t.assertTrue(passed);
333 name: "ReadAPI: isItem",
334 timeout: 5000, //1 second
335 runTest: function(t) {
337 // Simple test of the isItem function of the store
339 // Simple test of the isItem function of the store
340 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
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]));
356 onComplete: completedAll,
357 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
363 name: "ReadAPI: hasAttribute",
364 timeout: 5000, //1 second
365 runTest: function(t) {
367 // Simple test of the hasAttribute function of the store
369 // Simple test of the hasAttribute function of the store
371 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
373 var d = new doh.Deferred();
374 function onComplete(items){
375 t.is(1, items.length);
376 t.assertTrue(items[0] !== null);
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"));
388 t.assertTrue(atomStore.hasAttribute(items[0], "summary"));
389 t.assertTrue(atomStore.hasAttribute(items[0], "content"));
390 t.assertTrue(atomStore.hasAttribute(items[0], "title"));
393 var summary = atomStore.getValue(items[0], "summary");
394 var content = atomStore.getValue(items[0], "content");
395 var title = atomStore.getValue(items[0], "title");
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");
401 //Test that null attributes throw an exception
403 atomStore.hasAttribute(items[0], null);
416 onComplete: onComplete,
417 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
423 name: "ReadAPI: containsValue",
424 timeout: 5000, //1 second
425 runTest: function(t) {
427 // Simple test of the containsValue function of the store
429 // Simple test of the containsValue function of the store
431 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
433 var d = new doh.Deferred();
434 function onComplete(items){
435 t.is(1, items.length);
437 t.assertTrue(atomStore.containsValue(items[0], "id","http://shaneosullivan.wordpress.com/2008/01/22/using-aol-hosted-dojo-with-your-custom-code/"));
447 onComplete: onComplete,
448 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
454 name: "ReadAPI: getAttributes",
455 timeout: 5000, //1 second
456 runTest: function(t) {
458 // Simple test of the getAttributes function of the store
460 // Simple test of the getAttributes function of the store
462 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
464 var d = new doh.Deferred();
465 function onComplete(items){
466 t.is(1, items.length);
467 t.assertTrue(atomStore.isItem(items[0]));
469 var attributes = atomStore.getAttributes(items[0]);
470 console.log("getAttributes 4: "+attributes.length);
471 t.is(10, attributes.length);
480 onComplete: onComplete,
481 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
487 name: "ReadAPI: fetch_Category",
488 timeout: 5000, //1 second.
489 runTest: function(t) {
491 // Retrieve items from the store by category
493 // Simple test of the getAttributes function of the store
495 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
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]));
503 var categories = atomStore.getValues(items[0], "category");
504 t.assertTrue(dojo.some(categories, function(category){
505 return category.term == "aol";
507 categories = atomStore.getValues(items[1], "category");
508 t.assertTrue(dojo.some(categories, function(category){
509 return category.term == "aol";
520 onComplete: onComplete,
521 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
527 name: "ReadAPI: fetch_byID",
528 timeout: 5000, //1 second.
529 runTest: function(t) {
531 // Retrieve items from the store by category
533 // Simple test of the getAttributes function of the store
535 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
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]));
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");
553 id: "http://shaneosullivan.wordpress.com/2007/10/05/dojo-grid-has-landed/"
555 onComplete: onComplete,
556 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
562 name: "ReadAPI: fetch_alternate",
563 timeout: 5000, //1 second.
564 runTest: function(t) {
566 // Retrieve items from the store by category
568 // Simple test of the getAttributes function of the store
570 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
572 var d = new doh.Deferred();
573 function onComplete(items){
574 t.is(1, items.length);
575 t.assertTrue(atomStore.isItem(items[0]));
577 var alternate = atomStore.getValue(items[0], "alternate");
578 t.assertEqual(alternate.href, "http://shaneosullivan.wordpress.com/2007/10/05/dojo-grid-has-landed/");
586 id: "http://shaneosullivan.wordpress.com/2007/10/05/dojo-grid-has-landed/"
588 onComplete: onComplete,
589 onError: dojo.partial(dojox.data.tests.stores.AtomReadStore.error, t, d)
594 function testReadAPI_getFeatures(t){
596 // Simple test of the getFeatures function of the store
598 // Simple test of the getFeatures function of the store
600 var atomStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
602 var features = atomStore.getFeatures();
605 t.assertTrue((i === "dojo.data.api.Read"));
608 t.assertTrue(count === 1);
610 function testReadAPI_functionConformance(t){
612 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
614 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
616 var testStore = dojox.data.tests.stores.AtomReadStore.getBlog1Store();
617 var readApi = new dojo.data.api.Read();
621 if(i.toString().charAt(0) !== '_')
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);
636 t.assertTrue(passed);