Debian Codegraph @

dojox/data/tests/stores/JsonQueryRestStore.js

raw symbols SCIP
1 dojo.provide("dojox.data.tests.stores.JsonQueryRestStore");
2 dojo.require("dojox.data.ClientFilter");
3 dojo.require("dojox.data.JsonQueryRestStore");
4
5 dojox.data.tests.stores.JsonQueryRestStore.error = function(t, d, errData){
6 // summary:
7 // The error callback function to be used for all of the tests.
8 d.errback(errData);
9 };
10 testService = function(query){
11 lastQuery = query;
12 var deferred = new dojo.Deferred();
13 deferred.callback([
14 {id:1, name:"Ball", price: 5},
15 {id:2, name:"Car", price: 15},
16 {id:3, name:"Truck", price: 25},
17 {id:4, name:"Hula Hoop", price: 55}
18 ]);
19 return deferred;
20
21 };
22 testService.servicePath = "/testing";
23 jsonStore = new dojox.data.JsonQueryRestStore({service:testService});
24
25 doh.register("dojox.data.tests.stores.JsonQueryRestStore",
26 [
27 {
28 name: "Fetch using a query object",
29 timeout: 10000, //10 seconds.
30 runTest: function(t) {
31 // summary:
32 // Simple test of a basic fetch on JsonQueryRestStore of a simple query.
33 var d = new doh.Deferred();
34 jsonStore.fetch({query:{name:"Car"},
35 onComplete: function(items, request){
36 t.is(lastQuery,"[?(@.name='Car')]");
37 d.callback(true);
38 },
39 onError: dojo.partial(dojox.data.tests.stores.JsonQueryRestStore.error, doh, d)
40 });
41 return d; //Object
42 }
43 },
44 {
45 name: "Fetch+Sorting using a query object",
46 timeout: 10000, //10 seconds.
47 runTest: function(t) {
48 // summary:
49 // Simple test of a basic fetch on JsonQueryRestStore of a simple query.
50 var d = new doh.Deferred();
51 jsonStore.fetch({query:{name:"Car"},
52 sort:[{attribute:"price"}],
53 onComplete: function(items, request){
54 t.is(lastQuery,"[?(@.name='Car')][/@['price']]");
55 d.callback(true);
56 },
57 onError: dojo.partial(dojox.data.tests.stores.JsonQueryRestStore.error, doh, d)
58 });
59 return d; //Object
60 }
61 },
62 {
63 name: "Fetch all items (and cache for the next tests)",
64 timeout: 10000, //10 seconds.
65 runTest: function(t) {
66 // summary:
67 // Simple test of a basic fetch on JsonQueryRestStore of a simple query.
68 var d = new doh.Deferred();
69 jsonStore.fetch({query:"",
70 onComplete: function(items, request){
71 testItems = items;
72 console.log(items.length, items);
73 t.is(4, items.length);
74 d.callback(true);
75 },
76 onError: dojo.partial(dojox.data.tests.stores.JsonQueryRestStore.error, doh, d),
77 queryOptions:{cache:true}
78 });
79 return d; //Object
80 }
81 },
82 {
83 name: "Fetch using a query object",
84 timeout: 10000, //10 seconds.
85 runTest: function(t) {
86 // summary:
87 // Simple test of a basic fetch on JsonQueryRestStore of a simple query.
88 var d = new doh.Deferred();
89 lastQuery = null;
90 jsonStore.fetch({query:{name:"Car"},
91 onComplete: function(items, request){
92 t.is(1, items.length);
93 t.is(lastQuery, null); // should not be sent to the service
94 d.callback(true);
95 },
96 onError: dojo.partial(dojox.data.tests.stores.JsonQueryRestStore.error, doh, d)
97 });
98 return d; //Object
99 }
100 },
101 {
102 name: "Fetch using a JSONQuery",
103 timeout: 10000, //10 seconds.
104 runTest: function(t) {
105 // summary:
106 // Simple test of a basic fetch on JsonQueryRestStore of a simple query.
107 var d = new doh.Deferred();
108 lastQuery = null;
109 jsonStore.fetch({query:"?name='Car'",
110 onComplete: function(items, request){
111 t.is(1, items.length);
112 t.is(lastQuery, null); // should not be sent to the service
113 d.callback(true);
114 },
115 onError: dojo.partial(dojox.data.tests.stores.JsonQueryRestStore.error, doh, d)
116 });
117 return d; //Object
118 }
119 },
120 {
121 name: "Fetch using a JSONQuery with operator",
122 timeout: 10000, //10 seconds.
123 runTest: function(t) {
124 // summary:
125 // Simple test of a basic fetch on JsonQueryRestStore of a simple query.
126 var d = new doh.Deferred();
127 lastQuery = null;
128 jsonStore.fetch({query:"[?price<20]",
129 onComplete: function(items, request){
130 t.is(2, items.length);
131 t.is(lastQuery, null); // should not be sent to the service
132 d.callback(true);
133 },
134 onError: dojo.partial(dojox.data.tests.stores.JsonQueryRestStore.error, doh, d)
135 });
136 return d; //Object
137 }
138 },
139 {
140 name: "Fetch using a JSONQuery with operator and paging",
141 timeout: 10000, //10 seconds.
142 runTest: function(t) {
143 // summary:
144 // Simple test of a basic fetch on JsonQueryRestStore of a simple query.
145 var d = new doh.Deferred();
146 lastQuery = null;
147 jsonStore.fetch({query:"?price<20",start:1, count:1,
148 onComplete: function(items, request){
149 t.is(1, items.length);
150 t.is(lastQuery, null); // should not be sent to the service
151 d.callback(true);
152 },
153 onError: dojo.partial(dojox.data.tests.stores.JsonQueryRestStore.error, doh, d),
154 queryOptions:{cache:true}
155 });
156 return d; //Object
157 }
158 },
159 {
160 name: "Sorting",
161 timeout: 10000, //10 seconds.
162 runTest: function(t) {
163 // summary:
164 // Simple test of a basic fetch on JsonQueryRestStore of a simple query.
165 var d = new doh.Deferred();
166 lastQuery = null;
167 jsonStore.fetch({sort:[{attribute:"name", descending: true}],
168 onComplete: function(items, request){
169 t.is("Truck", items[0].name);
170 t.is("Ball", items[3].name);
171 t.is(lastQuery, null); // should not be sent to the service
172 d.callback(true);
173 },
174 onError: dojo.partial(dojox.data.tests.stores.JsonQueryRestStore.error, doh, d)
175 });
176 return d; //Object
177 }
178 },
179 {
180 name: "Sorting + Paging",
181 timeout: 10000, //10 seconds.
182 runTest: function(t) {
183 // summary:
184 // Simple test of a basic fetch on JsonQueryRestStore of a simple query.
185 jsonStore.jsonQueryPagination = true;
186 var d = new doh.Deferred();
187 lastQuery = null;
188 jsonStore.fetch({sort:[{attribute:"name", descending: true}],start:1, count:2,
189 onBegin: function(count){
190 t.is(count,4);
191 },
192 onComplete: function(items, request){
193 t.is("Hula Hoop", items[0].name);
194 t.is("Car", items[1].name);
195 t.is(items.length, 2);
196 t.is(lastQuery, null); // should not be sent to the service
197 d.callback(true);
198 },
199 onError: dojo.partial(dojox.data.tests.stores.JsonQueryRestStore.error, doh, d)
200 });
201 return d; //Object
202 }
203 }
204 ]
205 );