Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.data.tests.stores.OpmlStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.data.tests.stores.OpmlStore"] = true;
3
dojo.provide("dojox.data.tests.stores.OpmlStore");
4
dojo.require("dojox.data.OpmlStore");
5
dojo.require("dojo.data.api.Read");
6
 
7
dojox.data.tests.stores.OpmlStore.getDatasource = function(filepath){
8
	//  summary:
9
	//		A simple helper function for getting the sample data used in each of the tests.
10
	//  description:
11
	//		A simple helper function for getting the sample data used in each of the tests.
12
 
13
	var dataSource = {};
14
	if(dojo.isBrowser){
15
		dataSource.url = dojo.moduleUrl("dojox.data.tests", filepath).toString();
16
	}else{
17
		// When running tests in Rhino, xhrGet is not available,
18
		// so we have the file data in the code below.
19
		switch(filepath){
20
			case "stores/geography.xml":
21
				var opmlData = "";
22
				opmlData += '<?xml version="1.0" encoding="ISO-8859-1"?>\n';
23
				opmlData += '	<opml version="1.0">\n';
24
				opmlData += '		<head>\n';
25
				opmlData += '			<title>geography.opml</title>\n';
26
				opmlData += '			<dateCreated>2006-11-10</dateCreated>\n';
27
				opmlData += '			<dateModified>2006-11-13</dateModified>\n';
28
				opmlData += '			<ownerName>Magellan, Ferdinand</ownerName>\n';
29
				opmlData += '		</head>\n';
30
				opmlData += '		<body>\n';
31
				opmlData += '			<outline text="Africa" type="continent">\n';
32
				opmlData += '				<outline text="Egypt" type="country"/>\n';
33
				opmlData += '				<outline text="Kenya" type="country">\n';
34
				opmlData += '					<outline text="Nairobi" type="city"/>\n';
35
				opmlData += '					<outline text="Mombasa" type="city"/>\n';
36
				opmlData += '				</outline>\n';
37
				opmlData += '				<outline text="Sudan" type="country">\n';
38
				opmlData += '					<outline text="Khartoum" type="city"/>\n';
39
				opmlData += '				</outline>\n';
40
				opmlData += '			</outline>\n';
41
				opmlData += '			<outline text="Asia" type="continent">\n';
42
				opmlData += '				<outline text="China" type="country"/>\n';
43
				opmlData += '				<outline text="India" type="country"/>\n';
44
				opmlData += '				<outline text="Russia" type="country"/>\n';
45
				opmlData += '				<outline text="Mongolia" type="country"/>\n';
46
				opmlData += '			</outline>\n';
47
				opmlData += '			<outline text="Australia" type="continent" population="21 million">\n';
48
				opmlData += '				<outline text="Australia" type="country" population="21 million"/>\n';
49
				opmlData += '			</outline>\n';
50
				opmlData += '			<outline text="Europe" type="continent">\n';
51
				opmlData += '				<outline text="Germany" type="country"/>\n';
52
				opmlData += '				<outline text="France" type="country"/>\n';
53
				opmlData += '				<outline text="Spain" type="country"/>\n';
54
				opmlData += '				<outline text="Italy" type="country"/>\n';
55
				opmlData += '			</outline>\n';
56
				opmlData += '			<outline text="North America" type="continent">\n';
57
				opmlData += '				<outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km">\n';
58
				opmlData += '					<outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC"/>\n';
59
				opmlData += '					<outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC"/>\n';
60
				opmlData += '				</outline>\n';
61
				opmlData += '				<outline text="Canada" type="country" population="33 million" area="9,984,670 sq km">\n';
62
				opmlData += '					<outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC"/>\n';
63
				opmlData += '					<outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC"/>\n';
64
				opmlData += '				</outline>\n';
65
				opmlData += '				<outline text="United States of America" type="country"/>\n';
66
				opmlData += '			</outline>\n';
67
				opmlData += '			<outline text="South America" type="continent">\n';
68
				opmlData += '				<outline text="Brazil" type="country" population="186 million"/>\n';
69
				opmlData += '				<outline text="Argentina" type="country" population="40 million"/>\n';
70
				opmlData += '			</outline>\n';
71
				opmlData += '		</body>\n';
72
				opmlData += '	</opml>\n';
73
				break;
74
			case "stores/geography_withspeciallabel.xml":
75
				var opmlData = "";
76
				opmlData += '<?xml version="1.0" encoding="ISO-8859-1"?>\n';
77
				opmlData += '<opml version="1.0">\n';
78
				opmlData += '	<head>\n';
79
				opmlData += '		<title>geography.opml</title>\n';
80
				opmlData += '		<dateCreated>2006-11-10</dateCreated>\n';
81
				opmlData += '		<dateModified>2006-11-13</dateModified>\n';
82
				opmlData += '		<ownerName>Magellan, Ferdinand</ownerName>\n';
83
				opmlData += '	</head>\n';
84
				opmlData += '	<body>\n';
85
				opmlData += '		<outline text="Africa" type="continent" label="Continent/Africa">\n';
86
				opmlData += '			<outline text="Egypt" type="country" label="Country/Egypt"/>\n';
87
				opmlData += '			<outline text="Kenya" type="country" label="Country/Kenya">\n';
88
				opmlData += '				<outline text="Nairobi" type="city" label="City/Nairobi"/>\n';
89
				opmlData += '				<outline text="Mombasa" type="city" label="City/Mombasa"/>\n';
90
				opmlData += '			</outline>\n';
91
				opmlData += '			<outline text="Sudan" type="country" label="Country/Sudan">\n';
92
				opmlData += '				<outline text="Khartoum" type="city" label="City/Khartoum"/>\n';
93
				opmlData += '			</outline>\n';
94
				opmlData += '		</outline>\n';
95
				opmlData += '		<outline text="Asia" type="continent" label="Continent/Asia">\n';
96
				opmlData += '			<outline text="China" type="country" label="Country/China"/>\n';
97
				opmlData += '			<outline text="India" type="country" label="Country/India"/>\n';
98
				opmlData += '			<outline text="Russia" type="country" label="Country/Russia"/>\n';
99
				opmlData += '			<outline text="Mongolia" type="country" label="Country/Mongolia"/>\n';
100
				opmlData += '		</outline>\n';
101
				opmlData += '		<outline text="Australia" type="continent" population="21 million" label="Continent/Australia">\n';
102
				opmlData += '			<outline text="Australia" type="country" population="21 million" label="Country/Australia"/>\n';
103
				opmlData += '		</outline>\n';
104
				opmlData += '		<outline text="Europe" type="continent" label="Contintent/Europe">\n';
105
				opmlData += '			<outline text="Germany" type="country" label="Country/Germany"/>\n';
106
				opmlData += '			<outline text="France" type="country"  label="Country/France"/>\n';
107
				opmlData += '			<outline text="Spain" type="country"   label="Country/Spain"/>\n';
108
				opmlData += '			<outline text="Italy" type="country"   label="Country/Italy"/>\n';
109
				opmlData += '		</outline>\n';
110
				opmlData += '		<outline text="North America" type="continent" label="Continent/North America">\n';
111
				opmlData += '			<outline text="Mexico" type="country" population="108 million" area="1,972,550 sq km" label="Country/Mexico">\n';
112
				opmlData += '				<outline text="Mexico City" type="city" population="19 million" timezone="-6 UTC" label="City/Mexico City"/>\n';
113
				opmlData += '				<outline text="Guadalajara" type="city" population="4 million" timezone="-6 UTC"  label="City/Guadalajara"/>\n';
114
				opmlData += '			</outline>\n';
115
				opmlData += '			<outline text="Canada" type="country" population="33 million" area="9,984,670 sq km" label="Country/Canada">\n';
116
				opmlData += '				<outline text="Ottawa" type="city" population="0.9 million" timezone="-5 UTC"    label="City/Ottawa"/>\n';
117
				opmlData += '				<outline text="Toronto" type="city" population="2.5 million" timezone="-5 UTC"   label="City/Toronto"/>\n';
118
				opmlData += '			</outline>\n';
119
				opmlData += '			<outline text="United States of America" type="country" label="Country/United States of America"/>\n';
120
				opmlData += '		</outline>\n';
121
				opmlData += '		<outline text="South America" type="continent" label="Continent/South America">\n';
122
				opmlData += '			<outline text="Brazil" type="country" population="186 million" label="Country/Brazil"/>\n';
123
				opmlData += '			<outline text="Argentina" type="country" population="40 million" label="Country/Argentina"/>\n';
124
				opmlData += '		</outline>\n';
125
				opmlData += '	</body>\n';
126
				opmlData += '</opml>\n';
127
				break;
128
		}
129
		dataSource.data = opmlData;
130
	}
131
	return dataSource; //Object
132
}
133
 
134
dojox.data.tests.stores.OpmlStore.verifyItems = function(opmlStore, items, attribute, compareArray){
135
	//  summary:
136
	//		A helper function for validating that the items array is ordered
137
	//		the same as the compareArray
138
	if(items.length != compareArray.length){ return false; }
139
	for(var i = 0; i < items.length; i++){
140
		if(!(opmlStore.getValue(items[i], attribute) === compareArray[i])){
141
			return false; //Boolean
142
		}
143
	}
144
	return true; //Boolean
145
}
146
 
147
dojox.data.tests.stores.OpmlStore.error = function(t, d, errData){
148
	//  summary:
149
	//		The error callback function to be used for all of the tests.
150
	d.errback(errData);
151
}
152
 
153
doh.register("dojox.data.tests.stores.OpmlStore",
154
	[
155
		function testReadAPI_fetch_all(t){
156
			//	summary:
157
			//		Simple test of a basic fetch on OpmlStore.
158
			//	description:
159
			//		Simple test of a basic fetch on OpmlStore.
160
 
161
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
162
			var opmlStore = new dojox.data.OpmlStore(args);
163
 
164
			var d = new doh.Deferred();
165
			function completedAll(items){
166
				t.is(6, items.length);
167
				d.callback(true);
168
			}
169
 
170
			//Get everything...
171
			opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
172
			return d; //Object
173
		},
174
		function testReadAPI_fetch_one(t){
175
			//	summary:
176
			//		Simple test of a basic fetch on OpmlStore of a single item.
177
			//	description:
178
			//		Simple test of a basic fetch on OpmlStore of a single item.
179
 
180
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
181
			var opmlStore = new dojox.data.OpmlStore(args);
182
 
183
			var d = new doh.Deferred();
184
			function onComplete(items, request){
185
				t.is(1, items.length);
186
				d.callback(true);
187
			}
188
			opmlStore.fetch({ 	query: {text: "Asia"},
189
								onComplete: onComplete,
190
								onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
191
							});
192
			return d; //Object
193
		},
194
 
195
		function testReadAPI_fetch_one_Multiple(t){
196
			//	summary:
197
			//		Simple test of a basic fetch on OpmlStore of a single item.
198
			//	description:
199
			//		Simple test of a basic fetch on OpmlStore of a single item.
200
 
201
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
202
			var opmlStore = new dojox.data.OpmlStore(args);
203
 
204
			var d = new doh.Deferred();
205
			var done = [false,false];
206
			function onCompleteOne(items, request){
207
				done[0] = true;
208
				t.is(1, items.length);
209
				if(done[0] && done[1]){
210
					d.callback(true);
211
				}
212
			}
213
			function onCompleteTwo(items, request){
214
				done[1] = true;
215
				t.is(1, items.length);
216
				if(done[0] && done[1]){
217
					d.callback(true);
218
				}
219
			}
220
 
221
			opmlStore.fetch({ 	query: {text: "Asia"},
222
								onComplete: onCompleteOne,
223
								onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
224
							});
225
 
226
			opmlStore.fetch({ 	query: {text: "North America"},
227
								onComplete: onCompleteTwo,
228
								onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
229
							});
230
 
231
			return d; //Object
232
		},
233
 
234
		function testReadAPI_fetch_one_MultipleMixed(t){
235
			//	summary:
236
			//		Simple test of a basic fetch on OpmlStore of a single item mixing two fetch types.
237
			//	description:
238
			//		Simple test of a basic fetch on Cpmltore of a single item mixing two fetch types.
239
 
240
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
241
			var opmlStore = new dojox.data.OpmlStore(args);
242
 
243
			var d = new doh.Deferred();
244
 
245
			var done = [false, false];
246
			function onComplete(items, request){
247
				done[0] = true;
248
				t.is(1, items.length);
249
				console.log("Found item: " + opmlStore.getValue(items[0],"text") + " with identity: " + opmlStore.getIdentity(items[0]));
250
				t.is(0, opmlStore.getIdentity(items[0]));
251
				if(done[0] && done[1]){
252
					d.callback(true);
253
				}
254
			}
255
 
256
			function onItem(item){
257
				done[1] = true;
258
				t.assertTrue(item !== null);
259
				console.log("Found item: " + opmlStore.getValue(item,"text"));
260
				t.is('Egypt', opmlStore.getValue(item,"text")); //Should be the second node parsed, ergo id 1, first node is id 0.
261
				t.is(1, opmlStore.getIdentity(item));
262
				if(done[0] && done[1]){
263
					d.callback(true);
264
				}
265
			}
266
 
267
			opmlStore.fetch({ 	query: {text: "Africa"},
268
								onComplete: onComplete,
269
								onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
270
							});
271
 
272
            opmlStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
273
 
274
			return d; //Object
275
		},
276
 
277
		function testReadAPI_fetch_one_deep(t){
278
			//	summary:
279
			//		Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
280
			//	description:
281
			//		Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
282
 
283
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
284
			var opmlStore = new dojox.data.OpmlStore(args);
285
 
286
			var d = new doh.Deferred();
287
			function onComplete(items, request){
288
				t.is(1, items.length);
289
				d.callback(true);
290
			}
291
			opmlStore.fetch({ 	query: {text: "Mexico City"},
292
								queryOptions: {deep:true},
293
								onComplete: onComplete,
294
								onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
295
							});
296
			return d; //Object
297
		},
298
 
299
		function testReadAPI_fetch_one_deep_off(t){
300
			//	summary:
301
			//		Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
302
			//	description:
303
			//		Simple test of a basic fetch on OpmlStore of a single item that's nested down as a child item.
304
 
305
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
306
			var opmlStore = new dojox.data.OpmlStore(args);
307
 
308
			var d = new doh.Deferred();
309
			function onComplete(items, request){
310
				//Nothing should be found.
311
				t.is(0, items.length);
312
				d.callback(true);
313
			}
314
			opmlStore.fetch({ 	query: {text: "Mexico City"},
315
								onComplete: onComplete,
316
								onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
317
							});
318
			return d; //Object
319
		},
320
 
321
		function testReadAPI_fetch_all_streaming(t){
322
			//	summary:
323
			//		Simple test of a basic fetch on OpmlStore.
324
			//	description:
325
			//		Simple test of a basic fetch on OpmlStore.
326
 
327
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
328
			var opmlStore = new dojox.data.OpmlStore(args);
329
 
330
			var d = new doh.Deferred();
331
			count = 0;
332
 
333
			function onBegin(size, requestObj){
334
				t.is(6, size);
335
			}
336
			function onItem(item, requestObj){
337
				t.assertTrue(opmlStore.isItem(item));
338
				count++;
339
			}
340
			function onComplete(items, request){
341
				t.is(6, count);
342
				t.is(null, items);
343
				d.callback(true);
344
			}
345
 
346
			//Get everything...
347
			opmlStore.fetch({	onBegin: onBegin,
348
								onItem: onItem,
349
								onComplete: onComplete,
350
								onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
351
							});
352
			return d; //Object
353
		},
354
		function testReadAPI_fetch_paging(t){
355
			 //	summary:
356
			 //		Test of multiple fetches on a single result.  Paging, if you will.
357
			 //	description:
358
			 //		Test of multiple fetches on a single result.  Paging, if you will.
359
 
360
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
361
			var opmlStore = new dojox.data.OpmlStore(args);
362
 
363
			var d = new doh.Deferred();
364
			function dumpFirstFetch(items, request){
365
				t.is(5, items.length);
366
				request.start = 3;
367
				request.count = 1;
368
				request.onComplete = dumpSecondFetch;
369
				opmlStore.fetch(request);
370
			}
371
 
372
			function dumpSecondFetch(items, request){
373
				t.is(1, items.length);
374
				request.start = 0;
375
				request.count = 5;
376
				request.onComplete = dumpThirdFetch;
377
				opmlStore.fetch(request);
378
			}
379
 
380
			function dumpThirdFetch(items, request){
381
				t.is(5, items.length);
382
				request.start = 2;
383
				request.count = 20;
384
				request.onComplete = dumpFourthFetch;
385
				opmlStore.fetch(request);
386
			}
387
 
388
			function dumpFourthFetch(items, request){
389
				t.is(4, items.length);
390
				request.start = 9;
391
				request.count = 100;
392
				request.onComplete = dumpFifthFetch;
393
				opmlStore.fetch(request);
394
			}
395
 
396
			function dumpFifthFetch(items, request){
397
				t.is(0, items.length);
398
				request.start = 2;
399
				request.count = 20;
400
				request.onComplete = dumpSixthFetch;
401
				opmlStore.fetch(request);
402
			}
403
 
404
			function dumpSixthFetch(items, request){
405
				t.is(4, items.length);
406
			    d.callback(true);
407
			}
408
 
409
			function completed(items, request){
410
				t.is(6, items.length);
411
				request.start = 1;
412
				request.count = 5;
413
				request.onComplete = dumpFirstFetch;
414
				opmlStore.fetch(request);
415
			}
416
 
417
			opmlStore.fetch({onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
418
			return d; //Object
419
 
420
		},
421
		function testReadAPI_getLabel(t){
422
			//	summary:
423
			//		Simple test of the getLabel function against a store set that has a label defined.
424
			//	description:
425
			//		Simple test of the getLabel function against a store set that has a label defined.
426
 
427
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
428
			var opmlStore = new dojox.data.OpmlStore(args);
429
 
430
			var d = new doh.Deferred();
431
			function onComplete(items, request){
432
				t.assertEqual(items.length, 1);
433
				var label = opmlStore.getLabel(items[0]);
434
				t.assertTrue(label !== null);
435
				t.assertEqual("Asia", label);
436
				d.callback(true);
437
			}
438
			opmlStore.fetch({ 	query: {text: "Asia"},
439
						   		onComplete: onComplete,
440
						   		onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
441
						   	});
442
			return d;
443
		},
444
		function testReadAPI_getLabelAttributes(t){
445
			//	summary:
446
			//		Simple test of the getLabelAttributes function against a store set that has a label defined.
447
			//	description:
448
			//		Simple test of the getLabelAttributes function against a store set that has a label defined.
449
 
450
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
451
			var opmlStore = new dojox.data.OpmlStore(args);
452
 
453
			var d = new doh.Deferred();
454
			function onComplete(items, request){
455
				t.assertEqual(items.length, 1);
456
				var labelList = opmlStore.getLabelAttributes(items[0]);
457
				t.assertTrue(dojo.isArray(labelList));
458
				t.assertEqual("text", labelList[0]);
459
				d.callback(true);
460
			}
461
			opmlStore.fetch({ 	query: {text: "Asia"},
462
							   	onComplete: onComplete,
463
							   	onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
464
							});
465
			return d;
466
		},
467
 
468
		function testReadAPI_getLabel_nondefault(t){
469
			//	summary:
470
			//		Simple test of the getLabel function against a store set that has a label defined.
471
			//	description:
472
			//		Simple test of the getLabel function against a store set that has a label defined.
473
 
474
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography_withspeciallabel.xml");
475
			args.label="label";
476
			var opmlStore = new dojox.data.OpmlStore(args);
477
 
478
			var d = new doh.Deferred();
479
			function onComplete(items, request){
480
				t.assertEqual(items.length, 1);
481
				var label = opmlStore.getLabel(items[0]);
482
				t.assertTrue(label !== null);
483
				t.assertEqual("Continent/Asia", label);
484
				d.callback(true);
485
			}
486
			opmlStore.fetch({ 	query: {text: "Asia"},
487
						   		onComplete: onComplete,
488
						   		onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
489
						   	});
490
			return d;
491
		},
492
		function testReadAPI_getLabelAttributes_nondefault(t){
493
			//	summary:
494
			//		Simple test of the getLabelAttributes function against a store set that has a label defined.
495
			//	description:
496
			//		Simple test of the getLabelAttributes function against a store set that has a label defined.
497
 
498
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography_withspeciallabel.xml");
499
			args.label="label";
500
			var opmlStore = new dojox.data.OpmlStore(args);
501
 
502
			var d = new doh.Deferred();
503
			function onComplete(items, request){
504
				t.assertEqual(items.length, 1);
505
				var labelList = opmlStore.getLabelAttributes(items[0]);
506
				t.assertTrue(dojo.isArray(labelList));
507
				t.assertEqual("label", labelList[0]);
508
				d.callback(true);
509
			}
510
			opmlStore.fetch({ 	query: {text: "Asia"},
511
							   	onComplete: onComplete,
512
							   	onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
513
							});
514
			return d;
515
		},
516
 
517
		function testReadAPI_getValue(t){
518
			//	summary:
519
			//		Simple test of the getValue function of the store.
520
			//	description:
521
			//		Simple test of the getValue function of the store.
522
 
523
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
524
			var opmlStore = new dojox.data.OpmlStore(args);
525
 
526
			var d = new doh.Deferred();
527
			function completedAll(items){
528
				t.is(6, items.length);
529
 
530
				t.is("Africa", 		opmlStore.getValue(items[0],"text"));
531
				t.is("Asia", 		opmlStore.getValue(items[1],"text"));
532
				t.is("Australia", 	opmlStore.getValue(items[2],"text"));
533
				t.is("Europe", 		opmlStore.getValue(items[3],"text"));
534
				t.is("North America", 	opmlStore.getValue(items[4],"text"));
535
				t.is("South America",	opmlStore.getValue(items[5],"text"));
536
 
537
				t.is("continent", 	opmlStore.getValue(items[1],"type"));
538
				t.is("21 million", 	opmlStore.getValue(items[2],"population"));
539
 
540
				var firstChild = opmlStore.getValue(items[4],"children");
541
				t.assertTrue(opmlStore.isItem(firstChild));
542
				t.is("Mexico", 		opmlStore.getValue(firstChild,"text"));
543
				t.is("country", 	opmlStore.getValue(firstChild,"type"));
544
				t.is("108 million", 	opmlStore.getValue(firstChild,"population"));
545
				t.is("1,972,550 sq km", opmlStore.getValue(firstChild,"area"));
546
 
547
				firstChild = opmlStore.getValue(firstChild,"children");
548
				t.assertTrue(opmlStore.isItem(firstChild));
549
				t.is("Mexico City", 	opmlStore.getValue(firstChild,"text"));
550
				t.is("city", 		opmlStore.getValue(firstChild,"type"));
551
				t.is("19 million", 	opmlStore.getValue(firstChild,"population"));
552
				t.is("-6 UTC", 		opmlStore.getValue(firstChild,"timezone"));
553
 
554
				d.callback(true);
555
			}
556
 
557
			//Get everything...
558
			opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
559
			return d; //Object
560
		},
561
		function testReadAPI_getValues(t){
562
			//	summary:
563
			//		Simple test of the getValues function of the store.
564
			//	description:
565
			//		Simple test of the getValues function of the store.
566
 
567
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
568
			var opmlStore = new dojox.data.OpmlStore(args);
569
 
570
			var d = new doh.Deferred();
571
			function completed(items){
572
				t.is(1, items.length);
573
 
574
				var children = opmlStore.getValues(items[0],"children");
575
				t.is(3, children.length);
576
				for(var i=0; i<children.length; i++){
577
					t.assertTrue(opmlStore.isItem(children[i]));
578
				}
579
 
580
				t.is("Mexico", 		opmlStore.getValues(children[0],"text")[0]);
581
				t.is("country", 	opmlStore.getValues(children[0],"type")[0]);
582
				t.is("108 million", 	opmlStore.getValues(children[0],"population")[0]);
583
				t.is("1,972,550 sq km", opmlStore.getValues(children[0],"area")[0]);
584
 
585
				t.is("Canada", 		opmlStore.getValues(children[1],"text")[0]);
586
				t.is("country", 	opmlStore.getValues(children[1],"type")[0]);
587
 
588
				children = opmlStore.getValues(children[1],"children");
589
				t.is(2, children.length);
590
				for(var i=0; i<children.length; i++){
591
					t.assertTrue(opmlStore.isItem(children[i]));
592
				}
593
				t.is("Ottawa", 	opmlStore.getValues(children[0],"text")[0]);
594
				t.is("Toronto", opmlStore.getValues(children[1],"text")[0]);
595
 
596
				d.callback(true);
597
			}
598
 
599
			//Get one item...
600
			opmlStore.fetch({	query: {text: "North America"},
601
								onComplete: completed,
602
								onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
603
			return d; //Object
604
		},
605
		function testReadAPI_isItem(t){
606
			//	summary:
607
			//		Simple test of the isItem function of the store
608
			//	description:
609
			//		Simple test of the isItem function of the store
610
 
611
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
612
			var opmlStore = new dojox.data.OpmlStore(args);
613
 
614
			var d = new doh.Deferred();
615
			function completedAll(items){
616
				t.is(6, items.length);
617
				for(var i=0; i<6; i++){
618
					t.assertTrue(opmlStore.isItem(items[i]));
619
				}
620
				t.assertTrue(!opmlStore.isItem({}));
621
				t.assertTrue(!opmlStore.isItem({ item: "not an item" }));
622
				t.assertTrue(!opmlStore.isItem("not an item"));
623
				t.assertTrue(!opmlStore.isItem(["not an item"]));
624
 
625
				d.callback(true);
626
			}
627
 
628
			//Get everything...
629
			opmlStore.fetch({ onComplete: completedAll, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
630
			return d; //Object
631
		},
632
		function testReadAPI_hasAttribute(t){
633
			//	summary:
634
			//		Simple test of the hasAttribute function of the store
635
			//	description:
636
			//		Simple test of the hasAttribute function of the store
637
 
638
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
639
			var opmlStore = new dojox.data.OpmlStore(args);
640
 
641
			var d = new doh.Deferred();
642
			function onComplete(items){
643
				t.is(1, items.length);
644
				t.assertTrue(items[0] !== null);
645
				t.assertTrue(opmlStore.hasAttribute(items[0], "text"));
646
				t.assertTrue(opmlStore.hasAttribute(items[0], "type"));
647
				t.assertTrue(!opmlStore.hasAttribute(items[0], "population"));
648
				t.assertTrue(!opmlStore.hasAttribute(items[0], "Nothing"));
649
				t.assertTrue(!opmlStore.hasAttribute(items[0], "Text"));
650
 
651
				//Test that null attributes throw an exception
652
				var passed = false;
653
				try{
654
					opmlStore.hasAttribute(items[0], null);
655
				}catch (e){
656
					passed = true;
657
				}
658
				t.assertTrue(passed);
659
 
660
				d.callback(true);
661
			}
662
 
663
			//Get one item...
664
			opmlStore.fetch({ 	query: {text: "Asia"},
665
								onComplete: onComplete,
666
								onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
667
							});
668
			return d; //Object
669
		},
670
		function testReadAPI_containsValue(t){
671
			//	summary:
672
			//		Simple test of the containsValue function of the store
673
			//	description:
674
			//		Simple test of the containsValue function of the store
675
 
676
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
677
			var opmlStore = new dojox.data.OpmlStore(args);
678
 
679
			var d = new doh.Deferred();
680
			function onComplete(items){
681
				t.is(1, items.length);
682
				t.assertTrue(items[0] !== null);
683
				t.assertTrue(opmlStore.containsValue(items[0], "text", "North America"));
684
				t.assertTrue(opmlStore.containsValue(items[0], "type", "continent"));
685
				t.assertTrue(!opmlStore.containsValue(items[0], "text", "America"));
686
				t.assertTrue(!opmlStore.containsValue(items[0], "Type", "continent"));
687
				t.assertTrue(!opmlStore.containsValue(items[0], "text", null));
688
 
689
				var children = opmlStore.getValues(items[0], "children");
690
				t.assertTrue(opmlStore.containsValue(items[0], "children", children[0]));
691
				t.assertTrue(opmlStore.containsValue(items[0], "children", children[1]));
692
				t.assertTrue(opmlStore.containsValue(items[0], "children", children[2]));
693
 
694
				//Test that null attributes throw an exception
695
				var passed = false;
696
				try{
697
					opmlStore.containsValue(items[0], null, "foo");
698
				}catch (e){
699
					passed = true;
700
				}
701
				t.assertTrue(passed);
702
 
703
				d.callback(true);
704
			}
705
 
706
			//Get one item...
707
			opmlStore.fetch({ 	query: {text: "North America"},
708
								onComplete: onComplete,
709
								onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)
710
							});
711
			return d; //Object
712
		},
713
		function testReadAPI_getAttributes(t){
714
			//	summary:
715
			//		Simple test of the getAttributes function of the store
716
			//	description:
717
			//		Simple test of the getAttributes function of the store
718
 
719
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
720
			var opmlStore = new dojox.data.OpmlStore(args);
721
 
722
			var d = new doh.Deferred();
723
			function onComplete(items){
724
				t.is(6, items.length);
725
				t.assertTrue(opmlStore.isItem(items[0]));
726
 
727
				var attributes = opmlStore.getAttributes(items[0]);
728
				t.is(3, attributes.length);
729
				for(var i = 0; i < attributes.length; i++){
730
					t.assertTrue((attributes[i] === "text" || attributes[i] === "type" || attributes[i] === "children"));
731
				}
732
 
733
				d.callback(true);
734
			}
735
 
736
			//Get everything...
737
			opmlStore.fetch({ onComplete: onComplete, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
738
			return d; //Object
739
		},
740
		function testReadAPI_getFeatures(t){
741
			//	summary:
742
			//		Simple test of the getFeatures function of the store
743
			//	description:
744
			//		Simple test of the getFeatures function of the store
745
 
746
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
747
			var opmlStore = new dojox.data.OpmlStore(args);
748
 
749
			var features = opmlStore.getFeatures();
750
			var count = 0;
751
			for(i in features){
752
				t.assertTrue((i === "dojo.data.api.Read") || (i === "dojo.data.api.Identity"));
753
				count++;
754
			}
755
			t.assertTrue(count === 2);
756
		},
757
		function testReadAPI_fetch_patternMatch0(t){
758
			//	summary:
759
			//		Function to test pattern matching of everything starting with Capital A
760
			//	description:
761
			//		Function to test pattern matching of everything starting with Capital A
762
 
763
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
764
			var opmlStore = new dojox.data.OpmlStore(args);
765
 
766
			var d = new doh.Deferred();
767
			function completed(items, request){
768
				t.is(3, items.length);
769
				var valueArray = [ "Africa", "Asia", "Australia"];
770
				t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", valueArray));
771
				d.callback(true);
772
			}
773
 
774
			opmlStore.fetch({query: {text: "A*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
775
			return d; //Object
776
		},
777
		function testReadAPI_fetch_patternMatch1(t){
778
			//	summary:
779
			//		Function to test pattern matching of everything with America in it.
780
			//	description:
781
			//		Function to test pattern matching of everything with America in it.
782
 
783
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
784
			var opmlStore = new dojox.data.OpmlStore(args);
785
 
786
			var d = new doh.Deferred();
787
			function completed(items, request){
788
				t.assertTrue(items.length === 2);
789
				var valueArray = [ "North America", "South America"];
790
				t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", valueArray));
791
				d.callback(true);
792
			}
793
 
794
			opmlStore.fetch({query: {text: "*America*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
795
			return d; //Object
796
		},
797
		function testReadAPI_fetch_patternMatch2(t){
798
			//	summary:
799
			//		Function to test exact pattern match
800
			//	description:
801
			//		Function to test exact pattern match
802
 
803
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
804
			var opmlStore = new dojox.data.OpmlStore(args);
805
 
806
			var d = new doh.Deferred();
807
			function completed(items, request){
808
				t.is(1, items.length);
809
				t.assertTrue(opmlStore.getValue(items[0], "text") === "Europe");
810
				d.callback(true);
811
			}
812
 
813
			opmlStore.fetch({query: {text: "Europe"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
814
			return d; //Object
815
		},
816
		function testReadAPI_fetch_patternMatch_caseInsensitive(t){
817
			//	summary:
818
			//		Function to test exact pattern match with case insensitivity set.
819
			//	description:
820
			//		Function to test exact pattern match with case insensitivity set.
821
 
822
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
823
			var opmlStore = new dojox.data.OpmlStore(args);
824
 
825
			var d = new doh.Deferred();
826
			function completed(items, request){
827
				t.is(1, items.length);
828
				t.assertTrue(opmlStore.getValue(items[0], "text") === "Asia");
829
				d.callback(true);
830
			}
831
 
832
			opmlStore.fetch({query: {text: "asia"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
833
			return d; //Object
834
		},
835
		function testReadAPI_fetch_patternMatch_caseSensitive(t){
836
			//	summary:
837
			//		Function to test exact pattern match with case sensitivity set.
838
			//	description:
839
			//		Function to test exact pattern match with case sensitivity set.
840
 
841
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
842
			var opmlStore = new dojox.data.OpmlStore(args);
843
 
844
			var d = new doh.Deferred();
845
			function completed(items, request){
846
				t.is(0, items.length);
847
				d.callback(true);
848
			}
849
 
850
			opmlStore.fetch({query: {text: "ASIA"}, queryOptions: {ignoreCase: false}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
851
			return d; //Object
852
		},
853
		function testReadAPI_fetch_sortAlphabetic(t){
854
			//	summary:
855
			//		Function to test sorting alphabetic ordering.
856
			//	description:
857
			//		Function to test sorting alphabetic ordering.
858
 
859
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
860
			var opmlStore = new dojox.data.OpmlStore(args);
861
 
862
			var d = new doh.Deferred();
863
			function completed(items, request){
864
				//Output should be in this order...
865
				var orderedArray = [ "Africa", "Asia", "Australia", "Europe", "North America", "South America"];
866
				t.is(6, items.length);
867
				t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
868
				d.callback(true);
869
			}
870
 
871
			var sortAttributes = [{attribute: "text"}];
872
			opmlStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
873
			return d; //Object
874
		},
875
		function testReadAPI_fetch_sortAlphabeticDescending(t){
876
			//	summary:
877
			//		Function to test sorting alphabetic ordering in descending mode.
878
			//	description:
879
			//		Function to test sorting alphabetic ordering in descending mode.
880
 
881
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
882
			var opmlStore = new dojox.data.OpmlStore(args);
883
 
884
			var d = new doh.Deferred();
885
			function completed(items, request){
886
				//Output should be in this order...
887
				var orderedArray = [ "South America", "North America", "Europe", "Australia", "Asia", "Africa"
888
					];
889
				t.is(6, items.length);
890
				t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
891
				d.callback(true);
892
			}
893
 
894
			var sortAttributes = [{attribute: "text", descending: true}];
895
			opmlStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
896
			return d; //Object
897
		},
898
		function testReadAPI_fetch_sortAlphabeticWithCount(t){
899
			//	summary:
900
			//		Function to test sorting numerically in descending order, returning only a specified number of them.
901
			//	description:
902
			//		Function to test sorting numerically in descending order, returning only a specified number of them.
903
 
904
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
905
			var opmlStore = new dojox.data.OpmlStore(args);
906
 
907
			var d = new doh.Deferred();
908
			function completed(items, request){
909
				//Output should be in this order...
910
				var orderedArray = [ "South America", "North America", "Europe", "Australia"
911
					];
912
				t.is(4, items.length);
913
				t.assertTrue(dojox.data.tests.stores.OpmlStore.verifyItems(opmlStore, items, "text", orderedArray));
914
				d.callback(true);
915
			}
916
 
917
			var sortAttributes = [{attribute: "text", descending: true}];
918
			opmlStore.fetch({sort: sortAttributes,
919
							count: 4,
920
							onComplete: completed,
921
							onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
922
			return d; //Object
923
		},
924
		function testReadAPI_functionConformance(t){
925
			//	summary:
926
			//		Simple test read API conformance.  Checks to see all declared functions are actual functions on the instances.
927
			//	description:
928
			//		Simple test read API conformance.  Checks to see all declared functions are actual functions on the instances.
929
 
930
			var testStore = new dojox.data.OpmlStore(dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml"));
931
			var readApi = new dojo.data.api.Read();
932
			var passed = true;
933
 
934
			for(i in readApi){
935
				if(i.toString().charAt(0) !== '_')
936
				{
937
					var member = readApi[i];
938
					//Check that all the 'Read' defined functions exist on the test store.
939
					if(typeof member === "function"){
940
						var testStoreMember = testStore[i];
941
						if(!(typeof testStoreMember === "function")){
942
							passed = false;
943
							break;
944
						}
945
					}
946
				}
947
			}
948
			t.assertTrue(passed);
949
		},
950
		function testIdentityAPI_fetchItemByIdentity(t){
951
			//	summary:
952
			//		Simple test of the fetchItemByIdentity function of the store.
953
			//	description:
954
			//		Simple test of the fetchItemByIdentity function of the store.
955
 
956
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
957
			var opmlStore = new dojox.data.OpmlStore(args);
958
 
959
			var d = new doh.Deferred();
960
			function onItem(item){
961
				t.assertTrue(item !== null);
962
				d.callback(true);
963
			}
964
            opmlStore.fetchItemByIdentity({identity: "1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
965
			return d;
966
		},
967
 
968
		function testIdentityAPI_fetchItemByIdentity_bad1(t){
969
			//	summary:
970
			//		Simple test of the fetchItemByIdentity function of the store.
971
			//	description:
972
			//		Simple test of the fetchItemByIdentity function of the store.
973
 
974
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
975
			var opmlStore = new dojox.data.OpmlStore(args);
976
 
977
			var d = new doh.Deferred();
978
			function onItem(item){
979
				t.assertTrue(item === null);
980
				d.callback(true);
981
			}
982
            opmlStore.fetchItemByIdentity({identity: "200", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
983
			return d;
984
		},
985
		function testIdentityAPI_fetchItemByIdentity_bad2(t){
986
			//	summary:
987
			//		Simple test of the fetchItemByIdentity function of the store.
988
			//	description:
989
			//		Simple test of the fetchItemByIdentity function of the store.
990
 
991
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
992
			var opmlStore = new dojox.data.OpmlStore(args);
993
			var d = new doh.Deferred();
994
			function onItem(item){
995
				t.assertTrue(item === null);
996
				d.callback(true);
997
			}
998
            opmlStore.fetchItemByIdentity({identity: "-1", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
999
			return d;
1000
		},
1001
		function testIdentityAPI_fetchItemByIdentity_bad3(t){
1002
			//	summary:
1003
			//		Simple test of the fetchItemByIdentity function of the store.
1004
			//	description:
1005
			//		Simple test of the fetchItemByIdentity function of the store.
1006
 
1007
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
1008
			var opmlStore = new dojox.data.OpmlStore(args);
1009
			var d = new doh.Deferred();
1010
			function onItem(item){
1011
				t.assertTrue(item === null);
1012
				d.callback(true);
1013
			}
1014
            opmlStore.fetchItemByIdentity({identity: "999999", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d)});
1015
			return d;
1016
		},
1017
		function testIdentityAPI_getIdentity(t){
1018
			//	summary:
1019
			//		Simple test of the fetchItemByIdentity function of the store.
1020
			//	description:
1021
			//		Simple test of the fetchItemByIdentity function of the store.
1022
 
1023
			var args = dojox.data.tests.stores.OpmlStore.getDatasource("stores/geography.xml");
1024
			var opmlStore = new dojox.data.OpmlStore(args);
1025
 
1026
			var d = new doh.Deferred();
1027
			function completed(items, request){
1028
				var passed = true;
1029
				for(var i = 0; i < items.length; i++){
1030
					console.log("Identity is: " + opmlStore.getIdentity(items[i]) + " count is : "+ i);
1031
					if(!(opmlStore.getIdentity(items[i]) == i)){
1032
						passed=false;
1033
						break;
1034
					}
1035
				}
1036
				t.assertTrue(passed);
1037
				d.callback(true);
1038
			}
1039
 
1040
			//Get everything...
1041
			opmlStore.fetch({ onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.OpmlStore.error, t, d), queryOptions: {deep: true}});
1042
			return d; //Object
1043
		},
1044
		function testIdentityAPI_functionConformance(t){
1045
			//	summary:
1046
			//		Simple test identity API conformance.  Checks to see all declared functions are actual functions on the instances.
1047
			//	description:
1048
			//		Simple test identity API conformance.  Checks to see all declared functions are actual functions on the instances.
1049
 
1050
			var testStore = new dojox.data.OpmlStore(dojox.data.tests.stores.CsvStore.getDatasource("stores/geography.xml"));
1051
			var identityApi = new dojo.data.api.Identity();
1052
			var passed = true;
1053
 
1054
			for(i in identityApi){
1055
				if(i.toString().charAt(0) !== '_')
1056
				{
1057
					var member = identityApi[i];
1058
					//Check that all the 'Read' defined functions exist on the test store.
1059
					if(typeof member === "function"){
1060
						console.log("Looking at function: [" + i + "]");
1061
						var testStoreMember = testStore[i];
1062
						if(!(typeof testStoreMember === "function")){
1063
							passed = false;
1064
							break;
1065
						}
1066
					}
1067
				}
1068
			}
1069
			t.assertTrue(passed);
1070
		}
1071
	]
1072
);
1073
 
1074
 
1075
}