2150 |
mathias |
1 |
if(!dojo._hasResource["tests.data.readOnlyItemFileTestTemplates"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["tests.data.readOnlyItemFileTestTemplates"] = true;
|
|
|
3 |
dojo.provide("tests.data.readOnlyItemFileTestTemplates");
|
|
|
4 |
dojo.require("dojo.data.api.Read");
|
|
|
5 |
dojo.require("dojo.data.api.Identity");
|
|
|
6 |
dojo.require("dojo.date");
|
|
|
7 |
dojo.require("dojo.date.stamp");
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
tests.data.readOnlyItemFileTestTemplates.registerTestsForDatastore = function(/* String */ datastoreClassName){
|
|
|
11 |
// summary:
|
|
|
12 |
// Given the name of a datastore class to use, this function creates
|
|
|
13 |
// a set of unit tests for that datastore, and registers the new test
|
|
|
14 |
// group with the doh test framework. The new unit tests are based
|
|
|
15 |
// on a set of "template" unit tests.
|
|
|
16 |
var datastoreClass = dojo.getObject(datastoreClassName);
|
|
|
17 |
var testTemplates = tests.data.readOnlyItemFileTestTemplates.testTemplates;
|
|
|
18 |
var testsForDatastore = [];
|
|
|
19 |
var makeNewTestFunction = function(template){
|
|
|
20 |
return function(t){return template.runTest(datastoreClass, t);};
|
|
|
21 |
};
|
|
|
22 |
for(var i = 0; i < testTemplates.length; ++i) {
|
|
|
23 |
var testTemplate = testTemplates[i];
|
|
|
24 |
var test = {};
|
|
|
25 |
test.name = testTemplate.name;
|
|
|
26 |
test.runTest = makeNewTestFunction(testTemplate);
|
|
|
27 |
testsForDatastore.push(test);
|
|
|
28 |
}
|
|
|
29 |
var testGroupName = "tests.data.readOnlyItemFileTestTemplates, with datastore " + datastoreClassName;
|
|
|
30 |
doh.register(testGroupName, testsForDatastore);
|
|
|
31 |
};
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
//-----------------------------------------------------
|
|
|
35 |
// testFile data-sets
|
|
|
36 |
tests.data.readOnlyItemFileTestTemplates.getTestData = function(name){
|
|
|
37 |
var data = null;
|
|
|
38 |
if(name === "countries"){
|
|
|
39 |
if(dojo.isBrowser){
|
|
|
40 |
data = {url: dojo.moduleUrl("tests", "data/countries.json").toString() };
|
|
|
41 |
}else{
|
|
|
42 |
data = {data: {
|
|
|
43 |
identifier:"abbr",
|
|
|
44 |
label:"name",
|
|
|
45 |
items:[
|
|
|
46 |
{abbr:"ec", name:"Ecuador", capital:"Quito"},
|
|
|
47 |
{abbr:'eg', name:'Egypt', capital:'Cairo'},
|
|
|
48 |
{abbr:'sv', name:'El Salvador', capital:'San Salvador'},
|
|
|
49 |
{abbr:'gq', name:'Equatorial Guinea', capital:'Malabo'},
|
|
|
50 |
{abbr:'er', name:'Eritrea', capital:'Asmara'},
|
|
|
51 |
{abbr:'ee', name:'Estonia', capital:'Tallinn'},
|
|
|
52 |
{abbr:'et', name:'Ethiopia', capital:'Addis Ababa'}
|
|
|
53 |
]
|
|
|
54 |
} };
|
|
|
55 |
}
|
|
|
56 |
}else if(name === "countries_withNull"){
|
|
|
57 |
if(dojo.isBrowser){
|
|
|
58 |
data = {url: dojo.moduleUrl("tests", "data/countries_withNull.json").toString() };
|
|
|
59 |
}else{
|
|
|
60 |
data = {data: {
|
|
|
61 |
identifier:"abbr",
|
|
|
62 |
items:[
|
|
|
63 |
{abbr:"ec", name:null, capital:"Quito"},
|
|
|
64 |
{abbr:'eg', name:null, capital:'Cairo'},
|
|
|
65 |
{abbr:'sv', name:'El Salvador', capital:'San Salvador'},
|
|
|
66 |
{abbr:'gq', name:'Equatorial Guinea', capital:'Malabo'},
|
|
|
67 |
{abbr:'er', name:'Eritrea', capital:'Asmara'},
|
|
|
68 |
{abbr:'ee', name:null, capital:'Tallinn'},
|
|
|
69 |
{abbr:'et', name:'Ethiopia', capital:'Addis Ababa'}
|
|
|
70 |
]
|
|
|
71 |
} };
|
|
|
72 |
}
|
|
|
73 |
}else if(name === "countries_withoutid"){
|
|
|
74 |
if(dojo.isBrowser){
|
|
|
75 |
data = {url: dojo.moduleUrl("tests", "data/countries_withoutid.json").toString() };
|
|
|
76 |
}else{
|
|
|
77 |
data = {data: {
|
|
|
78 |
label: "name",
|
|
|
79 |
items:[
|
|
|
80 |
{abbr:"ec", name:null, capital:"Quito"},
|
|
|
81 |
{abbr:'eg', name:null, capital:'Cairo'},
|
|
|
82 |
{abbr:'sv', name:'El Salvador', capital:'San Salvador'},
|
|
|
83 |
{abbr:'gq', name:'Equatorial Guinea', capital:'Malabo'},
|
|
|
84 |
{abbr:'er', name:'Eritrea', capital:'Asmara'},
|
|
|
85 |
{abbr:'ee', name:null, capital:'Tallinn'},
|
|
|
86 |
{abbr:'et', name:'Ethiopia', capital:'Addis Ababa'}
|
|
|
87 |
]
|
|
|
88 |
} };
|
|
|
89 |
}
|
|
|
90 |
}else if (name === "countries_withBoolean"){
|
|
|
91 |
if(dojo.isBrowser){
|
|
|
92 |
data = {url: dojo.moduleUrl("tests", "data/countries_withBoolean.json").toString() };
|
|
|
93 |
}else{
|
|
|
94 |
data = {data: {
|
|
|
95 |
identifier:"abbr",
|
|
|
96 |
items:[
|
|
|
97 |
{abbr:"ec", name:"Ecuador", capital:"Quito", real:true},
|
|
|
98 |
{abbr:'eg', name:'Egypt', capital:'Cairo', real:true},
|
|
|
99 |
{abbr:'sv', name:'El Salvador', capital:'San Salvador', real:true},
|
|
|
100 |
{abbr:'gq', name:'Equatorial Guinea', capital:'Malabo', real:true},
|
|
|
101 |
{abbr:'er', name:'Eritrea', capital:'Asmara', real:true},
|
|
|
102 |
{abbr:'ee', name:'Estonia', capital:'Tallinn', real:true},
|
|
|
103 |
{abbr:'et', name:'Ethiopia', capital:'Addis Ababa', real:true},
|
|
|
104 |
{abbr:'ut', name:'Utopia', capital:'Paradise', real:false}
|
|
|
105 |
]
|
|
|
106 |
} };
|
|
|
107 |
}
|
|
|
108 |
}else if (name === "countries_withDates"){
|
|
|
109 |
if(dojo.isBrowser){
|
|
|
110 |
data = {url: dojo.moduleUrl("tests", "data/countries_withDates.json").toString() };
|
|
|
111 |
}else{
|
|
|
112 |
data = {data: {
|
|
|
113 |
identifier:"abbr",
|
|
|
114 |
items:[
|
|
|
115 |
{abbr:"ec", name:"Ecuador", capital:"Quito"},
|
|
|
116 |
{abbr:'eg', name:'Egypt', capital:'Cairo'},
|
|
|
117 |
{abbr:'sv', name:'El Salvador', capital:'San Salvador'},
|
|
|
118 |
{abbr:'gq', name:'Equatorial Guinea', capital:'Malabo'},
|
|
|
119 |
{abbr:'er', name:'Eritrea', capital:'Asmara', independence:{_type:'Date', _value:"1993-05-24T00:00:00Z"}}, // May 24, 1993,
|
|
|
120 |
{abbr:'ee', name:'Estonia', capital:'Tallinn', independence:{_type:'Date', _value:"1991-08-20T00:00:00Z"}}, // August 20, 1991
|
|
|
121 |
{abbr:'et', name:'Ethiopia', capital:'Addis Ababa'}
|
|
|
122 |
]
|
|
|
123 |
} };
|
|
|
124 |
}
|
|
|
125 |
}else if (name === "geography_hierarchy_small"){
|
|
|
126 |
if(dojo.isBrowser){
|
|
|
127 |
data = {url: dojo.moduleUrl("tests", "data/geography_hierarchy_small.json").toString() };
|
|
|
128 |
}else{
|
|
|
129 |
data = {data: {
|
|
|
130 |
items:[
|
|
|
131 |
{ name:'Africa', countries:[
|
|
|
132 |
{ name:'Egypt', capital:'Cairo' },
|
|
|
133 |
{ name:'Kenya', capital:'Nairobi' },
|
|
|
134 |
{ name:'Sudan', capital:'Khartoum' }]},
|
|
|
135 |
{ name:'Australia', capital:'Canberra' },
|
|
|
136 |
{ name:'North America', countries:[
|
|
|
137 |
{ name:'Canada', population:'33 million', cities:[
|
|
|
138 |
{ name:'Toronto', population:'2.5 million' },
|
|
|
139 |
{ name:'Alberta', population:'1 million' }
|
|
|
140 |
]},
|
|
|
141 |
{ name: 'United States of America', capital: 'Washington DC', states:[
|
|
|
142 |
{ name: 'Missouri'},
|
|
|
143 |
{ name: 'Arkansas'}
|
|
|
144 |
]}
|
|
|
145 |
]}
|
|
|
146 |
]
|
|
|
147 |
}};
|
|
|
148 |
}
|
|
|
149 |
}else if (name === "data_multitype"){
|
|
|
150 |
if(dojo.isBrowser){
|
|
|
151 |
data = {url: dojo.moduleUrl("tests", "data/data_multitype.json").toString() };
|
|
|
152 |
}else{
|
|
|
153 |
data = {data: {
|
|
|
154 |
"identifier": "count",
|
|
|
155 |
"label": "count",
|
|
|
156 |
items: [
|
|
|
157 |
{ count: 1, value: "true" },
|
|
|
158 |
{ count: 2, value: true },
|
|
|
159 |
{ count: 3, value: "false"},
|
|
|
160 |
{ count: 4, value: false },
|
|
|
161 |
{ count: 5, value: true },
|
|
|
162 |
{ count: 6, value: true },
|
|
|
163 |
{ count: 7, value: "true" },
|
|
|
164 |
{ count: 8, value: "true" },
|
|
|
165 |
{ count: 9, value: "false"},
|
|
|
166 |
{ count: 10, value: false },
|
|
|
167 |
{ count: 11, value: [false, false]},
|
|
|
168 |
{ count: "12", value: [false, "true"]}
|
|
|
169 |
]
|
|
|
170 |
}
|
|
|
171 |
};
|
|
|
172 |
}
|
|
|
173 |
}
|
|
|
174 |
return data;
|
|
|
175 |
};
|
|
|
176 |
|
|
|
177 |
//-----------------------------------------------------
|
|
|
178 |
// testTemplates
|
|
|
179 |
tests.data.readOnlyItemFileTestTemplates.testTemplates = [
|
|
|
180 |
{
|
|
|
181 |
name: "Identity API: fetchItemByIdentity()",
|
|
|
182 |
runTest: function(datastore, t){
|
|
|
183 |
// summary:
|
|
|
184 |
// Simple test of the fetchItemByIdentity function of the store.
|
|
|
185 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
186 |
|
|
|
187 |
var d = new doh.Deferred();
|
|
|
188 |
function onItem(item){
|
|
|
189 |
t.assertTrue(item !== null);
|
|
|
190 |
if(item !== null){
|
|
|
191 |
var name = store.getValue(item,"name");
|
|
|
192 |
t.assertEqual(name, "El Salvador");
|
|
|
193 |
}
|
|
|
194 |
d.callback(true);
|
|
|
195 |
}
|
|
|
196 |
function onError(errData){
|
|
|
197 |
t.assertTrue(false);
|
|
|
198 |
d.errback(errData);
|
|
|
199 |
}
|
|
|
200 |
store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError});
|
|
|
201 |
return d; // Deferred
|
|
|
202 |
}
|
|
|
203 |
},
|
|
|
204 |
{
|
|
|
205 |
name: "Identity API: fetchItemByIdentity() notFound",
|
|
|
206 |
runTest: function(datastore, t){
|
|
|
207 |
// summary:
|
|
|
208 |
// Simple test of the fetchItemByIdentity function of the store.
|
|
|
209 |
// description:
|
|
|
210 |
// Simple test of the fetchItemByIdentity function of the store.
|
|
|
211 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
212 |
|
|
|
213 |
var d = new doh.Deferred();
|
|
|
214 |
function onItem(item){
|
|
|
215 |
t.assertTrue(item === null);
|
|
|
216 |
d.callback(true);
|
|
|
217 |
}
|
|
|
218 |
function onError(errData){
|
|
|
219 |
t.assertTrue(false);
|
|
|
220 |
d.errback(errData);
|
|
|
221 |
}
|
|
|
222 |
store.fetchItemByIdentity({identity: "sv_not", onItem: onItem, onError: onError});
|
|
|
223 |
return d; // Deferred
|
|
|
224 |
}
|
|
|
225 |
},
|
|
|
226 |
{
|
|
|
227 |
name: "Identity API: getIdentityAttributes()",
|
|
|
228 |
runTest: function(datastore, t){
|
|
|
229 |
// summary:
|
|
|
230 |
// Simple test of the getIdentityAttributes function.
|
|
|
231 |
// description:
|
|
|
232 |
// Simple test of the getIdentityAttributes function.
|
|
|
233 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
234 |
|
|
|
235 |
var d = new doh.Deferred();
|
|
|
236 |
function onItem(item){
|
|
|
237 |
t.assertTrue(item !== null)
|
|
|
238 |
var identifiers = store.getIdentityAttributes(item);
|
|
|
239 |
t.assertTrue(dojo.isArray(identifiers));
|
|
|
240 |
t.assertEqual(1, identifiers.length);
|
|
|
241 |
t.assertEqual("abbr", identifiers[0]);
|
|
|
242 |
d.callback(true);
|
|
|
243 |
}
|
|
|
244 |
function onError(errData){
|
|
|
245 |
t.assertTrue(false);
|
|
|
246 |
d.errback(errData);
|
|
|
247 |
}
|
|
|
248 |
store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError});
|
|
|
249 |
return d; // Deferred
|
|
|
250 |
}
|
|
|
251 |
},
|
|
|
252 |
{
|
|
|
253 |
name: "Identity API: fetchItemByIdentity() commentFilteredJson",
|
|
|
254 |
runTest: function(datastore, t){
|
|
|
255 |
// summary:
|
|
|
256 |
// Simple test of the fetchItemByIdentity function of the store.
|
|
|
257 |
// description:
|
|
|
258 |
// Simple test of the fetchItemByIdentity function of the store.
|
|
|
259 |
// This tests loading a comment-filtered json file so that people using secure
|
|
|
260 |
// data with this store can bypass the JavaSceipt hijack noted in Fortify's
|
|
|
261 |
// paper.
|
|
|
262 |
|
|
|
263 |
if(dojo.isBrowser){
|
|
|
264 |
var store = new datastore({url: dojo.moduleUrl("tests", "data/countries_commentFiltered.json").toString()});
|
|
|
265 |
|
|
|
266 |
var d = new doh.Deferred();
|
|
|
267 |
function onItem(item){
|
|
|
268 |
t.assertTrue(item !== null);
|
|
|
269 |
var name = store.getValue(item,"name");
|
|
|
270 |
t.assertEqual(name, "El Salvador");
|
|
|
271 |
d.callback(true);
|
|
|
272 |
}
|
|
|
273 |
function onError(errData){
|
|
|
274 |
t.assertTrue(false);
|
|
|
275 |
d.errback(errData);
|
|
|
276 |
}
|
|
|
277 |
store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError});
|
|
|
278 |
return d; // Deferred
|
|
|
279 |
}
|
|
|
280 |
}
|
|
|
281 |
},
|
|
|
282 |
{
|
|
|
283 |
name: "Identity API: fetchItemByIdentity() nullValue",
|
|
|
284 |
runTest: function(datastore, t){
|
|
|
285 |
// summary:
|
|
|
286 |
// Simple test of the fetchItemByIdentity function of the store, checling a null value.
|
|
|
287 |
// description:
|
|
|
288 |
// Simple test of the fetchItemByIdentity function of the store, checking a null value.
|
|
|
289 |
// This tests handling attributes in json that were defined as null properly.
|
|
|
290 |
// Introduced because of tracker: #3153
|
|
|
291 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_withNull"));
|
|
|
292 |
|
|
|
293 |
var d = new doh.Deferred();
|
|
|
294 |
function onItem(item){
|
|
|
295 |
t.assertTrue(item !== null);
|
|
|
296 |
var name = store.getValue(item,"name");
|
|
|
297 |
t.assertEqual(name, null);
|
|
|
298 |
d.callback(true);
|
|
|
299 |
}
|
|
|
300 |
function onError(errData){
|
|
|
301 |
t.assertTrue(false);
|
|
|
302 |
d.errback(errData);
|
|
|
303 |
}
|
|
|
304 |
store.fetchItemByIdentity({identity: "ec", onItem: onItem, onError: onError});
|
|
|
305 |
return d; // Deferred
|
|
|
306 |
}
|
|
|
307 |
},
|
|
|
308 |
{
|
|
|
309 |
name: "Identity API: fetchItemByIdentity() booleanValue",
|
|
|
310 |
runTest: function(datastore, t){
|
|
|
311 |
// summary:
|
|
|
312 |
// Simple test of the fetchItemByIdentity function of the store, checking a boolean value.
|
|
|
313 |
// description:
|
|
|
314 |
// Simple test of the fetchItemByIdentity function of the store, checking a boolean value.
|
|
|
315 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_withBoolean"));
|
|
|
316 |
|
|
|
317 |
var d = new doh.Deferred();
|
|
|
318 |
function onItem(item){
|
|
|
319 |
t.assertTrue(item !== null);
|
|
|
320 |
var name = store.getValue(item,"name");
|
|
|
321 |
t.assertEqual(name, "Utopia");
|
|
|
322 |
var real = store.getValue(item,"real");
|
|
|
323 |
t.assertEqual(real, false);
|
|
|
324 |
d.callback(true);
|
|
|
325 |
}
|
|
|
326 |
function onError(errData){
|
|
|
327 |
t.assertTrue(false);
|
|
|
328 |
d.errback(errData);
|
|
|
329 |
}
|
|
|
330 |
store.fetchItemByIdentity({identity: "ut", onItem: onItem, onError: onError});
|
|
|
331 |
return d; // Deferred
|
|
|
332 |
}
|
|
|
333 |
},
|
|
|
334 |
{
|
|
|
335 |
name: "Identity API: fetchItemByIdentity() withoutSpecifiedIdInData",
|
|
|
336 |
runTest: function(datastore, t){
|
|
|
337 |
// summary:
|
|
|
338 |
// Simple test of bug #4691, looking up something by assigned id, not one specified in the JSON data.
|
|
|
339 |
// description:
|
|
|
340 |
// Simple test of bug #4691, looking up something by assigned id, not one specified in the JSON data.
|
|
|
341 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_withoutid"));
|
|
|
342 |
|
|
|
343 |
var d = new doh.Deferred();
|
|
|
344 |
function onItem(item){
|
|
|
345 |
t.assertTrue(item !== null);
|
|
|
346 |
var name = store.getValue(item,"name");
|
|
|
347 |
t.assertEqual(name, "El Salvador");
|
|
|
348 |
d.callback(true);
|
|
|
349 |
}
|
|
|
350 |
function onError(errData){
|
|
|
351 |
t.assertTrue(false);
|
|
|
352 |
d.errback(errData);
|
|
|
353 |
}
|
|
|
354 |
store.fetchItemByIdentity({identity: "2", onItem: onItem, onError: onError});
|
|
|
355 |
return d; // Deferred
|
|
|
356 |
}
|
|
|
357 |
},
|
|
|
358 |
{
|
|
|
359 |
name: "Identity API: getIdentity()",
|
|
|
360 |
runTest: function(datastore, t){
|
|
|
361 |
// summary:
|
|
|
362 |
// Simple test of the getIdentity function of the store.
|
|
|
363 |
// description:
|
|
|
364 |
// Simple test of the getIdentity function of the store.
|
|
|
365 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
366 |
|
|
|
367 |
var d = new doh.Deferred();
|
|
|
368 |
function onItem(item){
|
|
|
369 |
t.assertTrue(item !== null);
|
|
|
370 |
t.assertTrue(store.getIdentity(item) === "sv");
|
|
|
371 |
d.callback(true);
|
|
|
372 |
}
|
|
|
373 |
function onError(errData){
|
|
|
374 |
t.assertTrue(false);
|
|
|
375 |
d.errback(errData);
|
|
|
376 |
}
|
|
|
377 |
store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError});
|
|
|
378 |
return d; // Deferred
|
|
|
379 |
}
|
|
|
380 |
},
|
|
|
381 |
{
|
|
|
382 |
name: "Identity API: getIdentity() withoutSpecifiedId",
|
|
|
383 |
runTest: function(datastore, t){
|
|
|
384 |
// summary:
|
|
|
385 |
// Simple test of the #4691 bug
|
|
|
386 |
// description:
|
|
|
387 |
// Simple test of the #4691 bug
|
|
|
388 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_withoutid"));
|
|
|
389 |
|
|
|
390 |
var d = new doh.Deferred();
|
|
|
391 |
function onItem(item, request){
|
|
|
392 |
t.assertTrue(item !== null);
|
|
|
393 |
t.assertTrue(store.getIdentity(item) === 2);
|
|
|
394 |
d.callback(true);
|
|
|
395 |
}
|
|
|
396 |
function onError(errData, request){
|
|
|
397 |
t.assertTrue(false);
|
|
|
398 |
d.errback(errData);
|
|
|
399 |
}
|
|
|
400 |
store.fetch({ query:{abbr: "sv"}, onItem: onItem, onError: onError});
|
|
|
401 |
return d; // Deferred
|
|
|
402 |
}
|
|
|
403 |
},
|
|
|
404 |
{
|
|
|
405 |
name: "Read API: fetch() all",
|
|
|
406 |
runTest: function(datastore, t){
|
|
|
407 |
// summary:
|
|
|
408 |
// Simple test of a basic fetch on ItemFileReadStore.
|
|
|
409 |
// description:
|
|
|
410 |
// Simple test of a basic fetch on ItemFileReadStore.
|
|
|
411 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
412 |
|
|
|
413 |
var d = new doh.Deferred();
|
|
|
414 |
function completedAll(items, request){
|
|
|
415 |
t.is(7, items.length);
|
|
|
416 |
d.callback(true);
|
|
|
417 |
}
|
|
|
418 |
function error(errData, request){
|
|
|
419 |
t.assertTrue(false);
|
|
|
420 |
d.errback(errData);
|
|
|
421 |
}
|
|
|
422 |
|
|
|
423 |
//Get everything...
|
|
|
424 |
store.fetch({ onComplete: completedAll, onError: error});
|
|
|
425 |
return d;
|
|
|
426 |
}
|
|
|
427 |
},
|
|
|
428 |
{
|
|
|
429 |
name: "Read API: fetch() one",
|
|
|
430 |
runTest: function(datastore, t){
|
|
|
431 |
// summary:
|
|
|
432 |
// Simple test of a basic fetch on ItemFileReadStore of a single item.
|
|
|
433 |
// description:
|
|
|
434 |
// Simple test of a basic fetch on ItemFileReadStore of a single item.
|
|
|
435 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
436 |
|
|
|
437 |
var d = new doh.Deferred();
|
|
|
438 |
function onComplete(items, request){
|
|
|
439 |
t.assertEqual(items.length, 1);
|
|
|
440 |
d.callback(true);
|
|
|
441 |
}
|
|
|
442 |
function onError(errData, request){
|
|
|
443 |
t.assertTrue(false);
|
|
|
444 |
d.errback(errData);
|
|
|
445 |
}
|
|
|
446 |
store.fetch({ query: {abbr: "ec"},
|
|
|
447 |
onComplete: onComplete,
|
|
|
448 |
onError: onError
|
|
|
449 |
});
|
|
|
450 |
return d;
|
|
|
451 |
}
|
|
|
452 |
},
|
|
|
453 |
{
|
|
|
454 |
name: "Read API: fetch() shallow",
|
|
|
455 |
runTest: function(datastore, t){
|
|
|
456 |
// summary:
|
|
|
457 |
// Simple test of a basic fetch on ItemFileReadStore of only toplevel items
|
|
|
458 |
// description:
|
|
|
459 |
// Simple test of a basic fetch on ItemFileReadStore of only toplevel items.
|
|
|
460 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("geography_hierarchy_small"));
|
|
|
461 |
|
|
|
462 |
var d = new doh.Deferred();
|
|
|
463 |
function onComplete(items, request){
|
|
|
464 |
t.assertEqual(items.length, 2);
|
|
|
465 |
d.callback(true);
|
|
|
466 |
}
|
|
|
467 |
function onError(errData, request){
|
|
|
468 |
t.assertTrue(false);
|
|
|
469 |
d.errback(errData);
|
|
|
470 |
}
|
|
|
471 |
//Find all items starting with A, only toplevel (root) items.
|
|
|
472 |
store.fetch({ query: {name: "A*"},
|
|
|
473 |
onComplete: onComplete,
|
|
|
474 |
onError: onError
|
|
|
475 |
});
|
|
|
476 |
return d;
|
|
|
477 |
}
|
|
|
478 |
},
|
|
|
479 |
{
|
|
|
480 |
name: "Read API: fetch() Multiple",
|
|
|
481 |
runTest: function(datastore, t){
|
|
|
482 |
// summary:
|
|
|
483 |
// Tests that multiple fetches at the same time queue up properly and do not clobber each other on initial load.
|
|
|
484 |
// description:
|
|
|
485 |
// Tests that multiple fetches at the same time queue up properly and do not clobber each other on initial load.
|
|
|
486 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("geography_hierarchy_small"));
|
|
|
487 |
|
|
|
488 |
var d = new doh.Deferred();
|
|
|
489 |
var done = [false, false];
|
|
|
490 |
|
|
|
491 |
function onCompleteOne(items, request){
|
|
|
492 |
done[0] = true;
|
|
|
493 |
t.assertEqual(items.length, 2);
|
|
|
494 |
if(done[0] && done[1]){
|
|
|
495 |
d.callback(true);
|
|
|
496 |
}
|
|
|
497 |
}
|
|
|
498 |
function onCompleteTwo(items, request){
|
|
|
499 |
done[1] = true;
|
|
|
500 |
if(done[0] && done[1]){
|
|
|
501 |
d.callback(true);
|
|
|
502 |
}
|
|
|
503 |
}
|
|
|
504 |
function onError(errData, request){
|
|
|
505 |
t.assertTrue(false);
|
|
|
506 |
d.errback(errData);
|
|
|
507 |
}
|
|
|
508 |
//Find all items starting with A, only toplevel (root) items.
|
|
|
509 |
store.fetch({ query: {name: "A*"},
|
|
|
510 |
onComplete: onCompleteOne,
|
|
|
511 |
onError: onError
|
|
|
512 |
});
|
|
|
513 |
|
|
|
514 |
//Find all items starting with A, only toplevel (root) items.
|
|
|
515 |
store.fetch({ query: {name: "N*"},
|
|
|
516 |
onComplete: onCompleteTwo,
|
|
|
517 |
onError: onError
|
|
|
518 |
});
|
|
|
519 |
|
|
|
520 |
return d;
|
|
|
521 |
}
|
|
|
522 |
},
|
|
|
523 |
{
|
|
|
524 |
name: "Read API: fetch() MultipleMixedFetch",
|
|
|
525 |
runTest: function(datastore, t){
|
|
|
526 |
// summary:
|
|
|
527 |
// Tests that multiple fetches at the same time queue up properly and do not clobber each other on initial load.
|
|
|
528 |
// description:
|
|
|
529 |
// Tests that multiple fetches at the same time queue up properly and do not clobber each other on initial load.
|
|
|
530 |
// Tests an item fetch and an identity fetch.
|
|
|
531 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
532 |
|
|
|
533 |
var d = new doh.Deferred();
|
|
|
534 |
var done = [false, false];
|
|
|
535 |
|
|
|
536 |
function onComplete(items, request){
|
|
|
537 |
done[0] = true;
|
|
|
538 |
t.assertEqual(items.length, 1);
|
|
|
539 |
if(done[0] && done[1]){
|
|
|
540 |
d.callback(true);
|
|
|
541 |
}
|
|
|
542 |
}
|
|
|
543 |
function onItem(item){
|
|
|
544 |
done[1] = true;
|
|
|
545 |
t.assertTrue(item !== null);
|
|
|
546 |
var name = store.getValue(item,"name");
|
|
|
547 |
t.assertEqual(name, "El Salvador");
|
|
|
548 |
|
|
|
549 |
if(done[0] && done[1]){
|
|
|
550 |
d.callback(true);
|
|
|
551 |
}
|
|
|
552 |
}
|
|
|
553 |
function onError(errData){
|
|
|
554 |
t.assertTrue(false);
|
|
|
555 |
d.errback(errData);
|
|
|
556 |
}
|
|
|
557 |
|
|
|
558 |
//Find all items starting with A, only toplevel (root) items.
|
|
|
559 |
store.fetch({ query: {name: "El*"},
|
|
|
560 |
onComplete: onComplete,
|
|
|
561 |
onError: onError
|
|
|
562 |
});
|
|
|
563 |
|
|
|
564 |
store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError});
|
|
|
565 |
return d;
|
|
|
566 |
}
|
|
|
567 |
},
|
|
|
568 |
{
|
|
|
569 |
name: "Read API: fetch() deep",
|
|
|
570 |
runTest: function(datastore, t){
|
|
|
571 |
// summary:
|
|
|
572 |
// Simple test of a basic fetch on ItemFileReadStore of all items (including children (nested))
|
|
|
573 |
// description:
|
|
|
574 |
// Simple test of a basic fetch on ItemFileReadStore of all items (including children (nested))
|
|
|
575 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("geography_hierarchy_small"));
|
|
|
576 |
|
|
|
577 |
var d = new doh.Deferred();
|
|
|
578 |
function onComplete(items, request){
|
|
|
579 |
t.assertEqual(items.length, 4);
|
|
|
580 |
d.callback(true);
|
|
|
581 |
}
|
|
|
582 |
function onError(errData, request){
|
|
|
583 |
t.assertTrue(false);
|
|
|
584 |
d.errback(errData);
|
|
|
585 |
}
|
|
|
586 |
//Find all items starting with A, including child (nested) items.
|
|
|
587 |
store.fetch({ query: {name: "A*"},
|
|
|
588 |
onComplete: onComplete,
|
|
|
589 |
onError: onError,
|
|
|
590 |
queryOptions: {deep:true}
|
|
|
591 |
});
|
|
|
592 |
return d;
|
|
|
593 |
}
|
|
|
594 |
},
|
|
|
595 |
{
|
|
|
596 |
name: "Read API: fetch() one_commentFilteredJson",
|
|
|
597 |
runTest: function(datastore, t){
|
|
|
598 |
// summary:
|
|
|
599 |
// Simple test of a basic fetch on ItemFileReadStore of a single item.
|
|
|
600 |
// description:
|
|
|
601 |
// Simple test of a basic fetch on ItemFileReadStore of a single item.
|
|
|
602 |
// This tests loading a comment-filtered json file so that people using secure
|
|
|
603 |
// data with this store can bypass the JavaSceipt hijack noted in Fortify's
|
|
|
604 |
// paper.
|
|
|
605 |
if(dojo.isBrowser){
|
|
|
606 |
var store = new datastore({url: dojo.moduleUrl("tests", "data/countries_commentFiltered.json").toString()});
|
|
|
607 |
|
|
|
608 |
var d = new doh.Deferred();
|
|
|
609 |
function onComplete(items, request){
|
|
|
610 |
t.assertEqual(items.length, 1);
|
|
|
611 |
d.callback(true);
|
|
|
612 |
}
|
|
|
613 |
function onError(errData, request){
|
|
|
614 |
t.assertTrue(false);
|
|
|
615 |
d.errback(errData);
|
|
|
616 |
}
|
|
|
617 |
store.fetch({ query: {abbr: "ec"},
|
|
|
618 |
onComplete: onComplete,
|
|
|
619 |
onError: onError
|
|
|
620 |
});
|
|
|
621 |
return d;
|
|
|
622 |
}
|
|
|
623 |
}
|
|
|
624 |
},
|
|
|
625 |
{
|
|
|
626 |
name: "Read API: fetch() withNull",
|
|
|
627 |
runTest: function(datastore, t){
|
|
|
628 |
// summary:
|
|
|
629 |
// Simple test of a basic fetch on ItemFileReadStore of a single item where some attributes are null.
|
|
|
630 |
// description:
|
|
|
631 |
// Simple test of a basic fetch on ItemFileReadStore of a single item where some attributes are null.
|
|
|
632 |
// Introduced because of tracker: #3153
|
|
|
633 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_withNull"));
|
|
|
634 |
|
|
|
635 |
var d = new doh.Deferred();
|
|
|
636 |
function onComplete(items, request){
|
|
|
637 |
t.assertEqual(4, items.length);
|
|
|
638 |
d.callback(true);
|
|
|
639 |
}
|
|
|
640 |
function onError(errData, request){
|
|
|
641 |
t.assertTrue(false);
|
|
|
642 |
d.errback(errData);
|
|
|
643 |
}
|
|
|
644 |
store.fetch({ query: {name: "E*"},
|
|
|
645 |
onComplete: onComplete,
|
|
|
646 |
onError: onError
|
|
|
647 |
});
|
|
|
648 |
return d;
|
|
|
649 |
}
|
|
|
650 |
},
|
|
|
651 |
{
|
|
|
652 |
name: "Read API: fetch() all_streaming",
|
|
|
653 |
runTest: function(datastore, t){
|
|
|
654 |
// summary:
|
|
|
655 |
// Simple test of a basic fetch on ItemFileReadStore.
|
|
|
656 |
// description:
|
|
|
657 |
// Simple test of a basic fetch on ItemFileReadStore.
|
|
|
658 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
659 |
|
|
|
660 |
var d = new doh.Deferred();
|
|
|
661 |
count = 0;
|
|
|
662 |
|
|
|
663 |
function onBegin(size, requestObj){
|
|
|
664 |
t.assertEqual(size, 7);
|
|
|
665 |
}
|
|
|
666 |
function onItem(item, requestObj){
|
|
|
667 |
t.assertTrue(store.isItem(item));
|
|
|
668 |
count++;
|
|
|
669 |
}
|
|
|
670 |
function onComplete(items, request){
|
|
|
671 |
t.assertEqual(count, 7);
|
|
|
672 |
t.assertTrue(items === null);
|
|
|
673 |
d.callback(true);
|
|
|
674 |
}
|
|
|
675 |
function onError(errData, request){
|
|
|
676 |
t.assertTrue(false);
|
|
|
677 |
d.errback(errData);
|
|
|
678 |
}
|
|
|
679 |
|
|
|
680 |
//Get everything...
|
|
|
681 |
store.fetch({ onBegin: onBegin,
|
|
|
682 |
onItem: onItem,
|
|
|
683 |
onComplete: onComplete,
|
|
|
684 |
onError: onError
|
|
|
685 |
});
|
|
|
686 |
return d;
|
|
|
687 |
}
|
|
|
688 |
},
|
|
|
689 |
{
|
|
|
690 |
name: "Read API: fetch() paging",
|
|
|
691 |
runTest: function(datastore, t){
|
|
|
692 |
// summary:
|
|
|
693 |
// Test of multiple fetches on a single result. Paging, if you will.
|
|
|
694 |
// description:
|
|
|
695 |
// Test of multiple fetches on a single result. Paging, if you will.
|
|
|
696 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
697 |
|
|
|
698 |
var d = new doh.Deferred();
|
|
|
699 |
function dumpFirstFetch(items, request){
|
|
|
700 |
t.assertEqual(items.length, 5);
|
|
|
701 |
request.start = 3;
|
|
|
702 |
request.count = 1;
|
|
|
703 |
request.onComplete = dumpSecondFetch;
|
|
|
704 |
store.fetch(request);
|
|
|
705 |
}
|
|
|
706 |
|
|
|
707 |
function dumpSecondFetch(items, request){
|
|
|
708 |
t.assertEqual(items.length, 1);
|
|
|
709 |
request.start = 0;
|
|
|
710 |
request.count = 5;
|
|
|
711 |
request.onComplete = dumpThirdFetch;
|
|
|
712 |
store.fetch(request);
|
|
|
713 |
}
|
|
|
714 |
|
|
|
715 |
function dumpThirdFetch(items, request){
|
|
|
716 |
t.assertEqual(items.length, 5);
|
|
|
717 |
request.start = 2;
|
|
|
718 |
request.count = 20;
|
|
|
719 |
request.onComplete = dumpFourthFetch;
|
|
|
720 |
store.fetch(request);
|
|
|
721 |
}
|
|
|
722 |
|
|
|
723 |
function dumpFourthFetch(items, request){
|
|
|
724 |
t.assertEqual(items.length, 5);
|
|
|
725 |
request.start = 9;
|
|
|
726 |
request.count = 100;
|
|
|
727 |
request.onComplete = dumpFifthFetch;
|
|
|
728 |
store.fetch(request);
|
|
|
729 |
}
|
|
|
730 |
|
|
|
731 |
function dumpFifthFetch(items, request){
|
|
|
732 |
t.assertEqual(items.length, 0);
|
|
|
733 |
request.start = 2;
|
|
|
734 |
request.count = 20;
|
|
|
735 |
request.onComplete = dumpSixthFetch;
|
|
|
736 |
store.fetch(request);
|
|
|
737 |
}
|
|
|
738 |
|
|
|
739 |
function dumpSixthFetch(items, request){
|
|
|
740 |
t.assertEqual(items.length, 5);
|
|
|
741 |
d.callback(true);
|
|
|
742 |
}
|
|
|
743 |
|
|
|
744 |
function completed(items, request){
|
|
|
745 |
t.assertEqual(items.length, 7);
|
|
|
746 |
request.start = 1;
|
|
|
747 |
request.count = 5;
|
|
|
748 |
request.onComplete = dumpFirstFetch;
|
|
|
749 |
store.fetch(request);
|
|
|
750 |
}
|
|
|
751 |
|
|
|
752 |
function error(errData, request){
|
|
|
753 |
t.assertTrue(false);
|
|
|
754 |
d.errback(errData);
|
|
|
755 |
}
|
|
|
756 |
store.fetch({onComplete: completed, onError: error});
|
|
|
757 |
return d;
|
|
|
758 |
}
|
|
|
759 |
},
|
|
|
760 |
{
|
|
|
761 |
name: "Read API: fetch() with MultiType Match",
|
|
|
762 |
runTest: function(datastore, t){
|
|
|
763 |
// summary:
|
|
|
764 |
// Simple test of a basic fetch againct an attribute that has different types for the value across items
|
|
|
765 |
// description:
|
|
|
766 |
// Simple test of a basic fetch againct an attribute that has different types for the value across items
|
|
|
767 |
// Introduced because of tracker: #4931
|
|
|
768 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("data_multitype"));
|
|
|
769 |
|
|
|
770 |
var d = new doh.Deferred();
|
|
|
771 |
function onComplete(items, request){
|
|
|
772 |
t.assertEqual(4, items.length);
|
|
|
773 |
d.callback(true);
|
|
|
774 |
}
|
|
|
775 |
function onError(errData, request){
|
|
|
776 |
t.assertTrue(false);
|
|
|
777 |
d.errback(errData);
|
|
|
778 |
}
|
|
|
779 |
store.fetch({ query: {count: "1*"},
|
|
|
780 |
onComplete: onComplete,
|
|
|
781 |
onError: onError
|
|
|
782 |
});
|
|
|
783 |
return d;
|
|
|
784 |
}
|
|
|
785 |
},
|
|
|
786 |
{
|
|
|
787 |
name: "Read API: fetch() with MultiType, MultiValue Match",
|
|
|
788 |
runTest: function(datastore, t){
|
|
|
789 |
// summary:
|
|
|
790 |
// Simple test of a basic fetch againct an attribute that has different types for the value across items
|
|
|
791 |
// description:
|
|
|
792 |
// Simple test of a basic fetch againct an attribute that has different types for the value across items
|
|
|
793 |
// Introduced because of tracker: #4931
|
|
|
794 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("data_multitype"));
|
|
|
795 |
|
|
|
796 |
var d = new doh.Deferred();
|
|
|
797 |
function onComplete(items, request){
|
|
|
798 |
t.assertEqual(7, items.length);
|
|
|
799 |
d.callback(true);
|
|
|
800 |
}
|
|
|
801 |
function onError(errData, request){
|
|
|
802 |
t.assertTrue(false);
|
|
|
803 |
d.errback(errData);
|
|
|
804 |
}
|
|
|
805 |
store.fetch({ query: {value: "true"},
|
|
|
806 |
onComplete: onComplete,
|
|
|
807 |
onError: onError
|
|
|
808 |
});
|
|
|
809 |
return d;
|
|
|
810 |
}
|
|
|
811 |
},
|
|
|
812 |
{
|
|
|
813 |
name: "Read API: getLabel()",
|
|
|
814 |
runTest: function(datastore, t){
|
|
|
815 |
// summary:
|
|
|
816 |
// Simple test of the getLabel function against a store set that has a label defined.
|
|
|
817 |
// description:
|
|
|
818 |
// Simple test of the getLabel function against a store set that has a label defined.
|
|
|
819 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
820 |
|
|
|
821 |
var d = new doh.Deferred();
|
|
|
822 |
function onComplete(items, request){
|
|
|
823 |
t.assertEqual(items.length, 1);
|
|
|
824 |
var label = store.getLabel(items[0]);
|
|
|
825 |
t.assertTrue(label !== null);
|
|
|
826 |
t.assertEqual("Ecuador", label);
|
|
|
827 |
d.callback(true);
|
|
|
828 |
}
|
|
|
829 |
function onError(errData, request){
|
|
|
830 |
t.assertTrue(false);
|
|
|
831 |
d.errback(errData);
|
|
|
832 |
}
|
|
|
833 |
store.fetch({ query: {abbr: "ec"},
|
|
|
834 |
onComplete: onComplete,
|
|
|
835 |
onError: onError
|
|
|
836 |
});
|
|
|
837 |
return d;
|
|
|
838 |
}
|
|
|
839 |
},
|
|
|
840 |
{
|
|
|
841 |
name: "Read API: getLabelAttributes()",
|
|
|
842 |
runTest: function(datastore, t){
|
|
|
843 |
// summary:
|
|
|
844 |
// Simple test of the getLabelAttributes function against a store set that has a label defined.
|
|
|
845 |
// description:
|
|
|
846 |
// Simple test of the getLabelAttributes function against a store set that has a label defined.
|
|
|
847 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
848 |
|
|
|
849 |
var d = new doh.Deferred();
|
|
|
850 |
function onComplete(items, request){
|
|
|
851 |
t.assertEqual(items.length, 1);
|
|
|
852 |
var labelList = store.getLabelAttributes(items[0]);
|
|
|
853 |
t.assertTrue(dojo.isArray(labelList));
|
|
|
854 |
t.assertEqual("name", labelList[0]);
|
|
|
855 |
d.callback(true);
|
|
|
856 |
}
|
|
|
857 |
function onError(errData, request){
|
|
|
858 |
t.assertTrue(false);
|
|
|
859 |
d.errback(errData);
|
|
|
860 |
}
|
|
|
861 |
store.fetch({ query: {abbr: "ec"},
|
|
|
862 |
onComplete: onComplete,
|
|
|
863 |
onError: onError
|
|
|
864 |
});
|
|
|
865 |
return d;
|
|
|
866 |
}
|
|
|
867 |
},
|
|
|
868 |
{
|
|
|
869 |
name: "Read API: getValue()",
|
|
|
870 |
runTest: function(datastore, t){
|
|
|
871 |
// summary:
|
|
|
872 |
// Simple test of the getValue function of the store.
|
|
|
873 |
// description:
|
|
|
874 |
// Simple test of the getValue function of the store.
|
|
|
875 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
876 |
|
|
|
877 |
var d = new doh.Deferred();
|
|
|
878 |
function onItem(item){
|
|
|
879 |
t.assertTrue(item !== null);
|
|
|
880 |
var name = store.getValue(item,"name");
|
|
|
881 |
t.assertTrue(name === "El Salvador");
|
|
|
882 |
d.callback(true);
|
|
|
883 |
}
|
|
|
884 |
function onError(errData){
|
|
|
885 |
t.assertTrue(false);
|
|
|
886 |
d.errback(errData);
|
|
|
887 |
}
|
|
|
888 |
store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError});
|
|
|
889 |
return d; // Deferred
|
|
|
890 |
}
|
|
|
891 |
},
|
|
|
892 |
{
|
|
|
893 |
name: "Read API: getValues()",
|
|
|
894 |
runTest: function(datastore, t){
|
|
|
895 |
// summary:
|
|
|
896 |
// Simple test of the getValues function of the store.
|
|
|
897 |
// description:
|
|
|
898 |
// Simple test of the getValues function of the store.
|
|
|
899 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
900 |
|
|
|
901 |
var d = new doh.Deferred();
|
|
|
902 |
function onItem(item){
|
|
|
903 |
t.assertTrue(item !== null);
|
|
|
904 |
var names = store.getValues(item,"name");
|
|
|
905 |
t.assertTrue(dojo.isArray(names));
|
|
|
906 |
t.assertEqual(names.length, 1);
|
|
|
907 |
t.assertEqual(names[0], "El Salvador");
|
|
|
908 |
d.callback(true);
|
|
|
909 |
}
|
|
|
910 |
function onError(errData){
|
|
|
911 |
t.assertTrue(false);
|
|
|
912 |
d.errback(errData);
|
|
|
913 |
}
|
|
|
914 |
store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError});
|
|
|
915 |
return d; // Deferred
|
|
|
916 |
}
|
|
|
917 |
},
|
|
|
918 |
{
|
|
|
919 |
name: "Read API: isItem()",
|
|
|
920 |
runTest: function(datastore, t){
|
|
|
921 |
// summary:
|
|
|
922 |
// Simple test of the isItem function of the store
|
|
|
923 |
// description:
|
|
|
924 |
// Simple test of the isItem function of the store
|
|
|
925 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
926 |
|
|
|
927 |
var d = new doh.Deferred();
|
|
|
928 |
function onItem(item){
|
|
|
929 |
t.assertTrue(item !== null);
|
|
|
930 |
t.assertTrue(store.isItem(item));
|
|
|
931 |
t.assertTrue(!store.isItem({}));
|
|
|
932 |
d.callback(true);
|
|
|
933 |
}
|
|
|
934 |
function onError(errData){
|
|
|
935 |
t.assertTrue(false);
|
|
|
936 |
d.errback(errData);
|
|
|
937 |
}
|
|
|
938 |
store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError});
|
|
|
939 |
return d; // Deferred
|
|
|
940 |
}
|
|
|
941 |
},
|
|
|
942 |
{
|
|
|
943 |
name: "Read API: isItem() multistore",
|
|
|
944 |
runTest: function(datastore, t){
|
|
|
945 |
// summary:
|
|
|
946 |
// Simple test of the isItem function of the store
|
|
|
947 |
// to verify two different store instances do not accept
|
|
|
948 |
// items from each other.
|
|
|
949 |
// description:
|
|
|
950 |
// Simple test of the isItem function of the store
|
|
|
951 |
// to verify two different store instances do not accept
|
|
|
952 |
// items from each other.
|
|
|
953 |
|
|
|
954 |
// Two different instances, even if they read from the same URL
|
|
|
955 |
// should not accept items between each other!
|
|
|
956 |
var store1 = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
957 |
var store2 = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
958 |
|
|
|
959 |
var d = new doh.Deferred();
|
|
|
960 |
function onItem1(item1){
|
|
|
961 |
t.assertTrue(item1 !== null);
|
|
|
962 |
|
|
|
963 |
function onItem2(item2){
|
|
|
964 |
t.assertTrue(item1 !== null);
|
|
|
965 |
t.assertTrue(item2 !== null);
|
|
|
966 |
t.assertTrue(store1.isItem(item1));
|
|
|
967 |
t.assertTrue(store2.isItem(item2));
|
|
|
968 |
t.assertTrue(!store1.isItem(item2));
|
|
|
969 |
t.assertTrue(!store2.isItem(item1));
|
|
|
970 |
d.callback(true);
|
|
|
971 |
}
|
|
|
972 |
store2.fetchItemByIdentity({identity: "sv", onItem: onItem2, onError: onError});
|
|
|
973 |
|
|
|
974 |
}
|
|
|
975 |
function onError(errData){
|
|
|
976 |
t.assertTrue(false);
|
|
|
977 |
d.errback(errData);
|
|
|
978 |
}
|
|
|
979 |
store1.fetchItemByIdentity({identity: "sv", onItem: onItem1, onError: onError});
|
|
|
980 |
return d; // Deferred
|
|
|
981 |
}
|
|
|
982 |
},
|
|
|
983 |
{
|
|
|
984 |
name: "Read API: hasAttribute()",
|
|
|
985 |
runTest: function(datastore, t){
|
|
|
986 |
// summary:
|
|
|
987 |
// Simple test of the hasAttribute function of the store
|
|
|
988 |
// description:
|
|
|
989 |
// Simple test of the hasAttribute function of the store
|
|
|
990 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
991 |
|
|
|
992 |
var d = new doh.Deferred();
|
|
|
993 |
function onItem(item){
|
|
|
994 |
t.assertTrue(item !== null);
|
|
|
995 |
t.assertTrue(store.hasAttribute(item, "abbr"));
|
|
|
996 |
t.assertTrue(!store.hasAttribute(item, "abbr_not"));
|
|
|
997 |
|
|
|
998 |
//Test that null attributes throw an exception
|
|
|
999 |
var passed = false;
|
|
|
1000 |
try{
|
|
|
1001 |
store.hasAttribute(item, null);
|
|
|
1002 |
}catch (e){
|
|
|
1003 |
passed = true;
|
|
|
1004 |
}
|
|
|
1005 |
t.assertTrue(passed);
|
|
|
1006 |
d.callback(true);
|
|
|
1007 |
}
|
|
|
1008 |
function onError(errData){
|
|
|
1009 |
t.assertTrue(false);
|
|
|
1010 |
d.errback(errData);
|
|
|
1011 |
}
|
|
|
1012 |
store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError});
|
|
|
1013 |
return d; // Deferred
|
|
|
1014 |
}
|
|
|
1015 |
},
|
|
|
1016 |
{
|
|
|
1017 |
name: "Read API: containsValue()",
|
|
|
1018 |
runTest: function(datastore, t){
|
|
|
1019 |
// summary:
|
|
|
1020 |
// Simple test of the containsValue function of the store
|
|
|
1021 |
// description:
|
|
|
1022 |
// Simple test of the containsValue function of the store
|
|
|
1023 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
1024 |
|
|
|
1025 |
var d = new doh.Deferred();
|
|
|
1026 |
function onItem(item){
|
|
|
1027 |
t.assertTrue(item !== null);
|
|
|
1028 |
t.assertTrue(store.containsValue(item, "abbr", "sv"));
|
|
|
1029 |
t.assertTrue(!store.containsValue(item, "abbr", "sv1"));
|
|
|
1030 |
t.assertTrue(!store.containsValue(item, "abbr", null));
|
|
|
1031 |
|
|
|
1032 |
//Test that null attributes throw an exception
|
|
|
1033 |
var passed = false;
|
|
|
1034 |
try{
|
|
|
1035 |
store.containsValue(item, null, "foo");
|
|
|
1036 |
}catch (e){
|
|
|
1037 |
passed = true;
|
|
|
1038 |
}
|
|
|
1039 |
t.assertTrue(passed);
|
|
|
1040 |
d.callback(true);
|
|
|
1041 |
}
|
|
|
1042 |
function onError(errData){
|
|
|
1043 |
t.assertTrue(false);
|
|
|
1044 |
d.errback(errData);
|
|
|
1045 |
}
|
|
|
1046 |
store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError});
|
|
|
1047 |
return d; // Deferred
|
|
|
1048 |
}
|
|
|
1049 |
},
|
|
|
1050 |
{
|
|
|
1051 |
name: "Read API: getAttributes()",
|
|
|
1052 |
runTest: function(datastore, t){
|
|
|
1053 |
// summary:
|
|
|
1054 |
// Simple test of the getAttributes function of the store
|
|
|
1055 |
// description:
|
|
|
1056 |
// Simple test of the getAttributes function of the store
|
|
|
1057 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
1058 |
|
|
|
1059 |
var d = new doh.Deferred();
|
|
|
1060 |
function onItem(item){
|
|
|
1061 |
t.assertTrue(item !== null);
|
|
|
1062 |
t.assertTrue(store.isItem(item));
|
|
|
1063 |
|
|
|
1064 |
var attributes = store.getAttributes(item);
|
|
|
1065 |
t.assertEqual(attributes.length, 3);
|
|
|
1066 |
for(var i = 0; i < attributes.length; i++){
|
|
|
1067 |
t.assertTrue((attributes[i] === "name" || attributes[i] === "abbr" || attributes[i] === "capital"));
|
|
|
1068 |
}
|
|
|
1069 |
d.callback(true);
|
|
|
1070 |
}
|
|
|
1071 |
function onError(errData){
|
|
|
1072 |
t.assertTrue(false);
|
|
|
1073 |
d.errback(errData);
|
|
|
1074 |
}
|
|
|
1075 |
store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError});
|
|
|
1076 |
return d; // Deferred
|
|
|
1077 |
}
|
|
|
1078 |
},
|
|
|
1079 |
{
|
|
|
1080 |
name: "Read API: getFeatures()",
|
|
|
1081 |
runTest: function(datastore, t){
|
|
|
1082 |
// summary:
|
|
|
1083 |
// Simple test of the getFeatures function of the store
|
|
|
1084 |
// description:
|
|
|
1085 |
// Simple test of the getFeatures function of the store
|
|
|
1086 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
1087 |
|
|
|
1088 |
var features = store.getFeatures();
|
|
|
1089 |
t.assertTrue(features["dojo.data.api.Read"] != null);
|
|
|
1090 |
t.assertTrue(features["dojo.data.api.Identity"] != null);
|
|
|
1091 |
}
|
|
|
1092 |
},
|
|
|
1093 |
{
|
|
|
1094 |
name: "Read API: fetch() patternMatch0",
|
|
|
1095 |
runTest: function(datastore, t){
|
|
|
1096 |
// summary:
|
|
|
1097 |
// Function to test pattern matching of everything starting with lowercase e
|
|
|
1098 |
// description:
|
|
|
1099 |
// Function to test pattern matching of everything starting with lowercase e
|
|
|
1100 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
1101 |
|
|
|
1102 |
var d = new doh.Deferred();
|
|
|
1103 |
function completed(items, request) {
|
|
|
1104 |
t.assertEqual(items.length, 5);
|
|
|
1105 |
var passed = true;
|
|
|
1106 |
for(var i = 0; i < items.length; i++){
|
|
|
1107 |
var value = store.getValue(items[i], "abbr");
|
|
|
1108 |
if(!(value === "ec" || value === "eg" || value === "er" || value === "ee" || value === "et")){
|
|
|
1109 |
passed=false;
|
|
|
1110 |
break;
|
|
|
1111 |
}
|
|
|
1112 |
}
|
|
|
1113 |
t.assertTrue(passed);
|
|
|
1114 |
if (passed){
|
|
|
1115 |
d.callback(true);
|
|
|
1116 |
}else{
|
|
|
1117 |
d.errback(new Error("Unexpected abbreviation found, match failure."));
|
|
|
1118 |
}
|
|
|
1119 |
}
|
|
|
1120 |
function error(error, request) {
|
|
|
1121 |
t.assertTrue(false);
|
|
|
1122 |
d.errback(error);
|
|
|
1123 |
}
|
|
|
1124 |
store.fetch({query: {abbr: "e*"}, onComplete: completed, onError: error});
|
|
|
1125 |
return d;
|
|
|
1126 |
}
|
|
|
1127 |
},
|
|
|
1128 |
{
|
|
|
1129 |
name: "Read API: fetch() patternMatch1",
|
|
|
1130 |
runTest: function(datastore, t){
|
|
|
1131 |
// summary:
|
|
|
1132 |
// Function to test pattern matching of everything with $ in it.
|
|
|
1133 |
// description:
|
|
|
1134 |
// Function to test pattern matching of everything with $ in it.
|
|
|
1135 |
|
|
|
1136 |
var store = new datastore({data: { identifier: "uniqueId",
|
|
|
1137 |
items: [ {uniqueId: 1, value:"foo*bar"},
|
|
|
1138 |
{uniqueId: 2, value:"bar*foo"},
|
|
|
1139 |
{uniqueId: 3, value:"boomBam"},
|
|
|
1140 |
{uniqueId: 4, value:"bit$Bite"},
|
|
|
1141 |
{uniqueId: 5, value:"ouagadogou"},
|
|
|
1142 |
{uniqueId: 6, value:"BaBaMaSaRa***Foo"},
|
|
|
1143 |
{uniqueId: 7, value:"squawl"},
|
|
|
1144 |
{uniqueId: 8, value:"seaweed"},
|
|
|
1145 |
{uniqueId: 9, value:"jfq4@#!$!@Rf14r14i5u"}
|
|
|
1146 |
]
|
|
|
1147 |
}
|
|
|
1148 |
});
|
|
|
1149 |
|
|
|
1150 |
var d = new doh.Deferred();
|
|
|
1151 |
function completed(items, request){
|
|
|
1152 |
t.assertEqual(items.length, 2);
|
|
|
1153 |
var passed = true;
|
|
|
1154 |
for(var i = 0; i < items.length; i++){
|
|
|
1155 |
var value = store.getValue(items[i], "value");
|
|
|
1156 |
if(!(value === "bit$Bite" || value === "jfq4@#!$!@Rf14r14i5u")){
|
|
|
1157 |
passed=false;
|
|
|
1158 |
break;
|
|
|
1159 |
}
|
|
|
1160 |
}
|
|
|
1161 |
t.assertTrue(passed);
|
|
|
1162 |
if (passed){
|
|
|
1163 |
d.callback(true);
|
|
|
1164 |
}else{
|
|
|
1165 |
d.errback(new Error("Unexpected pattern matched. Filter failure."));
|
|
|
1166 |
}
|
|
|
1167 |
}
|
|
|
1168 |
function error(error, request){
|
|
|
1169 |
t.assertTrue(false);
|
|
|
1170 |
d.errback(error);
|
|
|
1171 |
}
|
|
|
1172 |
store.fetch({query: {value: "*$*"}, onComplete: completed, onError: error});
|
|
|
1173 |
return d;
|
|
|
1174 |
}
|
|
|
1175 |
},
|
|
|
1176 |
{
|
|
|
1177 |
name: "Read API: fetch() patternMatch2",
|
|
|
1178 |
runTest: function(datastore, t){
|
|
|
1179 |
// summary:
|
|
|
1180 |
// Function to test exact pattern match
|
|
|
1181 |
// description:
|
|
|
1182 |
// Function to test exact pattern match
|
|
|
1183 |
|
|
|
1184 |
var store = new datastore({data: { identifier: "uniqueId",
|
|
|
1185 |
items: [ {uniqueId: 1, value:"foo*bar"},
|
|
|
1186 |
{uniqueId: 2, value:"bar*foo"},
|
|
|
1187 |
{uniqueId: 3, value:"boomBam"},
|
|
|
1188 |
{uniqueId: 4, value:"bit$Bite"},
|
|
|
1189 |
{uniqueId: 5, value:"ouagadogou"},
|
|
|
1190 |
{uniqueId: 6, value:"BaBaMaSaRa***Foo"},
|
|
|
1191 |
{uniqueId: 7, value:"squawl"},
|
|
|
1192 |
{uniqueId: 8, value:"seaweed"},
|
|
|
1193 |
{uniqueId: 9, value:"jfq4@#!$!@Rf14r14i5u"}
|
|
|
1194 |
]
|
|
|
1195 |
}
|
|
|
1196 |
});
|
|
|
1197 |
|
|
|
1198 |
var d = new doh.Deferred();
|
|
|
1199 |
function completed(items, request){
|
|
|
1200 |
t.assertEqual(items.length, 1);
|
|
|
1201 |
var passed = true;
|
|
|
1202 |
for(var i = 0; i < items.length; i++){
|
|
|
1203 |
var value = store.getValue(items[i], "value");
|
|
|
1204 |
if(!(value === "bar*foo")){
|
|
|
1205 |
passed=false;
|
|
|
1206 |
break;
|
|
|
1207 |
}
|
|
|
1208 |
}
|
|
|
1209 |
t.assertTrue(passed);
|
|
|
1210 |
if (passed){
|
|
|
1211 |
d.callback(true);
|
|
|
1212 |
}else{
|
|
|
1213 |
d.errback(new Error("Unexpected abbreviation found, match failure."));
|
|
|
1214 |
}
|
|
|
1215 |
}
|
|
|
1216 |
function error(error, request){
|
|
|
1217 |
t.assertTrue(false);
|
|
|
1218 |
d.errback(error);
|
|
|
1219 |
}
|
|
|
1220 |
store.fetch({query: {value: "bar\*foo"}, onComplete: completed, onError: error});
|
|
|
1221 |
return d;
|
|
|
1222 |
}
|
|
|
1223 |
},
|
|
|
1224 |
{
|
|
|
1225 |
name: "Read API: fetch() patternMatch_caseSensitive",
|
|
|
1226 |
runTest: function(datastore, t){
|
|
|
1227 |
// summary:
|
|
|
1228 |
// Function to test pattern matching of a pattern case-sensitively
|
|
|
1229 |
// description:
|
|
|
1230 |
// Function to test pattern matching of a pattern case-sensitively
|
|
|
1231 |
|
|
|
1232 |
var store = new datastore({data: { identifier: "uniqueId",
|
|
|
1233 |
items: [ {uniqueId: 1, value:"foo*bar"},
|
|
|
1234 |
{uniqueId: 2, value:"bar*foo"},
|
|
|
1235 |
{uniqueId: 3, value:"BAR*foo"},
|
|
|
1236 |
{uniqueId: 4, value:"BARBananafoo"}
|
|
|
1237 |
]
|
|
|
1238 |
}
|
|
|
1239 |
});
|
|
|
1240 |
|
|
|
1241 |
var d = new doh.Deferred();
|
|
|
1242 |
function completed(items, request){
|
|
|
1243 |
t.assertEqual(1, items.length);
|
|
|
1244 |
var passed = true;
|
|
|
1245 |
for(var i = 0; i < items.length; i++){
|
|
|
1246 |
var value = store.getValue(items[i], "value");
|
|
|
1247 |
if(!(value === "bar*foo")){
|
|
|
1248 |
passed=false;
|
|
|
1249 |
break;
|
|
|
1250 |
}
|
|
|
1251 |
}
|
|
|
1252 |
t.assertTrue(passed);
|
|
|
1253 |
if (passed){
|
|
|
1254 |
d.callback(true);
|
|
|
1255 |
}else{
|
|
|
1256 |
d.errback(new Error("Unexpected pattern matched. Filter failure."));
|
|
|
1257 |
}
|
|
|
1258 |
}
|
|
|
1259 |
function error(error, request){
|
|
|
1260 |
t.assertTrue(false);
|
|
|
1261 |
d.errback(error);
|
|
|
1262 |
}
|
|
|
1263 |
store.fetch({query: {value: "bar\\*foo"}, queryOptions: {ignoreCase: false} , onComplete: completed, onError: error});
|
|
|
1264 |
return d;
|
|
|
1265 |
}
|
|
|
1266 |
},
|
|
|
1267 |
{
|
|
|
1268 |
name: "Read API: fetch() patternMatch_caseInsensitive",
|
|
|
1269 |
runTest: function(datastore, t){
|
|
|
1270 |
// summary:
|
|
|
1271 |
// Function to test pattern matching of a pattern case-insensitively
|
|
|
1272 |
// description:
|
|
|
1273 |
// Function to test pattern matching of a pattern case-insensitively
|
|
|
1274 |
|
|
|
1275 |
var store = new datastore({data: { identifier: "uniqueId",
|
|
|
1276 |
items: [ {uniqueId: 1, value:"foo*bar"},
|
|
|
1277 |
{uniqueId: 2, value:"bar*foo"},
|
|
|
1278 |
{uniqueId: 3, value:"BAR*foo"},
|
|
|
1279 |
{uniqueId: 4, value:"BARBananafoo"}
|
|
|
1280 |
]
|
|
|
1281 |
}
|
|
|
1282 |
});
|
|
|
1283 |
|
|
|
1284 |
var d = new doh.Deferred();
|
|
|
1285 |
function completed(items, request){
|
|
|
1286 |
t.assertEqual(items.length, 2);
|
|
|
1287 |
var passed = true;
|
|
|
1288 |
for(var i = 0; i < items.length; i++){
|
|
|
1289 |
var value = store.getValue(items[i], "value");
|
|
|
1290 |
if(!(value === "BAR*foo" || value === "bar*foo")){
|
|
|
1291 |
passed=false;
|
|
|
1292 |
break;
|
|
|
1293 |
}
|
|
|
1294 |
}
|
|
|
1295 |
t.assertTrue(passed);
|
|
|
1296 |
if (passed){
|
|
|
1297 |
d.callback(true);
|
|
|
1298 |
}else{
|
|
|
1299 |
d.errback(new Error("Unexpected pattern matched. Filter failure."));
|
|
|
1300 |
}
|
|
|
1301 |
}
|
|
|
1302 |
function error(error, request){
|
|
|
1303 |
t.assertTrue(false);
|
|
|
1304 |
d.errback(error);
|
|
|
1305 |
}
|
|
|
1306 |
store.fetch({query: {value: "bar\\*foo"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: error});
|
|
|
1307 |
return d;
|
|
|
1308 |
}
|
|
|
1309 |
},
|
|
|
1310 |
{
|
|
|
1311 |
name: "Read API: fetch() sortNumeric",
|
|
|
1312 |
runTest: function(datastore, t){
|
|
|
1313 |
// summary:
|
|
|
1314 |
// Function to test sorting numerically.
|
|
|
1315 |
// description:
|
|
|
1316 |
// Function to test sorting numerically.
|
|
|
1317 |
|
|
|
1318 |
var store = new datastore({data: { identifier: "uniqueId",
|
|
|
1319 |
items: [ {uniqueId: 0, value:"fo|o*b.ar"},
|
|
|
1320 |
{uniqueId: 1, value:"ba|r*foo"},
|
|
|
1321 |
{uniqueId: 2, value:"boomBam"},
|
|
|
1322 |
{uniqueId: 3, value:"bit$Bite"},
|
|
|
1323 |
{uniqueId: 4, value:"ouagadogou"},
|
|
|
1324 |
{uniqueId: 5, value:"jfq4@#!$!@|f1.$4r14i5u"},
|
|
|
1325 |
{uniqueId: 6, value:"BaB{aMa|SaRa***F}oo"},
|
|
|
1326 |
{uniqueId: 7, value:"squawl"},
|
|
|
1327 |
{uniqueId: 9, value:"seaweed"},
|
|
|
1328 |
{uniqueId: 10, value:"zulu"},
|
|
|
1329 |
{uniqueId: 8, value:"seaweed"}
|
|
|
1330 |
]
|
|
|
1331 |
}
|
|
|
1332 |
});
|
|
|
1333 |
|
|
|
1334 |
var d = new doh.Deferred();
|
|
|
1335 |
function completed(items, request){
|
|
|
1336 |
t.assertEqual(items.length, 11);
|
|
|
1337 |
var passed = true;
|
|
|
1338 |
for(var i = 0; i < items.length; i++){
|
|
|
1339 |
var value = store.getValue(items[i], "value");
|
|
|
1340 |
if(!(store.getValue(items[i], "uniqueId") === i)){
|
|
|
1341 |
passed=false;
|
|
|
1342 |
break;
|
|
|
1343 |
}
|
|
|
1344 |
}
|
|
|
1345 |
t.assertTrue(passed);
|
|
|
1346 |
if (passed){
|
|
|
1347 |
d.callback(true);
|
|
|
1348 |
}else{
|
|
|
1349 |
d.errback(new Error("Unexpected sorting order found, sort failure."));
|
|
|
1350 |
}
|
|
|
1351 |
}
|
|
|
1352 |
|
|
|
1353 |
function error(error, request){
|
|
|
1354 |
t.assertTrue(false);
|
|
|
1355 |
d.errback(error);
|
|
|
1356 |
}
|
|
|
1357 |
|
|
|
1358 |
var sortAttributes = [{attribute: "uniqueId"}];
|
|
|
1359 |
store.fetch({onComplete: completed, onError: error, sort: sortAttributes});
|
|
|
1360 |
return d;
|
|
|
1361 |
}
|
|
|
1362 |
},
|
|
|
1363 |
{
|
|
|
1364 |
name: "Read API: fetch() sortNumericDescending",
|
|
|
1365 |
runTest: function(datastore, t){
|
|
|
1366 |
// summary:
|
|
|
1367 |
// Function to test sorting numerically.
|
|
|
1368 |
// description:
|
|
|
1369 |
// Function to test sorting numerically.
|
|
|
1370 |
|
|
|
1371 |
var store = new datastore({data: { identifier: "uniqueId",
|
|
|
1372 |
items: [ {uniqueId: 0, value:"fo|o*b.ar"},
|
|
|
1373 |
{uniqueId: 1, value:"ba|r*foo"},
|
|
|
1374 |
{uniqueId: 2, value:"boomBam"},
|
|
|
1375 |
{uniqueId: 3, value:"bit$Bite"},
|
|
|
1376 |
{uniqueId: 4, value:"ouagadogou"},
|
|
|
1377 |
{uniqueId: 5, value:"jfq4@#!$!@|f1.$4r14i5u"},
|
|
|
1378 |
{uniqueId: 6, value:"BaB{aMa|SaRa***F}oo"},
|
|
|
1379 |
{uniqueId: 7, value:"squawl"},
|
|
|
1380 |
{uniqueId: 9, value:"seaweed"},
|
|
|
1381 |
{uniqueId: 10, value:"zulu"},
|
|
|
1382 |
{uniqueId: 8, value:"seaweed"}
|
|
|
1383 |
]
|
|
|
1384 |
}
|
|
|
1385 |
});
|
|
|
1386 |
var d = new doh.Deferred();
|
|
|
1387 |
function completed(items, request){
|
|
|
1388 |
t.assertEqual(items.length, 11);
|
|
|
1389 |
var passed = true;
|
|
|
1390 |
for(var i = 0; i < items.length; i++){
|
|
|
1391 |
var value = store.getValue(items[i], "value");
|
|
|
1392 |
if(!((items.length - (store.getValue(items[i], "uniqueId") + 1)) === i)){
|
|
|
1393 |
passed=false;
|
|
|
1394 |
break;
|
|
|
1395 |
}
|
|
|
1396 |
}
|
|
|
1397 |
t.assertTrue(passed);
|
|
|
1398 |
if (passed){
|
|
|
1399 |
d.callback(true);
|
|
|
1400 |
}else{
|
|
|
1401 |
d.errback(new Error("Unexpected sorting order found, sort failure."));
|
|
|
1402 |
}
|
|
|
1403 |
}
|
|
|
1404 |
|
|
|
1405 |
function error(error, request){
|
|
|
1406 |
t.assertTrue(false);
|
|
|
1407 |
d.errback(error);
|
|
|
1408 |
}
|
|
|
1409 |
|
|
|
1410 |
var sortAttributes = [{attribute: "uniqueId", descending: true}];
|
|
|
1411 |
store.fetch({onComplete: completed, onError: error, sort: sortAttributes});
|
|
|
1412 |
return d;
|
|
|
1413 |
}
|
|
|
1414 |
},
|
|
|
1415 |
{
|
|
|
1416 |
name: "Read API: fetch() sortNumericWithCount",
|
|
|
1417 |
runTest: function(datastore, t){
|
|
|
1418 |
// summary:
|
|
|
1419 |
// Function to test sorting numerically in descending order, returning only a specified number of them.
|
|
|
1420 |
// description:
|
|
|
1421 |
// Function to test sorting numerically in descending order, returning only a specified number of them.
|
|
|
1422 |
|
|
|
1423 |
var store = new datastore({data: { identifier: "uniqueId",
|
|
|
1424 |
items: [ {uniqueId: 0, value:"fo|o*b.ar"},
|
|
|
1425 |
{uniqueId: 1, value:"ba|r*foo"},
|
|
|
1426 |
{uniqueId: 2, value:"boomBam"},
|
|
|
1427 |
{uniqueId: 3, value:"bit$Bite"},
|
|
|
1428 |
{uniqueId: 4, value:"ouagadogou"},
|
|
|
1429 |
{uniqueId: 5, value:"jfq4@#!$!@|f1.$4r14i5u"},
|
|
|
1430 |
{uniqueId: 6, value:"BaB{aMa|SaRa***F}oo"},
|
|
|
1431 |
{uniqueId: 7, value:"squawl"},
|
|
|
1432 |
{uniqueId: 9, value:"seaweed"},
|
|
|
1433 |
{uniqueId: 10, value:"zulu"},
|
|
|
1434 |
{uniqueId: 8, value:"seaweed"}
|
|
|
1435 |
]
|
|
|
1436 |
}
|
|
|
1437 |
});
|
|
|
1438 |
|
|
|
1439 |
var d = new doh.Deferred();
|
|
|
1440 |
function completed(items, request){
|
|
|
1441 |
t.assertEqual(items.length, 5);
|
|
|
1442 |
var itemId = 10;
|
|
|
1443 |
var passed = true;
|
|
|
1444 |
for(var i = 0; i < items.length; i++){
|
|
|
1445 |
var value = store.getValue(items[i], "value");
|
|
|
1446 |
if(!(store.getValue(items[i], "uniqueId") === itemId)){
|
|
|
1447 |
passed=false;
|
|
|
1448 |
break;
|
|
|
1449 |
}
|
|
|
1450 |
itemId--; // Decrement the item id. We are descending sorted, so it should go 10, 9, 8, etc.
|
|
|
1451 |
}
|
|
|
1452 |
t.assertTrue(passed);
|
|
|
1453 |
if (passed){
|
|
|
1454 |
d.callback(true);
|
|
|
1455 |
}else{
|
|
|
1456 |
d.errback(new Error("Unexpected sorting order found, sort failure."));
|
|
|
1457 |
}
|
|
|
1458 |
}
|
|
|
1459 |
|
|
|
1460 |
function error(error, request){
|
|
|
1461 |
t.assertTrue(false);
|
|
|
1462 |
d.errback(error);
|
|
|
1463 |
}
|
|
|
1464 |
|
|
|
1465 |
var sortAttributes = [{attribute: "uniqueId", descending: true}];
|
|
|
1466 |
store.fetch({onComplete: completed, onError: error, sort: sortAttributes, count: 5});
|
|
|
1467 |
return d;
|
|
|
1468 |
}
|
|
|
1469 |
},
|
|
|
1470 |
{
|
|
|
1471 |
name: "Read API: fetch() sortAlphabetic",
|
|
|
1472 |
runTest: function(datastore, t){
|
|
|
1473 |
// summary:
|
|
|
1474 |
// Function to test sorting alphabetic ordering.
|
|
|
1475 |
// description:
|
|
|
1476 |
// Function to test sorting alphabetic ordering.
|
|
|
1477 |
|
|
|
1478 |
var store = new datastore({data: { identifier: "uniqueId",
|
|
|
1479 |
items: [ {uniqueId: 0, value:"abc"},
|
|
|
1480 |
{uniqueId: 1, value:"bca"},
|
|
|
1481 |
{uniqueId: 2, value:"abcd"},
|
|
|
1482 |
{uniqueId: 3, value:"abcdefg"},
|
|
|
1483 |
{uniqueId: 4, value:"lmnop"},
|
|
|
1484 |
{uniqueId: 5, value:"foghorn"},
|
|
|
1485 |
{uniqueId: 6, value:"qberty"},
|
|
|
1486 |
{uniqueId: 7, value:"qwerty"},
|
|
|
1487 |
{uniqueId: 8, value:""},
|
|
|
1488 |
{uniqueId: 9, value:"seaweed"},
|
|
|
1489 |
{uniqueId: 10, value:"123abc"}
|
|
|
1490 |
|
|
|
1491 |
]
|
|
|
1492 |
}
|
|
|
1493 |
});
|
|
|
1494 |
|
|
|
1495 |
var d = new doh.Deferred();
|
|
|
1496 |
function completed(items, request){
|
|
|
1497 |
//Output should be in this order...
|
|
|
1498 |
var orderedArray = [ "",
|
|
|
1499 |
"123abc",
|
|
|
1500 |
"abc",
|
|
|
1501 |
"abcd",
|
|
|
1502 |
"abcdefg",
|
|
|
1503 |
"bca",
|
|
|
1504 |
"foghorn",
|
|
|
1505 |
"lmnop",
|
|
|
1506 |
"qberty",
|
|
|
1507 |
"qwerty",
|
|
|
1508 |
"seaweed"
|
|
|
1509 |
];
|
|
|
1510 |
t.assertEqual(items.length, 11);
|
|
|
1511 |
var passed = true;
|
|
|
1512 |
for(var i = 0; i < items.length; i++){
|
|
|
1513 |
var value = store.getValue(items[i], "value");
|
|
|
1514 |
if(!(store.getValue(items[i], "value") === orderedArray[i])){
|
|
|
1515 |
passed=false;
|
|
|
1516 |
break;
|
|
|
1517 |
}
|
|
|
1518 |
}
|
|
|
1519 |
t.assertTrue(passed);
|
|
|
1520 |
if (passed){
|
|
|
1521 |
d.callback(true);
|
|
|
1522 |
}else{
|
|
|
1523 |
d.errback(new Error("Unexpected sorting order found, sort failure."));
|
|
|
1524 |
}
|
|
|
1525 |
}
|
|
|
1526 |
|
|
|
1527 |
function error(error, request) {
|
|
|
1528 |
t.assertTrue(false);
|
|
|
1529 |
d.errback(error);
|
|
|
1530 |
}
|
|
|
1531 |
|
|
|
1532 |
var sortAttributes = [{attribute: "value"}];
|
|
|
1533 |
store.fetch({onComplete: completed, onError: error, sort: sortAttributes});
|
|
|
1534 |
return d;
|
|
|
1535 |
}
|
|
|
1536 |
},
|
|
|
1537 |
{
|
|
|
1538 |
name: "Read API: fetch() sortAlphabeticDescending",
|
|
|
1539 |
runTest: function(datastore, t){
|
|
|
1540 |
// summary:
|
|
|
1541 |
// Function to test sorting alphabetic ordering in descending mode.
|
|
|
1542 |
// description:
|
|
|
1543 |
// Function to test sorting alphabetic ordering in descending mode.
|
|
|
1544 |
|
|
|
1545 |
var store = new datastore({data: { identifier: "uniqueId",
|
|
|
1546 |
items: [ {uniqueId: 0, value:"abc"},
|
|
|
1547 |
{uniqueId: 1, value:"bca"},
|
|
|
1548 |
{uniqueId: 2, value:"abcd"},
|
|
|
1549 |
{uniqueId: 3, value:"abcdefg"},
|
|
|
1550 |
{uniqueId: 4, value:"lmnop"},
|
|
|
1551 |
{uniqueId: 5, value:"foghorn"},
|
|
|
1552 |
{uniqueId: 6, value:"qberty"},
|
|
|
1553 |
{uniqueId: 7, value:"qwerty"},
|
|
|
1554 |
{uniqueId: 8, value:""},
|
|
|
1555 |
{uniqueId: 9, value:"seaweed"},
|
|
|
1556 |
{uniqueId: 10, value:"123abc"}
|
|
|
1557 |
|
|
|
1558 |
]
|
|
|
1559 |
}
|
|
|
1560 |
});
|
|
|
1561 |
var d = new doh.Deferred();
|
|
|
1562 |
function completed(items, request){
|
|
|
1563 |
//Output should be in this order...
|
|
|
1564 |
var orderedArray = [ "",
|
|
|
1565 |
"123abc",
|
|
|
1566 |
"abc",
|
|
|
1567 |
"abcd",
|
|
|
1568 |
"abcdefg",
|
|
|
1569 |
"bca",
|
|
|
1570 |
"foghorn",
|
|
|
1571 |
"lmnop",
|
|
|
1572 |
"qberty",
|
|
|
1573 |
"qwerty",
|
|
|
1574 |
"seaweed"
|
|
|
1575 |
];
|
|
|
1576 |
orderedArray = orderedArray.reverse();
|
|
|
1577 |
t.assertEqual(items.length, 11);
|
|
|
1578 |
|
|
|
1579 |
var passed = true;
|
|
|
1580 |
for(var i = 0; i < items.length; i++){
|
|
|
1581 |
var value = store.getValue(items[i], "value");
|
|
|
1582 |
if(!(store.getValue(items[i], "value") === orderedArray[i])){
|
|
|
1583 |
passed=false;
|
|
|
1584 |
break;
|
|
|
1585 |
}
|
|
|
1586 |
}
|
|
|
1587 |
t.assertTrue(passed);
|
|
|
1588 |
if (passed){
|
|
|
1589 |
d.callback(true);
|
|
|
1590 |
}else{
|
|
|
1591 |
d.errback(new Error("Unexpected sorting order found, sort failure."));
|
|
|
1592 |
}
|
|
|
1593 |
}
|
|
|
1594 |
|
|
|
1595 |
function error(error, request) {
|
|
|
1596 |
t.assertTrue(false);
|
|
|
1597 |
d.errback(error);
|
|
|
1598 |
}
|
|
|
1599 |
|
|
|
1600 |
var sortAttributes = [{attribute: "value", descending: true}];
|
|
|
1601 |
store.fetch({onComplete: completed, onError: error, sort: sortAttributes});
|
|
|
1602 |
return d;
|
|
|
1603 |
}
|
|
|
1604 |
},
|
|
|
1605 |
{
|
|
|
1606 |
name: "Read API: fetch() sortDate",
|
|
|
1607 |
runTest: function(datastore, t){
|
|
|
1608 |
// summary:
|
|
|
1609 |
// Function to test sorting date.
|
|
|
1610 |
// description:
|
|
|
1611 |
// Function to test sorting date.
|
|
|
1612 |
|
|
|
1613 |
var store = new datastore({data: { identifier: "uniqueId",
|
|
|
1614 |
items: [ {uniqueId: 0, value: new Date(0)},
|
|
|
1615 |
{uniqueId: 1, value: new Date(100)},
|
|
|
1616 |
{uniqueId: 2, value:new Date(1000)},
|
|
|
1617 |
{uniqueId: 3, value:new Date(2000)},
|
|
|
1618 |
{uniqueId: 4, value:new Date(3000)},
|
|
|
1619 |
{uniqueId: 5, value:new Date(4000)},
|
|
|
1620 |
{uniqueId: 6, value:new Date(5000)},
|
|
|
1621 |
{uniqueId: 7, value:new Date(6000)},
|
|
|
1622 |
{uniqueId: 8, value:new Date(7000)},
|
|
|
1623 |
{uniqueId: 9, value:new Date(8000)},
|
|
|
1624 |
{uniqueId: 10, value:new Date(9000)}
|
|
|
1625 |
|
|
|
1626 |
]
|
|
|
1627 |
}
|
|
|
1628 |
});
|
|
|
1629 |
|
|
|
1630 |
var d = new doh.Deferred();
|
|
|
1631 |
function completed(items,request){
|
|
|
1632 |
var orderedArray = [0,100,1000,2000,3000,4000,5000,6000,7000,8000,9000];
|
|
|
1633 |
t.assertEqual(items.length, 11);
|
|
|
1634 |
var passed = true;
|
|
|
1635 |
for(var i = 0; i < items.length; i++){
|
|
|
1636 |
var value = store.getValue(items[i], "value");
|
|
|
1637 |
if(!(store.getValue(items[i], "value").getTime() === orderedArray[i])){
|
|
|
1638 |
passed=false;
|
|
|
1639 |
break;
|
|
|
1640 |
}
|
|
|
1641 |
}
|
|
|
1642 |
t.assertTrue(passed);
|
|
|
1643 |
if (passed){
|
|
|
1644 |
d.callback(true);
|
|
|
1645 |
}else{
|
|
|
1646 |
d.errback(new Error("Unexpected sorting order found, sort failure."));
|
|
|
1647 |
}
|
|
|
1648 |
}
|
|
|
1649 |
|
|
|
1650 |
function error(error, request){
|
|
|
1651 |
t.assertTrue(false);
|
|
|
1652 |
d.errback(error);
|
|
|
1653 |
}
|
|
|
1654 |
|
|
|
1655 |
var sortAttributes = [{attribute: "value"}];
|
|
|
1656 |
store.fetch({onComplete: completed, onError: error, sort: sortAttributes});
|
|
|
1657 |
return d;
|
|
|
1658 |
}
|
|
|
1659 |
},
|
|
|
1660 |
{
|
|
|
1661 |
name: "Read API: fetch() sortDateDescending",
|
|
|
1662 |
runTest: function(datastore, t){
|
|
|
1663 |
// summary:
|
|
|
1664 |
// Function to test sorting date in descending order.
|
|
|
1665 |
// description:
|
|
|
1666 |
// Function to test sorting date in descending order.
|
|
|
1667 |
|
|
|
1668 |
var store = new datastore({data: { identifier: "uniqueId",
|
|
|
1669 |
items: [ {uniqueId: 0, value: new Date(0)},
|
|
|
1670 |
{uniqueId: 1, value: new Date(100)},
|
|
|
1671 |
{uniqueId: 2, value:new Date(1000)},
|
|
|
1672 |
{uniqueId: 3, value:new Date(2000)},
|
|
|
1673 |
{uniqueId: 4, value:new Date(3000)},
|
|
|
1674 |
{uniqueId: 5, value:new Date(4000)},
|
|
|
1675 |
{uniqueId: 6, value:new Date(5000)},
|
|
|
1676 |
{uniqueId: 7, value:new Date(6000)},
|
|
|
1677 |
{uniqueId: 8, value:new Date(7000)},
|
|
|
1678 |
{uniqueId: 9, value:new Date(8000)},
|
|
|
1679 |
{uniqueId: 10, value:new Date(9000)}
|
|
|
1680 |
|
|
|
1681 |
]
|
|
|
1682 |
}
|
|
|
1683 |
});
|
|
|
1684 |
|
|
|
1685 |
var d = new doh.Deferred();
|
|
|
1686 |
function completed(items,request){
|
|
|
1687 |
var orderedArray = [0,100,1000,2000,3000,4000,5000,6000,7000,8000,9000];
|
|
|
1688 |
orderedArray = orderedArray.reverse();
|
|
|
1689 |
t.assertEqual(items.length, 11);
|
|
|
1690 |
var passed = true;
|
|
|
1691 |
for(var i = 0; i < items.length; i++){
|
|
|
1692 |
var value = store.getValue(items[i], "value");
|
|
|
1693 |
if(!(store.getValue(items[i], "value").getTime() === orderedArray[i])){
|
|
|
1694 |
passed=false;
|
|
|
1695 |
break;
|
|
|
1696 |
}
|
|
|
1697 |
}
|
|
|
1698 |
t.assertTrue(passed);
|
|
|
1699 |
if (passed){
|
|
|
1700 |
d.callback(true);
|
|
|
1701 |
}else{
|
|
|
1702 |
d.errback(new Error("Unexpected sorting order found, sort failure."));
|
|
|
1703 |
}
|
|
|
1704 |
}
|
|
|
1705 |
|
|
|
1706 |
function error(error, request){
|
|
|
1707 |
t.assertTrue(false);
|
|
|
1708 |
d.errback(error);
|
|
|
1709 |
}
|
|
|
1710 |
|
|
|
1711 |
var sortAttributes = [{attribute: "value", descending: true}];
|
|
|
1712 |
store.fetch({onComplete: completed, onError: error, sort: sortAttributes});
|
|
|
1713 |
return d;
|
|
|
1714 |
}
|
|
|
1715 |
},
|
|
|
1716 |
{
|
|
|
1717 |
name: "Read API: fetch() sortMultiple",
|
|
|
1718 |
runTest: function(datastore, t){
|
|
|
1719 |
// summary:
|
|
|
1720 |
// Function to test sorting on multiple attributes.
|
|
|
1721 |
// description:
|
|
|
1722 |
// Function to test sorting on multiple attributes.
|
|
|
1723 |
|
|
|
1724 |
var store = new datastore({data: { identifier: "uniqueId",
|
|
|
1725 |
items: [ {uniqueId: 1, value:"fo|o*b.ar"},
|
|
|
1726 |
{uniqueId: 2, value:"ba|r*foo"},
|
|
|
1727 |
{uniqueId: 3, value:"boomBam"},
|
|
|
1728 |
{uniqueId: 4, value:"bit$Bite"},
|
|
|
1729 |
{uniqueId: 5, value:"ouagadogou"},
|
|
|
1730 |
{uniqueId: 6, value:"jfq4@#!$!@|f1.$4r14i5u"},
|
|
|
1731 |
{uniqueId: 7, value:"BaB{aMa|SaRa***F}oo"},
|
|
|
1732 |
{uniqueId: 8, value:"squawl"},
|
|
|
1733 |
{uniqueId: 10, value:"seaweed"},
|
|
|
1734 |
{uniqueId: 12, value:"seaweed"},
|
|
|
1735 |
{uniqueId: 11, value:"zulu"},
|
|
|
1736 |
{uniqueId: 9, value:"seaweed"}
|
|
|
1737 |
]
|
|
|
1738 |
}
|
|
|
1739 |
});
|
|
|
1740 |
|
|
|
1741 |
var d = new doh.Deferred();
|
|
|
1742 |
function completed(items, request){
|
|
|
1743 |
var orderedArray0 = [7,2,4,3,1,6,5,12,10,9,8,11];
|
|
|
1744 |
var orderedArray1 = [ "BaB{aMa|SaRa***F}oo",
|
|
|
1745 |
"ba|r*foo",
|
|
|
1746 |
"bit$Bite",
|
|
|
1747 |
"boomBam",
|
|
|
1748 |
"fo|o*b.ar",
|
|
|
1749 |
"jfq4@#!$!@|f1.$4r14i5u",
|
|
|
1750 |
"ouagadogou",
|
|
|
1751 |
"seaweed",
|
|
|
1752 |
"seaweed",
|
|
|
1753 |
"seaweed",
|
|
|
1754 |
"squawl",
|
|
|
1755 |
"zulu"
|
|
|
1756 |
];
|
|
|
1757 |
var passed = true;
|
|
|
1758 |
for(var i = 0; i < items.length; i++){
|
|
|
1759 |
var value = store.getValue(items[i], "value");
|
|
|
1760 |
if(!( (store.getValue(items[i], "uniqueId") === orderedArray0[i])&&
|
|
|
1761 |
(store.getValue(items[i], "value") === orderedArray1[i]))
|
|
|
1762 |
){
|
|
|
1763 |
passed=false;
|
|
|
1764 |
break;
|
|
|
1765 |
}
|
|
|
1766 |
}
|
|
|
1767 |
t.assertTrue(passed);
|
|
|
1768 |
if (passed){
|
|
|
1769 |
d.callback(true);
|
|
|
1770 |
}else{
|
|
|
1771 |
d.errback(new Error("Unexpected sorting order found, sort failure."));
|
|
|
1772 |
}
|
|
|
1773 |
}
|
|
|
1774 |
|
|
|
1775 |
function error(error, request){
|
|
|
1776 |
t.assertTrue(false);
|
|
|
1777 |
d.errback(error);
|
|
|
1778 |
}
|
|
|
1779 |
|
|
|
1780 |
var sortAttributes = [{ attribute: "value"}, { attribute: "uniqueId", descending: true}];
|
|
|
1781 |
store.fetch({onComplete: completed, onError: error, sort: sortAttributes});
|
|
|
1782 |
return d;
|
|
|
1783 |
}
|
|
|
1784 |
},
|
|
|
1785 |
{
|
|
|
1786 |
name: "Read API: fetch() sortMultipleSpecialComparator",
|
|
|
1787 |
runTest: function(datastore, t){
|
|
|
1788 |
// summary:
|
|
|
1789 |
// Function to test sorting on multiple attributes with a custom comparator.
|
|
|
1790 |
// description:
|
|
|
1791 |
// Function to test sorting on multiple attributes with a custom comparator.
|
|
|
1792 |
|
|
|
1793 |
var store = new datastore({data: { identifier: "uniqueId",
|
|
|
1794 |
items: [ {uniqueId: 1, status:"CLOSED"},
|
|
|
1795 |
{uniqueId: 2, status:"OPEN"},
|
|
|
1796 |
{uniqueId: 3, status:"PENDING"},
|
|
|
1797 |
{uniqueId: 4, status:"BLOCKED"},
|
|
|
1798 |
{uniqueId: 5, status:"CLOSED"},
|
|
|
1799 |
{uniqueId: 6, status:"OPEN"},
|
|
|
1800 |
{uniqueId: 7, status:"PENDING"},
|
|
|
1801 |
{uniqueId: 8, status:"PENDING"},
|
|
|
1802 |
{uniqueId: 10, status:"BLOCKED"},
|
|
|
1803 |
{uniqueId: 12, status:"BLOCKED"},
|
|
|
1804 |
{uniqueId: 11, status:"OPEN"},
|
|
|
1805 |
{uniqueId: 9, status:"CLOSED"}
|
|
|
1806 |
]
|
|
|
1807 |
}
|
|
|
1808 |
});
|
|
|
1809 |
|
|
|
1810 |
|
|
|
1811 |
store.comparatorMap = {};
|
|
|
1812 |
store.comparatorMap["status"] = function(a,b) {
|
|
|
1813 |
var ret = 0;
|
|
|
1814 |
// We want to map these by what the priority of these items are, not by alphabetical.
|
|
|
1815 |
// So, custom comparator.
|
|
|
1816 |
var enumMap = { OPEN: 3, BLOCKED: 2, PENDING: 1, CLOSED: 0};
|
|
|
1817 |
if (enumMap[a] > enumMap[b]) {
|
|
|
1818 |
ret = 1;
|
|
|
1819 |
}
|
|
|
1820 |
if (enumMap[a] < enumMap[b]) {
|
|
|
1821 |
ret = -1;
|
|
|
1822 |
}
|
|
|
1823 |
return ret;
|
|
|
1824 |
};
|
|
|
1825 |
|
|
|
1826 |
var sortAttributes = [{attribute: "status", descending: true}, { attribute: "uniqueId", descending: true}];
|
|
|
1827 |
|
|
|
1828 |
var d = new doh.Deferred();
|
|
|
1829 |
function completed(items, findResult){
|
|
|
1830 |
var orderedArray = [11,6,2,12,10,4,8,7,3,9,5,1];
|
|
|
1831 |
var passed = true;
|
|
|
1832 |
for(var i = 0; i < items.length; i++){
|
|
|
1833 |
var value = store.getValue(items[i], "value");
|
|
|
1834 |
if(!(store.getValue(items[i], "uniqueId") === orderedArray[i])){
|
|
|
1835 |
passed=false;
|
|
|
1836 |
break;
|
|
|
1837 |
}
|
|
|
1838 |
}
|
|
|
1839 |
t.assertTrue(passed);
|
|
|
1840 |
if (passed){
|
|
|
1841 |
d.callback(true);
|
|
|
1842 |
}else{
|
|
|
1843 |
d.errback(new Error("Unexpected sorting order found, sort failure."));
|
|
|
1844 |
}
|
|
|
1845 |
}
|
|
|
1846 |
|
|
|
1847 |
function error(errData, request){
|
|
|
1848 |
t.assertTrue(false);
|
|
|
1849 |
d.errback(errData);
|
|
|
1850 |
}
|
|
|
1851 |
store.fetch({onComplete: completed, onError: error, sort: sortAttributes});
|
|
|
1852 |
return d;
|
|
|
1853 |
}
|
|
|
1854 |
},
|
|
|
1855 |
{
|
|
|
1856 |
name: "Read API: fetch() sortAlphabeticWithUndefined",
|
|
|
1857 |
runTest: function(datastore, t){
|
|
|
1858 |
// summary:
|
|
|
1859 |
// Function to test sorting alphabetic ordering.
|
|
|
1860 |
// description:
|
|
|
1861 |
// Function to test sorting alphabetic ordering.
|
|
|
1862 |
|
|
|
1863 |
var store = new datastore({data: { identifier: "uniqueId",
|
|
|
1864 |
items: [ {uniqueId: 0, value:"abc"},
|
|
|
1865 |
{uniqueId: 1, value:"bca"},
|
|
|
1866 |
{uniqueId: 2, value:"abcd"},
|
|
|
1867 |
{uniqueId: 3, value:"abcdefg"},
|
|
|
1868 |
{uniqueId: 4, value:"lmnop"},
|
|
|
1869 |
{uniqueId: 5, value:"foghorn"},
|
|
|
1870 |
{uniqueId: 6, value:"qberty"},
|
|
|
1871 |
{uniqueId: 7, value:"qwerty"},
|
|
|
1872 |
{uniqueId: 8 }, //Deliberate undefined value
|
|
|
1873 |
{uniqueId: 9, value:"seaweed"},
|
|
|
1874 |
{uniqueId: 10, value:"123abc"}
|
|
|
1875 |
|
|
|
1876 |
]
|
|
|
1877 |
}
|
|
|
1878 |
});
|
|
|
1879 |
|
|
|
1880 |
var d = new doh.Deferred();
|
|
|
1881 |
function completed(items, request){
|
|
|
1882 |
//Output should be in this order...
|
|
|
1883 |
var orderedArray = [10,0,2,3,1,5,4,6,7,9,8];
|
|
|
1884 |
t.assertEqual(items.length, 11);
|
|
|
1885 |
var passed = true;
|
|
|
1886 |
for(var i = 0; i < items.length; i++){
|
|
|
1887 |
if(!(store.getValue(items[i], "uniqueId") === orderedArray[i])){
|
|
|
1888 |
passed=false;
|
|
|
1889 |
break;
|
|
|
1890 |
}
|
|
|
1891 |
}
|
|
|
1892 |
t.assertTrue(passed);
|
|
|
1893 |
if (passed){
|
|
|
1894 |
d.callback(true);
|
|
|
1895 |
}else{
|
|
|
1896 |
d.errback(new Error("Unexpected sorting order found, sort failure."));
|
|
|
1897 |
}
|
|
|
1898 |
}
|
|
|
1899 |
|
|
|
1900 |
function error(error, request) {
|
|
|
1901 |
t.assertTrue(false);
|
|
|
1902 |
d.errback(error);
|
|
|
1903 |
}
|
|
|
1904 |
|
|
|
1905 |
var sortAttributes = [{attribute: "value"}];
|
|
|
1906 |
store.fetch({onComplete: completed, onError: error, sort: sortAttributes});
|
|
|
1907 |
return d;
|
|
|
1908 |
}
|
|
|
1909 |
},
|
|
|
1910 |
{
|
|
|
1911 |
name: "Read API: errorCondition_idCollision_inMemory",
|
|
|
1912 |
runTest: function(datastore, t){
|
|
|
1913 |
// summary:
|
|
|
1914 |
// Simple test of the errors thrown when there is an id collision in the data.
|
|
|
1915 |
// Added because of tracker: #2546
|
|
|
1916 |
// description:
|
|
|
1917 |
// Simple test of the errors thrown when there is an id collision in the data.
|
|
|
1918 |
// Added because of tracker: #2546
|
|
|
1919 |
|
|
|
1920 |
var store = new datastore({ data: { identifier: "uniqueId",
|
|
|
1921 |
items: [{uniqueId: 12345, value:"foo"},
|
|
|
1922 |
{uniqueId: 123456, value:"bar"},
|
|
|
1923 |
{uniqueId: 12345, value:"boom"},
|
|
|
1924 |
{uniqueId: 123457, value:"bit"}
|
|
|
1925 |
]
|
|
|
1926 |
}
|
|
|
1927 |
});
|
|
|
1928 |
var d = new doh.Deferred();
|
|
|
1929 |
function onComplete(items, request){
|
|
|
1930 |
//This is bad if this fires, this case should fail and not call onComplete.
|
|
|
1931 |
t.assertTrue(false);
|
|
|
1932 |
d.callback(false);
|
|
|
1933 |
}
|
|
|
1934 |
|
|
|
1935 |
function reportError(errData, request){
|
|
|
1936 |
//This is good if this fires, it is expected.
|
|
|
1937 |
t.assertTrue(true);
|
|
|
1938 |
d.callback(true);
|
|
|
1939 |
}
|
|
|
1940 |
store.fetch({onComplete: onComplete, onError: reportError});
|
|
|
1941 |
return d;
|
|
|
1942 |
}
|
|
|
1943 |
},
|
|
|
1944 |
{
|
|
|
1945 |
name: "Read API: errorCondition_idCollision_xhr",
|
|
|
1946 |
runTest: function(datastore, t){
|
|
|
1947 |
// summary:
|
|
|
1948 |
// Simple test of the errors thrown when there is an id collision in the data.
|
|
|
1949 |
// Added because of tracker: #2546
|
|
|
1950 |
// description:
|
|
|
1951 |
// Simple test of the errors thrown when there is an id collision in the data.
|
|
|
1952 |
// Added because of tracker: #2546
|
|
|
1953 |
|
|
|
1954 |
if(dojo.isBrowser){
|
|
|
1955 |
var store = new datastore({url: dojo.moduleUrl("tests", "data/countries_idcollision.json").toString() });
|
|
|
1956 |
var d = new doh.Deferred();
|
|
|
1957 |
function onComplete(items, request){
|
|
|
1958 |
//This is bad if this fires, this case should fail and not call onComplete.
|
|
|
1959 |
t.assertTrue(false);
|
|
|
1960 |
d.callback(false);
|
|
|
1961 |
}
|
|
|
1962 |
|
|
|
1963 |
function reportError(errData, request){
|
|
|
1964 |
//This is good if this fires, it is expected.
|
|
|
1965 |
t.assertTrue(true);
|
|
|
1966 |
d.callback(true);
|
|
|
1967 |
}
|
|
|
1968 |
store.fetch({onComplete: onComplete, onError: reportError});
|
|
|
1969 |
return d;
|
|
|
1970 |
}
|
|
|
1971 |
}
|
|
|
1972 |
},
|
|
|
1973 |
{
|
|
|
1974 |
name: "Read API: Date_datatype",
|
|
|
1975 |
runTest: function(datastore, t){
|
|
|
1976 |
//var store = new datastore(tests.data.readOnlyItemFileTestTemplates.testFile["countries_withDates"]);
|
|
|
1977 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries_withDates"));
|
|
|
1978 |
|
|
|
1979 |
var d = new doh.Deferred();
|
|
|
1980 |
function onItem(item){
|
|
|
1981 |
t.assertTrue(item !== null);
|
|
|
1982 |
var independenceDate = store.getValue(item, "independence");
|
|
|
1983 |
t.assertTrue(independenceDate instanceof Date);
|
|
|
1984 |
//Check to see if the value was deserialized properly. Since the store stores in UTC/GMT, it
|
|
|
1985 |
//should also be compared in the UTC/GMT mode
|
|
|
1986 |
t.assertTrue(dojo.date.stamp.toISOString(independenceDate, {zulu:true}) === "1993-05-24T00:00:00Z");
|
|
|
1987 |
d.callback(true);
|
|
|
1988 |
}
|
|
|
1989 |
function onError(errData){
|
|
|
1990 |
t.assertTrue(false);
|
|
|
1991 |
d.errback(errData);
|
|
|
1992 |
}
|
|
|
1993 |
store.fetchItemByIdentity({identity:"er", onItem:onItem, onError:onError});
|
|
|
1994 |
return d; // Deferred
|
|
|
1995 |
}
|
|
|
1996 |
},
|
|
|
1997 |
{
|
|
|
1998 |
name: "Read API: custom_datatype_Color_SimpleMapping",
|
|
|
1999 |
runTest: function(datastore, t){
|
|
|
2000 |
// summary:
|
|
|
2001 |
// Function to test using literal values with custom datatypes
|
|
|
2002 |
var dataset = {
|
|
|
2003 |
identifier:'name',
|
|
|
2004 |
items: [
|
|
|
2005 |
{ name:'Kermit', species:'frog', color:{_type:'Color', _value:'green'} },
|
|
|
2006 |
{ name:'Beaker', hairColor:{_type:'Color', _value:'red'} }
|
|
|
2007 |
]
|
|
|
2008 |
};
|
|
|
2009 |
var store = new datastore({
|
|
|
2010 |
data:dataset,
|
|
|
2011 |
typeMap:{'Color': dojo.Color}
|
|
|
2012 |
});
|
|
|
2013 |
var d = new doh.Deferred();
|
|
|
2014 |
function onItem(item){
|
|
|
2015 |
t.assertTrue(item !== null);
|
|
|
2016 |
var beaker = item;
|
|
|
2017 |
var hairColor = store.getValue(beaker, "hairColor");
|
|
|
2018 |
t.assertTrue(hairColor instanceof dojo.Color);
|
|
|
2019 |
t.assertTrue(hairColor.toHex() == "#ff0000");
|
|
|
2020 |
d.callback(true);
|
|
|
2021 |
}
|
|
|
2022 |
function onError(errData){
|
|
|
2023 |
d.errback(errData);
|
|
|
2024 |
}
|
|
|
2025 |
store.fetchItemByIdentity({identity:"Beaker", onItem:onItem, onError:onError});
|
|
|
2026 |
return d; // Deferred
|
|
|
2027 |
}
|
|
|
2028 |
},
|
|
|
2029 |
{
|
|
|
2030 |
name: "Read API: custom_datatype_Color_GeneralMapping",
|
|
|
2031 |
runTest: function(datastore, t){
|
|
|
2032 |
// summary:
|
|
|
2033 |
// Function to test using literal values with custom datatypes
|
|
|
2034 |
var dataset = {
|
|
|
2035 |
identifier:'name',
|
|
|
2036 |
items: [
|
|
|
2037 |
{ name:'Kermit', species:'frog', color:{_type:'Color', _value:'green'} },
|
|
|
2038 |
{ name:'Beaker', hairColor:{_type:'Color', _value:'red'} }
|
|
|
2039 |
]
|
|
|
2040 |
};
|
|
|
2041 |
var store = new datastore({
|
|
|
2042 |
data:dataset,
|
|
|
2043 |
typeMap:{'Color': {
|
|
|
2044 |
type: dojo.Color,
|
|
|
2045 |
deserialize: function(value){
|
|
|
2046 |
return new dojo.Color(value);
|
|
|
2047 |
}
|
|
|
2048 |
}
|
|
|
2049 |
}
|
|
|
2050 |
});
|
|
|
2051 |
var d = new doh.Deferred();
|
|
|
2052 |
function onItem(item){
|
|
|
2053 |
t.assertTrue(item !== null);
|
|
|
2054 |
var beaker = item;
|
|
|
2055 |
var hairColor = store.getValue(beaker, "hairColor");
|
|
|
2056 |
t.assertTrue(hairColor instanceof dojo.Color);
|
|
|
2057 |
t.assertTrue(hairColor.toHex() == "#ff0000");
|
|
|
2058 |
d.callback(true);
|
|
|
2059 |
}
|
|
|
2060 |
function onError(errData){
|
|
|
2061 |
d.errback(errData);
|
|
|
2062 |
}
|
|
|
2063 |
store.fetchItemByIdentity({identity:"Beaker", onItem:onItem, onError:onError});
|
|
|
2064 |
return d; // Deferred
|
|
|
2065 |
}
|
|
|
2066 |
},
|
|
|
2067 |
{
|
|
|
2068 |
name: "Read API: hierarchical_data",
|
|
|
2069 |
runTest: function(datastore, t){
|
|
|
2070 |
//var store = new datastore(tests.data.readOnlyItemFileTestTemplates.testFile["geography_hierarchy_small"]);
|
|
|
2071 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("geography_hierarchy_small"));
|
|
|
2072 |
var d = new doh.Deferred();
|
|
|
2073 |
function onComplete(items, request){
|
|
|
2074 |
t.assertEqual(items.length, 1);
|
|
|
2075 |
var northAmerica = items[0];
|
|
|
2076 |
var canada = store.getValue(northAmerica, "countries");
|
|
|
2077 |
var toronto = store.getValue(canada, "cities");
|
|
|
2078 |
t.assertEqual(store.getValue(canada, "name"), "Canada");
|
|
|
2079 |
t.assertEqual(store.getValue(toronto, "name"), "Toronto");
|
|
|
2080 |
d.callback(true);
|
|
|
2081 |
}
|
|
|
2082 |
function onError(errData){
|
|
|
2083 |
d.errback(errData);
|
|
|
2084 |
}
|
|
|
2085 |
store.fetch({
|
|
|
2086 |
query: {name: "North America"},
|
|
|
2087 |
onComplete: onComplete,
|
|
|
2088 |
onError: onError
|
|
|
2089 |
});
|
|
|
2090 |
|
|
|
2091 |
return d; // Deferred
|
|
|
2092 |
}
|
|
|
2093 |
},
|
|
|
2094 |
{
|
|
|
2095 |
name: "Identity API: no_identifier_specified",
|
|
|
2096 |
runTest: function(datastore, t){
|
|
|
2097 |
var arrayOfItems = [
|
|
|
2098 |
{name:"Kermit", color:"green"},
|
|
|
2099 |
{name:"Miss Piggy", likes:"Kermit"},
|
|
|
2100 |
{name:"Beaker", hairColor:"red"}
|
|
|
2101 |
];
|
|
|
2102 |
var store = new datastore({data:{items:arrayOfItems}});
|
|
|
2103 |
var d = new doh.Deferred();
|
|
|
2104 |
function onComplete(items, request){
|
|
|
2105 |
var features = store.getFeatures();
|
|
|
2106 |
var hasIdentityFeature = Boolean(features['dojo.data.api.Identity']);
|
|
|
2107 |
t.assertTrue(hasIdentityFeature);
|
|
|
2108 |
for(var i = 0; i < items.length; ++i){
|
|
|
2109 |
var item = items[i];
|
|
|
2110 |
var identifier = store.getIdentityAttributes(item);
|
|
|
2111 |
t.assertTrue(identifier === null);
|
|
|
2112 |
var identity = store.getIdentity(item);
|
|
|
2113 |
t.assertTrue(typeof identity == "number");
|
|
|
2114 |
}
|
|
|
2115 |
d.callback(true);
|
|
|
2116 |
}
|
|
|
2117 |
function reportError(errData, request){
|
|
|
2118 |
d.errback(true);
|
|
|
2119 |
}
|
|
|
2120 |
store.fetch({onComplete: onComplete, onError: reportError});
|
|
|
2121 |
return d; // Deferred
|
|
|
2122 |
}
|
|
|
2123 |
},
|
|
|
2124 |
{
|
|
|
2125 |
name: "Identity API: hierarchical_data",
|
|
|
2126 |
runTest: function(datastore, t){
|
|
|
2127 |
var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("geography_hierarchy_small"));
|
|
|
2128 |
var d = new doh.Deferred();
|
|
|
2129 |
function onComplete(items, request){
|
|
|
2130 |
var features = store.getFeatures();
|
|
|
2131 |
var hasIdentityFeature = Boolean(features['dojo.data.api.Identity']);
|
|
|
2132 |
t.assertTrue(hasIdentityFeature);
|
|
|
2133 |
for(var i = 0; i < items.length; ++i){
|
|
|
2134 |
var item = items[i];
|
|
|
2135 |
var identifier = store.getIdentityAttributes(item);
|
|
|
2136 |
t.assertTrue(identifier === null);
|
|
|
2137 |
var identity = store.getIdentity(item);
|
|
|
2138 |
t.assertTrue(typeof identity == "number");
|
|
|
2139 |
}
|
|
|
2140 |
d.callback(true);
|
|
|
2141 |
}
|
|
|
2142 |
function reportError(errData, request){
|
|
|
2143 |
d.errback(true);
|
|
|
2144 |
}
|
|
|
2145 |
store.fetch({onComplete: onComplete, onError: reportError});
|
|
|
2146 |
return d; // Deferred
|
|
|
2147 |
}
|
|
|
2148 |
},
|
|
|
2149 |
{
|
|
|
2150 |
name: "Read API: functionConformance",
|
|
|
2151 |
runTest: function(datastore, t){
|
|
|
2152 |
// summary:
|
|
|
2153 |
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
|
|
|
2154 |
// description:
|
|
|
2155 |
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
|
|
|
2156 |
var testStore = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
2157 |
var readApi = new dojo.data.api.Read();
|
|
|
2158 |
var passed = true;
|
|
|
2159 |
|
|
|
2160 |
for(i in readApi){
|
|
|
2161 |
if(i.toString().charAt(0) !== '_')
|
|
|
2162 |
{
|
|
|
2163 |
var member = readApi[i];
|
|
|
2164 |
//Check that all the 'Read' defined functions exist on the test store.
|
|
|
2165 |
if(typeof member === "function"){
|
|
|
2166 |
var testStoreMember = testStore[i];
|
|
|
2167 |
if(!(typeof testStoreMember === "function")){
|
|
|
2168 |
passed = false;
|
|
|
2169 |
break;
|
|
|
2170 |
}
|
|
|
2171 |
}
|
|
|
2172 |
}
|
|
|
2173 |
}
|
|
|
2174 |
t.assertTrue(passed);
|
|
|
2175 |
}
|
|
|
2176 |
},
|
|
|
2177 |
{
|
|
|
2178 |
name: "Identity API: functionConformance",
|
|
|
2179 |
runTest: function(datastore, t){
|
|
|
2180 |
// summary:
|
|
|
2181 |
// Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
|
|
|
2182 |
// description:
|
|
|
2183 |
// Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances.
|
|
|
2184 |
var testStore = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries"));
|
|
|
2185 |
var identityApi = new dojo.data.api.Identity();
|
|
|
2186 |
var passed = true;
|
|
|
2187 |
|
|
|
2188 |
for(i in identityApi){
|
|
|
2189 |
|
|
|
2190 |
if(i.toString().charAt(0) !== '_')
|
|
|
2191 |
{
|
|
|
2192 |
var member = identityApi[i];
|
|
|
2193 |
//Check that all the 'Read' defined functions exist on the test store.
|
|
|
2194 |
if(typeof member === "function"){
|
|
|
2195 |
var testStoreMember = testStore[i];
|
|
|
2196 |
if(!(typeof testStoreMember === "function")){
|
|
|
2197 |
passed = false;
|
|
|
2198 |
break;
|
|
|
2199 |
}
|
|
|
2200 |
}
|
|
|
2201 |
}
|
|
|
2202 |
}
|
|
|
2203 |
t.assertTrue(passed);
|
|
|
2204 |
}
|
|
|
2205 |
}
|
|
|
2206 |
];
|
|
|
2207 |
|
|
|
2208 |
|
|
|
2209 |
}
|