OPENJPA-1097 Merge in test updates from 1.2.x

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@924005 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald Woods 2010-03-16 21:50:15 +00:00
parent 6bc5ff8d3c
commit 4bff5d71e8
1 changed files with 27 additions and 14 deletions

View File

@ -86,7 +86,7 @@ public class TestDetachNoProxy extends SingleEMFTestCase {
log.trace("** after find"); log.trace("** after find");
assertTrue(em.contains(e20)); assertTrue(em.contains(e20));
assertFalse(em.isDetached(e20)); assertFalse(em.isDetached(e20));
verifySerializable(e20, true); verifySerializable(e20, true, false);
// new openjpa-2.0.0 behavior, where detach() doesn't return updated entity, but does it in-place // new openjpa-2.0.0 behavior, where detach() doesn't return updated entity, but does it in-place
em.detach(e20); em.detach(e20);
@ -95,7 +95,7 @@ public class TestDetachNoProxy extends SingleEMFTestCase {
// in-place updated entity should not have any proxy classes and should be detached // in-place updated entity should not have any proxy classes and should be detached
assertFalse(em.contains(e20)); assertFalse(em.contains(e20));
assertTrue(em.isDetached(e20)); assertTrue(em.isDetached(e20));
verifySerializable(e20, false); verifySerializable(e20, false, false);
em.close(); em.close();
} }
@ -115,7 +115,7 @@ public class TestDetachNoProxy extends SingleEMFTestCase {
log.trace("** after find"); log.trace("** after find");
assertTrue(em.contains(e20)); assertTrue(em.contains(e20));
assertFalse(em.isDetached(e20)); assertFalse(em.isDetached(e20));
verifySerializable(e20, true); verifySerializable(e20, true, false);
// Test new detachCopy() method added in 2.0.0 // Test new detachCopy() method added in 2.0.0
Entity20 e20copy = em.detachCopy(e20); Entity20 e20copy = em.detachCopy(e20);
@ -124,11 +124,11 @@ public class TestDetachNoProxy extends SingleEMFTestCase {
// verify e20 is same as above // verify e20 is same as above
assertTrue(em.contains(e20)); assertTrue(em.contains(e20));
assertFalse(em.isDetached(e20)); assertFalse(em.isDetached(e20));
verifySerializable(e20, true); verifySerializable(e20, true, false);
// verify copy does not have any proxy classes (in-place updated) is detached // verify copy does not have any proxy classes (in-place updated) is detached
assertFalse(em.contains(e20copy)); assertFalse(em.contains(e20copy));
assertTrue(em.isDetached(e20copy)); assertTrue(em.isDetached(e20copy));
verifySerializable(e20copy, false); verifySerializable(e20copy, false, false);
em.close(); em.close();
} }
@ -150,7 +150,7 @@ public class TestDetachNoProxy extends SingleEMFTestCase {
log.trace("** after find Entity20(" + i + ")"); log.trace("** after find Entity20(" + i + ")");
assertTrue(em.contains(e20)); assertTrue(em.contains(e20));
assertFalse(em.isDetached(e20)); assertFalse(em.isDetached(e20));
verifySerializable(e20, true); verifySerializable(e20, true, false);
} }
// new openjpa-2.0.0 behavior, where detachAll() updates entities in-place // new openjpa-2.0.0 behavior, where detachAll() updates entities in-place
@ -164,7 +164,7 @@ public class TestDetachNoProxy extends SingleEMFTestCase {
// entity should not have any proxy classes (in-place updated) and is detached // entity should not have any proxy classes (in-place updated) and is detached
assertFalse(em.contains(e20)); assertFalse(em.contains(e20));
assertTrue(em.isDetached(e20)); assertTrue(em.isDetached(e20));
verifySerializable(e20, false); verifySerializable(e20, false, false);
} }
em.close(); em.close();
@ -187,7 +187,7 @@ public class TestDetachNoProxy extends SingleEMFTestCase {
log.trace("** after find Entity20(" + i + ")"); log.trace("** after find Entity20(" + i + ")");
assertTrue(em.contains(e20)); assertTrue(em.contains(e20));
assertFalse(em.isDetached(e20)); assertFalse(em.isDetached(e20));
verifySerializable(e20, true); verifySerializable(e20, true, false);
} }
em.clear(); em.clear();
@ -199,22 +199,35 @@ public class TestDetachNoProxy extends SingleEMFTestCase {
assertFalse(em.contains(e20)); assertFalse(em.contains(e20));
assertTrue(em.isDetached(e20)); assertTrue(em.isDetached(e20));
// entity should still have proxy classes and is detached, // entity should still have proxy classes and is detached,
// but once serialized the $proxy classes will be removed // Old 1.2.x Behavior -
verifySerializable(e20, true); // the $proxy classes are not removed during serialization
// verifySerializable(e20, true, true);
// OPENJPA-1097 New behavior - $proxy classes are removed
verifySerializable(e20, true, false);
} }
em.close(); em.close();
} }
/**
private void verifySerializable(Entity20 e20, boolean usesProxy) { * Test that the entity is/is not using our $proxy classes before
* and after serialization.
*
* @param e20 Entity to test.
* @param usesProxyBefore verify that the entity uses the $proxy classes
* before serialization if true and does not if false.
* @param usesProxyAfter verify that the entity uses the $proxy classes
* after serialization if true and does not if false.
*/
private void verifySerializable(Entity20 e20, boolean usesProxyBefore,
boolean usesProxyAfter) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = null; ObjectOutputStream oos = null;
byte[] e20bytes = null; byte[] e20bytes = null;
if (log.isTraceEnabled()) if (log.isTraceEnabled())
log.trace("verifySerializable() - before serialize"); log.trace("verifySerializable() - before serialize");
verifyEntities(e20, usesProxy); verifyEntities(e20, usesProxyBefore);
// first serialize // first serialize
try { try {
@ -240,7 +253,7 @@ public class TestDetachNoProxy extends SingleEMFTestCase {
e20new = (Entity20) ois.readObject(); e20new = (Entity20) ois.readObject();
if (log.isTraceEnabled()) if (log.isTraceEnabled())
log.trace("verifySerializable() - after deserialize"); log.trace("verifySerializable() - after deserialize");
verifyEntities(e20new, false); verifyEntities(e20new, usesProxyAfter);
} catch (IOException e) { } catch (IOException e) {
fail(e.toString()); fail(e.toString());
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {