]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/data/tests/stores/jsonPathStore.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojox / data / tests / stores / jsonPathStore.js
1 if(!dojo._hasResource["dojox.data.tests.stores.jsonPathStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.data.tests.stores.jsonPathStore"] = true;
3 dojo.provide("dojox.data.tests.stores.jsonPathStore");
4 dojo.require("dojox.data.jsonPathStore");
5
6 dojox.data.tests.stores.jsonPathStore.error = function(t, d, errData){
7         //  summary:
8         //              The error callback function to be used for all of the tests.
9         d.errback(errData);     
10 }
11
12 dojox.data.tests.testData=dojo.toJson({"store": {"book": [{"category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95}, {"category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99}, {"category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99}, {"category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99}], "bicycle": {"color": "red", "price": 19.95}}});
13
14 dojox.data.tests.test_ID_Data=dojo.toJson({"gadgetList": {"myId": "product", "1000": {"name": "Gadget", "type": "Junk", "myId": "1000", "price": "19.99"}, "1001": {"name": "Gadget2", "type": "Junk", "myId": "1010", "price": "17.99"}, "1003": {"name": "Gadget3", "type": "Junk", "myId": "1009", "price": "15.99"}, "1004": {"name": "Gadget4", "type": "Junk", "myId": "1008", "price": "13.99"}, "1005": {"name": "Gadget5", "type": "Junk", "myId": "1007", "price": "11.99"}, "1006": {"name": "Gadget6", "type": "Junk", "myId": "1006", "price": "9.99"}}, "testList": {"a": {"name": "test", "type": "Junk", "myId": "3000", "price": "19.99"}, "b": {"name": "test2", "type": "Junk", "myId": "3010", "price": "17.99"}, "c": {"name": "test3", "type": "Junk", "myId": "3009", "price": "15.99"}, "d": {"name": "test4", "type": "Junk", "myId": "3008", "price": "13.99"}, "e": {"name": "test5", "type": "Junk", "myId": "3007", "price": "11.99"}, "f": {"name": "test6", "type": "Junk", "myId": "3006", "price": "9.99"}}, "bricknbrack": [{"name": "BrickNBrack", "type": "Junk", "myId": "2000", "price": "19.99"}, {"name": "BrickNBrack2", "type": "Junk", "myId": "2010", "price": "17.99"}, {"name": "BrickNBrack3", "type": "Junk", "myId": "2009", "price": "15.99"}, {"name": "BrickNBrack4", "type": "Junk", "myId": "2008", "price": "13.99"}, {"name": "BrickNBrack5", "type": "Junk", "myId": "2007", "price": "11.99"}, {"name": "BrickNBrack6", "type": "Junk", "myId": "2006", "price": "9.99"}]});
15
16 doh.register("dojox.data.tests.stores.jsonPathStore", 
17         [
18                 {
19                         name: "Create, Index, Export: {clone: true, suppressExportMeta: true}", 
20                         options: {clone: true, suppressExportMeta: true},
21                         runTest: function(t) {
22                                 var original= dojox.data.tests.test_ID_Data;
23                                 var store= new dojox.data.jsonPathStore({
24                                         data: original,
25                                         mode: dojox.data.SYNC_MODE,
26                                         idAttribute: "myId",
27                                         indexOnLoad: true
28                                 });
29
30                                 //snapshot of the store after creation; 
31                                 var storeWithMeta = dojo.toJson(store._data);
32                                 var result = store.dump(this.options); 
33                                 doh.assertEqual(storeWithMeta, result);
34                         }
35                 },
36                 {
37                         name: "Create, Index, Export: {cleanMeta: true, clone: true}", 
38                         options: {cleanMeta: true, clone: true, suppressExportMeta: true},
39                         runTest: function(t) {
40                                 var original= dojox.data.tests.test_ID_Data;
41                                 var store= new dojox.data.jsonPathStore({
42                                         data: original,
43                                         mode: dojox.data.SYNC_MODE,
44                                         idAttribute: "myId",
45                                         indexOnLoad: true
46                                 });
47
48                                 var result = store.dump(this.options); 
49                                 doh.assertEqual(original, result);
50                         }
51                 },
52                 {
53                         name: "Create, Index, Export: {suppressExportMeta: true}", 
54                         options: {suppressExportMeta: true},
55                         runTest: function(t) {
56                                 var original= dojox.data.tests.test_ID_Data;
57                                 var store= new dojox.data.jsonPathStore({
58                                         data: original,
59                                         mode: dojox.data.SYNC_MODE,
60                                         idAttribute: "myId",
61                                         indexOnLoad: true
62                                 });
63
64                                 //snapshot of the store after creation; 
65                                 var storeWithMeta = dojo.toJson(store._data);
66                                 var result = store.dump(this.options); 
67                                 doh.assertEqual(storeWithMeta, result);
68                         }
69                 },
70                 {
71                         name: "Create, Index, Export: {clone: true, type: 'raw',  suppressExportMeta: true}", 
72                         options: {clone: true, type: "raw", suppressExportMeta: true},
73                         runTest: function(t) {
74                                 var original= dojox.data.tests.test_ID_Data;
75                                 var store= new dojox.data.jsonPathStore({
76                                         data: original,
77                                         mode: dojox.data.SYNC_MODE,
78                                         idAttribute: "myId",
79                                         indexOnLoad: true
80                                 });
81
82                                 //snapshot of the store after creation; 
83                                 var storeWithMeta = dojo.toJson(store._data);
84                                 var result = dojo.toJson(store.dump(this.options)); 
85                                 doh.assertEqual(storeWithMeta, result);
86                         }
87                 },
88                 {
89                         name: "Create, Index, Export: {clone: true, suppressExportMeta: true}", 
90                         options: {cleanMeta: true},
91                         runTest: function(t) {
92                                 var original= dojox.data.tests.test_ID_Data;
93                                 var store= new dojox.data.jsonPathStore({
94                                         data: original,
95                                         mode: dojox.data.SYNC_MODE,
96                                         idAttribute: "myId",
97                                         indexOnLoad: true
98                                 });
99
100                                 //snapshot of the store after creation; 
101                                 var result = store.dump(this.options); 
102                                 doh.assertEqual(original, result);
103                         }
104                 },
105                 {
106                         name: "Create, Index, Export: {type: raw}", 
107                         options: {type: "raw"},
108                         runTest: function(t) {
109                                 var original= dojox.data.tests.test_ID_Data;
110                                 var store= new dojox.data.jsonPathStore({
111                                         data: original,
112                                         mode: dojox.data.SYNC_MODE,
113                                         idAttribute: "myId",
114                                         indexOnLoad: true
115                                 });
116
117                                 //snapshot of the store after creation; 
118                                 var result = dojo.toJson(store.dump(this.options)); 
119                                 var storeWithMeta = dojo.toJson(store._data);
120                                 doh.assertEqual(storeWithMeta, result);
121                         }
122                 },
123                 {
124                         name: "ReadAPI:  fetch() Empty Request Test [SYNC_MODE]",
125                         runTest: function(t) {
126                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE});
127                                 var success = dojo.toJson([{"book": [{"category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95, "_meta": {"path": "$['store']['book'][0]", "autoId": true, "referenceIds": ["_ref_1"]}, "_id": "_auto_3"}, {"category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99, "_meta": {"path": "$['store']['book'][1]", "autoId": true, "referenceIds": ["_ref_2"]}, "_id": "_auto_4"}, {"category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99, "_meta": {"path": "$['store']['book'][2]", "autoId": true, "referenceIds": ["_ref_3"]}, "_id": "_auto_5"}, {"category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99, "_meta": {"path": "$['store']['book'][3]", "autoId": true, "referenceIds": ["_ref_4"]}, "_id": "_auto_6"}], "bicycle": {"color": "red", "price": 19.95, "_meta": {"path": "$['store']['bicycle']", "autoId": true, "referenceIds": ["_ref_5"]}, "_id": "_auto_2"}, "_meta": {"path": "$['store']", "autoId": true, "referenceIds": ["_ref_0"]}, "_id": "_auto_0"}, [{"category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95, "_meta": {"path": "$['store']['book'][0]", "autoId": true, "referenceIds": ["_ref_1"]}, "_id": "_auto_3"}, {"category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99, "_meta": {"path": "$['store']['book'][1]", "autoId": true, "referenceIds": ["_ref_2"]}, "_id": "_auto_4"}, {"category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99, "_meta": {"path": "$['store']['book'][2]", "autoId": true, "referenceIds": ["_ref_3"]}, "_id": "_auto_5"}, {"category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99, "_meta": {"path": "$['store']['book'][3]", "autoId": true, "referenceIds": ["_ref_4"]}, "_id": "_auto_6"}], {"color": "red", "price": 19.95, "_meta": {"path": "$['store']['bicycle']", "autoId": true, "referenceIds": ["_ref_5"]}, "_id": "_auto_2"}, {"category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95, "_meta": {"path": "$['store']['book'][0]", "autoId": true, "referenceIds": ["_ref_1"]}, "_id": "_auto_3"}, {"category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99, "_meta": {"path": "$['store']['book'][1]", "autoId": true, "referenceIds": ["_ref_2"]}, "_id": "_auto_4"}, {"category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99, "_meta": {"path": "$['store']['book'][2]", "autoId": true, "referenceIds": ["_ref_3"]}, "_id": "_auto_5"}, {"category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99, "_meta": {"path": "$['store']['book'][3]", "autoId": true, "referenceIds": ["_ref_4"]}, "_id": "_auto_6"}]);
128                                 var result = dojo.toJson(store.fetch());
129                                 doh.assertEqual(success, result);
130                                 return true;
131                         }
132                 },
133
134                 {
135                         name: "ReadAPI:  fetch('$.store.book[*]') test [SYNC_MODE]",
136                         runTest: function(t) {
137                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE});
138                                 var success = dojo.toJson([{"category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95, "_meta": {"path": "$['store']['book'][0]", "autoId": true, "referenceIds": ["_ref_1"]}, "_id": "_auto_3"}, {"category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99, "_meta": {"path": "$['store']['book'][1]", "autoId": true, "referenceIds": ["_ref_2"]}, "_id": "_auto_4"}, {"category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99, "_meta": {"path": "$['store']['book'][2]", "autoId": true, "referenceIds": ["_ref_3"]}, "_id": "_auto_5"}, {"category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99, "_meta": {"path": "$['store']['book'][3]", "autoId": true, "referenceIds": ["_ref_4"]}, "_id": "_auto_6"}]);
139                                 var result = dojo.toJson(store.fetch({query:"$.store.book[*]"}));       
140                                 doh.assertEqual(success, result);
141                                 return true;
142                         }
143                 },
144                 {
145                         name: "ReadAPI:  fetch('$.store.book[*]') test [ASYNC_MODE forced SYNC_MODE by string parameter]",
146                         runTest: function(t) {
147                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.ASYNC_MODE});
148                                 var success = dojo.toJson([{"category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95, "_meta": {"path": "$['store']['book'][0]", "autoId": true, "referenceIds": ["_ref_1"]}, "_id": "_auto_3"}, {"category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99, "_meta": {"path": "$['store']['book'][1]", "autoId": true, "referenceIds": ["_ref_2"]}, "_id": "_auto_4"}, {"category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99, "_meta": {"path": "$['store']['book'][2]", "autoId": true, "referenceIds": ["_ref_3"]}, "_id": "_auto_5"}, {"category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99, "_meta": {"path": "$['store']['book'][3]", "autoId": true, "referenceIds": ["_ref_4"]}, "_id": "_auto_6"}]);
149                                 var result = dojo.toJson(store.fetch("$.store.book[*]"));       
150                                 doh.assertEqual(success, result);
151                                 return true;
152                         }
153                 },
154                 {
155                         name: "ReadAPI:  fetch({query: '$.store.book[*]', start: 2})",
156                         runTest: function(t) {
157                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE});
158                                 var success = dojo.toJson([{"category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99, "_meta": {"path": "$['store']['book'][2]", "autoId": true, "referenceIds": ["_ref_3"]}, "_id": "_auto_5"}, {"category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99, "_meta": {"path": "$['store']['book'][3]", "autoId": true, "referenceIds": ["_ref_4"]}, "_id": "_auto_6"}]);
159                                 var result = dojo.toJson(store.fetch({query: '$.store.book[*]', start: 2}));
160                                 doh.assertEqual(success, result);
161                                 return true;
162                         }
163                 },
164                 {
165                         name: "ReadAPI:  fetch({query: '$.store.book[*]', start: 2, count: 1})",
166                         runTest: function(t) {
167                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE});
168                                 var result = store.fetch({query: "$.store.book[*]", start: 2, count: 1});       
169                                 doh.assertEqual(result[0].author, 'Herman Melville');
170                                 return true;
171                         }
172                 },
173
174                 {
175                         name: "ReadAPI: fetch(query: '$.store.book[0]'...callbacks...) [ASYNC_MODE]",
176                         runTest: function(datastore, t){
177                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData});
178                                 var d = new doh.Deferred();
179                                 function onBegin(count, args){
180                                         doh.assertEqual(1, count);      
181                                 }
182                                 function onItem(item){
183                                         doh.assertTrue(store.isItem(item));
184                                 }
185
186                                 function onComplete(results){
187                                         doh.assertEqual(1, results.length);
188                                         doh.assertEqual("Nigel Rees", results[0]["author"]);
189                                         d.callback(true);
190                                 }
191
192                                 function onError(errData){
193                                         t.assertTrue(false);
194                                         d.errback(errData);
195                                 }
196
197                                 store.fetch({query: "$.store.book[0]", onBegin: onBegin, onItem: onItem, onError: onError, onComplete: onComplete});
198                                 return d; // Deferred
199                         }
200                 },
201                 {
202                         name: "ReadAPI: isItem() test", 
203                         runTest: function(t) {
204                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE});
205                                 var result = store.fetch("$.store.book[*].author");     
206                                 doh.assertFalse(store.isItem(result[0]));
207                                 result = store.fetch("$.store.book[*]");        
208                                 doh.assertTrue(store.isItem(result[0]));
209                                 return true;
210                         }
211                 },
212                 {
213                         name: "ReadAPI: getValue() test", 
214                         runTest: function(t) {
215                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE});
216                                 var data = store.fetch("$.store.book[*]");      
217                                 var result = store.getValue(data[0], "author"); 
218                                 doh.assertEqual("Nigel Rees", result);
219                                 return true;
220                         }
221                 },
222                 {
223                         name: "ReadAPI: getValues() test", 
224                         runTest: function(t) {
225                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE});
226                                 var result = store.fetch("$.store.book[*]");    
227                                 doh.assertEqual(dojo.toJson(store.getValues(result[0], "author")),dojo.toJson(["Nigel Rees"]));
228                                 return true;
229                         }
230                 },
231                 {
232                         name: "ReadAPI: getAttributes() test", 
233                         runTest: function(t) {
234                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE});
235                                 var result = store.fetch("$.store.book[*]");    
236                                 doh.assertEqual(dojo.toJson(store.getAttributes(result[0])),'["category","author","title","price","_meta","_id"]');
237                                 return true;
238                         }
239                 },
240                 {
241                         name: "ReadAPI: getAttributes() test [hideMetaAttributes]", 
242                         runTest: function(t) {
243                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE, hideMetaAttributes: true});
244                                 var result = store.fetch("$.store.book[*]");    
245                                 doh.assertEqual('["category","author","title","price","_id"]',dojo.toJson(store.getAttributes(result[0])));
246                                 return true;
247                         }
248                 },
249                 {
250                         name: "ReadAPI: hasAttribute() test", 
251                         runTest: function(t) {
252                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE});
253                                 var result = store.fetch("$.store.book[*]");    
254                                 doh.assertTrue(store.hasAttribute(result[0], "author"));
255                                 doh.assertFalse(store.hasAttribute(result[0],"_im_invalid_fooBar"));
256                                 return true;
257                         }
258                 },
259
260                 {
261                         name: "ReadAPI: containsValue() test", 
262                         runTest: function(t) {
263                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE});
264                                 var result = store.fetch("$.store.book[*]");    
265                                 doh.assertTrue(store.containsValue(result[0], "author", "Nigel Rees"));
266                                 doh.assertFalse(store.containsValue(result[0], "author", "_im_invalid_fooBar"));
267                                 return true;
268                         }
269                 },
270                 {
271                         name: "ReadAPI: getFeatures() test", 
272                         runTest: function(t) {
273                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE});
274                                 //doh.debug("Store Features: ", dojo.toJson(store.getFeatures()));
275                                 var success='{"dojo.data.api.Read":true,"dojo.data.api.Identity":true,"dojo.data.api.Write":true,"dojo.data.api.Notification":true}';
276                                 doh.assertEqual(success,dojo.toJson(store.getFeatures()));
277                                 return true;
278                         }
279                 },
280                 {
281                         name: "ReadAPI: getLabel(item) test [multiple label attributes]", 
282                         runTest: function(t) {
283                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE, labelAttribute: ["title", "author"]});
284                                 var result = store.fetch("$.store.book[0]")[0];         
285                                 doh.assertEqual("Sayings of the Century Nigel Rees",store.getLabel(result));
286                                 return true;
287                         }
288                 },
289                 {
290                         name: "ReadAPI: getLabelAttributes(item) test [multiple label attributes]", 
291                         runTest: function(t) {
292                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE, labelAttribute: ["title", "author"]});
293                                 var result = store.fetch("$.store.book[0]")[0];         
294                                 doh.assertEqual('["title","author"]',dojo.toJson(store.getLabelAttributes(result)));
295                                 return true;
296                         }
297                 },
298                 {
299                         name: "ReadAPI: getLabelAttributes(item) test [single label attribute]", 
300                         runTest: function(t) {
301                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE, labelAttribute: ["title"]});
302                                 var result = store.fetch("$.store.book[0]")[0];         
303                                 doh.assertEqual('["title"]',dojo.toJson(store.getLabelAttributes(result)));
304                                 return true;
305                         }
306                 },
307                 {
308                         name: "jsonPathStore Feature: override createLabel", 
309                         runTest: function(t) {
310                                 var createLabel = function(item){
311                                         return item[this.labelAttribute[0]] + " By " + item[this.labelAttribute[1]];
312                                 };
313
314                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE, labelAttribute: ["title", "author"], createLabel: createLabel});
315                                 var result = store.fetch("$.store.book[0]")[0];         
316                                 doh.assertEqual('Sayings of the Century By Nigel Rees',store.getLabel(result));
317                                 return true;
318                         }
319                 },
320                 {
321                         name: "jsonPathStore Feature: autoIdentity", 
322                         runTest: function(t) {
323                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE, idAttribute: "_id"});
324                                 var result = dojo.toJson(store.fetch("$.store.book[0]")[0]);    
325                                 var success=dojo.toJson( {"category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95, "_meta": {"path": "$['store']['book'][0]", "autoId": true, "referenceIds": ["_ref_1"]}, "_id": "_auto_3"});
326                                 doh.assertEqual(success,result);
327                                 return true;
328                         }
329                 },
330
331                 {
332                         name: "jsonPathStore Feature: autoIdentity [clean export removing added id attributes in addition to meta]", 
333                         runTest: function(t) {
334                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE, idAttribute: "_id"});
335                                 //do a search to popuplate some of the itesm with autoId data
336                                 var result = store.fetch("$.store.book[0]");    
337                                 result = store.dump({cleanMeta: true});
338                                 doh.assertEqual(dojox.data.tests.testData,result);
339                                 return true;
340                         }
341                 },
342
343                 {
344                         name: "IdentityAPI: getIdentity(item)", 
345                         runTest: function(t) {
346                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE, idAttribute: "_id"});
347                                 var data= store.fetch("$.store.book[0]")[0];    
348                                 var result= store.getIdentity(data);
349                                 var success="_auto_3";
350                                 doh.assertEqual(success,result);
351                                 return true;
352                         }
353                 },
354
355                 {
356                 
357                         name: "IdentityAPI: fetchItemByIdentity(item) [SYNC_MODE]", 
358                         runTest: function(t){
359                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE, idAttribute: "_id"});
360
361                                 var data= store.fetch("$.store.book[0]")[0];    
362                                 var id = store.getIdentity(data);
363                                 var result = dojo.toJson(store.fetchItemByIdentity({identity:id}));
364                                 var success = dojo.toJson(data);                
365                                 doh.assertEqual(success,result);
366                                 return true;
367                         }
368                 },
369                 {
370                 
371                         name: "jsonPathStore Feature: byId(item) [fetchItemByIdentity alias] [SYNC_MODE]", 
372                         runTest: function(t){
373                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE, idAttribute: "_id"});
374
375                                 var data= store.fetch("$.store.book[0]")[0];    
376                                 var id = store.getIdentity(data);
377                                 var result = dojo.toJson(store.byId({identity:id}));
378                                 var success = dojo.toJson(data);                
379                                 doh.assertEqual(success,result);
380                                 return true;
381                         }
382                 },
383
384                 {
385                         name: "IdentityAPI: fetchItemByIdentity(id) single Item [ASYNC_MODE]",
386                         timeout: 1000,
387                         runTest: function(datastore, t){
388                                 //      summary:
389                                 //              Simple test of the fetchItemByIdentity function of the store.
390                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, indexOnLoad: true});
391                                 var d = new doh.Deferred();
392                                 var query = {query: "$.store.book[0]", mode: dojox.data.SYNC_MODE};
393                                 var data = store.fetch(query)[0];
394                                 var id = store.getIdentity(data);
395
396                                 function onItem(item){
397                                         doh.assertTrue(store.isItem(item));
398                                         doh.assertEqual(data["author"], item["author"]);
399                                         d.callback(true);
400                                 }
401
402                                 function onError(errData){
403
404                                         t.assertTrue(false);
405                                         d.errback(errData);
406                                 }
407
408                                 store.fetchItemByIdentity({identity: id, onItem: onItem, onError: onError});
409
410                                 return d; // Deferred
411                         }
412                 },
413                 {
414                         name: "IdentityAPI: getIdentityAttributes(item) ", 
415                         runTest: function(t) {
416                                 var store= new dojox.data.jsonPathStore({data:dojox.data.tests.testData, mode: dojox.data.SYNC_MODE, idAttribute: "_id"});
417                                 var data= store.fetch("$.store.book[0]")[0];    
418                                 var result = dojo.toJson(store.getIdentityAttributes(data));
419                                 var success = '["_id"]';
420                                 doh.assertEqual(success,result);
421                                 return true;
422                         }
423                 },
424                 {
425                         name: "WriteAPI: newItem(item) add to store root.",
426                         runTest: function(t) {
427                                 var original = dojox.data.tests.testData;
428                                 var store= new dojox.data.jsonPathStore({data:original, mode: dojox.data.SYNC_MODE, idAttribute: "_id"});
429
430                                 var testObject = {
431                                         propA: "foo",
432                                         propB: "bar"
433                                 }
434
435                                 var testObject2 = {
436                                         propA: "foo",
437                                         propB: "bar"
438                                 }
439
440                                 var newItem = store.newItem(testObject);
441                                 doh.assertTrue(store.isItem(newItem));  
442
443                                 newItem = store.newItem(testObject2);
444                                 doh.assertTrue(store.isItem(newItem));  
445
446                                 return true; 
447                         }
448                 },
449                 {
450                         name: "WriteAPI: newItem(item) no idAttribute on data item, added only with pInfo",
451                         runTest: function(t) {
452                                 var original = dojox.data.tests.testData;
453                                 var store= new dojox.data.jsonPathStore({data:original, mode: dojox.data.SYNC_MODE});
454
455                                 var parentItem = store.fetch("$.store.book[0]")[0];
456
457                                 var testObject = {
458                                         propA: "foo",
459                                         propB: "bar"
460                                 }
461
462                                 var newItem = store.newItem(testObject,{parent: parentItem, attribute: "TEST_PROPERTY"});
463                                 doh.assertTrue(store.isItem(newItem));  
464                                 return true; 
465                         }
466                 },
467                 {
468                         name: "WriteAPI: newItem(item) given id, no parent Attribute",
469                         runTest: function(t) {
470                                 var original = dojox.data.tests.testData;
471                                 var store= new dojox.data.jsonPathStore({data:original, mode: dojox.data.SYNC_MODE, idAttribute: "_id"});
472
473                                 var parentItem = store.fetch("$.store.book[0]")[0];
474
475                                 var testObject = {
476                                         _id: "99999",
477                                         propA: "foo",
478                                         propB: "bar"
479                                 }
480
481                                 var newItem = store.newItem(testObject,{parent: parentItem});
482                                 doh.assertTrue(store.isItem(newItem));  
483                                 return true; 
484                         }
485                 },
486                 {
487                         name: "WriteAPI: newItem(item) given id and  parent Attribute",
488                         runTest: function(t) {
489                                 var original = dojox.data.tests.testData;
490                                 var store= new dojox.data.jsonPathStore({data:original, mode: dojox.data.SYNC_MODE, idAttribute: "_id"});
491
492                                 var parentItem = store.fetch("$.store.book[0]")[0];
493
494                                 var testObject = {
495                                         _id: "99999",
496                                         propA: "foo",
497                                         propB: "bar"
498                                 }
499
500                                 var newItem = store.newItem(testObject,{parent: parentItem, attribute: "TEST"});
501                                 doh.assertTrue(store.isItem(newItem));  
502                                 return true; 
503                         }
504                 },
505                 {
506                         name: "WriteAPI: newItem(item) adding to an array",
507                         runTest: function(t) {
508                                 var original = dojox.data.tests.testData;
509                                 var store= new dojox.data.jsonPathStore({data:original, mode: dojox.data.SYNC_MODE, idAttribute: "_id"});
510
511                                 var parentItem = store.fetch("$.store")[0];
512
513                                 var testObject = {
514                                         _id: "99999",
515                                         propA: "foo",
516                                         propB: "bar"
517                                 }
518
519                                 var newItem = store.newItem(testObject,{parent: parentItem, attribute: "book"});
520                                 doh.assertTrue(store.isItem(newItem));  
521                                 return true; 
522                         }
523                 },
524                 {
525                         name: "WriteAPI: setValue(item, value)",
526                         runTest: function(t) {
527                                 var original = dojox.data.tests.testData;
528                                 var store= new dojox.data.jsonPathStore({data:original, mode: dojox.data.SYNC_MODE, indexOnLoad: true, idAttribute: "_id"});
529                                 var item = store.fetch("$.store")[0];
530
531                                 var snapshot = store.dump({clone:true, cleanMeta: false, suppressExportMeta: true});
532
533                                 store.setValue(item, "Foo", "Bar");
534                                 doh.assertEqual(store._data.store.Foo, "Bar");
535                                 doh.assertTrue(store._data.store._meta.isDirty);
536                                 store.save();
537                                 doh.assertFalse(store._data.store._meta.isDirty);
538                                 return true; 
539                         }
540                 },
541                 {
542                         name: "WriteAPI: setValues(item, value)",
543                         runTest: function(t) {
544                                 var original = dojox.data.tests.testData;
545                                 var store= new dojox.data.jsonPathStore({data:original, mode: dojox.data.SYNC_MODE, indexOnLoad: true, idAttribute: "_id"});
546                                 var item = store.fetch("$.store")[0];
547
548                                 var snapshot = store.dump({clone:true, cleanMeta: false, suppressExportMeta: true});
549
550                                 store.setValues(item, "Foo", ["Bar", "Diddly", "Ar"]);
551                                 doh.assertEqual(store._data.store.Foo[0], "Bar");
552                                 doh.assertEqual(store._data.store.Foo.length, 3);
553                                 doh.assertTrue(store._data.store._meta.isDirty);
554                                 store.save();
555                                 doh.assertFalse(store._data.store._meta.isDirty);
556                                 return true; 
557                         }
558                 },
559                 {
560                         name: "WriteAPI: unsetAttribute(item, attribute)",
561                         runTest: function(t) {
562                                 var original = dojox.data.tests.testData;
563                                 var store= new dojox.data.jsonPathStore({data:original, mode: dojox.data.SYNC_MODE, indexOnLoad: true, idAttribute: "_id"});
564                                 var item = store.fetch("$.store")[0];
565
566                                 var snapshot = store.dump({clone:true, cleanMeta: false, suppressExportMeta: true});
567
568                                 store.setValues(item, "Foo", ["Bar", "Diddly", "Ar"]);
569                                 doh.assertEqual(store._data.store.Foo[0], "Bar");
570                                 doh.assertEqual(store._data.store.Foo.length, 3);
571                                 doh.assertTrue(store._data.store._meta.isDirty);
572                                 store.save();
573                                 doh.assertFalse(store._data.store._meta.isDirty);
574                                 store.unsetAttribute(item,"Foo");
575                                 doh.assertFalse(item.Foo);
576                                 doh.assertTrue(store._data.store._meta.isDirty);
577                                 store.save();
578                                 doh.assertFalse(store._data.store._meta.isDirty);
579                                 return true; 
580                         }
581                 },
582                 {
583                         name: "WriteAPI: revert()",
584                         runTest: function(t) {
585                                 var original = dojox.data.tests.testData;
586                                 var store= new dojox.data.jsonPathStore({data:original, mode: dojox.data.SYNC_MODE, indexOnLoad: true, idAttribute: "_id"});
587                                 var item = store.fetch("$.store")[0];
588
589                                 var snapshot = store.dump({clone:true, cleanMeta: false, suppressExportMeta: true});
590
591                                 store.setValues(item, "Foo", ["Bar", "Diddly", "Ar"]);
592                                 doh.assertEqual(store._data.store.Foo[0], "Bar");
593                                 doh.assertEqual(store._data.store.Foo.length, 3);
594                                 doh.assertTrue(store._data.store._meta.isDirty);
595                                 store.revert();
596                                 doh.assertFalse(store._data.store._meta.isDirty);
597                                 doh.assertFalse(store._data.store.Foo);
598                                 return true; 
599                         }
600                 }
601         ]
602 );
603
604 }