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");
6 dojox.data.tests.stores.jsonPathStore.error = function(t, d, errData){
8 // The error callback function to be used for all of the tests.
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}}});
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"}]});
16 doh.register("dojox.data.tests.stores.jsonPathStore",
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({
25 mode: dojox.data.SYNC_MODE,
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);
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({
43 mode: dojox.data.SYNC_MODE,
48 var result = store.dump(this.options);
49 doh.assertEqual(original, result);
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({
59 mode: dojox.data.SYNC_MODE,
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);
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({
77 mode: dojox.data.SYNC_MODE,
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);
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({
95 mode: dojox.data.SYNC_MODE,
100 //snapshot of the store after creation;
101 var result = store.dump(this.options);
102 doh.assertEqual(original, result);
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({
112 mode: dojox.data.SYNC_MODE,
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);
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);
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);
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);
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);
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');
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);
182 function onItem(item){
183 doh.assertTrue(store.isItem(item));
186 function onComplete(results){
187 doh.assertEqual(1, results.length);
188 doh.assertEqual("Nigel Rees", results[0]["author"]);
192 function onError(errData){
197 store.fetch({query: "$.store.book[0]", onBegin: onBegin, onItem: onItem, onError: onError, onComplete: onComplete});
198 return d; // Deferred
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]));
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);
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"]));
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"]');
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])));
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"));
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"));
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()));
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));
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)));
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)));
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]];
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));
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);
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);
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);
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"});
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);
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"});
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);
385 name: "IdentityAPI: fetchItemByIdentity(id) single Item [ASYNC_MODE]",
387 runTest: function(datastore, t){
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);
396 function onItem(item){
397 doh.assertTrue(store.isItem(item));
398 doh.assertEqual(data["author"], item["author"]);
402 function onError(errData){
408 store.fetchItemByIdentity({identity: id, onItem: onItem, onError: onError});
410 return d; // Deferred
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);
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"});
440 var newItem = store.newItem(testObject);
441 doh.assertTrue(store.isItem(newItem));
443 newItem = store.newItem(testObject2);
444 doh.assertTrue(store.isItem(newItem));
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});
455 var parentItem = store.fetch("$.store.book[0]")[0];
462 var newItem = store.newItem(testObject,{parent: parentItem, attribute: "TEST_PROPERTY"});
463 doh.assertTrue(store.isItem(newItem));
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"});
473 var parentItem = store.fetch("$.store.book[0]")[0];
481 var newItem = store.newItem(testObject,{parent: parentItem});
482 doh.assertTrue(store.isItem(newItem));
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"});
492 var parentItem = store.fetch("$.store.book[0]")[0];
500 var newItem = store.newItem(testObject,{parent: parentItem, attribute: "TEST"});
501 doh.assertTrue(store.isItem(newItem));
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"});
511 var parentItem = store.fetch("$.store")[0];
519 var newItem = store.newItem(testObject,{parent: parentItem, attribute: "book"});
520 doh.assertTrue(store.isItem(newItem));
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];
531 var snapshot = store.dump({clone:true, cleanMeta: false, suppressExportMeta: true});
533 store.setValue(item, "Foo", "Bar");
534 doh.assertEqual(store._data.store.Foo, "Bar");
535 doh.assertTrue(store._data.store._meta.isDirty);
537 doh.assertFalse(store._data.store._meta.isDirty);
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];
548 var snapshot = store.dump({clone:true, cleanMeta: false, suppressExportMeta: true});
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);
555 doh.assertFalse(store._data.store._meta.isDirty);
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];
566 var snapshot = store.dump({clone:true, cleanMeta: false, suppressExportMeta: true});
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);
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);
578 doh.assertFalse(store._data.store._meta.isDirty);
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];
589 var snapshot = store.dump({clone:true, cleanMeta: false, suppressExportMeta: true});
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);
596 doh.assertFalse(store._data.store._meta.isDirty);
597 doh.assertFalse(store._data.store.Foo);