EJB-456 add more tests

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@17275 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2009-08-12 22:51:01 +00:00
parent e44e8c6d6a
commit 93cef4f9f1
2 changed files with 75 additions and 3 deletions

View File

@ -0,0 +1,43 @@
package org.hibernate.ejb.test.metadata;
import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
/**
* @author Emmanuel Bernard
*/
@Entity
public class House {
private Key key;
private String address1;
@EmbeddedId
public Key getKey() {
return key;
}
public void setKey(Key key) {
this.key = key;
}
public String getAddress1() {
return address1;
}
public void setAddress1(String address1) {
this.address1 = address1;
}
public static class Key implements Serializable {
private String uuid;
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}
}

View File

@ -6,6 +6,7 @@ import javax.persistence.metamodel.EntityType;
import javax.persistence.metamodel.Bindable; import javax.persistence.metamodel.Bindable;
import javax.persistence.metamodel.SingularAttribute; import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.Type; import javax.persistence.metamodel.Type;
import javax.persistence.metamodel.Attribute;
import org.hibernate.ejb.test.TestCase; import org.hibernate.ejb.test.TestCase;
@ -37,7 +38,13 @@ public class MetadataTest extends TestCase {
assertFalse( fridgeType.hasVersionAttribute() ); assertFalse( fridgeType.hasVersionAttribute() );
assertEquals( Type.PersistenceType.ENTITY, fridgeType.getPersistenceType() ); assertEquals( Type.PersistenceType.ENTITY, fridgeType.getPersistenceType() );
//TODO IdClass final EntityType<House> houseType = factory.getMetamodel().entity( House.class );
assertTrue( houseType.hasSingleIdAttribute() );
final SingularAttribute<House, House.Key> houseId = houseType.getDeclaredId( House.Key.class );
assertNotNull( houseId );
assertTrue( houseId.isId() );
assertEquals( Attribute.PersistentAttributeType.EMBEDDED, houseId.getPersistentAttributeType() );
final EntityType<Person> personType = factory.getMetamodel().entity( Person.class ); final EntityType<Person> personType = factory.getMetamodel().entity( Person.class );
assertFalse( personType.hasSingleIdAttribute() ); assertFalse( personType.hasSingleIdAttribute() );
final Set<SingularAttribute<? super Person,?>> ids = personType.getIdClassAttributes(); final Set<SingularAttribute<? super Person,?>> ids = personType.getIdClassAttributes();
@ -63,17 +70,39 @@ public class MetadataTest extends TestCase {
); );
assertEquals( Integer.class, singularAttribute.getBindableJavaType() ); assertEquals( Integer.class, singularAttribute.getBindableJavaType() );
assertEquals( Bindable.BindableType.SINGULAR_ATTRIBUTE, singularAttribute.getBindableType() ); assertEquals( Bindable.BindableType.SINGULAR_ATTRIBUTE, singularAttribute.getBindableType() );
assertFalse( singularAttribute.isId() );
assertFalse( singularAttribute.isOptional() );
assertEquals( Integer.class, singularAttribute.getType().getJavaType() );
final Attribute<? super Fridge, ?> attribute = entityType.getDeclaredAttribute( "temperature" );
assertNotNull( attribute );
assertEquals( "temperature", attribute.getName() );
assertEquals( Fridge.class, attribute.getDeclaringType().getJavaType() );
assertEquals( Attribute.PersistentAttributeType.BASIC, attribute.getPersistentAttributeType() );
assertEquals( Integer.class, attribute.getJavaType() );
assertFalse( attribute.isAssociation() );
assertFalse( attribute.isCollection() );
boolean found = false;
for (Attribute<Fridge, ?> attr : entityType.getDeclaredAttributes() ) {
if ("temperature".equals( attr.getName() ) ) {
found = true;
break;
}
}
assertTrue( found );
}
//TODO test embedded //TODO test embedded
//todo test plural //todo test plural
}
@Override @Override
public Class[] getAnnotatedClasses() { public Class[] getAnnotatedClasses() {
return new Class[]{ return new Class[]{
Fridge.class, Fridge.class,
FoodItem.class, FoodItem.class,
Person.class Person.class,
House.class
}; };
} }