From 174d09e34b139d7fb7b6284d892f34275fa8ccdb Mon Sep 17 00:00:00 2001 From: Emmanuel Bernard Date: Mon, 10 Aug 2009 03:59:59 +0000 Subject: [PATCH] EJB-456 start core of tests git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@17255 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../hibernate/ejb/test/metadata/FoodItem.java | 31 +++++++++++++ .../hibernate/ejb/test/metadata/Fridge.java | 43 +++++++++++++++++ .../ejb/test/metadata/MetadataTest.java | 46 +++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 entitymanager/src/test/java/org/hibernate/ejb/test/metadata/FoodItem.java create mode 100644 entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Fridge.java create mode 100644 entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/FoodItem.java b/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/FoodItem.java new file mode 100644 index 0000000000..45593f066f --- /dev/null +++ b/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/FoodItem.java @@ -0,0 +1,31 @@ +package org.hibernate.ejb.test.metadata; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.GeneratedValue; + +/** + * @author Emmanuel Bernard + */ +@Entity +public class FoodItem { + private Long id; + private String name; + + @Id @GeneratedValue + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Fridge.java b/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Fridge.java new file mode 100644 index 0000000000..e79cf76067 --- /dev/null +++ b/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Fridge.java @@ -0,0 +1,43 @@ +package org.hibernate.ejb.test.metadata; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.GeneratedValue; + +/** + * @author Emmanuel Bernard + */ +@Entity +public class Fridge { + private Long id; + private String brand; + private int temperature; + //dimensions + + @Id + @GeneratedValue + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + public int getTemperature() { + return temperature; + } + + public void setTemperature(int temperature) { + this.temperature = temperature; + } +} + diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java b/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java new file mode 100644 index 0000000000..003d28e60c --- /dev/null +++ b/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java @@ -0,0 +1,46 @@ +package org.hibernate.ejb.test.metadata; + +import javax.persistence.EntityManagerFactory; +import javax.persistence.metamodel.EntityType; +import javax.persistence.metamodel.Bindable; +import javax.persistence.metamodel.SingularAttribute; + +import org.hibernate.ejb.test.TestCase; + +/** + * @author Emmanuel Bernard + */ +public class MetadataTest extends TestCase { + + public void testBaseOfService() throws Exception { + EntityManagerFactory emf = factory; + assertNotNull( emf.getMetamodel() ); + final EntityType entityType = emf.getMetamodel().entity( Fridge.class ); + assertNotNull( entityType ); + } + + public void testBindable() throws Exception { + EntityManagerFactory emf = factory; + final EntityType entityType = emf.getMetamodel().entity( Fridge.class ); + assertEquals( Fridge.class, entityType.getBindableJavaType() ); + assertEquals( Bindable.BindableType.ENTITY_TYPE, entityType.getBindableType() ); + final SingularAttribute singularAttribute = entityType.getDeclaredSingularAttribute( + "temperature", + Integer.class + ); + assertEquals( Integer.class, singularAttribute.getBindableJavaType() ); + assertEquals( Bindable.BindableType.SINGULAR_ATTRIBUTE, singularAttribute.getBindableType() ); + + //TODO test embedded + //todo test plural + } + + @Override + public Class[] getAnnotatedClasses() { + return new Class[]{ + Fridge.class, + FoodItem.class + }; + } + +}