PageRenderTime 72ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/libcommon/DTK1.7/dojox/data/tests/stores/XmlStore.js

https://bitbucket.org/sasha.firsov/dojoplay2012
JavaScript | 1415 lines | 1069 code | 102 blank | 244 comment | 22 complexity | 41450f03f328dfe5e7ae3344e9544408 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, Apache-2.0, MIT

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file