HHH-7666 Replace unit tests' use of configuration()
This commit is contained in:
parent
b88b32382f
commit
f3a8760d22
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<PluralAttributeBinding> 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 );
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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( );
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<URLFavorite> links;
|
||||
|
||||
@Embedded
|
||||
Collection<String> ideas;
|
||||
|
||||
public Collection<String> getIdeas() {
|
||||
|
|
|
@ -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() );
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<Table> 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() ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<? extends EntityPersister> 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<? extends EntityPersister> 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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<Table> tables = ( Iterator<Table> ) cfg.getTableMappings();
|
||||
while (tables.hasNext()) {
|
||||
Table table = tables.next();
|
||||
if (tableName.equals( table.getName() ) ) {
|
||||
Iterator<Column> columns = (Iterator<Column>) 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<Table> tables = ( Iterator<Table> ) 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<Index> getIndexes( Class<?> entityClass,
|
||||
Metadata metadata ) throws AssertionFailure {
|
||||
return getTable( entityClass, metadata ).getIndexes().iterator();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<PluralAttributeBinding> 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 );
|
||||
|
|
Loading…
Reference in New Issue