PageRenderTime 183ms CodeModel.GetById 21ms RepoModel.GetById 18ms app.codeStats 0ms

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

http://datanucleus-appengine.googlecode.com/
Java | 71 lines | 46 code | 7 blank | 18 comment | 1 complexity | cb8158383e0a009af727c83a6e3fa0aa 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 javax.jdo.JDOException;
  15. import com.google.appengine.datanucleus.test.jdo.Issue62Child;
  16. import com.google.appengine.datanucleus.test.jdo.Issue62Parent;
  17. public class Issue62Test extends JDOTestCase {
  18. public void testMultipleOneToOne() {
  19. Issue62Parent parent;
  20. Issue62Child child;
  21. {
  22. child = new Issue62Child();
  23. parent = new Issue62Parent(child);
  24. pm.makePersistent(parent);
  25. pm.close();
  26. }
  27. // Create a second parent/child and next update the first child with the second parent
  28. Issue62Parent parent2;
  29. {
  30. pm = pmf.getPersistenceManager();
  31. parent2 = new Issue62Parent(new Issue62Child());
  32. pm.makePersistent(parent2);
  33. pm.close();
  34. try {
  35. pm = pmf.getPersistenceManager();
  36. pm.currentTransaction().begin();
  37. Issue62Child childToChangeParent = pm.getObjectById(Issue62Child.class, child.getId());
  38. assertNotNull(childToChangeParent);
  39. childToChangeParent.setParent(parent2);
  40. parent2.setChild(childToChangeParent);
  41. pm.currentTransaction().commit();
  42. fail("Didn't throw exception on attempt to change parent");
  43. } catch (JDOException jdoe) {
  44. // Expected
  45. }
  46. finally {
  47. if (pm.currentTransaction().isActive()) {
  48. pm.currentTransaction().rollback();
  49. }
  50. pm.close();
  51. }
  52. }
  53. // check the update
  54. {
  55. pm = pmf.getPersistenceManager();
  56. Issue62Child changedParent = pm.getObjectById(Issue62Child.class, child.getId());
  57. assertEquals(parent.getId(), changedParent.getParent().getId()); // <-- the update doen't take effect? why?
  58. pm.close();
  59. }
  60. }
  61. }