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