Author: epbernard
Date: 2009-08-12 18:51:01 -0400 (Wed, 12 Aug 2009)
New Revision: 17275
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/House.java
Modified:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
Log:
EJB-456 add more tests
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/House.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/House.java
(rev 0)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/House.java 2009-08-12
22:51:01 UTC (rev 17275)
@@ -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;
+ }
+ }
+}
Modified:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
===================================================================
---
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2009-08-12
14:55:01 UTC (rev 17274)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2009-08-12
22:51:01 UTC (rev 17275)
@@ -6,6 +6,7 @@
import javax.persistence.metamodel.Bindable;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.Type;
+import javax.persistence.metamodel.Attribute;
import org.hibernate.ejb.test.TestCase;
@@ -37,7 +38,13 @@
assertFalse( fridgeType.hasVersionAttribute() );
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
);
assertFalse( personType.hasSingleIdAttribute() );
final Set<SingularAttribute<? super Person,?>> ids =
personType.getIdClassAttributes();
@@ -63,17 +70,39 @@
);
assertEquals( Integer.class, singularAttribute.getBindableJavaType() );
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 plural
- }
@Override
public Class[] getAnnotatedClasses() {
return new Class[]{
Fridge.class,
FoodItem.class,
- Person.class
+ Person.class,
+ House.class
};
}
Show replies by date