HHH-9633 - Add tests that explicitly test the "main" NamingStrategy impls

This commit is contained in:
Steve Ebersole 2015-03-05 17:15:49 -06:00
parent fa157745b2
commit 9e84c1fa23
7 changed files with 144 additions and 3 deletions

View File

@ -33,6 +33,7 @@ public abstract class BaseAnnotationBindingTests extends BaseNamingTests {
protected void applyFixtures(Configuration cfg) {
cfg.addAnnotatedClass( Address.class )
.addAnnotatedClass( Customer.class )
.addAnnotatedClass( Industry.class )
.addAnnotatedClass( Order.class )
.addAnnotatedClass( ZipCode.class );
}

View File

@ -57,6 +57,7 @@ public abstract class BaseNamingTests extends BaseUnitTestCase {
validateCustomerRegisteredTrademarks( cfg );
validateCustomerAddresses( cfg );
validateCustomerOrders( cfg );
validateCustomerIndustries( cfg );
}
protected abstract void applyFixtures(Configuration cfg);
@ -238,4 +239,23 @@ public abstract class BaseNamingTests extends BaseUnitTestCase {
protected abstract void validateCustomerOrdersKeyColumn(Column column);
protected abstract void validateCustomerOrdersElementColumn(Column column);
protected void validateCustomerIndustries(Configuration cfg) {
final Collection collectionBinding = cfg.getCollectionMapping( Customer.class.getName() + ".industries" );
assertNotNull( collectionBinding );
validateCustomerIndustriesTableName( collectionBinding.getCollectionTable().getQuotedName() );
assertEquals( 1, collectionBinding.getKey().getColumnSpan() );
validateCustomerIndustriesKeyColumn( (Column) collectionBinding.getKey().getColumnIterator().next() );
assertEquals( 1, collectionBinding.getElement().getColumnSpan() );
validateCustomerIndustriesElementColumn( (Column) collectionBinding.getElement().getColumnIterator().next() );
}
protected abstract void validateCustomerIndustriesTableName(String name);
protected abstract void validateCustomerIndustriesKeyColumn(Column column);
protected abstract void validateCustomerIndustriesElementColumn(Column column);
}

View File

@ -31,13 +31,15 @@ import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.persistence.Version;
/**
* @author Steve Ebersole
*/
@Entity
@Entity( name="CuStOmEr" )
public class Customer {
private Integer id;
private Integer version;
@ -49,6 +51,8 @@ public class Customer {
private List<Order> orders;
private Set<Industry> industries;
@Id
@GeneratedValue
public Integer getId() {
@ -106,6 +110,7 @@ public class Customer {
}
@OneToMany( mappedBy = "customer" )
@OrderColumn
public List<Order> getOrders() {
return orders;
}
@ -113,4 +118,13 @@ public class Customer {
public void setOrders(List<Order> orders) {
this.orders = orders;
}
@ManyToMany
public Set<Industry> getIndustries() {
return industries;
}
public void setIndustries(Set<Industry> industries) {
this.industries = industries;
}
}

View File

@ -0,0 +1,57 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2015, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.namingstrategy.complete;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
* @author Steve Ebersole
*/
@Entity( name = "InDuStRy" )
public class Industry {
private Integer id;
private String name;
@Id
@GeneratedValue
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Basic
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -27,26 +27,30 @@ import java.util.Iterator;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.EJB3NamingStrategy;
import org.hibernate.cfg.naming.LegacyNamingStrategyDelegator;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.Selectable;
import org.hibernate.testing.TestForIssue;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertEquals;
/**
* @author Steve Ebersole
*/
@TestForIssue( jiraKey = "HHH-9633" )
public class LegacyJpaNamingWithAnnotationBindingTests extends BaseAnnotationBindingTests {
@Override
protected void applyFixtures(Configuration cfg) {
cfg.setNamingStrategy( EJB3NamingStrategy.INSTANCE );
cfg.setNamingStrategyDelegator( new LegacyNamingStrategyDelegator( EJB3NamingStrategy.INSTANCE ) );
super.applyFixtures( cfg );
}
@Override
protected void validateCustomerPrimaryTableName(String name) {
assertEquals( "Customer", name );
assertEquals( "CuStOmEr", name );
}
@Override
@ -198,4 +202,19 @@ public class LegacyJpaNamingWithAnnotationBindingTests extends BaseAnnotationBin
protected void validateCustomerOrdersElementColumn(Column column) {
assertEquals( "id", column.getQuotedName() );
}
@Override
protected void validateCustomerIndustriesTableName(String name) {
assertEquals( "CuStOmEr_InDuStRy", name );
}
@Override
protected void validateCustomerIndustriesKeyColumn(Column column) {
assertEquals( "CuStOmEr_id", column.getQuotedName() );
}
@Override
protected void validateCustomerIndustriesElementColumn(Column column) {
assertEquals( "industries_id", column.getQuotedName() );
}
}

View File

@ -31,6 +31,8 @@ import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.Selectable;
import org.hibernate.testing.TestForIssue;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertEquals;
@ -40,6 +42,7 @@ import static org.junit.Assert.assertEquals;
*
* @author Steve Ebersole
*/
@TestForIssue( jiraKey = "HHH-9633" )
public class LegacyJpaNamingWithHbmBindingTests extends BaseHbmBindingTests {
@Override
protected void applyFixtures(Configuration cfg) {
@ -201,4 +204,19 @@ public class LegacyJpaNamingWithHbmBindingTests extends BaseHbmBindingTests {
protected void validateCustomerOrdersElementColumn(Column column) {
assertEquals( "id", column.getQuotedName() );
}
@Override
protected void validateCustomerIndustriesTableName(String name) {
assertEquals( "Customer_industries", name );
}
@Override
protected void validateCustomerIndustriesKeyColumn(Column column) {
assertEquals( "id", column.getQuotedName() );
}
@Override
protected void validateCustomerIndustriesElementColumn(Column column) {
assertEquals( "elt", column.getQuotedName() );
}
}

View File

@ -58,6 +58,18 @@
<key/>
<one-to-many class="Order"/>
</set>
<set name="industries">
<key/>
<many-to-many class="Industry"/>
</set>
</class>
<class name="Industry">
<id name="id">
<generator class="increment"/>
</id>
<property name="name"/>
</class>
<class name="Order">