From cc7cfb5c4083ad218adfdab17a6d01be96197c3c Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Fri, 6 Jul 2012 13:13:11 -0700 Subject: [PATCH] HHH-7436 : Add FailureExpected test for unidirectional many-to-many --- ...ntityWithUnidirectionalManyToManys.hbm.xml | 26 +++++ .../EntityWithUnidirectionalManyToManys.java | 95 ++++++++++++++++++ .../UnidirectionalManyToManyBindingTests.java | 98 +++++++++++++++++++ 3 files changed, 219 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalManyToManys.hbm.xml create mode 100644 hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalManyToManys.java create mode 100644 hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/UnidirectionalManyToManyBindingTests.java diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalManyToManys.hbm.xml b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalManyToManys.hbm.xml new file mode 100644 index 0000000000..00b386ea5b --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalManyToManys.hbm.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalManyToManys.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalManyToManys.java new file mode 100644 index 0000000000..fe25860d15 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalManyToManys.java @@ -0,0 +1,95 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2012, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.metamodel.spi.binding; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; + +/** + * @author Gail Badner + */ +@Entity +public class EntityWithUnidirectionalManyToManys { + private Long id; + private String name; + private Collection theBag = new ArrayList(); + private Set theSet = new HashSet(); + private Collection thePropertyRefBag = new ArrayList(); + + public EntityWithUnidirectionalManyToManys() { + } + + public EntityWithUnidirectionalManyToManys(String name) { + this.name = name; + } + + @Id + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @OneToMany + public Collection getTheBag() { + return theBag; + } + + public void setTheBag(Collection theBag) { + this.theBag = theBag; + } + + @OneToMany + public Set getTheSet() { + return theSet; + } + + public void setTheSet(Set theSet) { + this.theSet = theSet; + } + + @OneToMany + public Collection getThePropertyRefSet() { + return thePropertyRefBag; + } + + public void setThePropertyRefSet(Set thePropertyRefSet) { + this.thePropertyRefBag = thePropertyRefSet; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/UnidirectionalManyToManyBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/UnidirectionalManyToManyBindingTests.java new file mode 100644 index 0000000000..cb5121a2c9 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/UnidirectionalManyToManyBindingTests.java @@ -0,0 +1,98 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2012, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.metamodel.spi.binding; + +import java.util.Collection; +import java.util.Set; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.hibernate.engine.FetchTiming; +import org.hibernate.metamodel.MetadataSourceProcessingOrder; +import org.hibernate.metamodel.MetadataSources; +import org.hibernate.metamodel.internal.MetadataImpl; +import org.hibernate.metamodel.spi.relational.Column; +import org.hibernate.metamodel.spi.relational.ForeignKey; +import org.hibernate.metamodel.spi.relational.Identifier; +import org.hibernate.metamodel.spi.relational.Value; +import org.hibernate.service.ServiceRegistryBuilder; +import org.hibernate.service.internal.StandardServiceRegistryImpl; +import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.junit4.BaseUnitTestCase; +import org.hibernate.type.BagType; +import org.hibernate.type.CollectionType; +import org.hibernate.type.SetType; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +/** + * @author Gail Badner + */ +public class UnidirectionalManyToManyBindingTests extends BaseUnitTestCase { + private StandardServiceRegistryImpl serviceRegistry; + + @Before + public void setUp() { + serviceRegistry = (StandardServiceRegistryImpl) new ServiceRegistryBuilder().buildServiceRegistry(); + } + + @After + public void tearDown() { + serviceRegistry.destroy(); + } + +// @Test +// public void testAnnotations() { +// doTest( MetadataSourceProcessingOrder.ANNOTATIONS_FIRST ); +// } + + @Test + @FailureExpected( jiraKey = "HHH-7436" ) + public void testHbm() { + doTest( MetadataSourceProcessingOrder.HBM_FIRST ); + } + + private void doTest(MetadataSourceProcessingOrder processingOrder) { + MetadataSources sources = new MetadataSources( serviceRegistry ); + sources.addResource( "org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalManyToManys.hbm.xml" ); + sources.addResource( "org/hibernate/metamodel/spi/binding/SimpleEntity.hbm.xml" ); + MetadataImpl metadata = (MetadataImpl) sources.getMetadataBuilder().with( processingOrder ).buildMetadata(); + + final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithUnidirectionalManyToManys.class.getName() ); + final EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() ); + assertNotNull( entityBinding ); + + assertEquals( Identifier.toIdentifier( "SimpleEntity" ), simpleEntityBinding.getPrimaryTable().getLogicalName() ); + assertEquals( 1, simpleEntityBinding.getPrimaryTable().getPrimaryKey().getColumnSpan() ); + Column simpleEntityIdColumn = simpleEntityBinding.getPrimaryTable().getPrimaryKey().getColumns().get( 0 ); + assertEquals( Identifier.toIdentifier("id") , simpleEntityIdColumn.getColumnName() ); + } +}