You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by de...@apache.org on 2010/04/02 21:38:58 UTC

svn commit: r930357 [5/8] - in /openjpa/branches/1.1.x: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/ openjpa-persistence-jdbc/sr...

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestOptimisticLockGroups.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestOptimisticLockGroups.java?rev=930357&r1=930356&r2=930357&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestOptimisticLockGroups.java (original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestOptimisticLockGroups.java Fri Apr  2 19:38:58 2010
@@ -1,358 +1,358 @@
-/*
- * TestOptimisticLockGroups.java
- *
- * Created on October 12, 2006, 2:57 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.    
- */
-package org.apache.openjpa.persistence.kernel;
-
-
-
-import org.apache.openjpa.persistence.kernel.common.apps.LockGroupPC;
-import org.apache.openjpa.persistence.kernel.common.apps.LockGroupPC2;
-import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
-
-import org.apache.openjpa.persistence.OpenJPAEntityManager;
-
-public class TestOptimisticLockGroups extends BaseKernelTest {
-
-    private Object oid;
-
-    /**
-     * Creates a new instance of TestOptimisticLockGroups
-     */
-    public TestOptimisticLockGroups() {
-    }
-
-    public TestOptimisticLockGroups(String name) {
-        super(name);
-    }
-
-    public void setUp() {
-        deleteAll(LockGroupPC.class);
-
-        OpenJPAEntityManager pm = getPM(false, false);
-        startTx(pm);
-        Object o = new LockGroupPC();
-        pm.persist(o);
-        endTx(pm);
-        oid = pm.getObjectId(o);
-        endEm(pm);
-    }
-
-    public void testDefaultLockGroupFailure1() {
-        OpenJPAEntityManager pm1 = getPM(false, false);
-        startTx(pm1);
-        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
-        pc1.setDefaultLockGroupStringField("pm1 value");
-
-        OpenJPAEntityManager pm2 = getPM(false, false);
-        startTx(pm2);
-        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
-        pc2.setDefaultLockGroupStringField("pm2 value");
-
-        endTx(pm1);
-        endEm(pm1);
-
-        try {
-            endTx(pm2);
-            fail("should not be able to commit change to same value");
-        } catch (Exception e) {
-            assertEquals(pc2, getFailedObject(e));
-        }
-        endEm(pm2);
-    }
-
-    public void testDefaultLockGroupFailure2() {
-        OpenJPAEntityManager pm1 = getPM(false, false);
-        startTx(pm1);
-        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
-        pc1.setDefaultLockGroupStringField("pm1 value");
-
-        OpenJPAEntityManager pm2 = getPM(false, false);
-        startTx(pm2);
-        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
-        pc2.setExplicitDefaultLockGroupIntField(2);
-
-        endTx(pm1);
-        endEm(pm1);
-
-        try {
-            endTx(pm2);
-            fail("should not be able to commit change to same value");
-        } catch (Exception e) {
-            assertEquals(pc2, getFailedObject(e));
-        }
-        endEm(pm2);
-    }
-
-    public void testNonDefaultLockGroupFailure1() {
-        OpenJPAEntityManager pm1 = getPM(false, false);
-        startTx(pm1);
-        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
-        pc1.setLockGroup0IntField(1);
-
-        OpenJPAEntityManager pm2 = getPM(false, false);
-        startTx(pm2);
-        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
-        pc2.setLockGroup0IntField(2);
-
-        endTx(pm1);
-        endEm(pm1);
-
-        try {
-            endTx(pm2);
-            fail("should not be able to commit change to same value");
-        } catch (Exception e) {
-            assertEquals(pc2, getFailedObject(e));
-        }
-        endEm(pm2);
-    }
-
-    public void testNonDefaultLockGroupFailure2() {
-        OpenJPAEntityManager pm1 = getPM(false, false);
-        startTx(pm1);
-        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
-        pc1.setLockGroup0IntField(1);
-
-        OpenJPAEntityManager pm2 = getPM(false, false);
-        startTx(pm2);
-        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
-        pc2.setLockGroup0StringField("pm2");
-
-        endTx(pm1);
-        endEm(pm1);
-
-        try {
-            endTx(pm2);
-            fail("should not be able to commit change to same value");
-        } catch (Exception e) {
-            assertEquals(pc2, getFailedObject(e));
-        }
-        endEm(pm2);
-    }
-
-    public void testMultipleLockGroupSuccess1() {
-        OpenJPAEntityManager pm1 = getPM(false, false);
-        startTx(pm1);
-        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
-        pc1.setDefaultLockGroupStringField("pm1 value");
-        pc1.setExplicitDefaultLockGroupIntField(1);
-
-        OpenJPAEntityManager pm2 = getPM(false, false);
-        startTx(pm2);
-        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
-        pc2.setLockGroup0IntField(2);
-
-        OpenJPAEntityManager pm3 = getPM(false, false);
-        startTx(pm3);
-        LockGroupPC pc3 = (LockGroupPC) pm3.find(LockGroupPC.class, oid);
-        pc3.setLockGroup1RelationField(new RuntimeTest1());
-
-        endTx(pm1);
-        endEm(pm1);
-
-        endTx(pm2);
-        endEm(pm2);
-
-        endTx(pm3);
-        endEm(pm3);
-    }
-
-    public void testMultipleLockGroupSuccess2() {
-        OpenJPAEntityManager pm1 = getPM(false, false);
-        startTx(pm1);
-        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
-        pc1.setDefaultLockGroupStringField("pm1 value");
-        pc1.setLockGroup0IntField(1);
-
-        OpenJPAEntityManager pm2 = getPM(false, false);
-        startTx(pm2);
-        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
-        pc2.setLockGroup1RelationField(new RuntimeTest1());
-
-        endTx(pm2);
-        endEm(pm2);
-
-        endTx(pm1);
-        endEm(pm1);
-    }
-
-//        FIX ME: aokeke - test is taking so much resource and causing subsequent test to fail
-//        public void testNoLockGroupSuccess() {
-//        OpenJPAEntityManager pm1 = getPM(false, false);
-//        startTx(pm1,());
-//        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class,oid);
-//        pc1.setDefaultLockGroupStringField("pm1 value");
-//        pc1.setLockGroup0IntField(1);
-//        pc1.setUnlockedStringField("pm1 value");
-//        
-//        OpenJPAEntityManager pm2 = getPM(false, false);
-//        startTx(pm2,());
-//        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class,oid);
-//        pc2.setLockGroup1RelationField(new RuntimeTest1());
-//        pc2.setUnlockedStringField("pm2 value");
-//        
-//        endTx(pm1,());
-//        endEm(pm1);
-//        
-//        endTx(pm2,());
-//        endEm(pm2);
-//    }
-
-    public void testAttachDetachSuccess()
-        throws Exception {
-        OpenJPAEntityManager pm1 = getPM(false, false);
-        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
-        Object detached = pm1.detach(pc1);
-        startTx(pm1);
-        pc1.setLockGroup0IntField(1);
-        pc1.setUnlockedStringField("pm1 changed value");
-        endTx(pm1);
-        endEm(pm1);
-
-        /*
-         // won't work without non-transient detached state
-         ByteArrayOutputStream baos = new ByteArrayOutputStream ();
-         ObjectOutputStream oos = new ObjectOutputStream (baos);
-         oos.writeObject (detached);
-         oos.close ();
-         baos.close ();
-
-         ByteArrayInputStream bais =
-             new ByteArrayInputStream (baos.toByteArray ());
-         ObjectInputStream ois = new ObjectInputStream (bais);
-         LockGroupPC clone = (LockGroupPC) ois.readObject ();
-        */
-        LockGroupPC clone = (LockGroupPC) detached;
-        clone.setLockGroup1IntField(2);
-        clone.setUnlockedStringField("pm2 value");
-
-        OpenJPAEntityManager pm2 = getPM(false, false);
-        startTx(pm2);
-        pm2.merge(clone);
-        endTx(pm2);
-        endEm(pm2);
-    }
-
-    public void testAttachDetachFailure()
-        throws Exception {
-        OpenJPAEntityManager pm1 = getPM(false, false);
-        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
-        Object detached = pm1.detach(pc1);
-        startTx(pm1);
-        pc1.setLockGroup0IntField(1);
-        endTx(pm1);
-        endEm(pm1);
-
-        /*
-         // won't work without non-transient detached state
-         ByteArrayOutputStream baos = new ByteArrayOutputStream ();
-         ObjectOutputStream oos = new ObjectOutputStream (baos);
-         oos.writeObject (detached);
-         oos.close ();
-         baos.close ();
-
-         ByteArrayInputStream bais =
-             new ByteArrayInputStream (baos.toByteArray ());
-         ObjectInputStream ois = new ObjectInputStream (bais);
-         LockGroupPC clone = (LockGroupPC) ois.readObject ();
-        */
-        LockGroupPC clone = (LockGroupPC) detached;
-        clone.setLockGroup0IntField(2);
-
-        OpenJPAEntityManager pm2 = getPM(false, false);
-        startTx(pm2);
-        boolean failed = false;
-        try {
-            pm2.merge(clone);
-        } catch (Exception e) {
-            failed = true;
-        }
-
-        if (failed)
-            rollbackTx(pm2);
-        else {
-            try {
-                endTx(pm2);
-                fail("Allowed conflicting changes");
-            } catch (Exception jve) {
-            }
-        }
-    }
-
-    public void testLockGroupNone() {
-        OpenJPAEntityManager pm = getPM(false, false);
-//        pm.begin();
-        deleteAll(LockGroupPC2.class, pm);
-        startTx(pm);
-        LockGroupPC2 pc = new LockGroupPC2();
-        pc.setName("pc");
-        pm.persist(pc);
-        endTx(pm);
-        Object oid = pm.getObjectId(pc);
-        endEm(pm);
-
-        pm = getPM(false, false);
-        pc = (LockGroupPC2) pm.find(LockGroupPC2.class, oid);
-        startTx(pm);
-        pc.getList().add("foo");
-
-        OpenJPAEntityManager pm2 = getPM(false, false);
-        LockGroupPC2 pc2 = (LockGroupPC2) pm2.find(LockGroupPC2.class, oid);
-        startTx(pm2);
-        pc2.getList().add("bar");
-        endTx(pm2);
-        endEm(pm2);
-
-        endTx(pm);
-        endEm(pm);
-
-        pm = getPM(false, false);
-        pc = (LockGroupPC2) pm.find(LockGroupPC2.class, oid);
-        assertEquals(2, pc.getList().size());
-        endEm(pm);
-    }
-
-//    public void testKnownSubclass() {
-//        OpenJPAEntityManager pm = getPM(false, false);
-//        LockGroupPCKnownSubclass pc = new LockGroupPCKnownSubclass();
-//        pc.setDefaultLockGroupStringField("pc");
-//        startTx(pm,());
-//        pm.persist(pc);
-//        endTx(pm,());
-//        
-//        startTx(pm,());
-//        pc.setKnownSubclassStringField("foo");
-//        endTx(pm,());
-//    }
-
-    //FIXME jthomas - what do we need to substitute for JDOException ?
-//    private Object getFailedObject(JDOException e) {
-//        return ((JDOException) e.getNestedExceptions()[0]).getFailedObject();
-//    }
-
-    private Object getFailedObject(Exception e) {
-        return null;
-    }
-}
+/*
+ * TestOptimisticLockGroups.java
+ *
+ * Created on October 12, 2006, 2:57 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.LockGroupPC;
+import org.apache.openjpa.persistence.kernel.common.apps.LockGroupPC2;
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestOptimisticLockGroups extends BaseKernelTest {
+
+    private Object oid;
+
+    /**
+     * Creates a new instance of TestOptimisticLockGroups
+     */
+    public TestOptimisticLockGroups() {
+    }
+
+    public TestOptimisticLockGroups(String name) {
+        super(name);
+    }
+
+    public void setUp() {
+        deleteAll(LockGroupPC.class);
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+        Object o = new LockGroupPC();
+        pm.persist(o);
+        endTx(pm);
+        oid = pm.getObjectId(o);
+        endEm(pm);
+    }
+
+    public void testDefaultLockGroupFailure1() {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        startTx(pm1);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        pc1.setDefaultLockGroupStringField("pm1 value");
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
+        pc2.setDefaultLockGroupStringField("pm2 value");
+
+        endTx(pm1);
+        endEm(pm1);
+
+        try {
+            endTx(pm2);
+            fail("should not be able to commit change to same value");
+        } catch (Exception e) {
+            assertEquals(pc2, getFailedObject(e));
+        }
+        endEm(pm2);
+    }
+
+    public void testDefaultLockGroupFailure2() {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        startTx(pm1);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        pc1.setDefaultLockGroupStringField("pm1 value");
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
+        pc2.setExplicitDefaultLockGroupIntField(2);
+
+        endTx(pm1);
+        endEm(pm1);
+
+        try {
+            endTx(pm2);
+            fail("should not be able to commit change to same value");
+        } catch (Exception e) {
+            assertEquals(pc2, getFailedObject(e));
+        }
+        endEm(pm2);
+    }
+
+    public void testNonDefaultLockGroupFailure1() {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        startTx(pm1);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        pc1.setLockGroup0IntField(1);
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
+        pc2.setLockGroup0IntField(2);
+
+        endTx(pm1);
+        endEm(pm1);
+
+        try {
+            endTx(pm2);
+            fail("should not be able to commit change to same value");
+        } catch (Exception e) {
+            assertEquals(pc2, getFailedObject(e));
+        }
+        endEm(pm2);
+    }
+
+    public void testNonDefaultLockGroupFailure2() {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        startTx(pm1);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        pc1.setLockGroup0IntField(1);
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
+        pc2.setLockGroup0StringField("pm2");
+
+        endTx(pm1);
+        endEm(pm1);
+
+        try {
+            endTx(pm2);
+            fail("should not be able to commit change to same value");
+        } catch (Exception e) {
+            assertEquals(pc2, getFailedObject(e));
+        }
+        endEm(pm2);
+    }
+
+    public void testMultipleLockGroupSuccess1() {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        startTx(pm1);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        pc1.setDefaultLockGroupStringField("pm1 value");
+        pc1.setExplicitDefaultLockGroupIntField(1);
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
+        pc2.setLockGroup0IntField(2);
+
+        OpenJPAEntityManager pm3 = getPM(false, false);
+        startTx(pm3);
+        LockGroupPC pc3 = (LockGroupPC) pm3.find(LockGroupPC.class, oid);
+        pc3.setLockGroup1RelationField(new RuntimeTest1());
+
+        endTx(pm1);
+        endEm(pm1);
+
+        endTx(pm2);
+        endEm(pm2);
+
+        endTx(pm3);
+        endEm(pm3);
+    }
+
+    public void testMultipleLockGroupSuccess2() {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        startTx(pm1);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        pc1.setDefaultLockGroupStringField("pm1 value");
+        pc1.setLockGroup0IntField(1);
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
+        pc2.setLockGroup1RelationField(new RuntimeTest1());
+
+        endTx(pm2);
+        endEm(pm2);
+
+        endTx(pm1);
+        endEm(pm1);
+    }
+
+//        FIX ME: aokeke - test is taking so much resource and causing subsequent test to fail
+//        public void testNoLockGroupSuccess() {
+//        OpenJPAEntityManager pm1 = getPM(false, false);
+//        startTx(pm1,());
+//        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class,oid);
+//        pc1.setDefaultLockGroupStringField("pm1 value");
+//        pc1.setLockGroup0IntField(1);
+//        pc1.setUnlockedStringField("pm1 value");
+//        
+//        OpenJPAEntityManager pm2 = getPM(false, false);
+//        startTx(pm2,());
+//        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class,oid);
+//        pc2.setLockGroup1RelationField(new RuntimeTest1());
+//        pc2.setUnlockedStringField("pm2 value");
+//        
+//        endTx(pm1,());
+//        endEm(pm1);
+//        
+//        endTx(pm2,());
+//        endEm(pm2);
+//    }
+
+    public void testAttachDetachSuccess()
+        throws Exception {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        Object detached = pm1.detachCopy(pc1);
+        startTx(pm1);
+        pc1.setLockGroup0IntField(1);
+        pc1.setUnlockedStringField("pm1 changed value");
+        endTx(pm1);
+        endEm(pm1);
+
+        /*
+         // won't work without non-transient detached state
+         ByteArrayOutputStream baos = new ByteArrayOutputStream ();
+         ObjectOutputStream oos = new ObjectOutputStream (baos);
+         oos.writeObject (detached);
+         oos.close ();
+         baos.close ();
+
+         ByteArrayInputStream bais =
+             new ByteArrayInputStream (baos.toByteArray ());
+         ObjectInputStream ois = new ObjectInputStream (bais);
+         LockGroupPC clone = (LockGroupPC) ois.readObject ();
+        */
+        LockGroupPC clone = (LockGroupPC) detached;
+        clone.setLockGroup1IntField(2);
+        clone.setUnlockedStringField("pm2 value");
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        pm2.merge(clone);
+        endTx(pm2);
+        endEm(pm2);
+    }
+
+    public void testAttachDetachFailure()
+        throws Exception {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        Object detached = pm1.detachCopy(pc1);
+        startTx(pm1);
+        pc1.setLockGroup0IntField(1);
+        endTx(pm1);
+        endEm(pm1);
+
+        /*
+         // won't work without non-transient detached state
+         ByteArrayOutputStream baos = new ByteArrayOutputStream ();
+         ObjectOutputStream oos = new ObjectOutputStream (baos);
+         oos.writeObject (detached);
+         oos.close ();
+         baos.close ();
+
+         ByteArrayInputStream bais =
+             new ByteArrayInputStream (baos.toByteArray ());
+         ObjectInputStream ois = new ObjectInputStream (bais);
+         LockGroupPC clone = (LockGroupPC) ois.readObject ();
+        */
+        LockGroupPC clone = (LockGroupPC) detached;
+        clone.setLockGroup0IntField(2);
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        boolean failed = false;
+        try {
+            pm2.merge(clone);
+        } catch (Exception e) {
+            failed = true;
+        }
+
+        if (failed)
+            rollbackTx(pm2);
+        else {
+            try {
+                endTx(pm2);
+                fail("Allowed conflicting changes");
+            } catch (Exception jve) {
+            }
+        }
+    }
+
+    public void testLockGroupNone() {
+        OpenJPAEntityManager pm = getPM(false, false);
+//        pm.begin();
+        deleteAll(LockGroupPC2.class, pm);
+        startTx(pm);
+        LockGroupPC2 pc = new LockGroupPC2();
+        pc.setName("pc");
+        pm.persist(pc);
+        endTx(pm);
+        Object oid = pm.getObjectId(pc);
+        endEm(pm);
+
+        pm = getPM(false, false);
+        pc = (LockGroupPC2) pm.find(LockGroupPC2.class, oid);
+        startTx(pm);
+        pc.getList().add("foo");
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        LockGroupPC2 pc2 = (LockGroupPC2) pm2.find(LockGroupPC2.class, oid);
+        startTx(pm2);
+        pc2.getList().add("bar");
+        endTx(pm2);
+        endEm(pm2);
+
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM(false, false);
+        pc = (LockGroupPC2) pm.find(LockGroupPC2.class, oid);
+        assertEquals(2, pc.getList().size());
+        endEm(pm);
+    }
+
+//    public void testKnownSubclass() {
+//        OpenJPAEntityManager pm = getPM(false, false);
+//        LockGroupPCKnownSubclass pc = new LockGroupPCKnownSubclass();
+//        pc.setDefaultLockGroupStringField("pc");
+//        startTx(pm,());
+//        pm.persist(pc);
+//        endTx(pm,());
+//        
+//        startTx(pm,());
+//        pc.setKnownSubclassStringField("foo");
+//        endTx(pm,());
+//    }
+
+    //FIXME jthomas - what do we need to substitute for JDOException ?
+//    private Object getFailedObject(JDOException e) {
+//        return ((JDOException) e.getNestedExceptions()[0]).getFailedObject();
+//    }
+
+    private Object getFailedObject(Exception e) {
+        return null;
+    }
+}

Propchange: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestOptimisticLockGroups.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPersistenceManagerFactoryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPersistenceManagerFactoryImpl.java?rev=930357&r1=930356&r2=930357&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPersistenceManagerFactoryImpl.java (original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPersistenceManagerFactoryImpl.java Fri Apr  2 19:38:58 2010
@@ -1,229 +1,229 @@
-/*
- * TestOpenJPAEntityManagerFactoryImpl.java
- *
- * Created on October 13, 2006, 10:54 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.    
- */
-package org.apache.openjpa.persistence.kernel;
-
-import java.util.Map;
-
-import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
-import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest4;
-import org.apache.openjpa.conf.OpenJPAConfiguration;
-import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
-import org.apache.openjpa.event.LifecycleEvent;
-import org.apache.openjpa.event.LoadListener;
-import org.apache.openjpa.kernel.AbstractBrokerFactory;
-import org.apache.openjpa.kernel.BrokerImpl;
-import org.apache.openjpa.kernel.StoreManager;
-import org.apache.openjpa.lib.conf.ConfigurationProvider;
-import org.apache.openjpa.meta.MetaDataRepository;
-import org.apache.openjpa.persistence.JPAFacadeHelper;
-import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
-import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
-import org.apache.openjpa.persistence.OpenJPAPersistence;
-
-public class TestPersistenceManagerFactoryImpl extends BaseKernelTest {
-
-    private OpenJPAConfiguration _conf = null;
-
-    /**
-     * Creates a new instance of TestOpenJPAEntityManagerFactoryImpl
-     */
-    public TestPersistenceManagerFactoryImpl() {
-    }
-
-    public TestPersistenceManagerFactoryImpl(String test) {
-        super(test);
-    }
-
-    public void setUp() {
-        _conf = new OpenJPAConfigurationImpl();
-        _conf.setConnection2UserName("user");
-        _conf.setConnection2Password("pass");
-        _conf.setConnection2URL("url");
-    }
-
-    /**
-     * Test that configuration is frozen after retrieving a factory.
-     *
-     * This test case is for kodo persistencemanagerfactories and not openjpaentitymanagers.
-     * therefore its been commented out. 
-     * FIX ME: aokeke
-     */
-/*    public void testConfigurationFreeze() 
-    {
-        OpenJPAEntityManagerFactory pmf = getOpenJPAEntityManagerFactory(_conf.toProperties(false));
-        assertEquals("user", pmf.getConfiguration().getConnection2UserName());
-        assertEquals("url", pmf.getConfiguration().getConnection2URL());
-        try 
-        {
-            pmf.getConfiguration().setConnection2URL("url2");
-            fail("Allowed configuration change.");
-        } 
-        catch (Exception e) 
-        {
-        }
-    }*/
-
-    /**
-     * Test that persistence manager factories are being pooled.
-     *
-     * This test case is for kodo persistencemanagerfactories. It doesnt apply to 
-     * openjpaentitymanagerfactories therefore it will be commented out.
-     * FIX ME: aokeke
-     */
-    /*public void testFactoryPooling() {
-        Properties props = new Properties();
-        props.putAll(_conf.toProperties(false));
-        OpenJPAEntityManagerFactory pmf1 = getOpenJPAEntityManagerFactory(props);
-        
-        props = new Properties();
-        props.putAll(_conf.toProperties(false));
-        OpenJPAEntityManagerFactory pmf2 = getOpenJPAEntityManagerFactory(props);
-        
-        props = new Properties();
-        props.putAll(_conf.toProperties(false));
-        OpenJPAEntityManagerFactory pmf3 = getOpenJPAEntityManagerFactory(props);
-        
-        _conf.setConnectionURL("url2");
-        props = new Properties();
-        props.putAll(_conf.toProperties(false));
-        OpenJPAEntityManagerFactory pmf4 = getOpenJPAEntityManagerFactory
-                (_conf.toProperties(false));
-        
-        props = new Properties();
-        props.putAll(_conf.toProperties(false));
-        OpenJPAEntityManagerFactory pmf5 = getOpenJPAEntityManagerFactory(_conf.toProperties(false));
-        
-        assertTrue(JPAFacadeHelper.toBrokerFactory(pmf1) == JPAFacadeHelper.toBrokerFactory(pmf2));
-        assertTrue(JPAFacadeHelper.toBrokerFactory(pmf1) == JPAFacadeHelper.toBrokerFactory(pmf3));
-        assertTrue(JPAFacadeHelper.toBrokerFactory(pmf1) != JPAFacadeHelper.toBrokerFactory(pmf4));
-        assertTrue(JPAFacadeHelper.toBrokerFactory(pmf4) == JPAFacadeHelper.toBrokerFactory(pmf5));
-    }*/
-
-    /**
-     * Tests that lifecycle listeners are transferred from factory to
-     * persistence managers.
-     */
-    public void testFactoryLifecycleListeners() {
-        OpenJPAEntityManagerFactory pmf =
-            (OpenJPAEntityManagerFactory) getEmf();
-        OpenJPAEntityManagerFactorySPI pmfSPI =
-            ((OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.cast(pmf));
-
-        //FIXME jthomas        
-        LoadListener listener = new LoadListener() {
-            public void afterLoad(LifecycleEvent ev) {
-            }
-
-            public void afterRefresh(LifecycleEvent ev) {
-            }
-        };
-
-        pmfSPI
-            .addLifecycleListener(listener, new Class[]{ RuntimeTest4.class });
-
-        try {
-            BrokerImpl broker = (BrokerImpl) JPAFacadeHelper.toBroker
-                (pmf.createEntityManager());
-            MetaDataRepository repos = broker.getConfiguration().
-                getMetaDataRepositoryInstance();
-            assertTrue("no listeners defined added to Runtimetest4",
-                broker.getLifecycleEventManager().hasLoadListeners(
-                    new RuntimeTest4("foo"),
-                    repos.getMetaData(RuntimeTest4.class, null, true)));
-            assertFalse("there should be listeners def for runtimetest1",
-                broker.getLifecycleEventManager().hasLoadListeners
-                    (new RuntimeTest1(), repos.getMetaData
-                        (RuntimeTest1.class, null, true)));
-            broker.close();
-        } finally {
-            pmfSPI.removeLifecycleListener(listener);
-        }
-    }
-
-    /**
-     * Tests that pooling is maintained on deserialization.
-     * This test case is for kodo persistencemanagerfactories. It doesnt apply to 
-     * openjpaentitymanagerfactories therefore it will be commented out.
-     */
-    /*
-    public void testFactorySerialization()
-    throws Exception {
-        OpenJPAEntityManagerFactory pmf1 = getOpenJPAEntityManagerFactory(_conf.toProperties(false));
-        Object pmf2 = roundtrip(pmf1, true);
-        assertEquals(pmf1, pmf2);
-        assertTrue(JPAFacadeHelper.toBrokerFactory(pmf1) ==
-                JPAFacadeHelper.toBrokerFactory((OpenJPAEntityManagerFactory) pmf2));
-    }
-    */
-
-    /**
-     * Tests that the <code>Platform</code> property is set by the
-     * concrete PMF implementation.
-     */
-    public void testPlatform() {
-        OpenJPAEntityManagerFactory pmf =
-            (OpenJPAEntityManagerFactory) getEmf();
-        assertNotNull(pmf.getProperties().getProperty("Platform"));
-    }
-
-    protected OpenJPAEntityManagerFactory getEmf(Map props) {
-        props.put("openjpa.BrokerFactory", BrokerFactoryTest.class.getName());
-        return (OpenJPAEntityManagerFactory) super.getEmf(props);
-    }
-
-    public static class BrokerFactoryTest extends AbstractBrokerFactory {
-
-        // standard brokerfactory getter implemented by subclasses
-        public static synchronized BrokerFactoryTest getInstance(
-            ConfigurationProvider cp) {
-            Object key = toPoolKey(cp.getProperties());
-            BrokerFactoryTest factory =
-                (BrokerFactoryTest) getPooledFactoryForKey(key);
-            if (factory != null)
-                return factory;
-
-            factory = newInstance(cp);
-            pool(key, factory);
-            return factory;
-        }
-
-        // standard brokerfactory getter implemented by subclasses
-        public static BrokerFactoryTest newInstance(ConfigurationProvider cp) {
-            OpenJPAConfigurationImpl conf = new OpenJPAConfigurationImpl();
-            cp.setInto(conf);
-            return new BrokerFactoryTest(conf);
-        }
-
-        protected BrokerFactoryTest(OpenJPAConfiguration conf) {
-            super(conf);
-        }
-
-        protected StoreManager newStoreManager() {
-            return null;
-        }
-    }
-}
+/*
+ * TestOpenJPAEntityManagerFactoryImpl.java
+ *
+ * Created on October 13, 2006, 10:54 AM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel;
+
+import java.util.Map;
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest4;
+import org.apache.openjpa.conf.OpenJPAConfiguration;
+import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
+import org.apache.openjpa.event.LifecycleEvent;
+import org.apache.openjpa.event.LoadListener;
+import org.apache.openjpa.kernel.AbstractBrokerFactory;
+import org.apache.openjpa.kernel.BrokerImpl;
+import org.apache.openjpa.kernel.StoreManager;
+import org.apache.openjpa.lib.conf.ConfigurationProvider;
+import org.apache.openjpa.meta.MetaDataRepository;
+import org.apache.openjpa.persistence.JPAFacadeHelper;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+
+public class TestPersistenceManagerFactoryImpl extends BaseKernelTest {
+
+    private OpenJPAConfiguration _conf = null;
+
+    /**
+     * Creates a new instance of TestOpenJPAEntityManagerFactoryImpl
+     */
+    public TestPersistenceManagerFactoryImpl() {
+    }
+
+    public TestPersistenceManagerFactoryImpl(String test) {
+        super(test);
+    }
+
+    public void setUp() {
+        _conf = new OpenJPAConfigurationImpl();
+        _conf.setConnection2UserName("user");
+        _conf.setConnection2Password("pass");
+        _conf.setConnection2URL("url");
+    }
+
+    /**
+     * Test that configuration is frozen after retrieving a factory.
+     *
+     * This test case is for kodo persistencemanagerfactories and not openjpaentitymanagers.
+     * therefore its been commented out. 
+     * FIX ME: aokeke
+     */
+/*    public void testConfigurationFreeze() 
+    {
+        OpenJPAEntityManagerFactory pmf = getOpenJPAEntityManagerFactory(_conf.toProperties(false));
+        assertEquals("user", pmf.getConfiguration().getConnection2UserName());
+        assertEquals("url", pmf.getConfiguration().getConnection2URL());
+        try 
+        {
+            pmf.getConfiguration().setConnection2URL("url2");
+            fail("Allowed configuration change.");
+        } 
+        catch (Exception e) 
+        {
+        }
+    }*/
+
+    /**
+     * Test that persistence manager factories are being pooled.
+     *
+     * This test case is for kodo persistencemanagerfactories. It doesnt apply to 
+     * openjpaentitymanagerfactories therefore it will be commented out.
+     * FIX ME: aokeke
+     */
+    /*public void testFactoryPooling() {
+        Properties props = new Properties();
+        props.putAll(_conf.toProperties(false));
+        OpenJPAEntityManagerFactory pmf1 = getOpenJPAEntityManagerFactory(props);
+        
+        props = new Properties();
+        props.putAll(_conf.toProperties(false));
+        OpenJPAEntityManagerFactory pmf2 = getOpenJPAEntityManagerFactory(props);
+        
+        props = new Properties();
+        props.putAll(_conf.toProperties(false));
+        OpenJPAEntityManagerFactory pmf3 = getOpenJPAEntityManagerFactory(props);
+        
+        _conf.setConnectionURL("url2");
+        props = new Properties();
+        props.putAll(_conf.toProperties(false));
+        OpenJPAEntityManagerFactory pmf4 = getOpenJPAEntityManagerFactory
+                (_conf.toProperties(false));
+        
+        props = new Properties();
+        props.putAll(_conf.toProperties(false));
+        OpenJPAEntityManagerFactory pmf5 = getOpenJPAEntityManagerFactory(_conf.toProperties(false));
+        
+        assertTrue(JPAFacadeHelper.toBrokerFactory(pmf1) == JPAFacadeHelper.toBrokerFactory(pmf2));
+        assertTrue(JPAFacadeHelper.toBrokerFactory(pmf1) == JPAFacadeHelper.toBrokerFactory(pmf3));
+        assertTrue(JPAFacadeHelper.toBrokerFactory(pmf1) != JPAFacadeHelper.toBrokerFactory(pmf4));
+        assertTrue(JPAFacadeHelper.toBrokerFactory(pmf4) == JPAFacadeHelper.toBrokerFactory(pmf5));
+    }*/
+
+    /**
+     * Tests that lifecycle listeners are transferred from factory to
+     * persistence managers.
+     */
+    public void testFactoryLifecycleListeners() {
+        OpenJPAEntityManagerFactory pmf =
+            (OpenJPAEntityManagerFactory) getEmf();
+        OpenJPAEntityManagerFactorySPI pmfSPI =
+            ((OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.cast(pmf));
+
+        //FIXME jthomas        
+        LoadListener listener = new LoadListener() {
+            public void afterLoad(LifecycleEvent ev) {
+            }
+
+            public void afterRefresh(LifecycleEvent ev) {
+            }
+        };
+
+        pmfSPI
+            .addLifecycleListener(listener, new Class[]{ RuntimeTest4.class });
+
+        try {
+            BrokerImpl broker = (BrokerImpl) JPAFacadeHelper.toBroker
+                (pmf.createEntityManager());
+            MetaDataRepository repos = broker.getConfiguration().
+                getMetaDataRepositoryInstance();
+            assertTrue("no listeners defined added to Runtimetest4",
+                broker.getLifecycleEventManager().hasLoadListeners(
+                    new RuntimeTest4("foo"),
+                    repos.getMetaData(RuntimeTest4.class, null, true)));
+            assertFalse("there should be listeners def for runtimetest1",
+                broker.getLifecycleEventManager().hasLoadListeners
+                    (new RuntimeTest1(), repos.getMetaData
+                        (RuntimeTest1.class, null, true)));
+            broker.close();
+        } finally {
+            pmfSPI.removeLifecycleListener(listener);
+        }
+    }
+
+    /**
+     * Tests that pooling is maintained on deserialization.
+     * This test case is for kodo persistencemanagerfactories. It doesnt apply to 
+     * openjpaentitymanagerfactories therefore it will be commented out.
+     */
+    /*
+    public void testFactorySerialization()
+    throws Exception {
+        OpenJPAEntityManagerFactory pmf1 = getOpenJPAEntityManagerFactory(_conf.toProperties(false));
+        Object pmf2 = roundtrip(pmf1, true);
+        assertEquals(pmf1, pmf2);
+        assertTrue(JPAFacadeHelper.toBrokerFactory(pmf1) ==
+                JPAFacadeHelper.toBrokerFactory((OpenJPAEntityManagerFactory) pmf2));
+    }
+    */
+
+    /**
+     * Tests that the <code>Platform</code> property is set by the
+     * concrete PMF implementation.
+     */
+    public void testPlatform() {
+        OpenJPAEntityManagerFactory pmf =
+            (OpenJPAEntityManagerFactory) getEmf();
+        assertNotNull(pmf.getProperties().get("Platform"));
+    }
+
+    protected OpenJPAEntityManagerFactory getEmf(Map props) {
+        props.put("openjpa.BrokerFactory", BrokerFactoryTest.class.getName());
+        return (OpenJPAEntityManagerFactory) super.getEmf(props);
+    }
+
+    public static class BrokerFactoryTest extends AbstractBrokerFactory {
+
+        // standard brokerfactory getter implemented by subclasses
+        public static synchronized BrokerFactoryTest getInstance(
+            ConfigurationProvider cp) {
+            Object key = toPoolKey(cp.getProperties());
+            BrokerFactoryTest factory =
+                (BrokerFactoryTest) getPooledFactoryForKey(key);
+            if (factory != null)
+                return factory;
+
+            factory = newInstance(cp);
+            pool(key, factory);
+            return factory;
+        }
+
+        // standard brokerfactory getter implemented by subclasses
+        public static BrokerFactoryTest newInstance(ConfigurationProvider cp) {
+            OpenJPAConfigurationImpl conf = new OpenJPAConfigurationImpl();
+            cp.setInto(conf);
+            return new BrokerFactoryTest(conf);
+        }
+
+        protected BrokerFactoryTest(OpenJPAConfiguration conf) {
+            super(conf);
+        }
+
+        protected StoreManager newStoreManager() {
+            return null;
+        }
+    }
+}

Propchange: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPersistenceManagerFactoryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/managedinterface/TestManagedInterfaces.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/managedinterface/TestManagedInterfaces.java?rev=930357&r1=930356&r2=930357&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/managedinterface/TestManagedInterfaces.java (original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/managedinterface/TestManagedInterfaces.java Fri Apr  2 19:38:58 2010
@@ -1,463 +1,463 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.openjpa.persistence.managedinterface;
-
-import java.util.Set;
-import java.util.HashSet;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import javax.persistence.Query;
-import javax.persistence.EntityNotFoundException;
-
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
-import org.apache.openjpa.persistence.OpenJPAEntityManager;
-import org.apache.openjpa.persistence.JPAFacadeHelper;
-import org.apache.openjpa.persistence.Extent;
-import org.apache.openjpa.persistence.query.SimpleEntity;
-import org.apache.openjpa.meta.ClassMetaData;
-import org.apache.openjpa.persistence.PersistenceException;
-
-public class TestManagedInterfaces extends SingleEMFTestCase {
-
-    @Override
-    public void setUp() {
-        super.setUp(SimpleEntity.class, ManagedInterfaceEmbed.class,
-            ManagedInterfaceSup.class, ManagedIface.class,
-            ManagedInterfaceOwner.class, MixedInterface.class,
-            MixedInterfaceImpl.class, NonMappedInterfaceImpl.class,
-            CLEAR_TABLES);
-    }
-
-    public void testEmbeddedMetaData() {
-        emf.createEntityManager().close();
-        ClassMetaData ownerMeta = JPAFacadeHelper.getMetaData(emf,
-            ManagedIface.class);
-        ClassMetaData embeddedMeta = ownerMeta.getField("embed")
-            .getDefiningMetaData();
-        assertTrue(embeddedMeta.isManagedInterface());
-        assertTrue(embeddedMeta.isIntercepting());
-
-        ClassMetaData embeddableMeta = JPAFacadeHelper.getMetaData(emf,
-            ManagedInterfaceEmbed.class);
-        assertTrue(embeddableMeta.isManagedInterface());
-        assertTrue(embeddableMeta.isIntercepting());
-    }
-
-    public void testManagedInterface() throws Exception {
-        OpenJPAEntityManager em = emf.createEntityManager();
-        em.getTransaction().begin();
-        ManagedIface pc = em.createInstance(ManagedIface.class);
-        pc.setIntFieldSup(3);
-        pc.setIntField(4);
-        pc.setEmbed(em.createInstance(ManagedInterfaceEmbed.class));
-
-        pc.getEmbed().setEmbedIntField(5);
-        assertEquals(5, pc.getEmbed().getEmbedIntField());
-        em.persist(pc);
-        Object oid = em.getObjectId(pc);
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        pc = em.find(ManagedIface.class, oid);
-        assertEquals(3, pc.getIntFieldSup());
-        assertEquals(4, pc.getIntField());
-        assertEquals(5, pc.getEmbed().getEmbedIntField());
-        em.getTransaction().begin();
-        pc.setIntField(14);
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager ();
-        em.getTransaction().begin();
-        Query query = em.createQuery("select o from ManagedIface o " +
-            "where o.intField = 14");
-        pc = (ManagedIface) query.getSingleResult();
-        assertEquals(14, pc.getIntField());
-        em.remove(pc);
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        try {
-            assertNull(em.find(ManagedIface.class, oid));
-        } catch (EntityNotFoundException onfe) {}
-
-        em.close();
-    }
-
-    public void testInterfaceOwner() {
-        OpenJPAEntityManager em = emf.createEntityManager();
-        ManagedInterfaceOwner pc = new ManagedInterfaceOwner();
-        pc.setIFace(em.createInstance(ManagedInterfaceSup.class));
-        pc.setEmbed(em.createInstance(ManagedInterfaceEmbed.class));
-        pc.getIFace().setIntFieldSup(3);
-        pc.getEmbed().setEmbedIntField(5);
-
-        em.getTransaction().begin();
-        em.persist(pc);
-        Object oid = em.getObjectId(pc);
-        em.getTransaction().commit();
-        pc = em.find(ManagedInterfaceOwner.class, oid);
-        assertEquals(3, pc.getIFace().getIntFieldSup());
-        assertEquals(5, pc.getEmbed().getEmbedIntField());
-        em.close();
-
-        em = emf.createEntityManager();
-        pc = em.find(ManagedInterfaceOwner.class, oid);
-        assertEquals(3, pc.getIFace().getIntFieldSup());
-        assertEquals(5, pc.getEmbed().getEmbedIntField());
-        em.close();
-
-        em = emf.createEntityManager();
-        em.getTransaction().begin();
-        Query q = em.createQuery("select o from ManagedInterfaceOwner o " +
-            "where o.iface.intFieldSup = 3 and o.embed.embedIntField = 5");
-        pc = (ManagedInterfaceOwner) q.getSingleResult();
-        assertEquals(3, pc.getIFace().getIntFieldSup());
-        assertEquals(5, pc.getEmbed().getEmbedIntField());
-
-        pc.getIFace().setIntFieldSup(13);
-        pc.getEmbed().setEmbedIntField(15);
-        assertEquals(13, pc.getIFace().getIntFieldSup());
-        assertEquals(15, pc.getEmbed().getEmbedIntField());
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        pc = em.find(ManagedInterfaceOwner.class, oid);
-        assertEquals(13, pc.getIFace().getIntFieldSup());
-        assertEquals(15, pc.getEmbed().getEmbedIntField());
-        em.close();
-    }
-
-    public void testCollection() {
-        OpenJPAEntityManager em = emf.createEntityManager();
-        em.getTransaction().begin();
-        ManagedIface pc = em.createInstance(ManagedIface.class);
-        Set set = new HashSet();
-        set.add(new Integer(3));
-        set.add(new Integer(4));
-        set.add(new Integer(5));
-        pc.setSetInteger(set);
-        em.persist(pc);
-        Object oid = em.getObjectId(pc);
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        pc = em.find(ManagedIface.class, oid);
-        set = pc.getSetInteger();
-        assertEquals(3, set.size());
-        assertTrue(set.contains(new Integer(3)));
-        assertTrue(set.contains(new Integer(4)));
-        assertTrue(set.contains(new Integer(5)));
-        em.getTransaction().begin();
-        set.remove(new Integer(4));
-        set.add(new Integer(14));
-        set.add(new Integer(15));
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        pc = em.find(ManagedIface.class, oid);
-        set = pc.getSetInteger();
-        assertEquals(4, set.size());
-        assertTrue(set.contains(new Integer(3)));
-        assertTrue(set.contains(new Integer(5)));
-        assertTrue(set.contains(new Integer(14)));
-        assertTrue(set.contains(new Integer(15)));
-        em.getTransaction().begin();
-        pc.setSetInteger(null);
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        pc = em.find(ManagedIface.class, oid);
-        set = pc.getSetInteger();
-        assertTrue (set == null || set.size() == 0);
-        em.close();
-    }
-
-    public void testCollectionPC() {
-        OpenJPAEntityManager em = emf.createEntityManager();
-        em.getTransaction().begin();
-        ManagedIface pc = em.createInstance(ManagedIface.class);
-        Set set = new HashSet();
-        set.add(new SimpleEntity("a", "3"));
-        set.add(new SimpleEntity("b", "4"));
-        set.add(new SimpleEntity("c", "5"));
-        pc.setSetPC(set);
-        em.persist(pc);
-        Object oid = em.getObjectId(pc);
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        pc = em.find(ManagedIface.class, oid);
-        set = pc.getSetPC();
-        assertEquals(3, set.size());
-        Collection seen = new ArrayList();
-        SimpleEntity rel;
-        SimpleEntity toRem = null;
-        for (Iterator it = set.iterator(); it.hasNext();) {
-            rel = (SimpleEntity) it.next();
-            seen.add(rel.getName());
-            if (rel.getValue().equals("4"))
-                toRem = rel;
-        }
-        assertEquals(3, seen.size());
-        assertTrue(seen.contains("a"));
-        assertTrue(seen.contains("b"));
-        assertTrue(seen.contains("c"));
-        em.getTransaction().begin();
-        assertNotNull(toRem);
-        set.remove(toRem);
-        set.add(new SimpleEntity("x", "14"));
-        set.add(new SimpleEntity("y", "15"));
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        pc = em.find(ManagedIface.class, oid);
-        set = pc.getSetPC();
-        assertEquals(4, set.size());
-        seen.clear();
-        for (Iterator it = set.iterator(); it.hasNext();) {
-            rel = (SimpleEntity) it.next();
-            seen.add(rel.getName());
-        }
-        assertEquals(4, seen.size());
-        assertTrue(seen.contains("a"));
-        assertTrue(seen.contains("c"));
-        assertTrue(seen.contains("x"));
-        assertTrue(seen.contains("y"));
-        em.getTransaction().begin();
-        pc.setSetPC(null);
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        pc = em.find(ManagedIface.class, oid);
-        set = pc.getSetPC();
-        assertTrue (set == null || set.size() == 0);
-        em.close();
-    }
-
-    public void testCollectionInterfaces() {
-        OpenJPAEntityManager em = emf.createEntityManager();
-        em.getTransaction().begin();
-        ManagedIface pc = em.createInstance(ManagedIface.class);
-        Set set = new HashSet();
-        set.add(createInstance(em, 3));
-        set.add(createInstance(em, 4));
-        set.add(createInstance(em, 5));
-        pc.setSetI(set);
-        em.persist(pc);
-        Object oid = em.getObjectId(pc);
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        pc = em.find(ManagedIface.class, oid);
-        set = pc.getSetI();
-        assertEquals(3, set.size());
-        Collection seen = new ArrayList();
-        ManagedIface rel = null;
-        ManagedIface toRem = null;
-        for (Iterator it = set.iterator(); it.hasNext();) {
-            rel = (ManagedIface) it.next();
-            seen.add(new Integer(rel.getIntField()));
-            if (rel.getIntField() == 4)
-                toRem = rel;
-        }
-        assertEquals(3, seen.size());
-        assertTrue(seen.contains(new Integer(3)));
-        assertTrue(seen.contains(new Integer(4)));
-        assertTrue(seen.contains(new Integer(5)));
-        em.getTransaction().begin();
-        assertNotNull(toRem);
-        set.remove(toRem);
-        set.add(createInstance(em, 14));
-        set.add(createInstance(em, 15));
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        pc = em.find(ManagedIface.class, oid);
-        set = pc.getSetI();
-        assertEquals(4, set.size());
-        seen.clear();
-        for (Iterator it = set.iterator(); it.hasNext();) {
-            rel = (ManagedIface) it.next();
-            seen.add(new Integer(rel.getIntField()));
-        }
-        assertEquals(4, seen.size());
-        assertTrue(seen.contains(new Integer(3)));
-        assertTrue(seen.contains(new Integer(5)));
-        assertTrue(seen.contains(new Integer(14)));
-        assertTrue(seen.contains(new Integer(15)));
-        em.getTransaction().begin();
-        pc.setSetPC(null);
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        pc = em.find(ManagedIface.class, oid);
-        set = pc.getSetPC();
-        assertTrue (set == null || set.size() == 0);
-        em.close();
-    }
-
-    public void testMixedQuery() {
-        createMixed();
-
-        OpenJPAEntityManager em = emf.createEntityManager();
-        Query q = em.createQuery("select o from MixedInterface o " +
-            "where o.intField = 4");
-        Collection c = q.getResultList();
-        Set seen = new HashSet();
-        assertEquals(2, c.size());
-        MixedInterface pc;
-        for (Iterator it = c.iterator(); it.hasNext();) {
-            pc = (MixedInterface) it.next();
-            assertEquals(4, pc.getIntField());
-            seen.add(pc.getClass());
-        }
-        assertEquals(2, seen.size());
-        
-        // Changes of OPENJPA-485 had the positive (but unintended) consequence
-        // of making this case pass, which was failing before as reported in
-        // OPENJPA-481
-    }
-
-    public void testQueryForMixedInterfaceImpls() {
-        createMixed();
-
-        OpenJPAEntityManager em = emf.createEntityManager();
-        Query q = em.createQuery("select o from MixedInterfaceImpl o " +
-            "where o.intField = 4");
-        MixedInterface pc = (MixedInterface) q.getSingleResult();
-        assertEquals(4, pc.getIntField());
-        assertTrue(pc instanceof MixedInterfaceImpl);
-        em.close();
-    }
-
-    public void testMixedExtent() {
-        createMixed();
-
-        OpenJPAEntityManager em = emf.createEntityManager();
-        Extent e = em.createExtent(MixedInterface.class, true);
-        Set seen = new HashSet();
-        int size = 0;
-        for (Iterator it = e.iterator(); it.hasNext();) {
-            seen.add(it.next().getClass());
-            size++;
-        }
-        assertEquals(3, size);
-        assertEquals(2, seen.size());
-
-        e = em.createExtent(MixedInterface.class, false);
-        seen = new HashSet();
-        size = 0;
-        for (Iterator it = e.iterator(); it.hasNext();) {
-            seen.add(it.next().getClass());
-            size++;
-        }
-        assertEquals(1, size);
-        assertNotEquals(MixedInterfaceImpl.class, seen.iterator().next());
-        em.close();
-    }
-
-    private void createMixed() {
-        OpenJPAEntityManager em = emf.createEntityManager();
-        em.getTransaction().begin();
-        MixedInterface pc = em.createInstance(MixedInterface.class);
-        pc.setIntField(4);
-        em.persist(pc);
-        pc = new MixedInterfaceImpl();
-        pc.setIntField(4);
-        em.persist(pc);
-        pc = new MixedInterfaceImpl();
-        pc.setIntField(8);
-        em.persist(pc);
-        em.getTransaction().commit();
-        em.close();
-    }
-
-    public void testUnimplementedThrowsException() {
-        OpenJPAEntityManager em = emf.createEntityManager();
-        ManagedIface pc = createInstance(em, 1);
-        try {
-            pc.unimplemented();
-            fail("Exception expected.");
-        } catch (UnsupportedOperationException uoe) {} // good
-        em.close();
-    }
-
-    public void testNonMappedCreateInstanceException() {
-        // OpenJPA's support of non-mapped interfaces differs from JDO support;
-        // there is no special query or relation support for non-mapped
-        // interfaces in OpenJPA at this time.
-        OpenJPAEntityManager em = null;
-        try {
-            em = emf.createEntityManager();
-            em.createInstance(NonMappedInterface.class);
-            fail("IllegalArgumentException expected");
-        } catch (IllegalArgumentException e) {} // good
-        if (em != null)
-            em.close();
-    }
-
-    public void testDetach() {
-        OpenJPAEntityManager em = emf.createEntityManager();
-        em.getTransaction().begin();
-        ManagedIface pc = createInstance(em, 4);
-        em.persist(pc);
-        Object oid = em.getObjectId(pc);
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        ManagedIface pcx = em.find(ManagedIface.class, oid);
-        pc = em.detach(pcx);
-        em.close();
-
-        assertTrue(em.isDetached(pc));
-        pc.setIntField(7);
-
-        em = emf.createEntityManager();
-        em.getTransaction().begin();
-        em.merge(pc);
-        em.getTransaction().commit();
-        em.close();
-
-        em = emf.createEntityManager();
-        pc = em.find(ManagedIface.class, oid);
-        assertEquals(7, pc.getIntField());
-        em.close();
-    }
-
-    private ManagedIface createInstance(OpenJPAEntityManager em, int i) {
-        ManagedIface pc = em.createInstance(ManagedIface.class);
-        pc.setIntField(i);
-        return pc;
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.managedinterface;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import javax.persistence.Query;
+import javax.persistence.EntityNotFoundException;
+
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.JPAFacadeHelper;
+import org.apache.openjpa.persistence.Extent;
+import org.apache.openjpa.persistence.query.SimpleEntity;
+import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.persistence.PersistenceException;
+
+public class TestManagedInterfaces extends SingleEMFTestCase {
+
+    @Override
+    public void setUp() {
+        super.setUp(SimpleEntity.class, ManagedInterfaceEmbed.class,
+            ManagedInterfaceSup.class, ManagedIface.class,
+            ManagedInterfaceOwner.class, MixedInterface.class,
+            MixedInterfaceImpl.class, NonMappedInterfaceImpl.class,
+            CLEAR_TABLES);
+    }
+
+    public void testEmbeddedMetaData() {
+        emf.createEntityManager().close();
+        ClassMetaData ownerMeta = JPAFacadeHelper.getMetaData(emf,
+            ManagedIface.class);
+        ClassMetaData embeddedMeta = ownerMeta.getField("embed")
+            .getDefiningMetaData();
+        assertTrue(embeddedMeta.isManagedInterface());
+        assertTrue(embeddedMeta.isIntercepting());
+
+        ClassMetaData embeddableMeta = JPAFacadeHelper.getMetaData(emf,
+            ManagedInterfaceEmbed.class);
+        assertTrue(embeddableMeta.isManagedInterface());
+        assertTrue(embeddableMeta.isIntercepting());
+    }
+
+    public void testManagedInterface() throws Exception {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        ManagedIface pc = em.createInstance(ManagedIface.class);
+        pc.setIntFieldSup(3);
+        pc.setIntField(4);
+        pc.setEmbed(em.createInstance(ManagedInterfaceEmbed.class));
+
+        pc.getEmbed().setEmbedIntField(5);
+        assertEquals(5, pc.getEmbed().getEmbedIntField());
+        em.persist(pc);
+        Object oid = em.getObjectId(pc);
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        pc = em.find(ManagedIface.class, oid);
+        assertEquals(3, pc.getIntFieldSup());
+        assertEquals(4, pc.getIntField());
+        assertEquals(5, pc.getEmbed().getEmbedIntField());
+        em.getTransaction().begin();
+        pc.setIntField(14);
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager ();
+        em.getTransaction().begin();
+        Query query = em.createQuery("select o from ManagedIface o " +
+            "where o.intField = 14");
+        pc = (ManagedIface) query.getSingleResult();
+        assertEquals(14, pc.getIntField());
+        em.remove(pc);
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        try {
+            assertNull(em.find(ManagedIface.class, oid));
+        } catch (EntityNotFoundException onfe) {}
+
+        em.close();
+    }
+
+    public void testInterfaceOwner() {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        ManagedInterfaceOwner pc = new ManagedInterfaceOwner();
+        pc.setIFace(em.createInstance(ManagedInterfaceSup.class));
+        pc.setEmbed(em.createInstance(ManagedInterfaceEmbed.class));
+        pc.getIFace().setIntFieldSup(3);
+        pc.getEmbed().setEmbedIntField(5);
+
+        em.getTransaction().begin();
+        em.persist(pc);
+        Object oid = em.getObjectId(pc);
+        em.getTransaction().commit();
+        pc = em.find(ManagedInterfaceOwner.class, oid);
+        assertEquals(3, pc.getIFace().getIntFieldSup());
+        assertEquals(5, pc.getEmbed().getEmbedIntField());
+        em.close();
+
+        em = emf.createEntityManager();
+        pc = em.find(ManagedInterfaceOwner.class, oid);
+        assertEquals(3, pc.getIFace().getIntFieldSup());
+        assertEquals(5, pc.getEmbed().getEmbedIntField());
+        em.close();
+
+        em = emf.createEntityManager();
+        em.getTransaction().begin();
+        Query q = em.createQuery("select o from ManagedInterfaceOwner o " +
+            "where o.iface.intFieldSup = 3 and o.embed.embedIntField = 5");
+        pc = (ManagedInterfaceOwner) q.getSingleResult();
+        assertEquals(3, pc.getIFace().getIntFieldSup());
+        assertEquals(5, pc.getEmbed().getEmbedIntField());
+
+        pc.getIFace().setIntFieldSup(13);
+        pc.getEmbed().setEmbedIntField(15);
+        assertEquals(13, pc.getIFace().getIntFieldSup());
+        assertEquals(15, pc.getEmbed().getEmbedIntField());
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        pc = em.find(ManagedInterfaceOwner.class, oid);
+        assertEquals(13, pc.getIFace().getIntFieldSup());
+        assertEquals(15, pc.getEmbed().getEmbedIntField());
+        em.close();
+    }
+
+    public void testCollection() {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        ManagedIface pc = em.createInstance(ManagedIface.class);
+        Set set = new HashSet();
+        set.add(new Integer(3));
+        set.add(new Integer(4));
+        set.add(new Integer(5));
+        pc.setSetInteger(set);
+        em.persist(pc);
+        Object oid = em.getObjectId(pc);
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        pc = em.find(ManagedIface.class, oid);
+        set = pc.getSetInteger();
+        assertEquals(3, set.size());
+        assertTrue(set.contains(new Integer(3)));
+        assertTrue(set.contains(new Integer(4)));
+        assertTrue(set.contains(new Integer(5)));
+        em.getTransaction().begin();
+        set.remove(new Integer(4));
+        set.add(new Integer(14));
+        set.add(new Integer(15));
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        pc = em.find(ManagedIface.class, oid);
+        set = pc.getSetInteger();
+        assertEquals(4, set.size());
+        assertTrue(set.contains(new Integer(3)));
+        assertTrue(set.contains(new Integer(5)));
+        assertTrue(set.contains(new Integer(14)));
+        assertTrue(set.contains(new Integer(15)));
+        em.getTransaction().begin();
+        pc.setSetInteger(null);
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        pc = em.find(ManagedIface.class, oid);
+        set = pc.getSetInteger();
+        assertTrue (set == null || set.size() == 0);
+        em.close();
+    }
+
+    public void testCollectionPC() {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        ManagedIface pc = em.createInstance(ManagedIface.class);
+        Set set = new HashSet();
+        set.add(new SimpleEntity("a", "3"));
+        set.add(new SimpleEntity("b", "4"));
+        set.add(new SimpleEntity("c", "5"));
+        pc.setSetPC(set);
+        em.persist(pc);
+        Object oid = em.getObjectId(pc);
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        pc = em.find(ManagedIface.class, oid);
+        set = pc.getSetPC();
+        assertEquals(3, set.size());
+        Collection seen = new ArrayList();
+        SimpleEntity rel;
+        SimpleEntity toRem = null;
+        for (Iterator it = set.iterator(); it.hasNext();) {
+            rel = (SimpleEntity) it.next();
+            seen.add(rel.getName());
+            if (rel.getValue().equals("4"))
+                toRem = rel;
+        }
+        assertEquals(3, seen.size());
+        assertTrue(seen.contains("a"));
+        assertTrue(seen.contains("b"));
+        assertTrue(seen.contains("c"));
+        em.getTransaction().begin();
+        assertNotNull(toRem);
+        set.remove(toRem);
+        set.add(new SimpleEntity("x", "14"));
+        set.add(new SimpleEntity("y", "15"));
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        pc = em.find(ManagedIface.class, oid);
+        set = pc.getSetPC();
+        assertEquals(4, set.size());
+        seen.clear();
+        for (Iterator it = set.iterator(); it.hasNext();) {
+            rel = (SimpleEntity) it.next();
+            seen.add(rel.getName());
+        }
+        assertEquals(4, seen.size());
+        assertTrue(seen.contains("a"));
+        assertTrue(seen.contains("c"));
+        assertTrue(seen.contains("x"));
+        assertTrue(seen.contains("y"));
+        em.getTransaction().begin();
+        pc.setSetPC(null);
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        pc = em.find(ManagedIface.class, oid);
+        set = pc.getSetPC();
+        assertTrue (set == null || set.size() == 0);
+        em.close();
+    }
+
+    public void testCollectionInterfaces() {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        ManagedIface pc = em.createInstance(ManagedIface.class);
+        Set set = new HashSet();
+        set.add(createInstance(em, 3));
+        set.add(createInstance(em, 4));
+        set.add(createInstance(em, 5));
+        pc.setSetI(set);
+        em.persist(pc);
+        Object oid = em.getObjectId(pc);
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        pc = em.find(ManagedIface.class, oid);
+        set = pc.getSetI();
+        assertEquals(3, set.size());
+        Collection seen = new ArrayList();
+        ManagedIface rel = null;
+        ManagedIface toRem = null;
+        for (Iterator it = set.iterator(); it.hasNext();) {
+            rel = (ManagedIface) it.next();
+            seen.add(new Integer(rel.getIntField()));
+            if (rel.getIntField() == 4)
+                toRem = rel;
+        }
+        assertEquals(3, seen.size());
+        assertTrue(seen.contains(new Integer(3)));
+        assertTrue(seen.contains(new Integer(4)));
+        assertTrue(seen.contains(new Integer(5)));
+        em.getTransaction().begin();
+        assertNotNull(toRem);
+        set.remove(toRem);
+        set.add(createInstance(em, 14));
+        set.add(createInstance(em, 15));
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        pc = em.find(ManagedIface.class, oid);
+        set = pc.getSetI();
+        assertEquals(4, set.size());
+        seen.clear();
+        for (Iterator it = set.iterator(); it.hasNext();) {
+            rel = (ManagedIface) it.next();
+            seen.add(new Integer(rel.getIntField()));
+        }
+        assertEquals(4, seen.size());
+        assertTrue(seen.contains(new Integer(3)));
+        assertTrue(seen.contains(new Integer(5)));
+        assertTrue(seen.contains(new Integer(14)));
+        assertTrue(seen.contains(new Integer(15)));
+        em.getTransaction().begin();
+        pc.setSetPC(null);
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        pc = em.find(ManagedIface.class, oid);
+        set = pc.getSetPC();
+        assertTrue (set == null || set.size() == 0);
+        em.close();
+    }
+
+    public void testMixedQuery() {
+        createMixed();
+
+        OpenJPAEntityManager em = emf.createEntityManager();
+        Query q = em.createQuery("select o from MixedInterface o " +
+            "where o.intField = 4");
+        Collection c = q.getResultList();
+        Set seen = new HashSet();
+        assertEquals(2, c.size());
+        MixedInterface pc;
+        for (Iterator it = c.iterator(); it.hasNext();) {
+            pc = (MixedInterface) it.next();
+            assertEquals(4, pc.getIntField());
+            seen.add(pc.getClass());
+        }
+        assertEquals(2, seen.size());
+        
+        // Changes of OPENJPA-485 had the positive (but unintended) consequence
+        // of making this case pass, which was failing before as reported in
+        // OPENJPA-481
+    }
+
+    public void testQueryForMixedInterfaceImpls() {
+        createMixed();
+
+        OpenJPAEntityManager em = emf.createEntityManager();
+        Query q = em.createQuery("select o from MixedInterfaceImpl o " +
+            "where o.intField = 4");
+        MixedInterface pc = (MixedInterface) q.getSingleResult();
+        assertEquals(4, pc.getIntField());
+        assertTrue(pc instanceof MixedInterfaceImpl);
+        em.close();
+    }
+
+    public void testMixedExtent() {
+        createMixed();
+
+        OpenJPAEntityManager em = emf.createEntityManager();
+        Extent e = em.createExtent(MixedInterface.class, true);
+        Set seen = new HashSet();
+        int size = 0;
+        for (Iterator it = e.iterator(); it.hasNext();) {
+            seen.add(it.next().getClass());
+            size++;
+        }
+        assertEquals(3, size);
+        assertEquals(2, seen.size());
+
+        e = em.createExtent(MixedInterface.class, false);
+        seen = new HashSet();
+        size = 0;
+        for (Iterator it = e.iterator(); it.hasNext();) {
+            seen.add(it.next().getClass());
+            size++;
+        }
+        assertEquals(1, size);
+        assertNotEquals(MixedInterfaceImpl.class, seen.iterator().next());
+        em.close();
+    }
+
+    private void createMixed() {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        MixedInterface pc = em.createInstance(MixedInterface.class);
+        pc.setIntField(4);
+        em.persist(pc);
+        pc = new MixedInterfaceImpl();
+        pc.setIntField(4);
+        em.persist(pc);
+        pc = new MixedInterfaceImpl();
+        pc.setIntField(8);
+        em.persist(pc);
+        em.getTransaction().commit();
+        em.close();
+    }
+
+    public void testUnimplementedThrowsException() {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        ManagedIface pc = createInstance(em, 1);
+        try {
+            pc.unimplemented();
+            fail("Exception expected.");
+        } catch (UnsupportedOperationException uoe) {} // good
+        em.close();
+    }
+
+    public void testNonMappedCreateInstanceException() {
+        // OpenJPA's support of non-mapped interfaces differs from JDO support;
+        // there is no special query or relation support for non-mapped
+        // interfaces in OpenJPA at this time.
+        OpenJPAEntityManager em = null;
+        try {
+            em = emf.createEntityManager();
+            em.createInstance(NonMappedInterface.class);
+            fail("IllegalArgumentException expected");
+        } catch (IllegalArgumentException e) {} // good
+        if (em != null)
+            em.close();
+    }
+
+    public void testDetach() {
+        OpenJPAEntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        ManagedIface pc = createInstance(em, 4);
+        em.persist(pc);
+        Object oid = em.getObjectId(pc);
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        ManagedIface pcx = em.find(ManagedIface.class, oid);
+        pc = em.detachCopy(pcx);
+        em.close();
+
+        assertTrue(em.isDetached(pc));
+        pc.setIntField(7);
+
+        em = emf.createEntityManager();
+        em.getTransaction().begin();
+        em.merge(pc);
+        em.getTransaction().commit();
+        em.close();
+
+        em = emf.createEntityManager();
+        pc = em.find(ManagedIface.class, oid);
+        assertEquals(7, pc.getIntField());
+        em.close();
+    }
+
+    private ManagedIface createInstance(OpenJPAEntityManager em, int i) {
+        ManagedIface pc = em.createInstance(ManagedIface.class);
+        pc.setIntField(i);
+        return pc;
+    }
+}

Propchange: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/managedinterface/TestManagedInterfaces.java
------------------------------------------------------------------------------
    svn:eol-style = native