Debian Codegraph @

dojox/data/tests/stores/ServiceStore.js

raw symbols SCIP
1 dojo.provide("dojox.data.tests.stores.ServiceStore");
2 dojo.require("dojox.rpc.Service");
3 dojo.require("dojox.rpc.Rest");
4 //dojo.require("dojox.data.ClientFilter");
5 dojo.require("dojox.data.ServiceStore");
6 dojo.require("dojo.data.api.Read");
7 dojox.data.tests.stores.ServiceStore.error = function(t, d, errData){
8 // summary:
9 // The error callback function to be used for all of the tests.
10 d.errback(errData);
11 };
12 var testServices = new dojox.rpc.Service(require.toUrl("dojox/rpc/tests/resources/test.smd"));
13 var jsonStore = new dojox.data.ServiceStore({service:testServices.jsonRestStore});
14
15 doh.register("dojox.data.tests.stores.ServiceStore",
16 [
17 {
18 name: "Fetch some items",
19 timeout: 10000, //10 seconds.
20 runTest: function(t) {
21 // summary:
22 // Simple test of a basic fetch on ServiceStore of a simple query.
23 var d = new doh.Deferred();
24 jsonStore.fetch({query:"query",
25 onComplete: function(items, request){
26 t.is(4, items.length);
27 d.callback(true);
28 },
29 onError: dojo.partial(dojox.data.tests.stores.ServiceStore.error, doh, d)
30 });
31 return d; //Object
32 }
33 },
34 {
35 name: "fetchItemByIdentity, getValue, getValues, hasAttribute,containsValue, getAttributes, getIdentity",
36 timeout: 10000, //10 seconds.
37 runTest: function(t) {
38 // summary:
39 // Simple test of a basic fetch on ServiceStore of a single item.
40 var d = new doh.Deferred();
41 jsonStore.fetchItemByIdentity({identity:1,
42 onItem: function(item, request){
43 t.is("Object 1", item.name);
44 t.is("Object 1",jsonStore.getValue(item,"name"));
45 t.t(jsonStore.hasAttribute(item,"name"));
46 t.is(jsonStore.getValues(item,"name").length,1);
47 t.t(jsonStore.isItem(item));
48 t.t(jsonStore.isItemLoaded(item));
49 t.t(jsonStore.containsValue(item,"name","Object 1"));
50 t.f(jsonStore.containsValue(item,"name","Something Else"));
51 t.is(jsonStore.getIdentity(item),1);
52 t.t(dojo.indexOf(jsonStore.getAttributes(item),"name")>-1);
53 t.is("default",jsonStore.getValue(item,"nothing","default"));
54 d.callback(true);
55 },
56 onError: dojo.partial(dojox.data.tests.stores.ServiceStore.error, doh, d)
57 });
58 return d; //Object
59 }
60 },
61 {
62 name: "createLazyItem",
63 timeout: 10000, //10 seconds.
64 runTest: function(t) {
65 // summary:
66 // Simple test of a basic fetch on ServiceStore of a single item.
67 var d = new doh.Deferred();
68 var lazyItem = {
69 _loadObject: function(callback){
70 this.name="loaded";
71 delete this._loadObject;
72 callback(this);
73 }
74 };
75 t.f(jsonStore.isItemLoaded(lazyItem));
76 jsonStore.loadItem({item:lazyItem,onItem:function(){
77 t.t(jsonStore.isItemLoaded(lazyItem));
78 t.is(lazyItem.name,"loaded");
79 d.callback(true);
80 }});
81 return d; //Object
82 }
83 },
84 {
85 name: "lazyItem With Fetch",
86 timeout: 10000, //10 seconds.
87 runTest: function(t) {
88 var d = new doh.Deferred();
89 jsonStore.idAttribute = "id";
90 jsonStore.syncMode = true;
91 jsonStore.fetch({query:"query",
92 onComplete: function(items, request){
93 items[0]._loadObject = function(callback){
94 jsonStore.fetch({query:this.id,onComplete:callback});
95 }
96 t.t(jsonStore.getValue(items[0],"testArray").length);
97 d.callback(true);
98 },
99 onError: dojo.partial(dojox.data.tests.stores.ServiceStore.error, doh, d)
100 });
101 return d;
102 }
103 },
104 {
105 name: "ReadAPI: Fetch_20_Streaming",
106 timeout: 10000, //10 seconds. Json can sometimes be slow.
107 runTest: function(t) {
108 // summary:
109 // fetching with paging
110
111 var d = new doh.Deferred();
112 var count = 0;
113
114 function onItem(item, requestObj){
115 t.assertTrue(typeof item == 'number');
116 count++;
117 }
118 function onComplete(items, request){
119 t.is(20, count);
120
121 d.callback(true);
122 }
123 //Get everything...
124 jsonStore.fetch({
125 query: "bigQuery",
126 onBegin: null,
127 count: 20,
128 onItem: onItem,
129 onComplete: onComplete,
130 onError: dojo.partial(dojox.data.tests.stores.ServiceStore.error, t, d)
131 });
132 return d; //Object
133 }
134 },
135 function testReadAPI_functionConformance(t){
136 // summary:
137 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
138 // description:
139 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
140
141 var readApi = new dojo.data.api.Read();
142 var passed = true;
143
144 for(i in readApi){
145 if(i.toString().charAt(0) !== '_')
146 {
147 var member = readApi[i];
148 //Check that all the 'Read' defined functions exist on the test store.
149 if(typeof member === "function"){
150 var testStoreMember = jsonStore [i];
151 if(!(typeof testStoreMember === "function")){
152 passed = false;
153 break;
154 }
155 }
156 }
157 }
158 }
159 ]
160 );
161