diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java index 62e5739ccf..ad2d7e7d06 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java @@ -59,7 +59,7 @@ public class EntityTest extends BaseCoreFunctionalTestCase { @Test public void testLoad() throws Exception { //put an object in DB - assertEquals( "Flight", configuration().getClassMapping( Flight.class.getName() ).getTable().getName() ); + assertEquals( "Flight", getEntityBinding( Flight.class ).getPrimaryTableName() ); Session s = openSession(); Transaction tx = s.beginTransaction(); @@ -314,7 +314,7 @@ public class EntityTest extends BaseCoreFunctionalTestCase { @Test public void testEntityName() throws Exception { - assertEquals( "Corporation", configuration().getClassMapping( Company.class.getName() ).getTable().getName() ); + assertEquals( "Corporation", getEntityBinding( Company.class ).getPrimaryTableName() ); Session s = openSession(); Transaction tx = s.beginTransaction(); Company comp = new Company(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/beanvalidation/BeanValidationDisabledTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/beanvalidation/BeanValidationDisabledTest.java index 31c5df9fc1..7f17dc2cb0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/beanvalidation/BeanValidationDisabledTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/beanvalidation/BeanValidationDisabledTest.java @@ -23,21 +23,20 @@ */ package org.hibernate.test.annotations.beanvalidation; -import java.math.BigDecimal; -import javax.validation.ConstraintViolationException; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -import org.junit.Test; +import java.math.BigDecimal; + +import javax.validation.ConstraintViolationException; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.relational.Column; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import org.junit.Test; /** * @author Emmanuel Bernard @@ -62,11 +61,11 @@ public class BeanValidationDisabledTest extends BaseCoreFunctionalTestCase { } @Test - @FailureExpectedWithNewMetamodel public void testDDLDisabled() { - PersistentClass classMapping = configuration().getClassMapping( Address.class.getName() ); - Column countryColumn = (Column) classMapping.getProperty( "country" ).getColumnIterator().next(); + EntityBinding binding = getEntityBinding( Address.class ); + Column countryColumn = binding.getPrimaryTable().locateColumn( "country" ); assertTrue( "DDL constraints are applied", countryColumn.isNullable() ); + return; } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLTest.java index aa78a447ba..de4dab9d75 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLTest.java @@ -23,19 +23,18 @@ */ package org.hibernate.test.annotations.beanvalidation; -import org.junit.Test; - -import org.hibernate.mapping.Column; -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import org.hibernate.metamodel.spi.relational.Column; +import org.hibernate.metamodel.spi.relational.Index; +import org.hibernate.test.util.SchemaUtil; +import org.hibernate.testing.FailureExpectedWithNewMetamodel; +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + /** * Test verifying that DDL constraints get applied when Bean Validation / Hibernate Validator are enabled. * @@ -46,56 +45,49 @@ import static org.junit.Assert.assertTrue; public class DDLTest extends BaseCoreFunctionalTestCase { @Test public void testBasicDDL() { - PersistentClass classMapping = configuration().getClassMapping( Address.class.getName() ); - Column stateColumn = (Column) classMapping.getProperty( "state" ).getColumnIterator().next(); - assertEquals( stateColumn.getLength(), 3 ); - Column zipColumn = (Column) classMapping.getProperty( "zip" ).getColumnIterator().next(); - assertEquals( zipColumn.getLength(), 5 ); + Column stateColumn = SchemaUtil.getColumn( Address.class, "state", metadata() ); + assertEquals( stateColumn.getSize().getLength(), 3 ); + Column zipColumn = SchemaUtil.getColumn( Address.class, "zip", metadata() ); + assertEquals( zipColumn.getSize().getLength(), 5 ); assertFalse( zipColumn.isNullable() ); } @Test public void testApplyOnIdColumn() throws Exception { - PersistentClass classMapping = configuration().getClassMapping( Tv.class.getName() ); - Column serialColumn = (Column) classMapping.getIdentifierProperty().getColumnIterator().next(); - assertEquals( "Validator annotation not applied on ids", 2, serialColumn.getLength() ); + Index index = SchemaUtil.getIndexes( Tv.class, metadata() ).next(); + assertEquals( "Validator annotation not applied on ids", 2, + index.getColumns().get( 0 ).getSize().getLength() ); } @Test @TestForIssue( jiraKey = "HHH-5281" ) public void testLengthConstraint() throws Exception { - PersistentClass classMapping = configuration().getClassMapping( Tv.class.getName() ); - Column modelColumn = (Column) classMapping.getProperty( "model" ).getColumnIterator().next(); - assertEquals( modelColumn.getLength(), 5 ); + Column column = SchemaUtil.getColumn( Tv.class, "model", metadata() ); + assertEquals( column.getSize().getLength(), 5 ); } @Test public void testApplyOnManyToOne() throws Exception { - PersistentClass classMapping = configuration().getClassMapping( TvOwner.class.getName() ); - Column serialColumn = (Column) classMapping.getProperty( "tv" ).getColumnIterator().next(); - assertEquals( "Validator annotations not applied on associations", false, serialColumn.isNullable() ); + Column column = SchemaUtil.getColumn( TvOwner.class, "tv", metadata() ); + assertEquals( "Validator annotations not applied on associations", false, column.isNullable() ); } @Test public void testSingleTableAvoidNotNull() throws Exception { - PersistentClass classMapping = configuration().getClassMapping( Rock.class.getName() ); - Column serialColumn = (Column) classMapping.getProperty( "bit" ).getColumnIterator().next(); - assertTrue( "Notnull should not be applied on single tables", serialColumn.isNullable() ); + Column column = SchemaUtil.getColumn( Rock.class, "bit", metadata() ); + assertTrue( "Notnull should not be applied on single tables", column.isNullable() ); } @Test public void testNotNullOnlyAppliedIfEmbeddedIsNotNullItself() throws Exception { - PersistentClass classMapping = configuration().getClassMapping( Tv.class.getName() ); - Property property = classMapping.getProperty( "tuner.frequency" ); - Column serialColumn = (Column) property.getColumnIterator().next(); + Column column = SchemaUtil.getColumn( Tv.class, "tuner.frequency", metadata() ); assertEquals( - "Validator annotations are applied on tuner as it is @NotNull", false, serialColumn.isNullable() + "Validator annotations are applied on tuner as it is @NotNull", false, column.isNullable() ); - property = classMapping.getProperty( "recorder.time" ); - serialColumn = (Column) property.getColumnIterator().next(); + column = SchemaUtil.getColumn( Tv.class, "recorder.time", metadata() ); assertEquals( - "Validator annotations are applied on tuner as it is @NotNull", true, serialColumn.isNullable() + "Validator annotations are applied on tuner as it is @NotNull", true, column.isNullable() ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLWithoutCallbackTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLWithoutCallbackTest.java index 6a8ca5358e..6ed7ba9e1e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLWithoutCallbackTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLWithoutCallbackTest.java @@ -23,23 +23,23 @@ */ package org.hibernate.test.annotations.beanvalidation; -import java.math.BigDecimal; -import javax.validation.ConstraintViolationException; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; -import org.junit.Test; +import java.math.BigDecimal; + +import javax.validation.ConstraintViolationException; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.spi.relational.Column; +import org.hibernate.test.util.SchemaUtil; import org.hibernate.testing.DialectChecks; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; +import org.junit.Test; /** * @author Vladimir Klyushnikov @@ -93,11 +93,9 @@ public class DDLWithoutCallbackTest extends BaseCoreFunctionalTestCase { } @Test - @FailureExpectedWithNewMetamodel public void testDDLEnabled() { - PersistentClass classMapping = configuration().getClassMapping( Address.class.getName() ); - Column countryColumn = (Column) classMapping.getProperty( "country" ).getColumnIterator().next(); - assertFalse( "DDL constraints are not applied", countryColumn.isNullable() ); + Column column = SchemaUtil.getColumn( Address.class, "country", metadata() ); + assertFalse( "DDL constraints are not applied", column.isNullable() ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java index 1ae8c72471..1f931af8c6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java @@ -34,8 +34,7 @@ import org.hibernate.Filter; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; -import org.hibernate.mapping.Collection; -import org.hibernate.mapping.Column; +import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; import org.hibernate.test.annotations.Country; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -251,32 +250,28 @@ public class CollectionElementTest extends BaseCoreFunctionalTestCase { @Test public void testDefaultValueColumnForBasic() throws Exception { - isDefaultValueCollectionColumnPresent( Boy.class.getName(), "hatedNames" ); - isDefaultValueCollectionColumnPresent( Boy.class.getName(), "preferredNames" ); - isCollectionColumnPresent( Boy.class.getName(), "nickNames", "nickNames" ); - isDefaultValueCollectionColumnPresent( Boy.class.getName(), "scorePerPreferredName"); + isCollectionColumnPresent( Boy.class.getName(), "hatedNames" ); + isCollectionColumnPresent( Boy.class.getName(), "preferredNames" ); + isCollectionColumnPresent( Boy.class.getName(), "nickNames" ); + isCollectionColumnPresent( Boy.class.getName(), "scorePerPreferredName"); } @Test public void testDefaultFKNameForElementCollection() throws Exception { - isCollectionColumnPresent( Boy.class.getName(), "hatedNames", "Boy_id" ); + isCollectionColumnPresent( Boy.class.getName(), "Boy_id" ); } - private void isLegacyValueCollectionColumnPresent(String collectionHolder, String propertyName) { - - } - - private void isDefaultValueCollectionColumnPresent(String collectionOwner, String propertyName) { - isCollectionColumnPresent( collectionOwner, propertyName, propertyName ); - } - - private void isCollectionColumnPresent(String collectionOwner, String propertyName, String columnName) { - final Collection collection = configuration().getCollectionMapping( collectionOwner + "." + propertyName ); - final Iterator columnIterator = collection.getCollectionTable().getColumnIterator(); + private void isCollectionColumnPresent(String collectionOwner, String columnName) { + // TODO: Is this correct? Cannot test due to ManyToOne issues. + Iterator bindings = getCollectionBindings(); boolean hasDefault = false; - while ( columnIterator.hasNext() ) { - Column column = (Column) columnIterator.next(); - if ( columnName.equals( column.getName() ) ) hasDefault = true; + while ( bindings.hasNext() ) { + PluralAttributeBinding binding = bindings.next(); + if ( binding.getAttribute().getName().equals( columnName ) + && binding.getAttribute().getAttributeContainer().getClassName().equals( collectionOwner ) ) { + hasDefault = true; + break; + } } assertTrue( "Could not find " + columnName, hasDefault ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/bidirectional/DerivedIdentityWithBidirectionalAssociationTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/bidirectional/DerivedIdentityWithBidirectionalAssociationTest.java index d974500302..6263993cfe 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/bidirectional/DerivedIdentityWithBidirectionalAssociationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/bidirectional/DerivedIdentityWithBidirectionalAssociationTest.java @@ -40,8 +40,8 @@ import static org.junit.Assert.assertTrue; public class DerivedIdentityWithBidirectionalAssociationTest extends BaseCoreFunctionalTestCase { @Test public void testBidirectionalAssociation() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_empId", configuration() ) ); - assertTrue( !SchemaUtil.isColumnPresent( "Dependent", "empPK", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_empId", metadata() ) ); + assertTrue( !SchemaUtil.isColumnPresent( "Dependent", "empPK", metadata() ) ); Employee e = new Employee(); e.empId = 1; e.empName = "Emmanuel"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/a/DerivedIdentitySimpleParentIdClassDepTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/a/DerivedIdentitySimpleParentIdClassDepTest.java index 2590287566..cddcfee63a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/a/DerivedIdentitySimpleParentIdClassDepTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/a/DerivedIdentitySimpleParentIdClassDepTest.java @@ -44,8 +44,8 @@ import static org.junit.Assert.assertTrue; public class DerivedIdentitySimpleParentIdClassDepTest extends BaseCoreFunctionalTestCase { @Test public void testManyToOne() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_empId", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "emp", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_empId", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "emp", metadata() ) ); Session s = openSession(); s.getTransaction().begin(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java index 64c5308555..8990c825d3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java @@ -40,8 +40,8 @@ import static org.junit.Assert.assertTrue; public class DerivedIdentitySimpleParentEmbeddedIdDepTest extends BaseCoreFunctionalTestCase { @Test public void testManyToOne() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_empId", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "empPK", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_empId", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "empPK", metadata() ) ); Employee e = new Employee(); e.empId = 1; e.empName = "Emmanuel"; @@ -64,8 +64,8 @@ public class DerivedIdentitySimpleParentEmbeddedIdDepTest extends BaseCoreFuncti @Test public void testOneToOne() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "ExclusiveDependent", "FK", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "ExclusiveDependent", "empPK", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "ExclusiveDependent", "FK", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "ExclusiveDependent", "empPK", metadata() ) ); Employee e = new Employee(); e.empId = 1; e.empName = "Emmanuel"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/c/DerivedIdentitySimpleParentEmbeddedDepTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/c/DerivedIdentitySimpleParentEmbeddedDepTest.java index 17f3a2b808..6c000b2488 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/c/DerivedIdentitySimpleParentEmbeddedDepTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/c/DerivedIdentitySimpleParentEmbeddedDepTest.java @@ -40,8 +40,8 @@ import static org.junit.Assert.assertTrue; public class DerivedIdentitySimpleParentEmbeddedDepTest extends BaseCoreFunctionalTestCase { @Test public void testManyToOne() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_empId", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "empPK", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_empId", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "empPK", metadata() ) ); Employee e = new Employee(); e.empId = 1; e.empName = "Emmanuel"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e2/a/DerivedIdentityIdClassParentIdClassDepTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e2/a/DerivedIdentityIdClassParentIdClassDepTest.java index 8f2a817d4e..c0c066f8ee 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e2/a/DerivedIdentityIdClassParentIdClassDepTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e2/a/DerivedIdentityIdClassParentIdClassDepTest.java @@ -18,11 +18,11 @@ import static org.junit.Assert.assertTrue; public class DerivedIdentityIdClassParentIdClassDepTest extends BaseCoreFunctionalTestCase { @Test public void testManytoOne() { - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK1", configuration() ) ); - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK2", configuration() ) ); - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "name", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "firstName", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "lastName", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK1", metadata() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK2", metadata() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "name", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "firstName", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "lastName", metadata() ) ); Employee e = new Employee(); e.firstName = "Emmanuel"; e.lastName = "Bernard"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e2/b/DerivedIdentityIdClassParentEmbeddedIdDepTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e2/b/DerivedIdentityIdClassParentEmbeddedIdDepTest.java index 00aa237aaf..b3579df0af 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e2/b/DerivedIdentityIdClassParentEmbeddedIdDepTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e2/b/DerivedIdentityIdClassParentEmbeddedIdDepTest.java @@ -18,11 +18,11 @@ import static org.junit.Assert.assertTrue; public class DerivedIdentityIdClassParentEmbeddedIdDepTest extends BaseCoreFunctionalTestCase { @Test public void testManyToOne() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_firstName", configuration() ) ); - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_lastName", configuration() ) ); - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "name", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "firstName", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "lastName", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_firstName", metadata() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "emp_lastName", metadata() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "name", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "firstName", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "lastName", metadata() ) ); Employee e = new Employee(); e.firstName = "Emmanuel"; e.lastName = "Bernard"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e3/a/DerivedIdentityEmbeddedIdParentIdClassTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e3/a/DerivedIdentityEmbeddedIdParentIdClassTest.java index b752189571..f8566a1475 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e3/a/DerivedIdentityEmbeddedIdParentIdClassTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e3/a/DerivedIdentityEmbeddedIdParentIdClassTest.java @@ -41,11 +41,11 @@ import static org.junit.Assert.assertTrue; public class DerivedIdentityEmbeddedIdParentIdClassTest extends BaseCoreFunctionalTestCase { @Test public void testManyToOne() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK1", configuration() ) ); - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK2", configuration() ) ); - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "dep_name", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "firstName", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "lastName", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK1", metadata() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK2", metadata() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "dep_name", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "firstName", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "lastName", metadata() ) ); Employee e = new Employee(); e.empId = new EmployeeId(); e.empId.firstName = "Emmanuel"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e3/b/DerivedIdentityEmbeddedIdParentEmbeddedIdDepTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e3/b/DerivedIdentityEmbeddedIdParentEmbeddedIdDepTest.java index e0f28f9593..8a437f7afa 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e3/b/DerivedIdentityEmbeddedIdParentEmbeddedIdDepTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e3/b/DerivedIdentityEmbeddedIdParentEmbeddedIdDepTest.java @@ -41,11 +41,11 @@ import static org.junit.Assert.assertTrue; public class DerivedIdentityEmbeddedIdParentEmbeddedIdDepTest extends BaseCoreFunctionalTestCase { @Test public void testManyToOne() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK1", configuration() ) ); - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK2", configuration() ) ); - assertTrue( SchemaUtil.isColumnPresent( "Dependent", "dep_name", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "firstName", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "lastName", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK1", metadata() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK2", metadata() ) ); + assertTrue( SchemaUtil.isColumnPresent( "Dependent", "dep_name", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "firstName", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "lastName", metadata() ) ); Employee e = new Employee(); e.empId = new EmployeeId(); e.empId.firstName = "Emmanuel"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java index 080c235338..5253aa5696 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java @@ -43,8 +43,8 @@ import static org.junit.Assert.assertTrue; public class DerivedIdentitySimpleParentSimpleDepTest extends BaseCoreFunctionalTestCase { @Test public void testOneToOneExplicitJoinColumn() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "id", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "id", metadata() ) ); Session s = openSession(); s.getTransaction().begin(); @@ -75,8 +75,8 @@ public class DerivedIdentitySimpleParentSimpleDepTest extends BaseCoreFunctional @Test public void testManyToOneExplicitJoinColumn() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "FinancialHistory", "patient_ssn", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "FinancialHistory", "id", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "FinancialHistory", "patient_ssn", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "FinancialHistory", "id", metadata() ) ); Session s = openSession(); s.getTransaction().begin(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/DerivedIdentitySimpleParentSimpleDepMapsIdTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/DerivedIdentitySimpleParentSimpleDepMapsIdTest.java index e062321bd1..fcee4b5cb4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/DerivedIdentitySimpleParentSimpleDepMapsIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/DerivedIdentitySimpleParentSimpleDepMapsIdTest.java @@ -44,8 +44,8 @@ import static org.junit.Assert.assertTrue; public class DerivedIdentitySimpleParentSimpleDepMapsIdTest extends BaseCoreFunctionalTestCase { @Test public void testOneToOneExplicitJoinColumn() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "id", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "id", metadata() ) ); Person e = new Person(); e.ssn = "aaa"; Session s = openSession( ); @@ -70,8 +70,8 @@ public class DerivedIdentitySimpleParentSimpleDepMapsIdTest extends BaseCoreFunc @Test public void testManyToOneExplicitJoinColumn() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "FinancialHistory", "FK", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "FinancialHistory", "id", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "FinancialHistory", "FK", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "FinancialHistory", "id", metadata() ) ); Person e = new Person(); e.ssn = "aaa"; Session s = openSession( ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/DerivedIdentityIdClassParentSameIdTypeIdClassDepTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/DerivedIdentityIdClassParentSameIdTypeIdClassDepTest.java index 0a9e2d108f..4049d4ccab 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/DerivedIdentityIdClassParentSameIdTypeIdClassDepTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/a/DerivedIdentityIdClassParentSameIdTypeIdClassDepTest.java @@ -43,9 +43,9 @@ public class DerivedIdentityIdClassParentSameIdTypeIdClassDepTest extends BaseCo @Test public void testOneToOneExplicitJoinColumn() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK1", configuration() ) ); - assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK2", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "firstname", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK1", metadata() ) ); + assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK2", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "firstname", metadata() ) ); Session s = openSession(); s.getTransaction().begin(); @@ -73,9 +73,9 @@ public class DerivedIdentityIdClassParentSameIdTypeIdClassDepTest extends BaseCo @Test public void testTckLikeBehavior() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK1", configuration() ) ); - assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK2", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "firstname", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK1", metadata() ) ); + assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK2", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "firstname", metadata() ) ); Session s = openSession(); s.getTransaction().begin(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/b/DerivedIdentityIdClassParentSameIdTypeEmbeddedIdDepTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/b/DerivedIdentityIdClassParentSameIdTypeEmbeddedIdDepTest.java index 39019bcad1..1aa339690e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/b/DerivedIdentityIdClassParentSameIdTypeEmbeddedIdDepTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/b/DerivedIdentityIdClassParentSameIdTypeEmbeddedIdDepTest.java @@ -40,9 +40,9 @@ import static org.junit.Assert.assertTrue; public class DerivedIdentityIdClassParentSameIdTypeEmbeddedIdDepTest extends BaseCoreFunctionalTestCase { @Test public void testOneToOneExplicitJoinColumn() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK1", configuration() ) ); - assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK2", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "firstname", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK1", metadata() ) ); + assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK2", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "firstname", metadata() ) ); Person e = new Person(); e.firstName = "Emmanuel"; e.lastName = "Bernard"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/c/ForeignGeneratorViaMapsIdTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/c/ForeignGeneratorViaMapsIdTest.java index 7e3523f0e0..43f08c994a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/c/ForeignGeneratorViaMapsIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e5/c/ForeignGeneratorViaMapsIdTest.java @@ -40,7 +40,7 @@ import static org.junit.Assert.assertTrue; public class ForeignGeneratorViaMapsIdTest extends BaseCoreFunctionalTestCase { @Test public void testForeignGenerator() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "patient_id", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "patient_id", metadata() ) ); Person e = new Person(); Session s = openSession( ); s.getTransaction().begin(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e6/a/DerivedIdentityEmbeddedIdParentSameIdTypeIdClassDepTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e6/a/DerivedIdentityEmbeddedIdParentSameIdTypeIdClassDepTest.java index 1ab701e451..39d4f96ef2 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e6/a/DerivedIdentityEmbeddedIdParentSameIdTypeIdClassDepTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e6/a/DerivedIdentityEmbeddedIdParentSameIdTypeIdClassDepTest.java @@ -40,9 +40,9 @@ import static org.junit.Assert.assertTrue; public class DerivedIdentityEmbeddedIdParentSameIdTypeIdClassDepTest extends BaseCoreFunctionalTestCase { @Test public void testOneToOneExplicitJoinColumn() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK1", configuration() ) ); - assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK2", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "firstname", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK1", metadata() ) ); + assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK2", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "firstname", metadata() ) ); Person e = new Person(); e.id = new PersonId(); e.id.firstName = "Emmanuel"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e6/b/DerivedIdentityEmbeddedIdParentSameIdTypeEmbeddedIdDepTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e6/b/DerivedIdentityEmbeddedIdParentSameIdTypeEmbeddedIdDepTest.java index ab073c7e9d..1110e24a2e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e6/b/DerivedIdentityEmbeddedIdParentSameIdTypeEmbeddedIdDepTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/derivedidentities/e6/b/DerivedIdentityEmbeddedIdParentSameIdTypeEmbeddedIdDepTest.java @@ -40,9 +40,9 @@ import static org.junit.Assert.assertTrue; public class DerivedIdentityEmbeddedIdParentSameIdTypeEmbeddedIdDepTest extends BaseCoreFunctionalTestCase { @Test public void testOneToOneExplicitJoinColumn() throws Exception { - assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK1", configuration() ) ); - assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK2", configuration() ) ); - assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "firstname", configuration() ) ); + assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK1", metadata() ) ); + assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK2", metadata() ) ); + assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "firstname", metadata() ) ); Person e = new Person(); e.id = new PersonId(); e.id.firstName = "Emmanuel"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java index cba60810f4..53ad741bfd 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java @@ -408,9 +408,9 @@ public class EmbeddedTest extends BaseCoreFunctionalTestCase { @Test public void testDefaultCollectionTable() throws Exception { //are the tables correct? - assertTrue( SchemaUtil.isTablePresent("WealthyPerson_vacationHomes", configuration() ) ); - assertTrue( SchemaUtil.isTablePresent("WealthyPerson_legacyVacationHomes", configuration() ) ); - assertTrue( SchemaUtil.isTablePresent("WelPers_VacHomes", configuration() ) ); + assertTrue( SchemaUtil.isTablePresent("WealthyPerson_vacationHomes", metadata() ) ); + assertTrue( SchemaUtil.isTablePresent("WealthyPerson_legacyVacationHomes", metadata() ) ); + assertTrue( SchemaUtil.isTablePresent("WelPers_VacHomes", metadata() ) ); //just to make sure, use the mapping Session s; @@ -532,7 +532,12 @@ public class EmbeddedTest extends BaseCoreFunctionalTestCase { CorpType.class, Nationality.class, Manager.class, - FavoriteThings.class + FavoriteThings.class, + Address.class, + Country.class, + InternetFavorites.class, + FixedLeg.class, + FloatLeg.class }; } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/InternetFavorites.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/InternetFavorites.java index f018512d4e..03956da79c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/InternetFavorites.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/InternetFavorites.java @@ -1,15 +1,13 @@ package org.hibernate.test.annotations.embedded; import java.util.Collection; + import javax.persistence.Embeddable; -import javax.persistence.Embedded; @Embeddable public class InternetFavorites { - @Embedded Collection links; - @Embedded Collection ideas; public Collection getIdeas() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/NewCustomEntityMappingAnnotationsTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/NewCustomEntityMappingAnnotationsTest.java index dbface1877..52b9fce443 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/NewCustomEntityMappingAnnotationsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/entity/NewCustomEntityMappingAnnotationsTest.java @@ -48,6 +48,8 @@ public class NewCustomEntityMappingAnnotationsTest extends BaseCoreFunctionalTes @Test public void testSameMappingValues() { + // TODO: These need to use the new metamodel, but the information + // is not available in EntityBinding. RootClass forest = (RootClass) configuration().getClassMapping( Forest.class.getName() ); RootClass forest2 = (RootClass) configuration().getClassMapping( Forest2.class.getName() ); assertEquals( forest.useDynamicInsert(), forest2.useDynamicInsert() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/EnumeratedTypeTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/EnumeratedTypeTest.java index 6bd7df24ff..bf7a6bd7c9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/EnumeratedTypeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/EnumeratedTypeTest.java @@ -1,22 +1,20 @@ package org.hibernate.test.annotations.enumerated; +import static org.junit.Assert.assertEquals; + import java.io.Serializable; -import org.junit.Test; - import org.hibernate.Session; -import org.hibernate.cfg.Configuration; import org.hibernate.criterion.Restrictions; -import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.test.annotations.enumerated.EntityEnum.Common; +import org.hibernate.test.annotations.enumerated.EntityEnum.FirstLetter; +import org.hibernate.test.annotations.enumerated.EntityEnum.LastNumber; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.type.EnumType; import org.hibernate.type.Type; - -import static org.hibernate.test.annotations.enumerated.EntityEnum.Common; -import static org.hibernate.test.annotations.enumerated.EntityEnum.FirstLetter; -import static org.hibernate.test.annotations.enumerated.EntityEnum.LastNumber; -import static org.junit.Assert.assertEquals; +import org.junit.Test; /** * Test type definition for enum @@ -28,31 +26,35 @@ public class EnumeratedTypeTest extends BaseCoreFunctionalTestCase { @Test public void testTypeDefinition() { - Configuration cfg = configuration(); - PersistentClass pc = cfg.getClassMapping( EntityEnum.class.getName() ); + EntityBinding binding = getEntityBinding( EntityEnum.class ); // ordinal default of EnumType - Type ordinalEnum = pc.getProperty( "ordinal" ).getType(); + Type ordinalEnum = binding.locateAttributeBinding( "ordinal" ) + .getHibernateTypeDescriptor().getResolvedTypeMapping(); assertEquals( Common.class, ordinalEnum.getReturnedClass() ); assertEquals( EnumType.class.getName(), ordinalEnum.getName() ); // string defined by Enumerated(STRING) - Type stringEnum = pc.getProperty( "string" ).getType(); + Type stringEnum = binding.locateAttributeBinding( "string" ) + .getHibernateTypeDescriptor().getResolvedTypeMapping(); assertEquals( Common.class, stringEnum.getReturnedClass() ); assertEquals( EnumType.class.getName(), stringEnum.getName() ); // explicit defined by @Type - Type first = pc.getProperty( "firstLetter" ).getType(); + Type first = binding.locateAttributeBinding( "firstLetter" ) + .getHibernateTypeDescriptor().getResolvedTypeMapping(); assertEquals( FirstLetter.class, first.getReturnedClass() ); assertEquals( FirstLetterType.class.getName(), first.getName() ); // implicit defined by @TypeDef in somewhere - Type last = pc.getProperty( "lastNumber" ).getType(); + Type last = binding.locateAttributeBinding( "lastNumber" ) + .getHibernateTypeDescriptor().getResolvedTypeMapping(); assertEquals( LastNumber.class, last.getReturnedClass() ); assertEquals( LastNumberType.class.getName(), last.getName() ); // implicit defined by @TypeDef in anywhere, but overrided by Enumerated(STRING) - Type implicitOverrideExplicit = pc.getProperty( "explicitOverridingImplicit" ).getType(); + Type implicitOverrideExplicit = binding.locateAttributeBinding( "explicitOverridingImplicit" ) + .getHibernateTypeDescriptor().getResolvedTypeMapping(); assertEquals( LastNumber.class, implicitOverrideExplicit.getReturnedClass() ); assertEquals( EnumType.class.getName(), implicitOverrideExplicit.getName() ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdTest.java index 96fa560e3f..ae5ddeb492 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdTest.java @@ -23,11 +23,12 @@ */ package org.hibernate.test.annotations.id; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import org.hibernate.Session; import org.hibernate.Transaction; -import org.hibernate.mapping.Column; +import org.hibernate.metamodel.spi.relational.Column; import org.hibernate.test.annotations.id.entities.Ball; import org.hibernate.test.annotations.id.entities.BreakDance; import org.hibernate.test.annotations.id.entities.Computer; @@ -45,11 +46,10 @@ import org.hibernate.test.annotations.id.entities.Shoe; import org.hibernate.test.annotations.id.entities.SoundSystem; import org.hibernate.test.annotations.id.entities.Store; import org.hibernate.test.annotations.id.entities.Tree; +import org.hibernate.test.util.SchemaUtil; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import org.junit.Test; /** * @author Emmanuel Bernard @@ -289,9 +289,9 @@ public class IdTest extends BaseCoreFunctionalTestCase { @Test public void testColumnDefinition() { - Column idCol = (Column) configuration().getClassMapping(Ball.class.getName()) - .getIdentifierProperty().getValue().getColumnIterator().next(); - assertEquals( "ball_id", idCol.getName() ); + Column idCol = SchemaUtil.getIndexes( Ball.class, metadata() ) + .next().getColumns().get( 0 ); + assertEquals( "ball_id", idCol.getColumnName().getText() ); } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java index a2e7adb7d6..68643e9067 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java @@ -23,11 +23,12 @@ */ package org.hibernate.test.annotations.id.sequences; -import org.junit.Test; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; import org.hibernate.Session; import org.hibernate.Transaction; -import org.hibernate.mapping.Column; +import org.hibernate.metamodel.spi.relational.Column; import org.hibernate.test.annotations.id.generationmappings.DedicatedSequenceEntity1; import org.hibernate.test.annotations.id.generationmappings.DedicatedSequenceEntity2; import org.hibernate.test.annotations.id.sequences.entities.Ball; @@ -47,14 +48,13 @@ import org.hibernate.test.annotations.id.sequences.entities.Shoe; import org.hibernate.test.annotations.id.sequences.entities.SoundSystem; import org.hibernate.test.annotations.id.sequences.entities.Store; import org.hibernate.test.annotations.id.sequences.entities.Tree; +import org.hibernate.test.util.SchemaUtil; import org.hibernate.testing.DialectChecks; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; +import org.junit.Test; /** * @author Emmanuel Bernard @@ -316,9 +316,9 @@ public class IdTest extends BaseCoreFunctionalTestCase { @Test public void testColumnDefinition() { - Column idCol = ( Column ) configuration().getClassMapping( Ball.class.getName() ) - .getIdentifierProperty().getValue().getColumnIterator().next(); - assertEquals( "ball_id", idCol.getName() ); + Column idCol = SchemaUtil.getIndexes( Ball.class, metadata() ) + .next().getColumns().get( 0 ); + assertEquals( "ball_id", idCol.getColumnName().getText() ); } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java index 0f4e4d9d75..feddfc0a8d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java @@ -39,6 +39,7 @@ import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.HSQLDialect; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Column; +import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -74,6 +75,7 @@ public class IndexedCollectionTest extends BaseCoreFunctionalTestCase { } private boolean isDefaultColumnPresent(String collectionOwner, String propertyName, String suffix) { + // TODO: Use getCollectionBindings, but unsure of suffix, etc. final Collection collection = configuration().getCollectionMapping( collectionOwner + "." + propertyName ); final Iterator columnIterator = collection.getCollectionTable().getColumnIterator(); boolean hasDefault = false; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java index b69be85c6e..5e45f97631 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java @@ -50,6 +50,7 @@ import static org.junit.Assert.fail; public class JoinTest extends BaseCoreFunctionalTestCase { @Test public void testDefaultValue() throws Exception { + // TODO: How to get Joins with EntityBindings? Join join = (Join) configuration().getClassMapping( Life.class.getName() ).getJoinClosureIterator().next(); assertEquals( "ExtendedLife", join.getTable().getName() ); org.hibernate.mapping.Column owner = new org.hibernate.mapping.Column(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/lob/SerializableToBlobTypeTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/lob/SerializableToBlobTypeTest.java index bf7d267edf..8f485fb5af 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/lob/SerializableToBlobTypeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/lob/SerializableToBlobTypeTest.java @@ -3,9 +3,7 @@ package org.hibernate.test.annotations.lob; import static org.junit.Assert.assertEquals; import org.hibernate.Session; -import org.hibernate.cfg.Configuration; -import org.hibernate.mapping.PersistentClass; - +import org.hibernate.metamodel.spi.binding.EntityBinding; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.type.SerializableToBlobType; @@ -21,26 +19,29 @@ import org.junit.Test; public class SerializableToBlobTypeTest extends BaseCoreFunctionalTestCase { @Test public void testTypeDefinition() { - Configuration cfg = configuration(); - PersistentClass pc = cfg.getClassMapping( EntitySerialize.class.getName() ); - + EntityBinding binding = getEntityBinding( EntitySerialize.class ); + // explicitLob of SerializableToBlobType - Type explicitLobType = pc.getProperty( "explicitLob" ).getType(); + Type explicitLobType = binding.locateAttributeBinding( "explicitLob" ) + .getHibernateTypeDescriptor().getResolvedTypeMapping(); assertEquals( ExplicitSerializable.class, explicitLobType.getReturnedClass() ); assertEquals( SerializableToBlobType.class.getName(), explicitLobType.getName() ); // explicit of ExplicitSerializableType - Type explicitType = pc.getProperty( "explicit" ).getType(); + Type explicitType = binding.locateAttributeBinding( "explicit" ) + .getHibernateTypeDescriptor().getResolvedTypeMapping(); assertEquals( ExplicitSerializable.class, explicitType.getReturnedClass() ); assertEquals( ExplicitSerializableType.class.getName(), explicitType.getName() ); // implicit of ImplicitSerializableType - Type implicitType = pc.getProperty( "implicit" ).getType(); + Type implicitType = binding.locateAttributeBinding( "implicit" ) + .getHibernateTypeDescriptor().getResolvedTypeMapping(); assertEquals( ImplicitSerializable.class, implicitType.getReturnedClass() ); assertEquals( ImplicitSerializableType.class.getName(), implicitType.getName() ); // explicitOverridingImplicit ExplicitSerializableType overrides ImplicitSerializableType - Type overrideType = pc.getProperty( "explicitOverridingImplicit" ).getType(); + Type overrideType = binding.locateAttributeBinding( "explicitOverridingImplicit" ) + .getHibernateTypeDescriptor().getResolvedTypeMapping(); assertEquals( ImplicitSerializable.class, overrideType.getReturnedClass() ); assertEquals( ExplicitSerializableType.class.getName(), overrideType.getName() ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetomany/OneToManyTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetomany/OneToManyTest.java index dfef57543d..27877e6e1c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetomany/OneToManyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetomany/OneToManyTest.java @@ -479,6 +479,7 @@ public class OneToManyTest extends BaseCoreFunctionalTestCase { @Test @TestForIssue( jiraKey = "HHH-4605" ) public void testJoinColumnConfiguredInXml() { + // TODO: How to check joins with EntityBinding? PersistentClass pc = configuration().getClassMapping( Model.class.getName() ); Table table = pc.getRootTable(); Iterator iter = table.getColumnIterator(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java index 0f54748096..6c90c739ea 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java @@ -311,6 +311,7 @@ public class OneToOneTest extends BaseCoreFunctionalTestCase { @Test @TestForIssue( jiraKey = "HHH-4606" ) public void testJoinColumnConfiguredInXml() { + // TODO: How to check joins with EntityBinding? PersistentClass pc = configuration().getClassMapping( Son.class.getName() ); Iterator iter = pc.getJoinIterator(); Table table = ( ( Join ) iter.next() ).getTable(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideSchemaTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideSchemaTest.java index 99d1c78d5c..a35c60f34a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideSchemaTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideSchemaTest.java @@ -1,17 +1,17 @@ package org.hibernate.test.annotations.override; -import java.util.Iterator; - -import org.junit.Assert; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import org.hibernate.dialect.H2Dialect; -import org.hibernate.mapping.Table; +import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.test.util.SchemaUtil; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Assert; +import org.junit.Test; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) @@ -37,24 +37,18 @@ public class AssociationOverrideSchemaTest extends BaseCoreFunctionalTestCase { @Test public void testJoinTableSchemaName() { - Iterator tableIterator = configuration().getTableMappings(); - while ( tableIterator.hasNext() ) { - Table table = tableIterator.next(); - if ( TABLE_NAME.equals( table.getName() ) ) { - Assert.assertEquals( SCHEMA_NAME, table.getSchema() ); - return; - } - } - Assert.fail(); + TableSpecification table = SchemaUtil.getTable( TABLE_NAME, metadata() ); + assertNotNull( table ); + assertEquals( SCHEMA_NAME, table.getSchema().getName().getSchema().getText()); } @Test public void testJoinTableJoinColumnName() { - Assert.assertTrue( SchemaUtil.isColumnPresent( TABLE_NAME, ID_COLUMN_NAME, configuration() ) ); + Assert.assertTrue( SchemaUtil.isColumnPresent( TABLE_NAME, ID_COLUMN_NAME, metadata() ) ); } @Test public void testJoinTableColumnName() { - Assert.assertTrue( SchemaUtil.isColumnPresent( TABLE_NAME, VALUE_COLUMN_NAME, configuration() ) ); + Assert.assertTrue( SchemaUtil.isColumnPresent( TABLE_NAME, VALUE_COLUMN_NAME, metadata() ) ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideTest.java index d3eb935fdb..24e9c7b2ad 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AssociationOverrideTest.java @@ -1,20 +1,19 @@ package org.hibernate.test.annotations.override; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.util.ArrayList; import java.util.Collection; import java.util.List; -import org.junit.Test; - import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.test.util.SchemaUtil; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import org.junit.Test; /** * @author Emmanuel Bernard @@ -50,15 +49,15 @@ public class AssociationOverrideTest extends BaseCoreFunctionalTestCase { @Test public void testDottedNotation() throws Exception { - assertTrue( SchemaUtil.isTablePresent( "Employee", configuration() ) ); + assertTrue( SchemaUtil.isTablePresent( "Employee", metadata() ) ); assertTrue( "Overridden @JoinColumn fails", - SchemaUtil.isColumnPresent( "Employee", "fld_address_fk", configuration() ) ); + SchemaUtil.isColumnPresent( "Employee", "fld_address_fk", metadata() ) ); - assertTrue( "Overridden @JoinTable name fails", SchemaUtil.isTablePresent( "tbl_empl_sites", configuration() ) ); + assertTrue( "Overridden @JoinTable name fails", SchemaUtil.isTablePresent( "tbl_empl_sites", metadata() ) ); assertTrue( "Overridden @JoinTable with default @JoinColumn fails", - SchemaUtil.isColumnPresent( "tbl_empl_sites", "employee_id", configuration() ) ); + SchemaUtil.isColumnPresent( "tbl_empl_sites", "employee_id", metadata() ) ); assertTrue( "Overridden @JoinTable.inverseJoinColumn fails", - SchemaUtil.isColumnPresent( "tbl_empl_sites", "to_website_fk", configuration() ) ); + SchemaUtil.isColumnPresent( "tbl_empl_sites", "to_website_fk", metadata() ) ); Session s = openSession(); Transaction tx = s.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java index 8dc14b7330..8e7ff9d6c7 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/override/AttributeOverrideTest.java @@ -59,7 +59,7 @@ public class AttributeOverrideTest extends BaseCoreFunctionalTestCase { } public boolean isColumnPresent(String tableName, String columnName) { - return SchemaUtil.isColumnPresent( tableName, columnName, configuration() ); + return SchemaUtil.isColumnPresent( tableName, columnName, metadata() ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/persister/PersisterTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/persister/PersisterTest.java index 482c33a3a4..30d974d1dc 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/persister/PersisterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/persister/PersisterTest.java @@ -23,15 +23,14 @@ */ package org.hibernate.test.annotations.persister; -import org.junit.Test; +import static org.junit.Assert.assertEquals; import org.hibernate.mapping.Collection; -import org.hibernate.mapping.PersistentClass; +import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.SingleTableEntityPersister; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertEquals; +import org.junit.Test; /** * @author Shawn Clowater @@ -41,21 +40,22 @@ public class PersisterTest extends BaseCoreFunctionalTestCase { @Test public void testEntityEntityPersisterAndPersisterSpecified() throws Exception { //checks to see that the persister specified with the @Persister annotation takes precedence if a @Entity.persister() is also specified - PersistentClass persistentClass = configuration().getClassMapping( Deck.class.getName() ); - assertEquals( "Incorrect Persister class for " + persistentClass.getMappedClass(), EntityPersister.class, - persistentClass.getEntityPersisterClass() ); + Class clazz = getEntityBinding( Deck.class ).getCustomEntityPersisterClass(); + assertEquals( "Incorrect Persister class for " + Deck.class.getName(), + EntityPersister.class, clazz ); } @Test public void testEntityEntityPersisterSpecified() throws Exception { //tests the persister specified with an @Entity.persister() - PersistentClass persistentClass = configuration().getClassMapping( Card.class.getName() ); - assertEquals( "Incorrect Persister class for " + persistentClass.getMappedClass(), - SingleTableEntityPersister.class, persistentClass.getEntityPersisterClass() ); + Class clazz = getEntityBinding( Card.class ).getCustomEntityPersisterClass(); + assertEquals( "Incorrect Persister class for " + Card.class.getName(), + SingleTableEntityPersister.class, clazz ); } @Test public void testCollectionPersisterSpecified() throws Exception { + // TODO: use getCollectionBindings() //tests the persister specified by the @Persister annotation on a collection Collection collection = configuration().getCollectionMapping( Deck.class.getName() + ".cards" ); assertEquals( "Incorrect Persister class for collection " + collection.getRole(), CollectionPersister.class, diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/various/TimestampTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/various/TimestampTest.java index a5556db111..0be4fafdee 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/various/TimestampTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/various/TimestampTest.java @@ -23,49 +23,48 @@ */ package org.hibernate.test.annotations.various; -import org.junit.Test; - -import org.hibernate.mapping.PersistentClass; -import org.hibernate.mapping.Property; -import org.hibernate.metadata.ClassMetadata; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.type.DbTimestampType; -import org.hibernate.type.TimestampType; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import org.hibernate.metadata.ClassMetadata; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.type.DbTimestampType; +import org.hibernate.type.TimestampType; +import org.hibernate.type.Type; +import org.junit.Test; + /** * Test for the @Timestamp annotation. * * @author Hardy Ferentschik + * @author Brett Meyer */ public class TimestampTest extends BaseCoreFunctionalTestCase { @Test - @FailureExpectedWithNewMetamodel public void testTimestampSourceIsVM() throws Exception { assertTimestampSource( VMTimestamped.class, TimestampType.class ); } @Test - @FailureExpectedWithNewMetamodel public void testTimestampSourceIsDB() throws Exception { assertTimestampSource( DBTimestamped.class, DbTimestampType.class ); } private void assertTimestampSource(Class clazz, Class expectedTypeClass) throws Exception { - buildConfiguration(); ClassMetadata meta = sessionFactory().getClassMetadata( clazz ); assertTrue( "Entity is annotated with @Timestamp and should hence be versioned", meta.isVersioned() ); - PersistentClass persistentClass = configuration().getClassMapping( clazz.getName() ); - assertNotNull( persistentClass ); - Property versionProperty = persistentClass.getVersion(); - assertNotNull( versionProperty ); - assertEquals( "Wrong timestamp type", expectedTypeClass, versionProperty.getType().getClass() ); + EntityBinding binding = getEntityBinding( clazz ); + assertNotNull( binding ); + Type type = binding.getHierarchyDetails().getEntityVersion() + .getVersioningAttributeBinding().getHibernateTypeDescriptor() + .getResolvedTypeMapping(); + assertNotNull( type ); + assertEquals( "Wrong timestamp type", expectedTypeClass, + type.getClass() ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java index 5c98e7fcfa..c74ba902db 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/NonExistentOrmVersionTest.java @@ -23,23 +23,23 @@ */ package org.hibernate.test.annotations.xml.ejb3; -import java.io.InputStream; +import static org.junit.Assert.assertTrue; -import org.junit.Test; +import java.io.InputStream; import org.hibernate.MappingException; import org.hibernate.cfg.Configuration; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertTrue; +import org.junit.Test; @TestForIssue(jiraKey = "HHH-6271") public class NonExistentOrmVersionTest extends BaseCoreFunctionalTestCase { + @Test public void testNonExistentOrmVersion() { try { - Configuration config = buildConfiguration(); + Configuration config = configuration(); String xmlFileName = "org/hibernate/test/annotations/xml/ejb3/orm5.xml"; InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFileName ); config.addInputStream( is ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java index 0eaa992d93..3a56504d49 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java @@ -23,6 +23,10 @@ */ package org.hibernate.test.legacy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.Serializable; import java.sql.Connection; import java.sql.SQLException; @@ -32,8 +36,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; -import org.junit.Test; - import org.hibernate.Hibernate; import org.hibernate.LockMode; import org.hibernate.ObjectNotFoundException; @@ -47,14 +49,11 @@ import org.hibernate.dialect.MckoiDialect; import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.SAPDBDialect; import org.hibernate.jdbc.AbstractWork; -import org.hibernate.mapping.MetaAttribute; -import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.binding.MetaAttribute; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.SkipLog; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import org.junit.Test; @FailureExpectedWithNewMetamodel @@ -104,10 +103,10 @@ public class MasterDetailTest extends LegacyTestCase { @Test public void testMeta() throws Exception { - PersistentClass clazz = configuration().getClassMapping( Master.class.getName() ); - MetaAttribute meta = clazz.getMetaAttribute("foo"); + EntityBinding binding = getEntityBinding( Master.class ); + MetaAttribute meta = binding.getMetaAttributeContext().getMetaAttribute("foo"); assertTrue( "foo".equals( meta.getValue() ) ); - meta = clazz.getProperty("name").getMetaAttribute("bar"); + meta = binding.getMetaAttributeContext().getMetaAttribute("bar"); assertTrue( meta.isMultiValued() ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/propertyref/basic/PropertyRefTest.java b/hibernate-core/src/test/java/org/hibernate/test/propertyref/basic/PropertyRefTest.java index ee82b58f67..b7df999ed4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/propertyref/basic/PropertyRefTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/propertyref/basic/PropertyRefTest.java @@ -23,11 +23,16 @@ */ package org.hibernate.test.propertyref.basic; +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; + import java.util.Iterator; import java.util.List; -import org.junit.Test; - import org.hibernate.FetchMode; import org.hibernate.Hibernate; import org.hibernate.Session; @@ -36,16 +41,11 @@ import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.mapping.Column; import org.hibernate.mapping.ForeignKey; -import org.hibernate.mapping.PersistentClass; +import org.hibernate.metamodel.spi.relational.TableSpecification; +import org.hibernate.test.util.SchemaUtil; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -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; +import org.junit.Test; /** * @author Gavin King @@ -273,9 +273,9 @@ public class PropertyRefTest extends BaseCoreFunctionalTestCase { @Test public void testForeignKeyCreation() { - PersistentClass classMapping = configuration().getClassMapping("org.hibernate.test.propertyref.basic.Account"); + TableSpecification table = SchemaUtil.getTable( Account.class, metadata() ); - Iterator foreignKeyIterator = classMapping.getTable().getForeignKeyIterator(); + Iterator foreignKeyIterator = table.getForeignKeys().iterator(); boolean found = false; while ( foreignKeyIterator.hasNext() ) { ForeignKey element = (ForeignKey) foreignKeyIterator.next(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/util/SchemaUtil.java b/hibernate-core/src/test/java/org/hibernate/test/util/SchemaUtil.java index 9793846b13..6c231b1972 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/util/SchemaUtil.java +++ b/hibernate-core/src/test/java/org/hibernate/test/util/SchemaUtil.java @@ -22,43 +22,67 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.test.util; + import java.util.Iterator; -import org.hibernate.cfg.Configuration; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Table; +import org.hibernate.AssertionFailure; +import org.hibernate.metamodel.Metadata; +import org.hibernate.metamodel.spi.binding.EntityBinding; +import org.hibernate.metamodel.spi.relational.Column; +import org.hibernate.metamodel.spi.relational.Index; +import org.hibernate.metamodel.spi.relational.TableSpecification; /** * Check that the Hibernate metamodel contains some database objects * - * @author Emmanuel Bernard + * @author Brett Meyer */ public abstract class SchemaUtil { - public static boolean isColumnPresent(String tableName, String columnName, Configuration cfg) { - final Iterator
tables = ( Iterator
) cfg.getTableMappings(); - while (tables.hasNext()) { - Table table = tables.next(); - if (tableName.equals( table.getName() ) ) { - Iterator columns = (Iterator) table.getColumnIterator(); - while ( columns.hasNext() ) { - Column column = columns.next(); - if ( columnName.equals( column.getName() ) ) { - return true; - } - } - } + + public static boolean isColumnPresent( + String tableName, String columnName, Metadata metadata ) { + try { + TableSpecification table = getTable( tableName, metadata ); + return ( table.locateColumn( columnName ) == null ) ? false : true; + } catch ( AssertionFailure e ) { + return false; } - return false; } - public static boolean isTablePresent(String tableName, Configuration cfg) { - final Iterator
tables = ( Iterator
) cfg.getTableMappings(); - while (tables.hasNext()) { - Table table = tables.next(); - if (tableName.equals( table.getName() ) ) { - return true; - } + public static boolean isTablePresent( String tableName, Metadata metadata ) { + try { + TableSpecification table = getTable( tableName, metadata ); + return ( table == null ) ? false : true; + } catch ( AssertionFailure e ) { + return false; } - return false; + } + + public static TableSpecification getTable( + Class entityClass, Metadata metadata ) throws AssertionFailure { + final EntityBinding binding = metadata.getEntityBinding( + entityClass.getName() ); + return binding.getPrimaryTable(); + } + + public static TableSpecification getTable( + String tableName, Metadata metadata ) throws AssertionFailure { + final EntityBinding binding = metadata.getEntityBinding( tableName ); + return binding.locateTable( tableName ); + } + + public static Column getColumn( Class entityClass, String columnName, + Metadata metadata ) throws AssertionFailure { + return getTable( entityClass, metadata ).locateColumn( columnName ); + } + + public static Column getColumn( String tableName, String columnName, + Metadata metadata ) throws AssertionFailure { + return getTable( tableName, metadata ).locateColumn( columnName ); + } + + public static Iterator getIndexes( Class entityClass, + Metadata metadata ) throws AssertionFailure { + return getTable( entityClass, metadata ).getIndexes().iterator(); } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java index 86928b054e..0a0f06bf66 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java @@ -23,6 +23,8 @@ */ package org.hibernate.testing.junit4; +import static org.junit.Assert.fail; + import java.io.InputStream; import java.sql.Blob; import java.sql.Clob; @@ -65,26 +67,22 @@ import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.Caching; import org.hibernate.metamodel.spi.binding.EntityBinding; -import org.hibernate.type.Type; - -import org.junit.After; -import org.junit.Before; - +import org.hibernate.metamodel.spi.binding.PluralAttributeBinding; import org.hibernate.testing.AfterClassOnce; import org.hibernate.testing.BeforeClassOnce; import org.hibernate.testing.OnExpectedFailure; import org.hibernate.testing.OnFailure; import org.hibernate.testing.SkipLog; import org.hibernate.testing.cache.CachingRegionFactory; - -import static org.junit.Assert.fail; +import org.hibernate.type.Type; +import org.junit.After; +import org.junit.Before; /** * Applies functional testing logic for core Hibernate testing on top of {@link BaseUnitTestCase} * * @author Steve Ebersole */ -@SuppressWarnings( {"deprecation"} ) public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { public static final String VALIDATE_DATA_CLEANUP = "hibernate.test.validateDataCleanup"; public static final String USE_NEW_METADATA_MAPPINGS = "hibernate.test.new_metadata_mappings"; @@ -93,6 +91,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { private boolean isMetadataUsed; private Configuration configuration; + private MetadataImplementor metadataImplementor; private StandardServiceRegistryImpl serviceRegistry; private SessionFactoryImplementor sessionFactory; @@ -106,6 +105,22 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { return configuration; } + protected MetadataImplementor metadata() { + return metadataImplementor; + } + + protected EntityBinding getEntityBinding(Class clazz) { + return metadataImplementor.getEntityBinding( clazz.getName() ); + } + + protected EntityBinding getRootEntityBinding(Class clazz) { + return metadataImplementor.getRootEntityBinding( clazz.getName() ); + } + + protected Iterator getCollectionBindings() { + return metadataImplementor.getCollectionBindings().iterator(); + } + protected StandardServiceRegistryImpl serviceRegistry() { return serviceRegistry; } @@ -145,7 +160,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { true ); if ( isMetadataUsed ) { - MetadataImplementor metadataImplementor = buildMetadata( bootRegistry, serviceRegistry ); + metadataImplementor = buildMetadata( bootRegistry, serviceRegistry ); afterConstructAndConfigureMetadata( metadataImplementor ); applyCacheSettings(metadataImplementor); sessionFactory = ( SessionFactoryImplementor ) metadataImplementor.buildSessionFactory(); @@ -178,13 +193,6 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { return (MetadataImplementor) sources.getMetadataBuilder( serviceRegistry ).build(); } - // TODO: is this still needed? - protected Configuration buildConfiguration() { - Configuration cfg = constructAndConfigureConfiguration(); - afterConstructAndConfigureConfiguration( cfg ); - return cfg; - } - private Configuration constructAndConfigureConfiguration() { Configuration cfg = constructConfiguration(); configure( cfg );