Debian Codegraph @

dojox/data/tests/stores/SnapLogicStore.js

raw symbols SCIP
1 dojo.provide("dojox.data.tests.stores.SnapLogicStore");
2 dojo.require("dojox.data.SnapLogicStore");
3 dojo.require("dojo.data.api.Read");
4
5 dojox.data.tests.stores.SnapLogicStore.pipelineUrl = require.toUrl("dojox/data/tests/stores/snap_pipeline.php").toString();
6 dojox.data.tests.stores.SnapLogicStore.pipelineSize = 14;
7 dojox.data.tests.stores.SnapLogicStore.attributes = ["empno", "ename", "job", "hiredate", "sal", "comm", "deptno"];
8
9 dojox.data.tests.stores.SnapLogicStore.error = function(t, d, errData){
10 // summary:
11 // The error callback function to be used for all of the tests.
12 d.errback(errData);
13 };
14
15 doh.register("dojox.data.tests.stores.SnapLogicStore",
16 [
17 {
18 name: "ReadAPI: Fetch One",
19 timeout: 3000, //3 seconds.
20 runTest: function(t) {
21 // summary:
22 // Simple test of a basic fetch from a SnapLogic pipeline
23 // description:
24 // Simple test of a basic fetch from a SnapLogic pipeline
25
26 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
27
28 var d = new doh.Deferred();
29 function onComplete(items, request){
30 t.assertEqual(1, items.length);
31 d.callback(true);
32 }
33 store.fetch({ count: 1,
34 onComplete: onComplete,
35 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, doh, d)
36 });
37 return d; //Object
38 }
39 },
40 {
41 name: "ReadAPI: Fetch_10_Streaming",
42 timeout: 3000, //3 seconds.
43 runTest: function(t) {
44 // summary:
45 // Simple test of a basic fetch on SnapLogic pipeline.
46 // description:
47 // Simple test of a basic fetch on SnapLogic pipeline.
48
49 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
50
51 var d = new doh.Deferred();
52 count = 0;
53
54 function onBegin(size, requestObj){
55 t.assertEqual(dojox.data.tests.stores.SnapLogicStore.pipelineSize, size);
56 }
57 function onItem(item, requestObj){
58 t.assertTrue(store.isItem(item));
59 count++;
60 }
61 function onComplete(items, request){
62 t.assertEqual(10, count);
63 t.assertTrue(items === null);
64 d.callback(true);
65 }
66
67 //Get everything...
68 store.fetch({ onBegin: onBegin,
69 count: 10,
70 onItem: onItem,
71 onComplete: onComplete,
72 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)
73 });
74 return d; //Object
75 }
76 },
77 {
78 name: "ReadAPI: Fetch Zero",
79 timeout: 3000, //3 seconds.
80 runTest: function(t) {
81 // summary:
82 // Try fetching 0 records. A count of the items in the pipeline should be returned.
83 // description:
84 // Try fetching 0 records. A count of the items in the pipeline should be returned.
85
86 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
87
88 var d = new doh.Deferred();
89 function onBegin(count, request){
90 t.assertEqual(dojox.data.tests.stores.SnapLogicStore.pipelineSize, count);
91 d.callback(true);
92 }
93 store.fetch({ count: 0,
94 onBegin: onBegin,
95 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, doh, d)
96 });
97 return d; //Object
98 }
99 },
100 {
101 name: "ReadAPI: Fetch_Paging",
102 timeout: 3000, //3 seconds.
103 runTest: function(t) {
104 // summary:
105 // Test of multiple fetches on a single result. Paging, if you will.
106 // description:
107 // Test of multiple fetches on a single result. Paging, if you will.
108
109 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
110
111 var d = new doh.Deferred();
112 function dumpFirstFetch(items, request){
113 t.assertEqual(request.count, items.length);
114 request.start = dojox.data.tests.stores.SnapLogicStore.pipelineSize / 3;
115 request.count = 1;
116 request.onComplete = dumpSecondFetch;
117 store.fetch(request);
118 }
119
120 function dumpSecondFetch(items, request){
121 t.assertEqual(1, items.length);
122 request.start = 0;
123 request.count = dojox.data.tests.stores.SnapLogicStore.pipelineSize / 2;
124 request.onComplete = dumpThirdFetch;
125 store.fetch(request);
126 }
127
128 function dumpThirdFetch(items, request){
129 t.assertEqual(request.count, items.length);
130 request.count = dojox.data.tests.stores.SnapLogicStore.pipelineSize * 2;
131 request.onComplete = dumpFourthFetch;
132 store.fetch(request);
133 }
134
135 function dumpFourthFetch(items, request){
136 t.assertEqual(dojox.data.tests.stores.SnapLogicStore.pipelineSize, items.length);
137 request.start = Math.floor(3 * dojox.data.tests.stores.SnapLogicStore.pipelineSize / 4);
138 request.count = dojox.data.tests.stores.SnapLogicStore.pipelineSize;
139 request.onComplete = dumpFifthFetch;
140 store.fetch(request);
141 }
142
143 function dumpFifthFetch(items, request){
144 t.assertEqual(dojox.data.tests.stores.SnapLogicStore.pipelineSize - request.start, items.length);
145 request.start = 2;
146 request.count = dojox.data.tests.stores.SnapLogicStore.pipelineSize * 10;
147 request.onComplete = dumpSixthFetch;
148 store.fetch(request);
149 }
150
151 function dumpSixthFetch(items, request){
152 t.assertEqual(dojox.data.tests.stores.SnapLogicStore.pipelineSize - request.start, items.length);
153 d.callback(true);
154 }
155
156 store.fetch({ count: 5,
157 onComplete: dumpFirstFetch,
158 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)});
159 return d; //Object
160 }
161 },
162 {
163 name: "ReadAPI: getLabel",
164 timeout: 3000, //3 seconds
165 runTest: function(t) {
166 // summary:
167 // Test that the label function returns undefined since it's not supported.
168 // description:
169 // Test that the label function returns undefined since it's not supported.
170
171 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
172
173 var d = new doh.Deferred();
174 function onComplete(items, request){
175 t.assertEqual(items.length, 1);
176 var label = store.getLabel(items[0]);
177 t.assertTrue(label === undefined);
178 d.callback(true);
179 }
180 store.fetch({ count: 1,
181 onComplete: onComplete,
182 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)
183 });
184 return d;
185 }
186 },
187 {
188 name: "ReadAPI: getLabelAttributes",
189 timeout: 3000, //3 seconds.
190 runTest: function(t) {
191 // summary:
192 // Simple test of the getLabelAttributes returns null since it's not supported.
193 // description:
194 // Simple test of the getLabelAttributes returns null since it's not supported.
195
196 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
197
198 var d = new doh.Deferred();
199 function onComplete(items, request){
200 t.assertEqual(items.length, 1);
201 var labelList = store.getLabelAttributes(items[0]);
202 t.assertTrue(labelList === null);
203 d.callback(true);
204 }
205 store.fetch({ count: 1,
206 onComplete: onComplete,
207 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)
208 });
209 return d;
210 }
211 },
212 {
213 name: "ReadAPI: getValue",
214 timeout: 3000, //3 seconds.
215 runTest: function(t) {
216 // summary:
217 // Simple test of the getValue function of the store.
218 // description:
219 // Simple test of the getValue function of the store.
220 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
221
222 var d = new doh.Deferred();
223 function completedAll(items){
224 t.assertEqual(1, items.length);
225 console.debug(items[0]);
226 t.assertTrue(store.getValue(items[0], "empno") === 7369);
227 t.assertTrue(store.getValue(items[0], "ename") === "SMITH,CLERK");
228 console.debug(store.getValue(items[0], "sal"));
229 t.assertTrue(store.getValue(items[0], "sal") == 800.00);
230 console.debug(1);
231 t.assertTrue(store.getValue(items[0], "deptno") === 20);
232 d.callback(true);
233 }
234
235 store.fetch({ count: 1,
236 onComplete: completedAll,
237 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)});
238 return d;
239 }
240 },
241 {
242 name: "ReadAPI: getValues",
243 timeout: 3000, //3 seconds.
244 runTest: function(t) {
245 // summary:
246 // Simple test of the getValue function of the store.
247 // description:
248 // Simple test of the getValue function of the store.
249 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
250
251 var d = new doh.Deferred();
252 function completedAll(items){
253 t.assertEqual(1, items.length);
254 for(var i = 0; i < dojox.data.tests.stores.SnapLogicStore.attributes.length; ++i){
255 var values = store.getValues(items[0], dojox.data.tests.stores.SnapLogicStore.attributes[i]);
256 t.assertTrue(dojo.isArray(values));
257 t.assertTrue(values[0] === store.getValue(items[0], dojox.data.tests.stores.SnapLogicStore.attributes[i]));
258 }
259 d.callback(true);
260 }
261
262 store.fetch({ count: 1,
263 onComplete: completedAll,
264 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)});
265 return d;
266 }
267 },
268 {
269 name: "ReadAPI: isItem",
270 timeout: 3000, //3 seconds.
271 runTest: function(t) {
272 // summary:
273 // Simple test of the isItem function of the store
274 // description:
275 // Simple test of the isItem function of the store
276 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
277
278 var d = new doh.Deferred();
279 function completedAll(items){
280 t.assertEqual(5, items.length);
281 for(var i=0; i < items.length; i++){
282 t.assertTrue(store.isItem(items[i]));
283 }
284 d.callback(true);
285 }
286
287 //Get everything...
288 store.fetch({ count: 5,
289 onComplete: completedAll,
290 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)});
291 return d; //Object
292 }
293 },
294 {
295 name: "ReadAPI: hasAttribute",
296 timeout: 3000, //3 seconds.
297 runTest: function(t) {
298 // summary:
299 // Simple test of the hasAttribute function of the store
300 // description:
301 // Simple test of the hasAttribute function of the store
302
303 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
304
305 var d = new doh.Deferred();
306 function onComplete(items){
307 t.assertEqual(1, items.length);
308 t.assertTrue(items[0] !== null);
309 for(var i = 0; i < dojox.data.tests.stores.SnapLogicStore.attributes.length; ++i){
310 t.assertTrue(store.hasAttribute(items[0], dojox.data.tests.stores.SnapLogicStore.attributes[i]));
311 }
312 t.assertTrue(!store.hasAttribute(items[0], "Nothing"));
313 t.assertTrue(!store.hasAttribute(items[0], "Text"));
314
315 //Test that null attributes throw an exception
316 var passed = false;
317 try{
318 store.hasAttribute(items[0], null);
319 }catch (e){
320 passed = true;
321 }
322 t.assertTrue(passed);
323 d.callback(true);
324 }
325
326 //Get one item...
327 store.fetch({ count: 1,
328 onComplete: onComplete,
329 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)
330 });
331 return d; //Object
332 }
333 },
334 {
335 name: "ReadAPI: containsValue",
336 timeout: 3000, //3 seconds.
337 runTest: function(t) {
338 // summary:
339 // Simple test of the containsValue function of the store
340 // description:
341 // Simple test of the containsValue function of the store
342
343 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
344
345 var d = new doh.Deferred();
346 function onComplete(items){
347 t.assertEqual(1, items.length);
348 var value = store.getValue(items[0], "LastName");
349 t.assertTrue(store.containsValue(items[0], "LastName", value));
350 d.callback(true);
351 }
352
353 //Get one item...
354 store.fetch({ count: 1,
355 onComplete: onComplete,
356 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)
357 });
358 return d; //Object
359 }
360 },
361 {
362 name: "ReadAPI: getAttributes",
363 timeout: 3000, //3 seconds.
364 runTest: function(t) {
365 // summary:
366 // Simple test of the getAttributes function of the store
367 // description:
368 // Simple test of the getAttributes function of the store
369
370 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
371
372 var d = new doh.Deferred();
373 function onComplete(items){
374 t.assertEqual(1, items.length);
375
376 var itemAttributes = store.getAttributes(items[0]);
377 t.assertEqual(dojox.data.tests.stores.SnapLogicStore.attributes.length, itemAttributes.length);
378 for(var i = 0; i < dojox.data.tests.stores.SnapLogicStore.attributes.length; ++i){
379 t.assertTrue(dojo.indexOf(itemAttributes, dojox.data.tests.stores.SnapLogicStore.attributes[i]) !== -1);
380 }
381 d.callback(true);
382 }
383
384 //Get everything...
385 store.fetch({ count: 1,
386 onComplete: onComplete,
387 onError: dojo.partial(dojox.data.tests.stores.SnapLogicStore.error, t, d)});
388 return d; //Object
389 }
390 },
391 function testReadAPI_getFeatures(t){
392 // summary:
393 // Simple test of the getFeatures function of the store
394 // description:
395 // Simple test of the getFeatures function of the store
396
397 var store = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
398
399 var features = store.getFeatures();
400 var count = 0;
401 for(var i in features){
402 t.assertEqual(i, "dojo.data.api.Read");
403 count++;
404 }
405
406 t.assertEqual(count, 1);
407 },
408 function testReadAPI_functionConformance(t){
409 // summary:
410 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
411 // description:
412 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
413
414 var testStore = new dojox.data.SnapLogicStore({url: dojox.data.tests.stores.SnapLogicStore.pipelineUrl});
415 var readApi = new dojo.data.api.Read();
416 var passed = true;
417
418 for(var i in readApi){
419 if(i.toString().charAt(0) !== '_'){
420 var member = readApi[i];
421 //Check that all the 'Read' defined functions exist on the test store.
422 if(typeof member === "function"){
423 var testStoreMember = testStore[i];
424 if(!(typeof testStoreMember === "function")){
425 passed = false;
426 break;
427 }
428 }
429 }
430 }
431 t.assertTrue(passed);
432 }
433 ]
434 );