Moving xml mapping files into resources folder. Creating subpackages for some tests

This commit is contained in:
Hardy Ferentschik 2012-07-23 17:02:43 +02:00
parent 58b5b7038b
commit 72af04524a
14 changed files with 54 additions and 79 deletions

View File

@ -35,17 +35,17 @@
* @author Gail Badner
*/
@Entity
public class EntityWithUnidirectionalManyToManys {
public class EntityWithUnidirectionalManyToMany {
private Long id;
private String name;
private Collection<SimpleEntity> theBag = new ArrayList<SimpleEntity>();
private Set<SimpleEntity> theSet = new HashSet<SimpleEntity>();
private Collection<SimpleEntity> thePropertyRefBag = new ArrayList<SimpleEntity>();
public EntityWithUnidirectionalManyToManys() {
public EntityWithUnidirectionalManyToMany() {
}
public EntityWithUnidirectionalManyToManys(String name) {
public EntityWithUnidirectionalManyToMany(String name) {
this.name = name;
}

View File

@ -23,35 +23,23 @@
*/
package org.hibernate.metamodel.spi.binding;
import java.util.Collection;
import java.util.Set;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.engine.FetchTiming;
import org.hibernate.metamodel.MetadataSourceProcessingOrder;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.internal.MetadataImpl;
import org.hibernate.metamodel.spi.binding.EntityWithUnidirectionalManyToMany;
import org.hibernate.metamodel.spi.relational.Column;
import org.hibernate.metamodel.spi.relational.ForeignKey;
import org.hibernate.metamodel.spi.relational.Identifier;
import org.hibernate.metamodel.spi.relational.Value;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.StandardServiceRegistryImpl;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.type.BagType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.SetType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* @author Gail Badner
@ -86,7 +74,7 @@ private void doTest(MetadataSourceProcessingOrder processingOrder) {
sources.addResource( "org/hibernate/metamodel/spi/binding/SimpleEntity.hbm.xml" );
MetadataImpl metadata = (MetadataImpl) sources.getMetadataBuilder().with( processingOrder ).buildMetadata();
final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithUnidirectionalManyToManys.class.getName() );
final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithUnidirectionalManyToMany.class.getName() );
final EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() );
assertNotNull( entityBinding );

View File

@ -1,27 +1,4 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2012, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.spi.binding;
package org.hibernate.metamodel.spi.binding.onetomany;
import java.util.ArrayList;
import java.util.Collection;
@ -34,11 +11,13 @@
import javax.persistence.Id;
import javax.persistence.OneToMany;
import org.hibernate.metamodel.spi.binding.SimpleEntity;
/**
* @author Gail Badner
*/
@Entity
public class EntityWithUnidirectionalOneToManys {
public class EntityWithUnidirectionalOneToMany {
private Long id;
private String name;
private Collection<SimpleEntity> theBag = new ArrayList<SimpleEntity>();
@ -47,13 +26,6 @@ public class EntityWithUnidirectionalOneToManys {
private Map<String, SimpleEntity> theMap = new HashMap<String, SimpleEntity>();
private Collection<SimpleEntity> thePropertyRefBag = new ArrayList<SimpleEntity>();
public EntityWithUnidirectionalOneToManys() {
}
public EntityWithUnidirectionalOneToManys(String name) {
this.name = name;
}
@Id
public Long getId() {
return id;
@ -116,3 +88,5 @@ public void setThePropertyRefSet(Set<SimpleEntity> thePropertyRefSet) {
this.thePropertyRefBag = thePropertyRefSet;
}
}

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.spi.binding;
package org.hibernate.metamodel.spi.binding.onetomany;
import java.util.Collection;
import java.util.List;
@ -29,6 +29,7 @@
import java.util.Set;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -36,6 +37,13 @@
import org.hibernate.metamodel.MetadataSourceProcessingOrder;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.internal.MetadataImpl;
import org.hibernate.metamodel.spi.binding.EntityBinding;
import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor;
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
import org.hibernate.metamodel.spi.binding.PluralAttributeElementNature;
import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding;
import org.hibernate.metamodel.spi.binding.SimpleEntity;
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
import org.hibernate.metamodel.spi.relational.Column;
import org.hibernate.metamodel.spi.relational.ForeignKey;
import org.hibernate.metamodel.spi.relational.Identifier;
@ -85,22 +93,25 @@ public void testHbm() {
private void doTest(MetadataSourceProcessingOrder processingOrder) {
MetadataSources sources = new MetadataSources( serviceRegistry );
// sources.addAnnotatedClass( EntityWithBasicCollections.class );
sources.addResource( "org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalOneToManys.hbm.xml" );
sources.addResource( "org/hibernate/metamodel/spi/binding/onetomany/EntityWithUnidirectionalOneToMany.hbm.xml" );
sources.addResource( "org/hibernate/metamodel/spi/binding/SimpleEntity.hbm.xml" );
MetadataImpl metadata = ( MetadataImpl ) sources.getMetadataBuilder().with( processingOrder ).buildMetadata();
final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithUnidirectionalOneToManys.class.getName() );
final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithUnidirectionalOneToMany.class.getName() );
final EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() );
assertNotNull( entityBinding );
assertEquals( Identifier.toIdentifier( "SimpleEntity" ), simpleEntityBinding.getPrimaryTable().getLogicalName() );
assertEquals(
Identifier.toIdentifier( "SimpleEntity" ),
simpleEntityBinding.getPrimaryTable().getLogicalName()
);
assertEquals( 1, simpleEntityBinding.getPrimaryTable().getPrimaryKey().getColumnSpan() );
Column simpleEntityIdColumn = simpleEntityBinding.getPrimaryTable().getPrimaryKey().getColumns().get( 0 );
assertEquals( Identifier.toIdentifier( "id" ), simpleEntityIdColumn.getColumnName() );
checkResult(
entityBinding,
metadata.getCollection( EntityWithUnidirectionalOneToManys.class.getName() + ".theBag" ),
metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".theBag" ),
BagType.class,
Collection.class,
simpleEntityBinding,
@ -112,7 +123,7 @@ private void doTest(MetadataSourceProcessingOrder processingOrder) {
checkResult(
entityBinding,
metadata.getCollection( EntityWithUnidirectionalOneToManys.class.getName() + ".theSet" ),
metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".theSet" ),
SetType.class,
Set.class,
simpleEntityBinding,
@ -124,7 +135,7 @@ private void doTest(MetadataSourceProcessingOrder processingOrder) {
checkResult(
entityBinding,
metadata.getCollection( EntityWithUnidirectionalOneToManys.class.getName() + ".theList" ),
metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".theList" ),
ListType.class,
List.class,
simpleEntityBinding,
@ -136,7 +147,7 @@ private void doTest(MetadataSourceProcessingOrder processingOrder) {
checkResult(
entityBinding,
metadata.getCollection( EntityWithUnidirectionalOneToManys.class.getName() + ".theMap" ),
metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".theMap" ),
MapType.class,
Map.class,
simpleEntityBinding,
@ -148,7 +159,7 @@ private void doTest(MetadataSourceProcessingOrder processingOrder) {
checkResult(
entityBinding,
metadata.getCollection( EntityWithUnidirectionalOneToManys.class.getName() + ".thePropertyRefBag" ),
metadata.getCollection( EntityWithUnidirectionalOneToMany.class.getName() + ".thePropertyRefBag" ),
BagType.class,
Collection.class,
simpleEntityBinding,
@ -169,11 +180,14 @@ private <X extends CollectionType> void checkResult(
Identifier expectedKeySourceColumnName,
FetchTiming expectedFetchTiming,
boolean expectedNullableCollectionKey) {
assertEquals(
Assert.assertEquals(
PluralAttributeElementNature.ONE_TO_MANY,
collectionBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature()
);
assertSame( collectionBinding, collectionOwnerBinding.locateAttributeBinding( collectionBinding.getAttribute().getName() ) );
assertSame(
collectionBinding,
collectionOwnerBinding.locateAttributeBinding( collectionBinding.getAttribute().getName() )
);
assertEquals( expectedFetchTiming, collectionBinding.getFetchTiming() );
assertEquals( expectedFetchTiming != FetchTiming.IMMEDIATE, collectionBinding.isLazy() );

View File

@ -4,7 +4,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<class name="SimpleEntity">
<id name="id">
<generator class="increment"/>
</id>

View File

@ -1,35 +1,35 @@
<?xml version="1.0"?>
<hibernate-mapping package="org.hibernate.metamodel.spi.binding"
<hibernate-mapping package="org.hibernate.metamodel.spi.binding.onetomany"
xmlns="http://www.hibernate.org/xsd/hibernate-mapping"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping hibernate-mapping-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<class name="EntityWithUnidirectionalOneToManys">
<class name="EntityWithUnidirectionalOneToMany">
<id name="id">
<generator class="increment"/>
</id>
<property name="name"/>
<bag name="theBag">
<key column="theBagOwner"/>
<one-to-many class="SimpleEntity"/>
<one-to-many class="org.hibernate.metamodel.spi.binding.SimpleEntity"/>
</bag>
<set name="theSet" lazy="false">
<key column="theSetOwner" not-null="true"/>
<one-to-many class="SimpleEntity"/>
<one-to-many class="org.hibernate.metamodel.spi.binding.SimpleEntity"/>
</set>
<list name="theList" lazy="false">
<key column="theListOwner" not-null="true"/>
<list-index column="list_index"/>
<one-to-many class="SimpleEntity"/>
<one-to-many class="org.hibernate.metamodel.spi.binding.SimpleEntity"/>
</list>
<map name="theMap">
<key column="theMapOwner" not-null="true"/>
<map-key column="map_key" type="string"/>
<one-to-many class="SimpleEntity"/>
<one-to-many class="org.hibernate.metamodel.spi.binding.SimpleEntity"/>
</map>
<bag name="thePropertyRefBag" lazy="extra">
<key column="ownerName" property-ref="name" not-null="true"/>
<one-to-many class="SimpleEntity"/>
<one-to-many class="org.hibernate.metamodel.spi.binding.SimpleEntity"/>
</bag>
</class>