/libcommon/DTK/dojox/data/tests/stores/XmlStore.js
JavaScript | 1415 lines | 1069 code | 102 blank | 244 comment | 22 complexity | 8c804b2e08a9dd1f9b45c069acd0fc48 MD5 | raw file
1dojo.provide("dojox.data.tests.stores.XmlStore"); 2dojo.require("dojox.data.XmlStore"); 3dojo.require("dojo.data.api.Read"); 4dojo.require("dojo.data.api.Write"); 5dojo.require("dojo.data.api.Identity"); 6 7 8dojox.data.tests.stores.XmlStore.getBooks3Store = function(){ 9 return new dojox.data.XmlStore({url: require.toUrl("dojox/data/tests/stores/books2.xml").toString(), label: "title", keyAttribute: "isbn"}); 10}; 11 12dojox.data.tests.stores.XmlStore.getBooks2Store = function(){ 13 return new dojox.data.XmlStore({url: require.toUrl("dojox/data/tests/stores/books2.xml").toString(), label: "title"}); 14}; 15 16dojox.data.tests.stores.XmlStore.getBooks2StorePC = function(){ 17 return new dojox.data.XmlStore({url: require.toUrl("dojox/data/tests/stores/books2.xml").toString(), label: "title", urlPreventCache: false}); 18}; 19 20dojox.data.tests.stores.XmlStore.getBooksStore = function(){ 21 return new dojox.data.XmlStore({url: require.toUrl("dojox/data/tests/stores/books.xml").toString(), label: "title"}); 22}; 23 24dojox.data.tests.stores.XmlStore.getCDataTestStore = function(){ 25 return new dojox.data.XmlStore({url: require.toUrl("dojox/data/tests/stores/cdata_test.xml").toString(), label: "title"}); 26}; 27 28dojox.data.tests.stores.XmlStore.getGeographyStore = function(){ 29 return new dojox.data.XmlStore({url: require.toUrl("dojox/data/tests/stores/geography2.xml").toString(), label: "text", keyAttribute: "text", attributeMap: {text: '@text'}, rootItem: "geography"}); 30}; 31 32doh.register("dojox.data.tests.stores.XmlStore", 33 [ 34 function testReadAPI_fetch_all(t){ 35 // summary: 36 // Simple test of fetching all xml items through an XML element called isbn 37 // description: 38 // Simple test of fetching all xml items through an XML element called isbn 39 var store = dojox.data.tests.stores.XmlStore.getBooksStore(); 40 41 var d = new doh.Deferred(); 42 function onComplete(items, request) { 43 t.assertEqual(20, items.length); 44 d.callback(true); 45 } 46 function onError(error, request) { 47 d.errback(error); 48 } 49 store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError}); 50 return d; //Object 51 }, 52 function testReadAPI_fetch_one(t){ 53 // summary: 54 // Simple test of fetching one xml items through an XML element called isbn 55 // description: 56 // Simple test of fetching one xml items through an XML element called isbn 57 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 58 59 var d = new doh.Deferred(); 60 function onComplete(items, request) { 61 t.assertEqual(1, items.length); 62 d.callback(true); 63 } 64 function onError(error, request) { 65 d.errback(error); 66 } 67 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError}); 68 return d; //Object 69 }, 70 { 71 name: "testReadAPI_fetch_paging", 72 timeout: 10000, 73 runTest: function(t){ 74 // summary: 75 // Simple test of fetching one xml items through an XML element called isbn 76 // description: 77 // Simple test of fetching one xml items through an XML element called isbn 78 var store = dojox.data.tests.stores.XmlStore.getBooksStore(); 79 var d = new doh.Deferred(); 80 81 var dumpSixthFetch = function(items, request){ 82 t.assertEqual(18, items.length); 83 d.callback(true); 84 }; 85 86 var dumpFifthFetch = function(items, request){ 87 t.assertEqual(11, items.length); 88 request.start = 2; 89 request.count = 20; 90 request.onComplete = dumpSixthFetch; 91 store.fetch(request); 92 }; 93 94 var dumpFourthFetch = function(items, request){ 95 t.assertEqual(18, items.length); 96 request.start = 9; 97 request.count = 100; 98 request.onComplete = dumpFifthFetch; 99 store.fetch(request); 100 }; 101 102 var dumpThirdFetch = function (items, request){ 103 t.assertEqual(5, items.length); 104 request.start = 2; 105 request.count = 20; 106 request.onComplete = dumpFourthFetch; 107 store.fetch(request); 108 }; 109 110 var dumpSecondFetch = function(items, request){ 111 t.assertEqual(1, items.length); 112 request.start = 0; 113 request.count = 5; 114 request.onComplete = dumpThirdFetch; 115 store.fetch(request); 116 }; 117 118 var dumpFirstFetch = function(items, request){ 119 t.assertEqual(5, items.length); 120 request.start = 3; 121 request.count = 1; 122 request.onComplete = dumpSecondFetch; 123 store.fetch(request); 124 }; 125 126 var completed = function(items, request){ 127 t.assertEqual(20, items.length); 128 request.start = 1; 129 request.count = 5; 130 request.onComplete = dumpFirstFetch; 131 store.fetch(request); 132 }; 133 134 135 function error(errData, request){ 136 d.errback(errData); 137 } 138 139 store.fetch({onComplete: completed, onError: error}); 140 return d; //Object 141 } 142 }, 143 function testReadAPI_fetch_pattern0(t){ 144 // summary: 145 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match 146 // description: 147 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match 148 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 149 var d = new doh.Deferred(); 150 function onComplete(items, request) { 151 t.assertEqual(1, items.length); 152 d.callback(true); 153 } 154 function onError(error, request) { 155 d.errback(error); 156 } 157 store.fetch({query:{isbn:"?9B574"}, onComplete: onComplete, onError: onError}); 158 return d; //Object 159 }, 160 161 function testReadAPI_fetch_pattern1(t){ 162 // summary: 163 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match 164 // description: 165 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match 166 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 167 var d = new doh.Deferred(); 168 function onComplete(items, request) { 169 t.assertEqual(4, items.length); 170 d.callback(true); 171 } 172 function onError(error, request) { 173 d.errback(error); 174 } 175 store.fetch({query:{isbn:"A9B57?"}, onComplete: onComplete, onError: onError}); 176 return d; //Object 177 }, 178 function testReadAPI_fetch_pattern1_preventCacheOff(t){ 179 // summary: 180 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match 181 // with preventCache off to test that it doesn't pass it when told not to. 182 // description: 183 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match 184 // with preventCache off to test that it doesn't pass it when told not to. 185 var store = dojox.data.tests.stores.XmlStore.getBooks2StorePC(); 186 var d = new doh.Deferred(); 187 function onComplete(items, request) { 188 t.assertEqual(4, items.length); 189 d.callback(true); 190 } 191 function onError(error, request) { 192 d.errback(error); 193 } 194 store.fetch({query:{isbn:"A9B57?"}, onComplete: onComplete, onError: onError}); 195 return d; //Object 196 }, 197 function testReadAPI_fetch_pattern2(t){ 198 // summary: 199 // Simple test of fetching one xml items through an XML element called isbn with * pattern match 200 // description: 201 // Simple test of fetching one xml items through an XML element called isbn with * pattern match 202 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 203 var d = new doh.Deferred(); 204 function onComplete(items, request) { 205 t.assertEqual(5, items.length); 206 d.callback(true); 207 } 208 function onError(error, request) { 209 d.errback(error); 210 } 211 store.fetch({query:{isbn:"A9*"}, onComplete: onComplete, onError: onError}); 212 return d; //Object 213 }, 214 function testReadAPI_fetch_pattern_multi(t){ 215 // summary: 216 // Simple test of fetching one xml items with a pattern of multiple attrs. 217 // description: 218 // Simple test of fetching one xml items with a pattern of multiple attrs. 219 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 220 var d = new doh.Deferred(); 221 function onComplete(items, request) { 222 t.assertEqual(1, items.length); 223 d.callback(true); 224 } 225 function onError(error, request) { 226 d.errback(error); 227 } 228 store.fetch({query:{isbn:"A9B57?", title: "?itle of 3"}, onComplete: onComplete, onError: onError}); 229 return d; //Object 230 }, 231 function testReadAPI_fetch_pattern_multiValuedValue(t){ 232 // summary: 233 // Simple test of fetching one xml items with a pattern of multiple attrs. 234 // description: 235 // Simple test of fetching one xml items with a pattern of multiple attrs. 236 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 237 var d = new doh.Deferred(); 238 function onComplete(items, request) { 239 t.assertEqual(1, items.length); 240 d.callback(true); 241 } 242 function onError(error, request) { 243 d.errback(error); 244 } 245 store.fetch({query:{author:"Third Author of 5"}, onComplete: onComplete, onError: onError}); 246 return d; //Object 247 }, 248 function testReadAPI_fetch_pattern_caseInsensitive(t){ 249 // summary: 250 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case insensitive mode. 251 // description: 252 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case insensitive mode. 253 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 254 var d = new doh.Deferred(); 255 function onComplete(items, request) { 256 t.assertEqual(1, items.length); 257 d.callback(true); 258 } 259 function onError(error, request) { 260 d.errback(error); 261 } 262 store.fetch({query:{isbn:"?9b574"}, queryOptions: {ignoreCase: true}, onComplete: onComplete, onError: onError}); 263 return d; //Object 264 }, 265 function testReadAPI_fetch_pattern_caseSensitive(t){ 266 // summary: 267 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case sensitive mode. 268 // description: 269 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match and in case sensitive mode. 270 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 271 var d = new doh.Deferred(); 272 function onComplete(items, request) { 273 t.assertEqual(1, items.length); 274 d.callback(true); 275 } 276 function onError(error, request) { 277 d.errback(error); 278 } 279 store.fetch({query:{isbn:"?9B574"}, queryOptions: {ignoreCase: false}, onComplete: onComplete, onError: onError}); 280 return d; //Object 281 }, 282 function testReadAPI_fetch_regexp(t){ 283 // summary: 284 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match 285 // description: 286 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match 287 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 288 var d = new doh.Deferred(); 289 function onComplete(items, request) { 290 t.assertEqual(1, items.length); 291 d.callback(true); 292 } 293 function onError(error, request) { 294 d.errback(error); 295 } 296 store.fetch({query:{isbn: new RegExp("^.9B574$")}, onComplete: onComplete, onError: onError}); 297 return d; //Object 298 }, 299 function testReadAPI_fetch_all_rootItem(t){ 300 // summary: 301 // Simple test of fetching all xml items through an XML element called isbn 302 // description: 303 // Simple test of fetching all xml items through an XML element called isbn 304 var store = new dojox.data.XmlStore({url: require.toUrl("dojox/data/tests/stores/books3.xml").toString(), 305 rootItem:"book"}); 306 307 var d = new doh.Deferred(); 308 function onComplete(items, request) { 309 t.assertEqual(5, items.length); 310 d.callback(true); 311 } 312 function onError(error, request) { 313 d.errback(error); 314 } 315 store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError}); 316 return d; //Object 317 }, 318 function testReadAPI_fetch_withAttrMap_all(t){ 319 var store = new dojox.data.XmlStore({url: require.toUrl("dojox/data/tests/stores/books_isbnAttr.xml").toString(), 320 attributeMap: {"book.isbn": "@isbn"}}); 321 322 var d = new doh.Deferred(); 323 function onComplete(items, request) { 324 t.assertEqual(5, items.length); 325 d.callback(true); 326 } 327 function onError(error, request) { 328 console.debug(error); 329 d.errback(error); 330 } 331 store.fetch({query:{isbn:"*"}, onComplete: onComplete, onError: onError}); 332 return d; //Object 333 }, 334 function testReadAPI_fetch_withAttrMap_one(t){ 335 var store = new dojox.data.XmlStore({url: require.toUrl("dojox/data/tests/stores/books_isbnAttr.xml").toString(), 336 attributeMap: {"book.isbn": "@isbn"}}); 337 338 var d = new doh.Deferred(); 339 function onComplete(items, request) { 340 t.assertEqual(1, items.length); 341 d.callback(true); 342 } 343 function onError(error, request) { 344 console.debug(error); 345 d.errback(error); 346 } 347 store.fetch({query:{isbn:"2"}, onComplete: onComplete, onError: onError}); 348 return d; //Object 349 }, 350 function testReadAPI_fetch_withAttrMap_pattern0(t){ 351 // summary: 352 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match 353 // description: 354 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match 355 var store = new dojox.data.XmlStore({url: require.toUrl("dojox/data/tests/stores/books_isbnAttr2.xml").toString(), 356 attributeMap: {"book.isbn": "@isbn"}}); 357 var d = new doh.Deferred(); 358 function onComplete(items, request) { 359 t.assertEqual(3, items.length); 360 d.callback(true); 361 } 362 function onError(error, request) { 363 d.errback(error); 364 } 365 store.fetch({query:{isbn:"ABC?"}, onComplete: onComplete, onError: onError}); 366 return d; //Object 367 }, 368 function testReadAPI_fetch_withAttrMap_pattern1(t){ 369 // summary: 370 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match 371 // description: 372 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match 373 var store = new dojox.data.XmlStore({url: require.toUrl("dojox/data/tests/stores/books_isbnAttr2.xml").toString(), 374 attributeMap: {"book.isbn": "@isbn"}}); 375 var d = new doh.Deferred(); 376 function onComplete(items, request) { 377 t.assertEqual(5, items.length); 378 d.callback(true); 379 } 380 function onError(error, request) { 381 d.errback(error); 382 } 383 store.fetch({query:{isbn:"A*"}, onComplete: onComplete, onError: onError}); 384 return d; //Object 385 }, 386 function testReadAPI_fetch_withAttrMap_pattern2(t){ 387 // summary: 388 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match 389 // description: 390 // Simple test of fetching one xml items through an XML element called isbn with ? pattern match 391 var store = new dojox.data.XmlStore({url: require.toUrl("dojox/data/tests/stores/books_isbnAttr2.xml").toString(), 392 attributeMap: {"book.isbn": "@isbn"}}); 393 var d = new doh.Deferred(); 394 function onComplete(items, request) { 395 t.assertEqual(2, items.length); 396 d.callback(true); 397 } 398 function onError(error, request) { 399 d.errback(error); 400 } 401 store.fetch({query:{isbn:"?C*"}, onComplete: onComplete, onError: onError}); 402 return d; //Object 403 }, 404 405 function testReadAPI_getLabel(t){ 406 // summary: 407 // Simple test of the getLabel function against a store set that has a label defined. 408 // description: 409 // Simple test of the getLabel function against a store set that has a label defined. 410 411 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 412 413 var d = new doh.Deferred(); 414 function onComplete(items, request){ 415 t.assertEqual(items.length, 1); 416 var label = store.getLabel(items[0]); 417 t.assertTrue(label !== null); 418 t.assertEqual("Title of 4", label); 419 d.callback(true); 420 } 421 function onError(error, request) { 422 d.errback(error); 423 } 424 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError}); 425 return d; 426 }, 427 function testReadAPI_getLabelAttributes(t){ 428 // summary: 429 // Simple test of the getLabelAttributes function against a store set that has a label defined. 430 // description: 431 // Simple test of the getLabelAttributes function against a store set that has a label defined. 432 433 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 434 435 var d = new doh.Deferred(); 436 function onComplete(items, request){ 437 t.assertEqual(items.length, 1); 438 var labelList = store.getLabelAttributes(items[0]); 439 t.assertTrue(dojo.isArray(labelList)); 440 t.assertEqual("title", labelList[0]); 441 d.callback(true); 442 } 443 function onError(error, request) { 444 d.errback(error); 445 } 446 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError}); 447 return d; 448 }, 449 450 function testReadAPI_getValue(t){ 451 // summary: 452 // Simple test of the getValue API 453 // description: 454 // Simple test of the getValue API 455 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 456 457 var d = new doh.Deferred(); 458 function onComplete(items, request) { 459 t.assertEqual(1, items.length); 460 var item = items[0]; 461 t.assertTrue(store.hasAttribute(item,"isbn")); 462 t.assertEqual(store.getValue(item,"isbn"), "A9B574"); 463 d.callback(true); 464 } 465 function onError(error, request) { 466 d.errback(error); 467 } 468 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError}); 469 return d; //Object 470 }, 471 function testReadAPI_getValue_cdata(t) { 472 // summary: 473 // Simple test of the getValue text() special attribute. 474 // description: 475 // Simple test of the getValue text() special attribute. 476 var store = dojox.data.tests.stores.XmlStore.getCDataTestStore(); 477 478 var d = new doh.Deferred(); 479 function onComplete(items, request) { 480 t.assertEqual(1, items.length); 481 var item = items[0]; 482 try{ 483 t.assertTrue(store.hasAttribute(item,"ids")); 484 t.assertEqual(store.getValue(item,"ids"), "{68d3c190-4b83-11dd-c204-000000000001}17"); 485 var title = store.getValue(item, "title"); 486 t.assertTrue(store.isItem(title)); 487 var titleValue = store.getValue(title, "text()"); 488 t.assertEqual("<b>First</b> 3", dojo.trim(titleValue)); 489 d.callback(true); 490 } catch (e) { 491 d.errback(e); 492 } 493 } 494 function onError(error, request) { 495 d.errback(error); 496 } 497 store.fetch({query:{ids:"{68d3c190-4b83-11dd-c204-000000000001}17"}, onComplete: onComplete, onError: onError}); 498 return d; //Object 499 }, 500 501 function testReadAPI_getValues_cdata(t) { 502 // summary: 503 // Simple test of the getValues text() special attribute. 504 // description: 505 // Simple test of the getValues text() special attribute. 506 var store = dojox.data.tests.stores.XmlStore.getCDataTestStore(); 507 508 var d = new doh.Deferred(); 509 function onComplete(items, request) { 510 t.assertEqual(1, items.length); 511 var item = items[0]; 512 try{ 513 t.assertTrue(store.hasAttribute(item,"ids")); 514 t.assertEqual(store.getValue(item,"ids"), "{68d3c190-4b83-11dd-c204-000000000001}17"); 515 var title = store.getValue(item, "title"); 516 t.assertTrue(store.isItem(title)); 517 var titleValue = store.getValues(title, "text()"); 518 t.assertEqual("<b>First</b> 3", dojo.trim(titleValue[0])); 519 d.callback(true); 520 } catch (e) { 521 d.errback(e); 522 } 523 } 524 function onError(error, request) { 525 d.errback(error); 526 } 527 store.fetch({query:{ids:"{68d3c190-4b83-11dd-c204-000000000001}17"}, onComplete: onComplete, onError: onError}); 528 return d; //Object 529 }, 530 function testReadAPI_getValue_cdata_toString(t) { 531 // summary: 532 // Simple test of the getValue and toString of the resulting 'XmlItem' API 533 // description: 534 // Simple test of the getValue and toString of the resulting 'XmlItem' API 535 var store = dojox.data.tests.stores.XmlStore.getCDataTestStore(); 536 537 var d = new doh.Deferred(); 538 function onComplete(items, request) { 539 t.assertEqual(1, items.length); 540 var item = items[0]; 541 try{ 542 t.assertTrue(store.hasAttribute(item,"ids")); 543 t.assertEqual(store.getValue(item,"ids"), "{68d3c190-4b83-11dd-c204-000000000001}17"); 544 var title = store.getValue(item, "title"); 545 t.assertTrue(store.isItem(title)); 546 var firstText = title.toString(); 547 t.assertEqual("<b>First</b> 3", dojo.trim(firstText)); 548 d.callback(true); 549 } catch (e) { 550 d.errback(e); 551 } 552 } 553 function onError(error, request) { 554 d.errback(error); 555 } 556 store.fetch({query:{ids:"{68d3c190-4b83-11dd-c204-000000000001}17"}, onComplete: onComplete, onError: onError}); 557 return d; //Object 558 }, 559 560 function testReadAPI_getValues(t){ 561 // summary: 562 // Simple test of the getValues API 563 // description: 564 // Simple test of the getValues API 565 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 566 567 var d = new doh.Deferred(); 568 function onComplete(items, request) { 569 t.assertEqual(1, items.length); 570 var item = items[0]; 571 t.assertTrue(store.hasAttribute(item,"isbn")); 572 var values = store.getValues(item,"isbn"); 573 t.assertEqual(1,values.length); 574 t.assertEqual("A9B574", values[0]); 575 d.callback(true); 576 } 577 function onError(error, request) { 578 d.errback(error); 579 } 580 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError}); 581 return d; //Object 582 }, 583 function testReadAPI_isItem(t){ 584 // summary: 585 // Simple test of the isItem API 586 // description: 587 // Simple test of the isItem API 588 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 589 590 var d = new doh.Deferred(); 591 function onComplete(items, request) { 592 t.assertEqual(1, items.length); 593 var item = items[0]; 594 t.assertTrue(store.isItem(item)); 595 t.assertTrue(!store.isItem({})); 596 t.assertTrue(!store.isItem("Foo")); 597 t.assertTrue(!store.isItem(1)); 598 d.callback(true); 599 } 600 function onError(error, request) { 601 d.errback(error); 602 } 603 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError}); 604 return d; //Object 605 }, 606 function testReadAPI_isItem_multistore(t){ 607 // summary: 608 // Simple test of the isItem API across multiple store instances. 609 // description: 610 // Simple test of the isItem API across multiple store instances. 611 var store1 = dojox.data.tests.stores.XmlStore.getBooks2Store(); 612 var store2 = dojox.data.tests.stores.XmlStore.getBooks2Store(); 613 var d = new doh.Deferred(); 614 615 var onError = function(error, request) { 616 d.errback(error); 617 }; 618 619 var onComplete1 = function(items, request) { 620 t.assertEqual(1, items.length); 621 var item1 = items[0]; 622 t.assertTrue(store1.isItem(item1)); 623 624 var onComplete2 = function(items, request) { 625 t.assertEqual(1, items.length); 626 var item2 = items[0]; 627 t.assertTrue(store2.isItem(item2)); 628 t.assertTrue(!store1.isItem(item2)); 629 t.assertTrue(!store2.isItem(item1)); 630 d.callback(true); 631 }; 632 store2.fetch({query:{isbn:"A9B574"}, onComplete: onComplete2, onError: onError}); 633 }; 634 store1.fetch({query:{isbn:"A9B574"}, onComplete: onComplete1, onError: onError}); 635 return d; //Object 636 }, 637 function testReadAPI_hasAttribute(t){ 638 // summary: 639 // Simple test of the hasAttribute API 640 // description: 641 // Simple test of the hasAttribute API 642 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 643 644 var d = new doh.Deferred(); 645 function onComplete(items, request) { 646 t.assertEqual(1, items.length); 647 var item = items[0]; 648 t.assertTrue(store.hasAttribute(item,"isbn")); 649 t.assertTrue(!store.hasAttribute(item,"bob")); 650 //Verify that XML attributes return false in this case. 651 t.assertTrue(store.hasAttribute(item,"@xmlAttribute")); 652 t.assertFalse(store.hasAttribute(item,"@bogus")); 653 d.callback(true); 654 } 655 function onError(error, request) { 656 d.errback(error); 657 } 658 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError}); 659 return d; //Object 660 }, 661 function testReadAPI_containsValue(t){ 662 // summary: 663 // Simple test of the containsValue API 664 // description: 665 // Simple test of the containsValue API 666 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 667 668 var d = new doh.Deferred(); 669 function onComplete(items, request) { 670 t.assertEqual(1, items.length); 671 var item = items[0]; 672 t.assertTrue(store.containsValue(item,"isbn", "A9B574")); 673 t.assertTrue(!store.containsValue(item,"isbn", "bob")); 674 d.callback(true); 675 } 676 function onError(error, request) { 677 d.errback(error); 678 } 679 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError}); 680 return d; //Object 681 }, 682 function testReadAPI_sortDescending(t){ 683 // summary: 684 // Simple test of the sorting API in descending order. 685 // description: 686 // Simple test of the sorting API in descending order. 687 var store = dojox.data.tests.stores.XmlStore.getBooksStore(); 688 689 //Comparison is done as a string type (toString comparison), so the order won't be numeric 690 //So have to compare in 'alphabetic' order. 691 var order = [9,8,7,6,5,4,3,20,2,19,18,17,16,15,14,13,12,11,10,1]; 692 693 var d = new doh.Deferred(); 694 function onComplete(items, request) { 695 console.log("Number of items: " + items.length); 696 t.assertEqual(20, items.length); 697 698 for(var i = 0; i < items.length; i++){ 699 t.assertEqual(order[i], store.getValue(items[i],"isbn").toString()); 700 } 701 d.callback(true); 702 } 703 function onError(error, request) { 704 d.errback(error); 705 } 706 707 var sortAttributes = [{attribute: "isbn", descending: true}]; 708 store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError}); 709 return d; //Object 710 }, 711 function testReadAPI_sortAscending(t){ 712 // summary: 713 // Simple test of the sorting API in ascending order. 714 // description: 715 // Simple test of the sorting API in ascending order. 716 var store = dojox.data.tests.stores.XmlStore.getBooksStore(); 717 718 //Comparison is done as a string type (toString comparison), so the order won't be numeric 719 //So have to compare in 'alphabetic' order. 720 var order = [1,10,11,12,13,14,15,16,17,18,19,2,20,3,4,5,6,7,8,9]; 721 722 var d = new doh.Deferred(); 723 function onComplete(items, request) { 724 t.assertEqual(20, items.length); 725 var itemId = 1; 726 for(var i = 0; i < items.length; i++){ 727 t.assertEqual(order[i], store.getValue(items[i],"isbn").toString()); 728 } 729 d.callback(true); 730 } 731 function onError(error, request) { 732 d.errback(error); 733 } 734 735 var sortAttributes = [{attribute: "isbn"}]; 736 store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError}); 737 return d; //Object 738 }, 739 function testReadAPI_sortDescendingNumeric(t){ 740 // summary: 741 // Simple test of the sorting API in descending order using a numeric comparator. 742 // description: 743 // Simple test of the sorting API in descending order using a numeric comparator. 744 var store = dojox.data.tests.stores.XmlStore.getBooksStore(); 745 746 //isbn should be treated as a numeric, not as a string comparison 747 store.comparatorMap = {}; 748 store.comparatorMap["isbn"] = function(a, b){ 749 var ret = 0; 750 if(parseInt(a.toString(), 10) > parseInt(b.toString(), 10)){ 751 ret = 1; 752 }else if(parseInt(a.toString(), 10) < parseInt(b.toString(), 10)){ 753 ret = -1; 754 } 755 return ret; //int, {-1,0,1} 756 }; 757 758 var d = new doh.Deferred(); 759 function onComplete(items, request) { 760 t.assertEqual(20, items.length); 761 var itemId = 20; 762 for(var i = 0; i < items.length; i++){ 763 t.assertEqual(itemId, store.getValue(items[i],"isbn").toString()); 764 itemId--; 765 } 766 d.callback(true); 767 } 768 function onError(error, request) { 769 d.errback(error); 770 } 771 772 var sortAttributes = [{attribute: "isbn", descending: true}]; 773 store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError}); 774 return d; //Object 775 }, 776 function testReadAPI_sortAscendingNumeric(t){ 777 // summary: 778 // Simple test of the sorting API in ascending order using a numeric comparator. 779 // description: 780 // Simple test of the sorting API in ascending order using a numeric comparator. 781 var store = dojox.data.tests.stores.XmlStore.getBooksStore(); 782 783 //isbn should be treated as a numeric, not as a string comparison 784 store.comparatorMap = {}; 785 store.comparatorMap["isbn"] = function(a, b){ 786 var ret = 0; 787 if(parseInt(a.toString(), 10) > parseInt(b.toString(), 10)){ 788 ret = 1; 789 }else if(parseInt(a.toString(), 10) < parseInt(b.toString(), 10)){ 790 ret = -1; 791 } 792 return ret; //int, {-1,0,1} 793 }; 794 795 var d = new doh.Deferred(); 796 function onComplete(items, request) { 797 t.assertEqual(20, items.length); 798 var itemId = 1; 799 for(var i = 0; i < items.length; i++){ 800 t.assertEqual(itemId, store.getValue(items[i],"isbn").toString()); 801 itemId++; 802 } 803 d.callback(true); 804 } 805 function onError(error, request) { 806 d.errback(error); 807 } 808 809 var sortAttributes = [{attribute: "isbn"}]; 810 store.fetch({query:{isbn:"*"}, sort: sortAttributes, onComplete: onComplete, onError: onError}); 811 return d; //Object 812 }, 813 function testReadAPI_isItemLoaded(t){ 814 // summary: 815 // Simple test of the isItemLoaded API 816 // description: 817 // Simple test of the isItemLoaded API 818 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 819 820 var d = new doh.Deferred(); 821 function onComplete(items, request) { 822 t.assertEqual(1, items.length); 823 var item = items[0]; 824 t.assertTrue(store.isItemLoaded(item)); 825 d.callback(true); 826 } 827 function onError(error, request) { 828 d.errback(error); 829 } 830 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError}); 831 return d; //Object 832 }, 833 function testReadAPI_getFeatures(t){ 834 // summary: 835 // Simple test of the getFeatures function of the store 836 // description: 837 // Simple test of the getFeatures function of the store 838 839 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 840 var features = store.getFeatures(); 841 var count = 0; 842 var i; 843 for(i in features){ 844 t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Write" || "dojo.data.api.Identity")); 845 count++; 846 } 847 t.assertEqual(3, count); 848 }, 849 function testReadAPI_getAttributes(t){ 850 // summary: 851 // Simple test of the getAttributes API 852 // description: 853 // Simple test of the getAttributes API 854 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 855 856 var d = new doh.Deferred(); 857 function onComplete(items, request) { 858 t.assertEqual(1, items.length); 859 var item = items[0]; 860 var attributes = store.getAttributes(item); 861 862 //Should be six, as all items should have tagName, childNodes, and text() special attributes 863 //in addition to any doc defined ones, which in this case are author, title, and isbn 864 //FIXME: Figure out why IE returns 5! Need to get firebug lite working in IE for that. 865 //Suspect it's childNodes, may not be defined if there are no child nodes. 866 for(var i = 0; i < attributes.length; i++){ 867 console.log("attribute found: " + attributes[i]); 868 } 869 if(dojo.isIE){ 870 t.assertEqual(5,attributes.length); 871 }else{ 872 t.assertEqual(6,attributes.length); 873 } 874 d.callback(true); 875 } 876 function onError(error, request) { 877 d.errback(error); 878 } 879 store.fetch({query:{isbn:"A9B577"}, onComplete: onComplete, onError: onError}); 880 return d; //Object 881 }, 882 function testWriteAPI_setValue(t){ 883 // summary: 884 // Simple test of the setValue API 885 // description: 886 // Simple test of the setValue API 887 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 888 889 var d = new doh.Deferred(); 890 function onComplete(items, request) { 891 t.assertEqual(1, items.length); 892 var item = items[0]; 893 t.assertTrue(store.containsValue(item,"isbn", "A9B574")); 894 store.setValue(item, "isbn", "A9B574-new"); 895 t.assertEqual(store.getValue(item,"isbn").toString(), "A9B574-new"); 896 d.callback(true); 897 } 898 function onError(error, request) { 899 d.errback(error); 900 } 901 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError}); 902 return d; //Object 903 }, 904 function testWriteAPI_setValues(t){ 905 // summary: 906 // Simple test of the setValues API 907 // description: 908 // Simple test of the setValues API 909 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 910 911 var d = new doh.Deferred(); 912 function onComplete(items, request) { 913 t.assertEqual(1, items.length); 914 var item = items[0]; 915 t.assertTrue(store.containsValue(item,"isbn", "A9B574")); 916 store.setValues(item, "isbn", ["A9B574-new1", "A9B574-new2"]); 917 var values = store.getValues(item,"isbn"); 918 t.assertEqual(values[0].toString(), "A9B574-new1"); 919 t.assertEqual(values[1].toString(), "A9B574-new2"); 920 store.setValues(values[0], "text()", ["A9B574", "-new3"]); 921 t.assertEqual(store.getValue(values[0],"text()").toString(), "A9B574-new3"); 922 d.callback(true); 923 } 924 function onError(error, request) { 925 d.errback(error); 926 } 927 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError}); 928 return d; //Object 929 }, 930 function testWriteAPI_unsetAttribute(t){ 931 // summary: 932 // Simple test of the unsetAttribute API 933 // description: 934 // Simple test of the unsetAttribute API 935 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 936 937 var d = new doh.Deferred(); 938 function onComplete(items, request) { 939 t.assertEqual(1, items.length); 940 var item = items[0]; 941 t.assertTrue(store.containsValue(item,"isbn", "A9B574")); 942 store.unsetAttribute(item,"isbn"); 943 t.assertTrue(!store.hasAttribute(item,"isbn")); 944 t.assertTrue(store.isDirty(item)); 945 d.callback(true); 946 } 947 function onError(error, request) { 948 d.errback(error); 949 } 950 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError}); 951 return d; //Object 952 }, 953 function testWriteAPI_isDirty(t){ 954 // summary: 955 // Simple test of the isDirty API 956 // description: 957 // Simple test of the isDirty API 958 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 959 960 var d = new doh.Deferred(); 961 function onComplete(items, request) { 962 t.assertEqual(1, items.length); 963 var item = items[0]; 964 t.assertTrue(store.containsValue(item,"isbn", "A9B574")); 965 store.setValue(item, "isbn", "A9B574-new"); 966 t.assertEqual(store.getValue(item,"isbn").toString(), "A9B574-new"); 967 t.assertTrue(store.isDirty(item)); 968 d.callback(true); 969 } 970 function onError(error, request) { 971 d.errback(error); 972 } 973 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError}); 974 return d; //Object 975 }, 976 function testWriteAPI_revert(t){ 977 // summary: 978 // Simple test of the write revert API 979 // description: 980 // Simple test of the write revert API 981 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 982 983 var d = new doh.Deferred(); 984 var onError = function(error, request) { 985 d.errback(error); 986 }; 987 var onComplete = function(items, request) { 988 t.assertEqual(1, items.length); 989 var item = items[0]; 990 t.assertTrue(store.containsValue(item,"isbn", "A9B574")); 991 t.assertTrue(!store.isDirty(item)); 992 store.setValue(item, "isbn", "A9B574-new"); 993 t.assertEqual(store.getValue(item,"isbn").toString(), "A9B574-new"); 994 t.assertTrue(store.isDirty(item)); 995 store.revert(); 996 997 //Fetch again to see if it reset the state. 998 var onComplete1 = function(items, request) { 999 t.assertEqual(1, items.length); 1000 var item = items[0]; 1001 t.assertTrue(store.containsValue(item,"isbn", "A9B574")); 1002 d.callback(true); 1003 }; 1004 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete1, onError: onError}); 1005 }; 1006 store.fetch({query:{isbn:"A9B574"}, onComplete: onComplete, onError: onError}); 1007 return d; //Object 1008 }, 1009 1010 function testIdentityAPI_getIdentity(t) { 1011 // summary: 1012 // Simple test of the Identity getIdentity API 1013 // description: 1014 // Simple test of the Identity getIdentity API 1015 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 1016 1017 var d = new doh.Deferred(); 1018 function onComplete(items, request) { 1019 t.assertEqual(1, items.length); 1020 var item = items[0]; 1021 try { 1022 t.assertTrue(store.containsValue(item,"isbn", "A9B5CC")); 1023 t.assertTrue(store.getIdentity(item) !== null); 1024 d.callback(true); 1025 } catch (e) { 1026 d.errback(e); 1027 } 1028 } 1029 function onError(error, request) { 1030 d.errback(error); 1031 } 1032 store.fetch({query:{isbn:"A9B5CC"}, onComplete: onComplete, onError: onError}); 1033 return d; //Object 1034 }, 1035 1036 function testIdentityAPI_getIdentityAttributes(t) { 1037 // summary: 1038 // Simple test of the Identity getIdentityAttributes API where it defaults to internal xpath (no keyAttribute) 1039 // description: 1040 // Simple test of the Identity getIdentityAttributes API where it defaults to internal xpath (no keyAttribute) 1041 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 1042 1043 var d = new doh.Deferred(); 1044 function onItem(item, request) { 1045 try{ 1046 t.assertTrue(item !== null); 1047 var idAttrs = store.getIdentityAttributes(item); 1048 t.assertTrue(idAttrs === null); 1049 t.assertEqual("/books[0]/book[4]", store.getIdentity(item)); 1050 d.callback(true); 1051 }catch(e){ 1052 d.errback(e); 1053 } 1054 } 1055 function onError(error, request) { 1056 d.errback(error); 1057 } 1058 store.fetchItemByIdentity({identity: "/books[0]/book[4]", onItem: onItem, onError: onError}); 1059 return d; //Object 1060 }, 1061 1062 function testIdentityAPI_getIdentityAttributes_usingKeyAttributeIdentity(t) { 1063 // summary: 1064 // Simple test of the Identity getIdentityAttributes API where identity is specified by the keyAttribute param 1065 // description: 1066 // Simple test of the Identity getIdentityAttributes API where identity is specified by the keyAttribute param 1067 var store = dojox.data.tests.stores.XmlStore.getBooks3Store(); 1068 1069 var d = new doh.Deferred(); 1070 function onItem(item, request) { 1071 try{ 1072 t.assertTrue(item !== null); 1073 var idAttrs = store.getIdentityAttributes(item); 1074 t.assertTrue(idAttrs !== null); 1075 t.assertTrue(idAttrs.length === 1); 1076 t.assertTrue(idAttrs[0] === "isbn"); 1077 d.callback(true); 1078 }catch(e){ 1079 d.errback(e); 1080 } 1081 } 1082 function onError(error, request) { 1083 d.errback(error); 1084 } 1085 store.fetchItemByIdentity({identity: "A9B574", onItem: onItem, onError: onError}); 1086 return d; //Object 1087 }, 1088 1089 function testIdentityAPI_fetchItemByIdentity(t) { 1090 // summary: 1091 // Simple test of the Identity getIdentity API where the store defaults the identity to a xpathlike lookup. 1092 // description: 1093 // Simple test of the Identity getIdentity API where the store defaults the identity to a xpathlike lookup. 1094 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 1095 1096 var d = new doh.Deferred(); 1097 function onItem(item, request) { 1098 try{ 1099 t.assertTrue(item !== null); 1100 t.assertEqual("/books[0]/book[4]", store.getIdentity(item)); 1101 d.callback(true); 1102 }catch(e){ 1103 d.errback(e); 1104 } 1105 } 1106 function onError(error, request) { 1107 d.errback(error); 1108 } 1109 store.fetchItemByIdentity({identity: "/books[0]/book[4]", onItem: onItem, onError: onError}); 1110 return d; //Object 1111 1112 }, 1113 1114 function testIdentityAPI_fetchItemByIdentity2(t) { 1115 // summary: 1116 // Simple test of the Identity getIdentity API where the store defaults the identity to a xpathlike lookup. 1117 // description: 1118 // Simple test of the Identity getIdentity API where the store defaults the identity to a xpathlike lookup. 1119 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 1120 1121 var d = new doh.Deferred(); 1122 function onItem(item, request) { 1123 try{ 1124 t.assertTrue(item !== null); 1125 t.assertEqual("/books[0]/book[0]", store.getIdentity(item)); 1126 d.callback(true); 1127 }catch(e){ 1128 d.errback(e); 1129 } 1130 } 1131 function onError(error, request) { 1132 d.errback(error); 1133 } 1134 store.fetchItemByIdentity({identity: "/books[0]/book[0]", onItem: onItem, onError: onError}); 1135 return d; //Object 1136 1137 }, 1138 1139 function testIdentityAPI_fetchItemByIdentity3(t) { 1140 // summary: 1141 // Simple test of the Identity getIdentity API where the store defaults the identity to a xpathlike lookup. 1142 // description: 1143 // Simple test of the Identity getIdentity API where the store defaults the identity to a xpathlike lookup. 1144 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 1145 1146 var d = new doh.Deferred(); 1147 function onItem(item, request) { 1148 try{ 1149 t.assertTrue(item !== null); 1150 t.assertEqual("/books[0]/book[2]", store.getIdentity(item)); 1151 d.callback(true); 1152 }catch(e){ 1153 d.errback(e); 1154 } 1155 } 1156 function onError(error, request) { 1157 d.errback(error); 1158 } 1159 store.fetchItemByIdentity({identity: "/books[0]/book[2]", onItem: onItem, onError: onError}); 1160 return d; //Object 1161 1162 }, 1163 1164 function testIdentityAPI_fetchItemByIdentity_usingKeyAttributeIdentity(t) { 1165 // summary: 1166 // Simple test of the Identity getIdentity API where identity is specified by the keyAttribute param 1167 // description: 1168 // Simple test of the Identity getIdentity API where identity is specified by the keyAttribute param 1169 var store = dojox.data.tests.stores.XmlStore.getBooks3Store(); 1170 1171 var d = new doh.Deferred(); 1172 function onItem(item, request) { 1173 try{ 1174 t.assertTrue(item !== null); 1175 t.assertEqual("A9B574", store.getIdentity(item)); 1176 d.callback(true); 1177 }catch(e){ 1178 d.errback(e); 1179 } 1180 } 1181 function onError(error, request) { 1182 d.errback(error); 1183 } 1184 store.fetchItemByIdentity({identity: "A9B574", onItem: onItem, onError: onError}); 1185 return d; //Object 1186 }, 1187 1188 function testIdentityAPI_fetchItemByIdentity_usingKeyAttributeIdentity2(t) { 1189 // summary: 1190 // Simple test of the Identity getIdentity API where identity is specified by the keyAttribute param 1191 // description: 1192 // Simple test of the Identity getIdentity API where identity is specified by the keyAttribute param 1193 var store = dojox.data.tests.stores.XmlStore.getBooks3Store(); 1194 1195 var d = new doh.Deferred(); 1196 function onItem(item, request) { 1197 try{ 1198 t.assertTrue(item !== null); 1199 t.assertEqual("A9B57C", store.getIdentity(item)); 1200 d.callback(true); 1201 }catch(e){ 1202 d.errback(e); 1203 } 1204 } 1205 function onError(error, request) { 1206 d.errback(error); 1207 } 1208 store.fetchItemByIdentity({identity: "A9B57C", onItem: onItem, onError: onError}); 1209 return d; //Object 1210 }, 1211 1212 function testIdentityAPI_fetchItemByIdentity_usingKeyAttributeIdentity3(t) { 1213 // summary: 1214 // Simple test of the Identity getIdentity API where identity is specified by the keyAttribute param 1215 // description: 1216 // Simple test of the Identity getIdentity API where identity is specified by the keyAttribute param 1217 var store = dojox.data.tests.stores.XmlStore.getBooks3Store(); 1218 1219 var d = new doh.Deferred(); 1220 function onItem(item, request) { 1221 try{ 1222 t.assertTrue(item !== null); 1223 t.assertEqual("A9B5CC", store.getIdentity(item)); 1224 d.callback(true); 1225 }catch(e){ 1226 d.errback(e); 1227 } 1228 } 1229 function onError(error, request) { 1230 d.errback(error); 1231 } 1232 store.fetchItemByIdentity({identity: "A9B5CC", onItem: onItem, onError: onError}); 1233 return d; //Object 1234 }, 1235 1236 function testIdentityAPI_fetchItemByIdentity_usingKeyAttributeIdentity4(t) { 1237 // summary: 1238 // Simple test of the Identity getIdentity API where identity is specified by the keyAttribute param 1239 // description: 1240 // Simple test of the Identity getIdentity API where identity is specified by the keyAttribute param 1241 var store = dojox.data.tests.stores.XmlStore.getGeographyStore(); 1242 1243 var d = new doh.Deferred(); 1244 function onItem(item, request) { 1245 try{ 1246 t.assertTrue(item !== null); 1247 t.assertEqual("Mexico City", store.getIdentity(item)); 1248 d.callback(true); 1249 }catch(e){ 1250 d.errback(e); 1251 } 1252 } 1253 function onError(error, request) { 1254 d.errback(error); 1255 } 1256 store.fetchItemByIdentity({identity: "Mexico City", onItem: onItem, onError: onError}); 1257 return d; //Object 1258 }, 1259 1260 1261 function testIdentityAPI_fetchItemByIdentity_fails(t) { 1262 // summary: 1263 // Simple test of the Identity getIdentity API 1264 // description: 1265 // Simple test of the Identity getIdentity API 1266 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 1267 1268 var d = new doh.Deferred(); 1269 function onItem(item, request) { 1270 t.assertTrue(item === null); 1271 d.callback(true); 1272 } 1273 function onError(error, request) { 1274 d.errback(error); 1275 } 1276 //In memory stores use dojo query syntax for the identifier. 1277 store.fetchItemByIdentity({identity: "/books[0]/book[200]", onItem: onItem, onError: onError}); 1278 return d; //Object 1279 }, 1280 1281 function testIdentityAPI_fetchItemByIdentity_fails2(t) { 1282 // summary: 1283 // Simple test of the Identity getIdentity API 1284 // description: 1285 // Simple test of the Identity getIdentity API 1286 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 1287 1288 var d = new doh.Deferred(); 1289 function onItem(item, request) { 1290 t.assertTrue(item === null); 1291 d.callback(true); 1292 } 1293 function onError(error, request) { 1294 d.errback(error); 1295 } 1296 //In memory stores use dojo query syntax for the identifier. 1297 store.fetchItemByIdentity({identity: "/books[1]/book[4]", onItem: onItem, onError: onError}); 1298 return d; //Object 1299 }, 1300 1301 function testIdentityAPI_fetchItemByIdentity_fails3(t) { 1302 // summary: 1303 // Simple test of the Identity getIdentity API 1304 // description: 1305 // Simple test of the Identity getIdentity API 1306 var store = dojox.data.tests.stores.XmlStore.getBooks2Store(); 1307 1308 var d = new doh.Deferred(); 1309 function onItem(item, request) { 1310 t.assertTrue(item === null); 1311 d.callback(true); 1312 } 1313 function onError(error, request) { 1314 d.errback(error); 1315 } 1316 //In memory stores use dojo query syntax for the identifier. 1317 store.fetchItemByIdentity({identity: "/books[1]/book[200]", onItem: onItem, onError: onError}); 1318 return d; //Object 1319 }, 1320 1321 function testIdentityAPI_fetchItemByIdentity_usingKeyAttributeIdentity_fails(t) { 1322 // summary: 1323 // Simple test of the Identity getIdentity API where identity is specified by the keyAttribute param 1324 // description: 1325 // Simple test of the Identity getIdentity API where identity is specified by the keyAttribute param 1326 var store = dojox.data.tests.stores.XmlStore.getBooks3Store(); 1327 1328 var d = new doh.Deferred(); 1329 function onItem(item, request) { 1330 try{ 1331 t.assertTrue(item === null); 1332 d.callback(true); 1333 }catch(e){ 1334 d.errback(e); 1335 } 1336 } 1337 function onError(error, request) { 1338 d.errback(error); 1339 } 1340 store.fetchItemByIdentity({identity: "A9B574_NONEXISTANT", onItem: onItem, onError: onError}); 1341 return d; //Object 1342 }, 1343 1344 function testReadAPI_functionConformance(t){ 1345 // summary: 1346 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances. 1347 // description: 1348 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances. 1349 1350 var testStore = dojox.data.tests.stores.XmlStore.getBooksStore(); 1351 var readApi = new dojo.data.api.Read(); 1352 var passed = true; 1353 var i; 1354 for(i in readApi){ 1355 var member = readApi[i]; 1356 //Check that all the 'Read' defined functions exist on the test store. 1357 if(typeof member === "function"){ 1358 var testStoreMember = testStore[i]; 1359 if(!(typeof testStoreMember === "function")){ 1360 console.log("Problem with function: [" + i + "]"); 1361 passed = false; 1362 break; 1363 } 1364 } 1365 } 1366 t.assertTrue(passed); 1367 }, 1368 function testWriteAPI_functionConformance(t){ 1369 // summary: 1370 // Simple test write API conformance. Checks to see all declared functions are actual functions on the instances. 1371 // description: 1372 // Simple test write API conformance. Checks to see all declared functions are actual functions on the instances. 1373 1374 var testStore = dojox.data.tests.stores.XmlStore.getBooksStore(); 1375 var writeApi = new dojo.data.api.Write(); 1376 var passed = true; 1377 var i; 1378 for(i in writeApi){ 1379 var member = writeApi[i]; 1380 //Check that all the 'Write' defined functions exist on the test store. 1381 if(typeof member === "function"){ 1382 var testStoreMember = testStore[i]; 1383 if(!(typeof testStoreMember === "function")){ 1384 passed = false; 1385 break; 1386 } 1387 } 1388 } 1389 t.assertTrue(passed); 1390 }, 1391 function testIdentityAPI_functionConformance(t){ 1392 // summary: 1393 // Simple test write API conformance. Checks to see all declared functions are actual functions on the instances. 1394 // description: 1395 // Simple test write API conformance. Checks to see all declared functions are actual functions on the instances. 1396 1397 var testStore = dojox.data.tests.stores.XmlStore.getBooksStore(); 1398 var identityApi = new dojo.data.api.Identity(); 1399 var passed = true; 1400 var i; 1401 for(i in identityApi){ 1402 var member = identityApi[i]; 1403 //Check that all the 'Write' defined functions exist on the test store. 1404 if(typeof member === "function"){ 1405 var testStoreMember = testStore[i]; 1406 if(!(typeof testStoreMember === "function")){ 1407 passed = false; 1408 break; 1409 } 1410 } 1411 } 1412 t.assertTrue(passed); 1413 } 1414 ] 1415);