PageRenderTime 27ms CodeModel.GetById 18ms app.highlight 7ms RepoModel.GetById 1ms 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
 1/**********************************************************************
 2Copyright (c) 2011 Google Inc.
 3
 4Licensed under the Apache License, Version 2.0 (the "License");
 5you may not use this file except in compliance with the License.
 6You may obtain a copy of the License at
 7
 8http://www.apache.org/licenses/LICENSE-2.0
 9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15**********************************************************************/
16package com.google.appengine.datanucleus.jdo;
17
18import javax.jdo.JDOException;
19
20import com.google.appengine.datanucleus.test.jdo.Issue62Child;
21import com.google.appengine.datanucleus.test.jdo.Issue62Parent;
22
23public class Issue62Test extends JDOTestCase {
24
25  public void testMultipleOneToOne() {
26    Issue62Parent parent;
27    Issue62Child child;
28    {
29      child = new Issue62Child();
30      parent = new Issue62Parent(child);
31      pm.makePersistent(parent);
32      pm.close();
33    }
34
35    // Create a second parent/child and next update the first child with the second parent
36    Issue62Parent parent2;
37    {
38      pm = pmf.getPersistenceManager();
39      parent2 = new Issue62Parent(new Issue62Child());
40      pm.makePersistent(parent2);
41      pm.close();
42
43      try {
44        pm = pmf.getPersistenceManager();
45        pm.currentTransaction().begin();
46        Issue62Child childToChangeParent = pm.getObjectById(Issue62Child.class, child.getId());
47        assertNotNull(childToChangeParent);
48        childToChangeParent.setParent(parent2);
49        parent2.setChild(childToChangeParent);
50        pm.currentTransaction().commit();
51        fail("Didn't throw exception on attempt to change parent");
52      } catch (JDOException jdoe) {
53        // Expected
54      }
55      finally {
56        if (pm.currentTransaction().isActive()) {
57          pm.currentTransaction().rollback();
58        }
59        pm.close();
60      }
61    }
62
63    // check the update
64    {
65      pm = pmf.getPersistenceManager();
66      Issue62Child changedParent = pm.getObjectById(Issue62Child.class, child.getId());
67      assertEquals(parent.getId(), changedParent.getParent().getId()); // <-- the update doen't take effect? why?
68      pm.close();
69    }
70  }
71}