From d59ac459faffbb62373e99086524d489af528350 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Mon, 24 Oct 2016 16:22:39 -0700 Subject: [PATCH] HHH-11196 - Hibernate 5 Bytecode Enhancement Association Management works just in one direction - add replicating test case --- .../bytecode/enhancement/EnhancerTest.java | 11 +++- ...oManyBidirectionalAssociationTestTask.java | 65 +++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/association/OneToManyBidirectionalAssociationTestTask.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/EnhancerTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/EnhancerTest.java index a12176e146..904f8168f4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/EnhancerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/EnhancerTest.java @@ -8,8 +8,6 @@ package org.hibernate.test.bytecode.enhancement; import org.hibernate.bytecode.enhance.spi.UnloadedClass; -import org.hibernate.test.bytecode.enhancement.detached.DetachedGetIdentifierTestTask; -import org.hibernate.test.bytecode.enhancement.cascade.CascadeWithFkConstraintTestTask; import org.hibernate.testing.DialectChecks; import org.hibernate.testing.FailureExpected; import org.hibernate.testing.RequiresDialectFeature; @@ -21,10 +19,13 @@ import org.hibernate.test.bytecode.enhancement.access.MixedAccessTestTask; import org.hibernate.test.bytecode.enhancement.association.InheritedAttributeAssociationTestTask; import org.hibernate.test.bytecode.enhancement.association.ManyToManyAssociationTestTask; import org.hibernate.test.bytecode.enhancement.association.OneToManyAssociationTestTask; +import org.hibernate.test.bytecode.enhancement.association.OneToManyBidirectionalAssociationTestTask; import org.hibernate.test.bytecode.enhancement.association.OneToOneAssociationTestTask; import org.hibernate.test.bytecode.enhancement.basic.BasicEnhancementTestTask; import org.hibernate.test.bytecode.enhancement.basic.HHH9529TestTask; import org.hibernate.test.bytecode.enhancement.cascade.CascadeDeleteTestTask; +import org.hibernate.test.bytecode.enhancement.cascade.CascadeWithFkConstraintTestTask; +import org.hibernate.test.bytecode.enhancement.detached.DetachedGetIdentifierTestTask; import org.hibernate.test.bytecode.enhancement.dirty.DirtyTrackingCollectionTestTask; import org.hibernate.test.bytecode.enhancement.dirty.DirtyTrackingTestTask; import org.hibernate.test.bytecode.enhancement.eviction.EvictionTestTask; @@ -111,6 +112,12 @@ public class EnhancerTest extends BaseUnitTestCase { EnhancerTestUtils.runEnhancerTestTask( InheritedAttributeAssociationTestTask.class ); } + @Test + @FailureExpected( jiraKey = "HHH-11196" ) + public void testHHH11196() { + EnhancerTestUtils.runEnhancerTestTask( OneToManyBidirectionalAssociationTestTask.class ); + } + @Test public void testLazy() { EnhancerTestUtils.runEnhancerTestTask( LazyLoadingTestTask.class ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/association/OneToManyBidirectionalAssociationTestTask.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/association/OneToManyBidirectionalAssociationTestTask.java new file mode 100644 index 0000000000..e15651e8ab --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/association/OneToManyBidirectionalAssociationTestTask.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.bytecode.enhancement.association; + +import java.util.List; + +import org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask; +import org.junit.Assert; + +/** + * @author Luis Barreiro + */ +public class OneToManyBidirectionalAssociationTestTask extends AbstractEnhancerTestTask { + + public Class[] getAnnotatedClasses() { + return new Class[] {Customer.class, CustomerInventory.class, Group.class, User.class}; + } + + public void prepare() { + } + + public void execute() { + Customer customer = new Customer(); + Assert.assertTrue( customer.getInventories().isEmpty() ); + + CustomerInventory customerInventory = new CustomerInventory(); + customerInventory.setCustomer( customer ); + + Assert.assertTrue( customer.getInventories().size() == 1 ); + Assert.assertTrue( customer.getInventories().contains( customerInventory ) ); + + Customer anotherCustomer = new Customer(); + Assert.assertTrue( anotherCustomer.getInventories().isEmpty() ); + customerInventory.setCustomer( anotherCustomer ); + + Assert.assertTrue( customer.getInventories().isEmpty() ); + Assert.assertTrue( anotherCustomer.getInventories().size() == 1 ); + Assert.assertTrue( anotherCustomer.getInventories().get( 0 ) == customerInventory ); + + customer.getInventories().add( customerInventory ); + + Assert.assertTrue( customerInventory.getCustomer() == customer ); + Assert.assertTrue( anotherCustomer.getInventories().isEmpty() ); + Assert.assertTrue( customer.getInventories().size() == 1 ); + + customer.addInventory( new CustomerInventory() ); + Assert.assertTrue( customer.getInventories().size() == 2 ); + + // Test remove + + List inventories = customer.getInventories(); + inventories.remove( customerInventory ); + customer.setInventories( inventories ); + + // This happens (and is expected) because there was no snapshot taken beforeQuery remove + Assert.assertNotNull( customerInventory.getCustomer() ); + } + + protected void cleanup() { + } +}