PageRenderTime 29ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/com/google/appengine/datanucleus/jdo/JDORecursiveParentTest.java

http://datanucleus-appengine.googlecode.com/
Java | 107 lines | 72 code | 17 blank | 18 comment | 3 complexity | 2c5ad4643fd30908ef6cdd89f61e276b MD5 | raw file
Possible License(s): Apache-2.0
  1. /**********************************************************************
  2. Copyright (c) 2011 Google Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. **********************************************************************/
  13. package com.google.appengine.datanucleus.jdo;
  14. import com.google.appengine.datanucleus.test.jdo.HasRecursiveParentJDO.HasRecursiveParent;
  15. /**
  16. * Test recursive relations (Issue 80)
  17. */
  18. public class JDORecursiveParentTest extends JDOTestCase {
  19. public void testCreateParentAndChildDifferentTxn() {
  20. HasRecursiveParent p = new HasRecursiveParent();
  21. p.setName("yam");
  22. beginTxn();
  23. pm.makePersistent(p);
  24. String pid = p.getId();
  25. commitTxn();
  26. beginTxn();
  27. HasRecursiveParent c = new HasRecursiveParent();
  28. c.setName("yum");
  29. HasRecursiveParent p2 = pm.getObjectById(HasRecursiveParent.class, pid);
  30. c.setParent(p2);
  31. p2.getChildren().add(c);
  32. pm.makePersistent(c);
  33. String cid = c.getId();
  34. commitTxn();
  35. beginTxn();
  36. HasRecursiveParent c2 = pm.getObjectById(HasRecursiveParent.class, cid);
  37. HasRecursiveParent p3 = c2.getParent();
  38. assertEquals(1, p3.getChildren().size());
  39. assertEquals("yam", p3.getName());
  40. assertEquals(p3.getChildren().iterator().next(), c2);
  41. commitTxn();
  42. }
  43. public void testCreateParentAndChildSameTxn() {
  44. HasRecursiveParent p = new HasRecursiveParent();
  45. p.setName("yam");
  46. HasRecursiveParent c = new HasRecursiveParent();
  47. c.setName("yum");
  48. c.setParent(p);
  49. p.getChildren().add(c);
  50. beginTxn();
  51. pm.makePersistent(p);
  52. String pid = p.getId();
  53. String cid = c.getId();
  54. commitTxn();
  55. beginTxn();
  56. HasRecursiveParent p2 = pm.getObjectById(HasRecursiveParent.class, pid);
  57. assertEquals(1, p2.getChildren().size());
  58. HasRecursiveParent c2 = p2.getChildren().iterator().next();
  59. assertEquals(cid, c2.getId());
  60. assertEquals("yum", c2.getName());
  61. assertEquals(c2.getParent(), p2);
  62. commitTxn();
  63. }
  64. public void testCreateParentHierarchie() {
  65. HasRecursiveParent p, p0 = p = new HasRecursiveParent();
  66. p.setName("yam4");
  67. for (int i = 3; i > 0; i--) {
  68. HasRecursiveParent c = new HasRecursiveParent();
  69. c.setName("yam" + i);
  70. c.setParent(p);
  71. p.getChildren().add(c);
  72. p = c;
  73. }
  74. beginTxn();
  75. pm.makePersistent(p0);
  76. String cid = p.getId();
  77. commitTxn();
  78. beginTxn();
  79. HasRecursiveParent c = pm.getObjectById(HasRecursiveParent.class, cid);
  80. int i = 1;
  81. while (c.getParent() != null) {
  82. assertEquals("yam" + (i++), c.getName());
  83. c = c.getParent();
  84. }
  85. commitTxn();
  86. }
  87. }