1 if(!dojo._hasResource["dojox.data.tests.stores.SnapLogicStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.data.tests.stores.SnapLogicStore"] = true;
3 dojo.provide("dojox.data.tests.stores.SnapLogicStore");
4 dojo.require("dojox.data.SnapLogicStore");
5 dojo.require("dojo.data.api.Read");
7 dojox.data.tests.stores.SnapLogicStore.pipelineUrl = dojo.moduleUrl("dojox.data.tests", "stores/snap_pipeline.php").toString();
8 dojox.data.tests.stores.SnapLogicStore.pipelineSize = 14;
9 dojox.data.tests.stores.SnapLogicStore.attributes = ["empno", "ename", "job", "hiredate", "sal", "comm", "deptno"];
11 dojox.data.tests.stores.SnapLogicStore.error = function(t, d, errData){
13 // The error callback function to be used for all of the tests.
17 doh.register("dojox.data.tests.stores.SnapLogicStore",
20 name: "ReadAPI: Fetch One",
21 timeout: 3000, //3 seconds.
22 runTest: function(t) {
24 // Simple test of a basic fetch from a SnapLogic pipeline
26 // Simple test of a basic fetch from a SnapLogic pipeline
28 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
30 var d = new doh.Deferred();
31 function onComplete(items, request){
32 t.assertEqual(1, items.length);
35 store.fetch({ count: 1,
36 onComplete: onComplete,
37 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, doh, d)
43 name: "ReadAPI: Fetch_10_Streaming",
44 timeout: 3000, //3 seconds.
45 runTest: function(t) {
47 // Simple test of a basic fetch on SnapLogic pipeline.
49 // Simple test of a basic fetch on SnapLogic pipeline.
51 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
53 var d = new doh.Deferred();
56 function onBegin(size, requestObj){
57 t.assertEqual(dojox.data.tests.stores.SnapLogicStore.pipelineSize, size);
59 function onItem(item, requestObj){
60 t.assertTrue(store.isItem(item));
63 function onComplete(items, request){
64 t.assertEqual(10, count);
65 t.assertTrue(items === null);
70 store.fetch({ onBegin: onBegin,
73 onComplete: onComplete,
74 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)
80 name: "ReadAPI: Fetch Zero",
81 timeout: 3000, //3 seconds.
82 runTest: function(t) {
84 // Try fetching 0 records. A count of the items in the pipeline should be returned.
86 // Try fetching 0 records. A count of the items in the pipeline should be returned.
88 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
90 var d = new doh.Deferred();
91 function onBegin(count, request){
92 t.assertEqual(dojox.data.tests.stores.SnapLogicStore.pipelineSize, count);
95 store.fetch({ count: 0,
97 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, doh, d)
103 name: "ReadAPI: Fetch_Paging",
104 timeout: 3000, //3 seconds.
105 runTest: function(t) {
107 // Test of multiple fetches on a single result. Paging, if you will.
109 // Test of multiple fetches on a single result. Paging, if you will.
111 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
113 var d = new doh.Deferred();
114 function dumpFirstFetch(items, request){
115 t.assertEqual(request.count, items.length);
116 request.start = dojox.data.tests.stores.SnapLogicStore.pipelineSize / 3;
118 request.onComplete = dumpSecondFetch;
119 store.fetch(request);
122 function dumpSecondFetch(items, request){
123 t.assertEqual(1, items.length);
125 request.count = dojox.data.tests.stores.SnapLogicStore.pipelineSize / 2;
126 request.onComplete = dumpThirdFetch;
127 store.fetch(request);
130 function dumpThirdFetch(items, request){
131 t.assertEqual(request.count, items.length);
132 request.count = dojox.data.tests.stores.SnapLogicStore.pipelineSize * 2;
133 request.onComplete = dumpFourthFetch;
134 store.fetch(request);
137 function dumpFourthFetch(items, request){
138 t.assertEqual(dojox.data.tests.stores.SnapLogicStore.pipelineSize, items.length);
139 request.start = Math.floor(3 * dojox.data.tests.stores.SnapLogicStore.pipelineSize / 4);
140 request.count = dojox.data.tests.stores.SnapLogicStore.pipelineSize;
141 request.onComplete = dumpFifthFetch;
142 store.fetch(request);
145 function dumpFifthFetch(items, request){
146 t.assertEqual(dojox.data.tests.stores.SnapLogicStore.pipelineSize - request.start, items.length);
148 request.count = dojox.data.tests.stores.SnapLogicStore.pipelineSize * 10;
149 request.onComplete = dumpSixthFetch;
150 store.fetch(request);
153 function dumpSixthFetch(items, request){
154 t.assertEqual(dojox.data.tests.stores.SnapLogicStore.pipelineSize - request.start, items.length);
158 store.fetch({ count: 5,
159 onComplete: dumpFirstFetch,
160 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)});
165 name: "ReadAPI: getLabel",
166 timeout: 3000, //3 seconds
167 runTest: function(t) {
169 // Test that the label function returns undefined since it's not supported.
171 // Test that the label function returns undefined since it's not supported.
173 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
175 var d = new doh.Deferred();
176 function onComplete(items, request){
177 t.assertEqual(items.length, 1);
178 var label = store.getLabel(items[0]);
179 t.assertTrue(label === undefined);
182 store.fetch({ count: 1,
183 onComplete: onComplete,
184 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)
190 name: "ReadAPI: getLabelAttributes",
191 timeout: 3000, //3 seconds.
192 runTest: function(t) {
194 // Simple test of the getLabelAttributes returns null since it's not supported.
196 // Simple test of the getLabelAttributes returns null since it's not supported.
198 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
200 var d = new doh.Deferred();
201 function onComplete(items, request){
202 t.assertEqual(items.length, 1);
203 var labelList = store.getLabelAttributes(items[0]);
204 t.assertTrue(labelList === null);
207 store.fetch({ count: 1,
208 onComplete: onComplete,
209 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)
215 name: "ReadAPI: getValue",
216 timeout: 3000, //3 seconds.
217 runTest: function(t) {
219 // Simple test of the getValue function of the store.
221 // Simple test of the getValue function of the store.
222 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
224 var d = new doh.Deferred();
225 function completedAll(items){
226 t.assertEqual(1, items.length);
227 console.debug(items[0]);
228 t.assertTrue(store.getValue(items[0], "empno") === 7369);
229 t.assertTrue(store.getValue(items[0], "ename") === "SMITH,CLERK");
230 console.debug(store.getValue(items[0], "sal"));
231 t.assertTrue(store.getValue(items[0], "sal") == 800.00);
233 t.assertTrue(store.getValue(items[0], "deptno") === 20);
237 store.fetch({ count: 1,
238 onComplete: completedAll,
239 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)});
244 name: "ReadAPI: getValues",
245 timeout: 3000, //3 seconds.
246 runTest: function(t) {
248 // Simple test of the getValue function of the store.
250 // Simple test of the getValue function of the store.
251 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
253 var d = new doh.Deferred();
254 function completedAll(items){
255 t.assertEqual(1, items.length);
256 for(var i = 0; i < dojox.data.tests.stores.SnapLogicStore.attributes.length; ++i){
257 var values = store.getValues(items[0], dojox.data.tests.stores.SnapLogicStore.attributes[i]);
258 t.assertTrue(dojo.isArray(values));
259 t.assertTrue(values[0] === store.getValue(items[0], dojox.data.tests.stores.SnapLogicStore.attributes[i]));
264 store.fetch({ count: 1,
265 onComplete: completedAll,
266 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)});
271 name: "ReadAPI: isItem",
272 timeout: 3000, //3 seconds.
273 runTest: function(t) {
275 // Simple test of the isItem function of the store
277 // Simple test of the isItem function of the store
278 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
280 var d = new doh.Deferred();
281 function completedAll(items){
282 t.assertEqual(5, items.length);
283 for(var i=0; i < items.length; i++){
284 t.assertTrue(store.isItem(items[i]));
290 store.fetch({ count: 5,
291 onComplete: completedAll,
292 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)});
297 name: "ReadAPI: hasAttribute",
298 timeout: 3000, //3 seconds.
299 runTest: function(t) {
301 // Simple test of the hasAttribute function of the store
303 // Simple test of the hasAttribute function of the store
305 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
307 var d = new doh.Deferred();
308 function onComplete(items){
309 t.assertEqual(1, items.length);
310 t.assertTrue(items[0] !== null);
311 for(var i = 0; i < dojox.data.tests.stores.SnapLogicStore.attributes.length; ++i){
312 t.assertTrue(store.hasAttribute(items[0], dojox.data.tests.stores.SnapLogicStore.attributes[i]));
314 t.assertTrue(!store.hasAttribute(items[0], "Nothing"));
315 t.assertTrue(!store.hasAttribute(items[0], "Text"));
317 //Test that null attributes throw an exception
320 store.hasAttribute(items[0], null);
324 t.assertTrue(passed);
329 store.fetch({ count: 1,
330 onComplete: onComplete,
331 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)
337 name: "ReadAPI: containsValue",
338 timeout: 3000, //3 seconds.
339 runTest: function(t) {
341 // Simple test of the containsValue function of the store
343 // Simple test of the containsValue function of the store
345 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
347 var d = new doh.Deferred();
348 function onComplete(items){
349 t.assertEqual(1, items.length);
350 var value = store.getValue(items[0], "LastName");
351 t.assertTrue(store.containsValue(items[0], "LastName", value));
356 store.fetch({ count: 1,
357 onComplete: onComplete,
358 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)
364 name: "ReadAPI: getAttributes",
365 timeout: 3000, //3 seconds.
366 runTest: function(t) {
368 // Simple test of the getAttributes function of the store
370 // Simple test of the getAttributes function of the store
372 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
374 var d = new doh.Deferred();
375 function onComplete(items){
376 t.assertEqual(1, items.length);
378 var itemAttributes = store.getAttributes(items[0]);
379 t.assertEqual(dojox.data.tests.stores.SnapLogicStore.attributes.length, itemAttributes.length);
380 for(var i = 0; i < dojox.data.tests.stores.SnapLogicStore.attributes.length; ++i){
381 t.assertTrue(dojo.indexOf(itemAttributes, dojox.data.tests.stores.SnapLogicStore.attributes[i]) !== -1);
387 store.fetch({ count: 1,
388 onComplete: onComplete,
389 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)});
393 function testReadAPI_getFeatures(t){
395 // Simple test of the getFeatures function of the store
397 // Simple test of the getFeatures function of the store
399 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
401 var features = store.getFeatures();
403 for(var i in features){
404 t.assertEqual(i, "dojo.data.api.Read");
408 t.assertEqual(count, 1);
410 function testReadAPI_functionConformance(t){
412 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
414 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
416 var testStore = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
417 var readApi = new dojo.data.api.Read();
420 for(var i in readApi){
421 if(i.toString().charAt(0) !== '_'){
422 var member = readApi[i];
423 //Check that all the 'Read' defined functions exist on the test store.
424 if(typeof member === "function"){
425 var testStoreMember = testStore[i];
426 if(!(typeof testStoreMember === "function")){
433 t.assertTrue(passed);