Debian Codegraph @

dojox/data/tests/stores/GoogleFeedStore.js

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