From 9ad55dc4bd146e8ef9298d252691acfeaa596b63 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Mon, 14 Mar 2011 12:51:04 -0500 Subject: [PATCH] HHH-5942 - Migrate to JUnit 4 --- .../hibernate/impl/SessionFactoryImpl.java | 8 +- .../org/hibernate/ejb/Ejb3Configuration.java | 103 ++++----- .../ejb/EntityManagerFactoryImpl.java | 22 +- .../ejb/HibernateEntityManagerFactory.java | 12 +- .../ejb/criteria/CriteriaCompilingTest.java | 21 +- .../ejb/criteria/QueryBuilderTest.java | 19 +- .../criteria/basic/AggregationResultTest.java | 30 ++- .../basic/BasicCriteriaUsageTest.java | 18 +- .../ejb/criteria/basic/ExpressionsTest.java | 49 ++++- .../ejb/criteria/basic/PredicateTest.java | 75 +++++-- .../components/ComponentCriteriaTest.java | 16 +- .../ejb/criteria/paths/ImplicitJoinTest.java | 8 +- .../subquery/CorrelatedSubqueryTest.java | 22 +- .../subquery/UncorrelatedSubqueryTest.java | 9 +- .../ejb/criteria/tuple/TupleCriteriaTest.java | 47 +++- .../AbstractMetamodelSpecificTest.java | 2 - .../ejb/metamodel/EmbeddedTypeTest.java | 18 +- .../BaseEntityManagerFunctionalTestCase.java | 207 ++++++++---------- .../hibernate/ejb/test/EntityManagerTest.java | 32 ++- .../ejb/test/association/AssociationTest.java | 30 ++- .../beanvalidation/BeanValidationTest.java | 35 ++- .../cachemodes/SharedCacheModesTest.java | 12 +- .../test/callbacks/CallbackAndDirtyTest.java | 36 ++- .../ejb/test/callbacks/CallbacksTest.java | 27 ++- .../ejb/test/cascade/CascadeTest.java | 39 +++- .../ejb/test/cascade/DeleteOrphanTest.java | 36 ++- .../test/cascade/DetachAndContainsTest.java | 42 +++- .../hibernate/ejb/test/cascade/FetchTest.java | 43 +++- .../ejb/test/cascade/FetchTest2.java | 39 +++- .../EntityManagerSerializationTest.java | 37 +++- .../ejb/test/emops/FlushModeTest.java | 10 +- .../hibernate/ejb/test/emops/FlushTest.java | 72 ++++-- .../ejb/test/emops/GetReferenceTest.java | 35 ++- .../hibernate/ejb/test/emops/MergeTest.java | 40 +++- .../hibernate/ejb/test/emops/RefreshTest.java | 33 ++- .../hibernate/ejb/test/emops/RemoveTest.java | 49 ++++- .../emops/cascade/CascadePersistTest.java | 33 ++- .../ejb/test/exception/ExceptionTest.java | 53 ++++- .../ejb/test/inheritance/InheritanceTest.java | 34 ++- .../org/hibernate/ejb/test/lob/BlobTest.java | 6 +- .../org/hibernate/ejb/test/lock/LockTest.java | 105 ++++++--- .../ejb/test/lock/QueryLockingTest.java | 26 ++- .../ejb/test/mapping/QuotingTest.java | 28 ++- .../ejb/test/metadata/MetadataTest.java | 62 ++++-- .../ejb/test/metadata/SecondMetadataTest.java | 32 ++- .../ejb/test/metadata/StaticMetadataTest.java | 12 +- .../org/hibernate/ejb/test/ops/FindTest.java | 33 ++- .../hibernate/ejb/test/ops/GetLoadTest.java | 24 +- .../hibernate/ejb/test/ops/MergeNewTest.java | 35 ++- .../org/hibernate/ejb/test/ops/MergeTest.java | 18 +- .../hibernate/ejb/test/ops/PersistTest.java | 36 ++- .../ejb/test/query/ComponentJoinsTest.java | 6 + .../hibernate/ejb/test/query/QueryTest.java | 96 ++++---- .../transaction/FlushAndTransactionTest.java | 78 ++++--- .../ejb/test/util/GetIdentifierTest.java | 40 +++- .../hibernate/ejb/test/util/IsLoadedTest.java | 34 ++- .../ejb/test/xml/CounterListener.java | 25 ++- .../test/xml/XmlAttributeOverrideTest.java | 37 +++- .../org/hibernate/ejb/test/xml/XmlTest.java | 29 ++- .../sequences/XmlAttributeOverrideTest.java | 33 ++- 60 files changed, 1663 insertions(+), 585 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java index 6c4aa74486..0313c6a7eb 100644 --- a/hibernate-core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java @@ -1077,9 +1077,11 @@ public final class SessionFactoryImpl } public void evictQueryRegions() { - for ( QueryCache queryCache : queryCaches.values() ) { - queryCache.clear(); - // TODO : cleanup entries in queryCaches + allCacheRegions ? + if ( queryCaches != null ) { + for ( QueryCache queryCache : queryCaches.values() ) { + queryCache.clear(); + // TODO : cleanup entries in queryCaches + allCacheRegions ? + } } } } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java index 2d12c86d79..272209ff60 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java @@ -23,6 +23,19 @@ */ package org.hibernate.ejb; +import javax.naming.BinaryRefAddr; +import javax.naming.NamingException; +import javax.naming.Reference; +import javax.naming.Referenceable; +import javax.persistence.Embeddable; +import javax.persistence.Entity; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityNotFoundException; +import javax.persistence.MappedSuperclass; +import javax.persistence.PersistenceException; +import javax.persistence.spi.PersistenceUnitInfo; +import javax.persistence.spi.PersistenceUnitTransactionType; +import javax.sql.DataSource; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -45,26 +58,17 @@ import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.StringTokenizer; -import javax.naming.BinaryRefAddr; -import javax.naming.NamingException; -import javax.naming.Reference; -import javax.naming.Referenceable; -import javax.persistence.Embeddable; -import javax.persistence.Entity; -import javax.persistence.EntityManagerFactory; -import javax.persistence.EntityNotFoundException; -import javax.persistence.MappedSuperclass; -import javax.persistence.PersistenceException; -import javax.persistence.spi.PersistenceUnitInfo; -import javax.persistence.spi.PersistenceUnitTransactionType; -import javax.sql.DataSource; + import org.dom4j.Element; +import org.jboss.logging.Logger; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; + import org.hibernate.HibernateException; import org.hibernate.Interceptor; import org.hibernate.MappingException; import org.hibernate.MappingNotFoundException; import org.hibernate.SessionFactory; -import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.cfg.NamingStrategy; @@ -95,11 +99,8 @@ import org.hibernate.mapping.PersistentClass; import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.secure.JACCConfiguration; import org.hibernate.service.internal.ServiceRegistryImpl; -import org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator; +import org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl; import org.hibernate.service.spi.ServiceRegistry; -import org.jboss.logging.Logger; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; /** * Allow a fine tuned configuration of an EJB 3.0 EntityManagerFactory @@ -127,7 +128,7 @@ public class Ejb3Configuration implements Serializable, Referenceable { private static final String PARSED_MAPPING_DOMS = "hibernate.internal.mapping_doms"; private static EntityNotFoundDelegate ejb3EntityNotFoundDelegate = new Ejb3EntityNotFoundDelegate(); - private static Configuration DEFAULT_CONFIGURATION = new AnnotationConfiguration(); + private static Configuration DEFAULT_CONFIGURATION = new Configuration(); private static class Ejb3EntityNotFoundDelegate implements EntityNotFoundDelegate, Serializable { public void handleEntityNotFound(String entityName, Serializable id) { @@ -142,8 +143,7 @@ public class Ejb3Configuration implements Serializable, Referenceable { private String persistenceUnitName; private String cfgXmlResource; - private AnnotationConfiguration cfg; - private final Map connectionProviderInjectionData; + private Configuration cfg; //made transient and not restored in deserialization on purpose, should no longer be called after restoration private transient EventListenerConfigurator listenerConfigurator; private PersistenceUnitTransactionType transactionType; @@ -154,8 +154,7 @@ public class Ejb3Configuration implements Serializable, Referenceable { public Ejb3Configuration() { - connectionProviderInjectionData = new HashMap(); - cfg = new AnnotationConfiguration(); + cfg = new Configuration(); cfg.setEntityNotFoundDelegate( ejb3EntityNotFoundDelegate ); listenerConfigurator = new EventListenerConfigurator( this ); } @@ -168,10 +167,8 @@ public class Ejb3Configuration implements Serializable, Referenceable { @SuppressWarnings({ "JavaDoc", "unchecked" }) public void setDataSource(DataSource ds) { if ( ds != null ) { - Map cpInjection = new HashMap(); - cpInjection.put( "dataSource", ds ); - connectionProviderInjectionData.put( ConnectionProviderInitiator.INJECTION_DATA, cpInjection ); - this.setProperty( Environment.CONNECTION_PROVIDER, InjectedDataSourceConnectionProvider.class.getName() ); + cfg.getProperties().put( Environment.DATASOURCE, ds ); + this.setProperty( Environment.CONNECTION_PROVIDER, DatasourceConnectionProviderImpl.class.getName() ); } } @@ -283,7 +280,7 @@ public class Ejb3Configuration implements Serializable, Referenceable { /** * Build the configuration from an entity manager name and given the * appropriate extra properties. Those properties override the one get through - * the peristence.xml file. + * the persistence.xml file. * If the persistence unit name is not found or does not match the Persistence Provider, null is returned * * This method is used in a non managed environment @@ -505,7 +502,7 @@ public class Ejb3Configuration implements Serializable, Referenceable { * @param info The persistence unit info passed in by the container (usually from processing a persistence.xml). * @param integration The map of integration properties from the container to configure the provider. * - * @return The configured EJB3Configurartion object + * @return this * * @see HibernatePersistence#createContainerEntityManagerFactory */ @@ -859,23 +856,10 @@ public class Ejb3Configuration implements Serializable, Referenceable { // This is used directly by JBoss so don't remove until further notice. bill@jboss.org @Deprecated public EntityManagerFactory createEntityManagerFactory(Map workingVars) { - Properties props = new Properties(); - if ( workingVars != null ) { - props.putAll( workingVars ); - //remove huge non String elements for a clean props - props.remove( AvailableSettings.CLASS_NAMES ); - props.remove( AvailableSettings.PACKAGE_NAMES ); - props.remove( AvailableSettings.HBXML_FILES ); - props.remove( AvailableSettings.LOADED_CLASSES ); - } - configure( props, workingVars ); + configure( workingVars ); return buildEntityManagerFactory(); } - public EntityManagerFactory createEntityManagerFactory(Map config, ServiceRegistryImpl serviceRegistry) { - return null; // todo : implement method body - } - /** * Process configuration and build an EntityManagerFactory when the configuration is ready * @deprecated @@ -906,7 +890,6 @@ public class Ejb3Configuration implements Serializable, Referenceable { discardOnClose, getSessionInterceptorClass( cfg.getProperties() ), cfg, - connectionProviderInjectionData, serviceRegistry ); } @@ -972,6 +955,20 @@ public class Ejb3Configuration implements Serializable, Referenceable { ); } + @SuppressWarnings( {"unchecked"}) + public Ejb3Configuration configure(Map configValues) { + Properties props = new Properties(); + if ( configValues != null ) { + props.putAll( configValues ); + //remove huge non String elements for a clean props + props.remove( AvailableSettings.CLASS_NAMES ); + props.remove( AvailableSettings.PACKAGE_NAMES ); + props.remove( AvailableSettings.HBXML_FILES ); + props.remove( AvailableSettings.LOADED_CLASSES ); + } + return configure( props, configValues ); + } + /** * Configures this configuration object from 2 distinctly different sources. * @@ -1139,13 +1136,13 @@ public class Ejb3Configuration implements Serializable, Referenceable { } } if ( workingVars.containsKey( AvailableSettings.XML_FILE_NAMES ) ) { - Collection xmlFiles = (Collection) workingVars.get( - AvailableSettings.XML_FILE_NAMES - ); + Collection xmlFiles = (Collection) workingVars.get( AvailableSettings.XML_FILE_NAMES ); for ( String xmlFile : xmlFiles ) { Boolean useMetaInf = null; try { - if ( xmlFile.endsWith( META_INF_ORM_XML ) ) useMetaInf = true; + if ( xmlFile.endsWith( META_INF_ORM_XML ) ) { + useMetaInf = true; + } cfg.addResource( xmlFile ); } catch( MappingNotFoundException e ) { @@ -1162,8 +1159,12 @@ public class Ejb3Configuration implements Serializable, Referenceable { throw new PersistenceException( getExceptionHeader() + "Error while reading JPA XML file: " + xmlFile, me); } - if (Boolean.TRUE.equals(useMetaInf)) LOG.exceptionHeaderFound(getExceptionHeader(), META_INF_ORM_XML); - else if (Boolean.FALSE.equals(useMetaInf)) LOG.exceptionHeaderNotFound(getExceptionHeader(), META_INF_ORM_XML); + if (Boolean.TRUE.equals(useMetaInf)) { + LOG.exceptionHeaderFound(getExceptionHeader(), META_INF_ORM_XML); + } + else if (Boolean.FALSE.equals(useMetaInf)) { + LOG.exceptionHeaderNotFound(getExceptionHeader(), META_INF_ORM_XML); + } } } if ( workingVars.containsKey( AvailableSettings.HBXML_FILES ) ) { @@ -1562,7 +1563,7 @@ public class Ejb3Configuration implements Serializable, Referenceable { * tool. * DO NOT update configuration through it. */ - public AnnotationConfiguration getHibernateConfiguration() { + public Configuration getHibernateConfiguration() { //TODO make it really read only (maybe through proxying) return cfg; } diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java index ca5d60d17c..070524c50b 100755 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java @@ -21,12 +21,6 @@ */ package org.hibernate.ejb; -import java.io.Serializable; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Properties; import javax.persistence.Cache; import javax.persistence.EntityManager; import javax.persistence.PersistenceContextType; @@ -35,10 +29,16 @@ import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.metamodel.Metamodel; import javax.persistence.spi.LoadState; import javax.persistence.spi.PersistenceUnitTransactionType; +import java.io.Serializable; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; + import org.hibernate.EntityMode; import org.hibernate.Hibernate; import org.hibernate.SessionFactory; -import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.Configuration; import org.hibernate.ejb.criteria.CriteriaBuilderImpl; import org.hibernate.ejb.metamodel.MetamodelImpl; @@ -46,7 +46,6 @@ import org.hibernate.ejb.util.PersistenceUtilHelper; import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.mapping.PersistentClass; import org.hibernate.metadata.ClassMetadata; -import org.hibernate.service.internal.ServiceRegistryImpl; import org.hibernate.service.spi.ServiceRegistry; /** @@ -57,7 +56,6 @@ import org.hibernate.service.spi.ServiceRegistry; * @author Steve Ebersole */ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory { - private final transient ServiceRegistry serviceRegistry; private final SessionFactory sessionFactory; private final PersistenceUnitTransactionType transactionType; private final boolean discardOnClose; @@ -66,7 +64,6 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory { private final Metamodel metamodel; private final HibernatePersistenceUnitUtil util; private final Map properties; - private final Map connectionProviderInjectionData; private final PersistenceUtilHelper.MetadataCache cache = new PersistenceUtilHelper.MetadataCache(); @@ -75,10 +72,8 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory { PersistenceUnitTransactionType transactionType, boolean discardOnClose, Class sessionInterceptorClass, - AnnotationConfiguration cfg, - Map connectionProviderInjectionData, + Configuration cfg, ServiceRegistry serviceRegistry) { - this.serviceRegistry = serviceRegistry; this.sessionFactory = cfg.buildSessionFactory( serviceRegistry ); this.transactionType = transactionType; this.discardOnClose = discardOnClose; @@ -98,7 +93,6 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory { addAll( props, ( (SessionFactoryImplementor) sessionFactory ).getProperties() ); addAll( props, cfg.getProperties() ); this.properties = Collections.unmodifiableMap( props ); - this.connectionProviderInjectionData = new HashMap(); } private static void addAll(HashMap propertyMap, Properties properties) { diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerFactory.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerFactory.java index 605b9c0df3..239a9ff23c 100755 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerFactory.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerFactory.java @@ -1,8 +1,10 @@ /* - * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2009-2011, 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 Middleware LLC. + * 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 @@ -19,11 +21,11 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ - -//$Id$ package org.hibernate.ejb; -import java.io.Serializable; + import javax.persistence.EntityManagerFactory; +import java.io.Serializable; + import org.hibernate.SessionFactory; /** diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/CriteriaCompilingTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/CriteriaCompilingTest.java index a1cdea87ea..ca43d59325 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/CriteriaCompilingTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/CriteriaCompilingTest.java @@ -22,14 +22,16 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.criteria; + +import javax.persistence.EntityManager; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; -import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; + import org.hibernate.ejb.metamodel.Address; import org.hibernate.ejb.metamodel.Alias; import org.hibernate.ejb.metamodel.Country; @@ -49,12 +51,14 @@ import org.hibernate.ejb.test.callbacks.VideoSystem; import org.hibernate.ejb.test.inheritance.Fruit; import org.hibernate.ejb.test.inheritance.Strawberry; +import org.junit.Assert; +import org.junit.Test; + /** - * TODO : javadoc - * * @author Steve Ebersole */ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase { + @Override public Class[] getAnnotatedClasses() { return new Class[] { Customer.class, @@ -79,6 +83,7 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase { }; } + @Test public void testJustSimpleRootCriteria() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -98,6 +103,7 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testSimpleJoinCriteria() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -113,6 +119,7 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testSimpleFetchCriteria() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -128,6 +135,7 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testSerialization() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -145,6 +153,7 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @SuppressWarnings( {"unchecked"}) private T serializeDeserialize(T object) { T serializedObject = null; try { @@ -161,7 +170,7 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase { byteIn.close(); } catch (Exception e) { - fail("Unable to serialize / deserialize the object: " + e.getMessage() ); + Assert.fail( "Unable to serialize / deserialize the object: " + e.getMessage() ); } return serializedObject; } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/QueryBuilderTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/QueryBuilderTest.java index e67cdb5857..a4b62f83cd 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/QueryBuilderTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/QueryBuilderTest.java @@ -22,14 +22,16 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.criteria; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; + import javax.persistence.EntityManager; import javax.persistence.TypedQuery; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; import javax.persistence.metamodel.EntityType; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + import org.hibernate.ejb.criteria.predicate.ComparisonPredicate; import org.hibernate.ejb.metamodel.Address; import org.hibernate.ejb.metamodel.Alias; @@ -46,9 +48,11 @@ import org.hibernate.ejb.metamodel.ShelfLife; import org.hibernate.ejb.metamodel.Spouse; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + /** - * TODO : javadoc - * * @author Steve Ebersole */ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { @@ -70,6 +74,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { }; } + @Test public void testEqualityComparisonLiteralConversion() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -108,6 +113,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testEqualityComparisonEntityConversion() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -149,6 +155,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testTypeConversion() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -180,6 +187,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testConstructor() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -204,6 +212,7 @@ public class QueryBuilderTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testDateTimeFunctions() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/AggregationResultTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/AggregationResultTest.java index a72a3e463d..5a4e60b7ec 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/AggregationResultTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/AggregationResultTest.java @@ -22,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.criteria.basic; + import java.math.BigDecimal; import java.math.BigInteger; import javax.persistence.EntityManager; @@ -33,25 +34,27 @@ import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest; import org.hibernate.ejb.metamodel.Product; import org.hibernate.ejb.metamodel.Product_; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + /** - * TODO : javadoc - * * @author Steve Ebersole */ public class AggregationResultTest extends AbstractMetamodelSpecificTest { private CriteriaBuilder builder; - @Override - public void setUp() throws Exception { - super.setUp(); - builder = factory.getCriteriaBuilder(); + @Before + public void createTestData() { + builder = entityManagerFactory().getCriteriaBuilder(); + EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); Product product = new Product(); product.setId( "product1" ); product.setPrice( 1.23d ); product.setQuantity( 1000 ); - product.setPartNumber( Integer.MAX_VALUE + 1 ); + product.setPartNumber( ( (long) Integer.MAX_VALUE ) + 1 ); product.setRating( 1.999f ); product.setSomeBigInteger( BigInteger.valueOf( 987654321 ) ); product.setSomeBigDecimal( BigDecimal.valueOf( 987654.321 ) ); @@ -60,19 +63,19 @@ public class AggregationResultTest extends AbstractMetamodelSpecificTest { em.close(); } - @Override - public void tearDown() throws Exception { + @After + public void cleanUpTestData() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); em.createQuery( "delete Product" ).executeUpdate(); em.getTransaction().commit(); em.close(); - super.tearDown(); } /** * Sum of Longs should return a Long */ + @Test public void testSumOfLongs() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -88,6 +91,7 @@ public class AggregationResultTest extends AbstractMetamodelSpecificTest { /** * Sum of Integers should return an Integer; note that this is distinctly different than JPAQL */ + @Test public void testSumOfIntegers() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -103,6 +107,7 @@ public class AggregationResultTest extends AbstractMetamodelSpecificTest { /** * Sum of Doubles should return a Double */ + @Test public void testSumOfDoubles() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -118,6 +123,7 @@ public class AggregationResultTest extends AbstractMetamodelSpecificTest { /** * Sum of Floats should return a Float; note that this is distinctly different than JPAQL */ + @Test public void testSumOfFloats() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -133,6 +139,7 @@ public class AggregationResultTest extends AbstractMetamodelSpecificTest { /** * Sum of BigInteger should return a BigInteger */ + @Test public void testSumOfBigIntegers() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -148,6 +155,7 @@ public class AggregationResultTest extends AbstractMetamodelSpecificTest { /** * Sum of BigDecimal should return a BigDecimal */ + @Test public void testSumOfBigDecimals() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -160,7 +168,7 @@ public class AggregationResultTest extends AbstractMetamodelSpecificTest { em.close(); } - public void assertReturnType(Class expectedType, Object value) { + private void assertReturnType(Class expectedType, Object value) { if ( value != null && ! expectedType.isInstance( value ) ) { throw new AssertionFailedError( "Result value was not of expected type: expected [" + expectedType.getName() diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/BasicCriteriaUsageTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/BasicCriteriaUsageTest.java index 5bd736b9eb..e7f4aefac1 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/BasicCriteriaUsageTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/BasicCriteriaUsageTest.java @@ -1,8 +1,10 @@ /* - * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2009-2011, 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 Middleware LLC. + * 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 @@ -20,6 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.criteria.basic; + import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.ParameterExpression; @@ -29,17 +32,21 @@ import javax.persistence.metamodel.SingularAttribute; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + /** - * TODO : javadoc - * * @author Steve Ebersole */ public class BasicCriteriaUsageTest extends BaseEntityManagerFunctionalTestCase { - + @Override public Class[] getAnnotatedClasses() { return new Class[] { Wall.class }; } + @Test public void testParameterCollection() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -57,6 +64,7 @@ public class BasicCriteriaUsageTest extends BaseEntityManagerFunctionalTestCase em.close(); } + @Test public void testTrivialCompilation() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java index 1639dfb180..39ef1283ae 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java @@ -22,10 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.criteria.basic; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Collections; -import java.util.List; + import javax.persistence.EntityManager; import javax.persistence.TypedQuery; import javax.persistence.criteria.CriteriaBuilder; @@ -33,6 +30,11 @@ import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.ParameterExpression; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Collections; +import java.util.List; + import org.hibernate.Query; import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest; import org.hibernate.ejb.metamodel.Phone; @@ -40,6 +42,12 @@ import org.hibernate.ejb.metamodel.Product; import org.hibernate.ejb.metamodel.Product_; import org.hibernate.impl.AbstractQueryImpl; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + /** * Tests that various expressions operate as expected * @@ -48,10 +56,10 @@ import org.hibernate.impl.AbstractQueryImpl; public class ExpressionsTest extends AbstractMetamodelSpecificTest { private CriteriaBuilder builder; - @Override - public void setUp() throws Exception { - super.setUp(); - builder = factory.getCriteriaBuilder(); + @Before + public void prepareTestData() { + builder = entityManagerFactory().getCriteriaBuilder(); + EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); Product product = new Product(); @@ -67,6 +75,16 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { em.close(); } + @After + public void cleanupTestData() { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); + em.remove( em.find( Product.class, "product1" ) ); + em.getTransaction().commit(); + em.close(); + } + + @Test public void testEmptyConjunction() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -79,6 +97,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { em.close(); } + @Test public void testEmptyConjunctionIsTrue() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -91,6 +110,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { em.close(); } + @Test public void testEmptyConjunctionIsFalse() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -103,6 +123,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { em.close(); } + @Test public void testEmptyDisjunction() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -115,6 +136,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { em.close(); } + @Test public void testEmptyDisjunctionIsTrue() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -127,6 +149,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { em.close(); } + @Test public void testEmptyDisjunctionIsFalse() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -139,6 +162,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { em.close(); } + @Test public void testDiff() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -151,6 +175,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { em.close(); } + @Test public void testDiffWithQuotient() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -171,6 +196,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { em.close(); } + @Test public void testSumWithQuotient() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -191,6 +217,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { em.close(); } + @Test public void testQuotientAndMultiply() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -224,7 +251,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { em.close(); } - + @Test public void testParameterReuse() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -248,6 +275,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { return hqlQueryImpl.getParameterMetadata().getNamedParameterNames().size(); } + @Test public void testInExplicitTupleList() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -260,6 +288,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { em.close(); } + @Test public void testInExplicitTupleListVarargs() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -272,6 +301,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { em.close(); } + @Test public void testInExpressionVarargs() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -284,6 +314,7 @@ public class ExpressionsTest extends AbstractMetamodelSpecificTest { em.close(); } + @Test public void testJoinedElementCollectionValuesInTupleList() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/PredicateTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/PredicateTest.java index be4d0393e5..331e6ad530 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/PredicateTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/PredicateTest.java @@ -22,15 +22,23 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.criteria.basic; -import java.util.List; + import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; +import java.util.List; + import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest; import org.hibernate.ejb.metamodel.Order; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * Test the various predicates. * @@ -38,25 +46,25 @@ import org.hibernate.ejb.metamodel.Order; * @author Hardy Ferentschik */ public class PredicateTest extends AbstractMetamodelSpecificTest { - - private EntityManager em; private CriteriaBuilder builder; - public void setUp() throws Exception { - super.setUp(); - builder = factory.getCriteriaBuilder(); - em = getOrCreateEntityManager(); - createTestOrders(); - em.getTransaction().begin(); - } + @Before + public void prepareTestData() { + builder = entityManagerFactory().getCriteriaBuilder(); - public void tearDown() throws Exception { + EntityManager em = entityManagerFactory().createEntityManager(); + em.getTransaction().begin(); + em.persist( new Order( "order-1", 1.0d ) ); + em.persist( new Order( "order-2", 10.0d ) ); + em.persist( new Order( "order-3", new char[]{'r','u'} ) ); em.getTransaction().commit(); em.close(); - super.tearDown(); } + @Test public void testEmptyConjunction() { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); // yes this is a retarded case, but explicitly allowed in the JPA spec CriteriaQuery orderCriteria = builder.createQuery( Order.class ); Root orderRoot = orderCriteria.from( Order.class ); @@ -66,9 +74,14 @@ public class PredicateTest extends AbstractMetamodelSpecificTest { List orders = em.createQuery( orderCriteria ).getResultList(); assertTrue( orders.size() == 3 ); + em.getTransaction().commit(); + em.close(); } + @Test public void testEmptyDisjunction() { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); // yes this is a retarded case, but explicitly allowed in the JPA spec CriteriaQuery orderCriteria = builder.createQuery( Order.class ); Root orderRoot = orderCriteria.from( Order.class ); @@ -78,12 +91,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest { List orders = em.createQuery( orderCriteria ).getResultList(); assertTrue( orders.size() == 3 ); + em.getTransaction().commit(); + em.close(); } /** * Check simple not. */ + @Test public void testSimpleNot() { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); CriteriaQuery orderCriteria = builder.createQuery( Order.class ); Root orderRoot = orderCriteria.from( Order.class ); @@ -92,12 +110,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest { List orders = em.createQuery( orderCriteria ).getResultList(); assertTrue( orders.size() == 2 ); + em.getTransaction().commit(); + em.close(); } /** * Check complicated not. */ + @Test public void testComplicatedNotOr() { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); CriteriaQuery orderCriteria = builder.createQuery( Order.class ); Root orderRoot = orderCriteria.from( Order.class ); @@ -110,12 +133,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest { assertTrue( orders.size() == 1 ); Order order = orders.get( 0 ); assertEquals( "order-3", order.getId() ); + em.getTransaction().commit(); + em.close(); } /** * Check complicated not. */ + @Test public void testNotMultipleOr() { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); CriteriaQuery orderCriteria = builder.createQuery( Order.class ); Root orderRoot = orderCriteria.from( Order.class ); @@ -127,12 +155,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest { List orders = em.createQuery( orderCriteria ).getResultList(); assertTrue( orders.size() == 0 ); + em.getTransaction().commit(); + em.close(); } /** * Check complicated not. */ + @Test public void testComplicatedNotAnd() { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); CriteriaQuery orderCriteria = builder.createQuery( Order.class ); Root orderRoot = orderCriteria.from( Order.class ); @@ -143,20 +176,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest { List orders = em.createQuery( orderCriteria ).getResultList(); assertTrue( orders.size() == 3 ); - } - - private void createTestOrders() { - em.getTransaction().begin(); - em.persist( new Order( "order-1", 1.0d ) ); - em.persist( new Order( "order-2", 10.0d ) ); - em.persist( new Order( "order-3", new char[]{'r','u'} ) ); em.getTransaction().commit(); + em.close(); } /** * Check predicate for field which has simple char array type (char[]). */ + @Test public void testCharArray() { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); CriteriaQuery orderCriteria = builder.createQuery( Order.class ); Root orderRoot = orderCriteria.from( Order.class ); @@ -166,12 +196,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest { List orders = em.createQuery( orderCriteria ).getResultList(); assertTrue( orders.size() == 1 ); + em.getTransaction().commit(); + em.close(); } /** * Check predicate for field which has simple char array type (byte[]). */ + @Test public void testByteArray() { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); CriteriaQuery orderCriteria = builder.createQuery( Order.class ); Root orderRoot = orderCriteria.from( Order.class ); @@ -181,6 +216,8 @@ public class PredicateTest extends AbstractMetamodelSpecificTest { List orders = em.createQuery( orderCriteria ).getResultList(); assertTrue( orders.size() == 0 ); + em.getTransaction().commit(); + em.close(); } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/components/ComponentCriteriaTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/components/ComponentCriteriaTest.java index 3707a6c0b9..42c6b977dd 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/components/ComponentCriteriaTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/components/ComponentCriteriaTest.java @@ -22,23 +22,30 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.criteria.components; -import java.util.List; + import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; +import java.util.List; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Assert; +import org.junit.Test; + +import org.hibernate.testing.TestForIssue; + /** - * * @author alan.oleary */ public class ComponentCriteriaTest extends BaseEntityManagerFunctionalTestCase { + @Override public Class[] getAnnotatedClasses() { return new Class[] { Client.class }; } + @Test public void testEmbeddableInPath() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -54,7 +61,7 @@ public class ComponentCriteriaTest extends BaseEntityManagerFunctionalTestCase { Root root = cq.from(Client.class); cq.where(cb.equal(root.get("name").get("firstName"), client.getName().getFirstName())); List list = em.createQuery(cq).getResultList(); - assertEquals(1, list.size()); + Assert.assertEquals( 1, list.size() ); em.getTransaction().commit(); em.close(); @@ -65,8 +72,9 @@ public class ComponentCriteriaTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test + @TestForIssue( jiraKey = "HHH-4586" ) public void testParameterizedFunctions() { - // HHH-4586 EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); CriteriaBuilder cb = em.getCriteriaBuilder(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/paths/ImplicitJoinTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/paths/ImplicitJoinTest.java index 0ca63abddc..7bf54ffe0f 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/paths/ImplicitJoinTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/paths/ImplicitJoinTest.java @@ -22,25 +22,27 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.criteria.paths; + import javax.persistence.EntityManager; import javax.persistence.TypedQuery; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Join; import javax.persistence.criteria.Root; + import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest; import org.hibernate.ejb.metamodel.LineItem; import org.hibernate.ejb.metamodel.LineItem_; import org.hibernate.ejb.metamodel.Order; import org.hibernate.ejb.metamodel.Order_; +import org.junit.Test; + /** - * TODO : javadoc - * * @author Steve Ebersole */ public class ImplicitJoinTest extends AbstractMetamodelSpecificTest { - + @Test public void testImplicitJoinFromExplicitCollectionJoin() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/CorrelatedSubqueryTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/CorrelatedSubqueryTest.java index 4799b7f4fd..e9f0838f39 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/CorrelatedSubqueryTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/CorrelatedSubqueryTest.java @@ -22,12 +22,14 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.criteria.subquery; + import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Join; import javax.persistence.criteria.Root; import javax.persistence.criteria.Subquery; + import org.hibernate.dialect.SybaseASE15Dialect; import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest; import org.hibernate.ejb.metamodel.Customer; @@ -37,14 +39,17 @@ import org.hibernate.ejb.metamodel.LineItem_; import org.hibernate.ejb.metamodel.Order; import org.hibernate.ejb.metamodel.Order_; +import org.junit.Test; + +import org.hibernate.testing.SkipForDialect; + /** - * TODO : javadoc - * * @author Steve Ebersole */ public class CorrelatedSubqueryTest extends AbstractMetamodelSpecificTest { + @Test public void testBasicCorrelation() { - CriteriaBuilder builder = factory.getCriteriaBuilder(); + CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder(); EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -62,8 +67,9 @@ public class CorrelatedSubqueryTest extends AbstractMetamodelSpecificTest { em.close(); } + @Test public void testRestrictedCorrelation() { - CriteriaBuilder builder = factory.getCriteriaBuilder(); + CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder(); EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -83,9 +89,10 @@ public class CorrelatedSubqueryTest extends AbstractMetamodelSpecificTest { em.close(); } - @org.hibernate.testing.SkipForDialect(value=SybaseASE15Dialect.class, jiraKey="HHH-3032") + @Test + @SkipForDialect(value=SybaseASE15Dialect.class, jiraKey="HHH-3032") public void testCorrelationExplicitSelectionCorrelation() { - CriteriaBuilder builder = factory.getCriteriaBuilder(); + CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder(); EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -106,8 +113,9 @@ public class CorrelatedSubqueryTest extends AbstractMetamodelSpecificTest { em.close(); } + @Test public void testRestrictedCorrelationNoExplicitSelection() { - CriteriaBuilder builder = factory.getCriteriaBuilder(); + CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder(); EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/UncorrelatedSubqueryTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/UncorrelatedSubqueryTest.java index 1700280a0c..cf4a9dbd68 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/UncorrelatedSubqueryTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/UncorrelatedSubqueryTest.java @@ -22,26 +22,29 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.criteria.subquery; + import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Join; import javax.persistence.criteria.Root; import javax.persistence.criteria.Subquery; + import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest; import org.hibernate.ejb.metamodel.Customer; import org.hibernate.ejb.metamodel.Customer_; import org.hibernate.ejb.metamodel.Order; import org.hibernate.ejb.metamodel.Order_; +import org.junit.Test; + /** - * TODO : javadoc - * * @author Steve Ebersole */ public class UncorrelatedSubqueryTest extends AbstractMetamodelSpecificTest { + @Test public void testEqualAll() { - CriteriaBuilder builder = factory.getCriteriaBuilder(); + CriteriaBuilder builder = entityManagerFactory().getCriteriaBuilder(); EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/tuple/TupleCriteriaTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/tuple/TupleCriteriaTest.java index eadcf76cbf..23ac7bc046 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/tuple/TupleCriteriaTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/criteria/tuple/TupleCriteriaTest.java @@ -1,21 +1,52 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.criteria.tuple; -import java.util.List; + import javax.persistence.EntityManager; import javax.persistence.Tuple; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Path; import javax.persistence.criteria.Root; +import java.util.List; + import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest; import org.hibernate.ejb.metamodel.Customer; import org.hibernate.ejb.metamodel.Customer_; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * @author Emmanuel Bernard */ public class TupleCriteriaTest extends AbstractMetamodelSpecificTest { + @Test public void testArray() { - EntityManager em = factory.createEntityManager(); + EntityManager em = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); Customer c1 = new Customer(); c1.setId( "c1" ); @@ -25,7 +56,7 @@ public class TupleCriteriaTest extends AbstractMetamodelSpecificTest { em.getTransaction().commit(); em.close(); - em = factory.createEntityManager(); + em = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); final CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery q = cb.createQuery(Object[].class); @@ -38,16 +69,16 @@ public class TupleCriteriaTest extends AbstractMetamodelSpecificTest { em.getTransaction().commit(); em.close(); - em = factory.createEntityManager(); + em = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); em.createQuery( "delete Customer" ).executeUpdate(); em.getTransaction().commit(); em.close(); } - + @Test public void testTuple() { - EntityManager em = factory.createEntityManager(); + EntityManager em = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); Customer c1 = new Customer(); @@ -58,7 +89,7 @@ public class TupleCriteriaTest extends AbstractMetamodelSpecificTest { em.getTransaction().commit(); em.close(); - em = factory.createEntityManager(); + em = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); final CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery criteria = builder.createTupleQuery(); @@ -82,7 +113,7 @@ public class TupleCriteriaTest extends AbstractMetamodelSpecificTest { em.getTransaction().commit(); em.close(); - em = factory.createEntityManager(); + em = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); em.createQuery( "delete Customer" ).executeUpdate(); em.getTransaction().commit(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/metamodel/AbstractMetamodelSpecificTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/metamodel/AbstractMetamodelSpecificTest.java index 3ea2ac07d2..b2c8008d08 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/metamodel/AbstractMetamodelSpecificTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/metamodel/AbstractMetamodelSpecificTest.java @@ -25,8 +25,6 @@ package org.hibernate.ejb.metamodel; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; /** - * TODO : javadoc - * * @author Steve Ebersole */ public abstract class AbstractMetamodelSpecificTest extends BaseEntityManagerFunctionalTestCase { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/metamodel/EmbeddedTypeTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/metamodel/EmbeddedTypeTest.java index 340689fa83..0d838fb5cd 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/metamodel/EmbeddedTypeTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/metamodel/EmbeddedTypeTest.java @@ -22,14 +22,22 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.metamodel; + import javax.persistence.EntityManager; import javax.persistence.metamodel.EntityType; import javax.persistence.metamodel.SingularAttribute; + import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import org.hibernate.testing.TestForIssue; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + /** - * TODO : javadoc - * * @author Steve Ebersole */ public class EmbeddedTypeTest extends BaseEntityManagerFunctionalTestCase { @@ -40,8 +48,9 @@ public class EmbeddedTypeTest extends BaseEntityManagerFunctionalTestCase { }; } + @Test + @TestForIssue( jiraKey = "HHH-4702" ) public void testSingularAttributeAccessByName() { - // HHH-4702 EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -55,8 +64,9 @@ public class EmbeddedTypeTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test + @TestForIssue( jiraKey = "HHH-5821" ) public void testVersionAttributeMetadata() { - // HHH-5821 EntityManager em = getOrCreateEntityManager(); EntityType metadata = em.getMetamodel().entity( VersionedEntity.class ); assertNotNull( metadata.getDeclaredVersion( int.class ) ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/BaseEntityManagerFunctionalTestCase.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/BaseEntityManagerFunctionalTestCase.java index 985d03df4b..758209b67b 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/BaseEntityManagerFunctionalTestCase.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/BaseEntityManagerFunctionalTestCase.java @@ -42,8 +42,9 @@ import org.hibernate.ejb.Ejb3Configuration; import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.service.internal.ServiceRegistryImpl; -import org.hibernate.testing.AfterClassOnce; -import org.hibernate.testing.BeforeClassOnce; +import org.junit.After; +import org.junit.Before; + import org.hibernate.testing.junit4.BaseUnitTestCase; import static org.hibernate.testing.TestLogger.LOG; @@ -55,32 +56,46 @@ import static org.hibernate.testing.TestLogger.LOG; * @author Hardy Ferentschik */ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCase { + // IMPL NOTE : Here we use @Before and @After (instead of @BeforeClassOnce and @AfterClassOnce like we do in + // BaseCoreFunctionalTestCase) because the old HEM test methodology was to create an EMF for each test method. + private static final Dialect dialect = Dialect.getDialect(); - private static ServiceRegistryImpl serviceRegistry; - private static EntityManagerFactory factory; + + private Ejb3Configuration ejb3Configuration; + private ServiceRegistryImpl serviceRegistry; + private EntityManagerFactory entityManagerFactory; + private EntityManager em; private ArrayList isolatedEms = new ArrayList(); - public static Dialect getDialect() { + protected Dialect getDialect() { return dialect; } - protected - @BeforeClassOnce - private void buildSessionFactory() throws Exception { + protected EntityManagerFactory entityManagerFactory() { + return entityManagerFactory; + } + + protected ServiceRegistryImpl serviceRegistry() { + return serviceRegistry; + } + + @Before + @SuppressWarnings( {"UnusedDeclaration"}) + public void buildSessionFactory() throws Exception { LOG.trace( "Building session factory" ); - Ejb3Configuration ejb3Configuration = buildConfiguration(); + ejb3Configuration = buildConfiguration(); + ejb3Configuration.configure( getConfig() ); + afterConfigurationBuilt( ejb3Configuration ); serviceRegistry = buildServiceRegistry( ejb3Configuration.getHibernateConfiguration() ); - factory = ejb3Configuration.createEntityManagerFactory( getConfig(), serviceRegistry ); + applyServices( serviceRegistry ); + entityManagerFactory = ejb3Configuration.buildEntityManagerFactory( serviceRegistry ); afterEntityManagerFactoryBuilt(); } protected Ejb3Configuration buildConfiguration() { Ejb3Configuration ejb3Cfg = constructConfiguration(); - configure( ejb3Cfg.getHibernateConfiguration() ); addMappings( ejb3Cfg.getHibernateConfiguration() ); - ejb3Cfg.getHibernateConfiguration().buildMappings(); - afterConfigurationBuilt( ejb3Cfg.getHibernateConfiguration() ); return ejb3Cfg; } @@ -98,7 +113,19 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa return ejb3Configuration; } - protected void configure(Configuration hibernateConfiguration) { + protected void addMappings(Configuration configuration) { + String[] mappings = getMappings(); + if ( mappings != null ) { + for ( String mapping : mappings ) { + configuration.addResource( mapping, getClass().getClassLoader() ); + } + } + } + + protected static final String[] NO_MAPPINGS = new String[0]; + + protected String[] getMappings() { + return NO_MAPPINGS; } protected Map getConfig() { @@ -108,16 +135,10 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa classes.addAll( Arrays.asList( getAnnotatedClasses() ) ); config.put( AvailableSettings.LOADED_CLASSES, classes ); for ( Map.Entry entry : getCachedClasses().entrySet() ) { - config.put( - AvailableSettings.CLASS_CACHE_PREFIX + "." + entry.getKey().getName(), - entry.getValue() - ); + config.put( AvailableSettings.CLASS_CACHE_PREFIX + "." + entry.getKey().getName(), entry.getValue() ); } for ( Map.Entry entry : getCachedCollections().entrySet() ) { - config.put( - AvailableSettings.COLLECTION_CACHE_PREFIX + "." + entry.getKey(), - entry.getValue() - ); + config.put( AvailableSettings.COLLECTION_CACHE_PREFIX + "." + entry.getKey(), entry.getValue() ); } if ( getEjb3DD().length > 0 ) { ArrayList dds = new ArrayList(); @@ -132,44 +153,25 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa protected void addConfigOptions(Map options) { } - protected void addMappings(Configuration configuration) { - String[] mappings = getMappings(); - if ( mappings != null ) { - for ( String mapping : mappings ) { - configuration.addResource( - getBaseForMappings() + mapping, - getClass().getClassLoader() - ); + private Properties loadProperties() { + Properties props = new Properties(); + InputStream stream = Persistence.class.getResourceAsStream( "/hibernate.properties" ); + if ( stream != null ) { + try { + props.load( stream ); + } + catch ( Exception e ) { + throw new RuntimeException( "could not load hibernate.properties" ); + } + finally { + try { + stream.close(); + } + catch ( IOException ignored ) { + } } } -// Class[] annotatedClasses = getAnnotatedClasses(); -// if ( annotatedClasses != null ) { -// for ( Class annotatedClass : annotatedClasses ) { -// configuration.addAnnotatedClass( annotatedClass ); -// } -// } -// String[] annotatedPackages = getAnnotatedPackages(); -// if ( annotatedPackages != null ) { -// for ( String annotatedPackage : annotatedPackages ) { -// configuration.addPackage( annotatedPackage ); -// } -// } -// String[] xmlFiles = getOrmXmlFiles(); -// if ( xmlFiles != null ) { -// for ( String xmlFile : xmlFiles ) { -// configuration.addResource( xmlFile ); -// } -// } - } - - protected static final String[] NO_MAPPINGS = new String[0]; - - protected String[] getMappings() { - return NO_MAPPINGS; - } - - protected String getBaseForMappings() { - return "org/hibernate/test/"; + return props; } protected static final Class[] NO_CLASSES = new Class[0]; @@ -178,15 +180,20 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa return NO_CLASSES; } - protected String[] getAnnotatedPackages() { - return NO_MAPPINGS; + public Map getCachedClasses() { + return new HashMap(); } - protected String[] getOrmXmlFiles() { - return NO_MAPPINGS; + public Map getCachedCollections() { + return new HashMap(); } - protected void afterConfigurationBuilt(Configuration hibernateConfiguration) { + public String[] getEjb3DD() { + return new String[] { }; + } + + @SuppressWarnings( {"UnusedParameters"}) + protected void afterConfigurationBuilt(Ejb3Configuration ejb3Configuration) { } protected ServiceRegistryImpl buildServiceRegistry(Configuration configuration) { @@ -194,11 +201,10 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa properties.putAll( configuration.getProperties() ); Environment.verifyProperties( properties ); ConfigurationHelper.resolvePlaceHolders( properties ); - ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl( properties ); - applyServices( serviceRegistry ); - return serviceRegistry; + return new ServiceRegistryImpl( properties ); } + @SuppressWarnings( {"UnusedParameters"}) protected void applyServices(ServiceRegistryImpl serviceRegistry) { } @@ -210,22 +216,29 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa } - @AfterClassOnce + @After + @SuppressWarnings( {"UnusedDeclaration"}) public void releaseResources() { - cleanUnclosed( this.em ); - for ( EntityManager isolatedEm : isolatedEms ) { - cleanUnclosed( isolatedEm ); + releaseUnclosedEntityManagers(); + + if ( entityManagerFactory != null ) { + entityManagerFactory.close(); } - if ( factory != null ) { - factory.close(); - } if ( serviceRegistry != null ) { serviceRegistry.destroy(); } } - private void cleanUnclosed(EntityManager em) { + private void releaseUnclosedEntityManagers() { + releaseUnclosedEntityManager( this.em ); + + for ( EntityManager isolatedEm : isolatedEms ) { + releaseUnclosedEntityManager( isolatedEm ); + } + } + + private void releaseUnclosedEntityManager(EntityManager em) { if ( em == null ) { return; } @@ -243,65 +256,29 @@ public abstract class BaseEntityManagerFunctionalTestCase extends BaseUnitTestCa protected EntityManager getOrCreateEntityManager() { if ( em == null || !em.isOpen() ) { - em = factory.createEntityManager(); + em = entityManagerFactory.createEntityManager(); } return em; } protected EntityManager createIsolatedEntityManager() { - EntityManager isolatedEm = factory.createEntityManager(); + EntityManager isolatedEm = entityManagerFactory.createEntityManager(); isolatedEms.add( isolatedEm ); return isolatedEm; } protected EntityManager createIsolatedEntityManager(Map props) { - EntityManager isolatedEm = factory.createEntityManager(props); + EntityManager isolatedEm = entityManagerFactory.createEntityManager(props); isolatedEms.add( isolatedEm ); return isolatedEm; } - /** - * always reopen a new EM and clse the existing one - */ protected EntityManager createEntityManager(Map properties) { + // always reopen a new EM and close the existing one if ( em != null && em.isOpen() ) { em.close(); } - em = factory.createEntityManager( properties ); + em = entityManagerFactory.createEntityManager( properties ); return em; } - - public String[] getEjb3DD() { - return new String[] { }; - } - - public Map getCachedClasses() { - return new HashMap(); - } - - public Map getCachedCollections() { - return new HashMap(); - } - - public static Properties loadProperties() { - Properties props = new Properties(); - InputStream stream = Persistence.class.getResourceAsStream( "/hibernate.properties" ); - if ( stream != null ) { - try { - props.load( stream ); - } - catch ( Exception e ) { - throw new RuntimeException( "could not load hibernate.properties" ); - } - finally { - try { - stream.close(); - } - catch ( IOException ioe ) { - } - } - } - props.setProperty( Environment.HBM2DDL_AUTO, "create-drop" ); - return props; - } } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/EntityManagerTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/EntityManagerTest.java index f76aa4babf..6664c596c1 100755 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/EntityManagerTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/EntityManagerTest.java @@ -39,11 +39,17 @@ import java.util.Map; import org.hibernate.FlushMode; import org.hibernate.HibernateException; +import org.hibernate.cfg.Environment; import org.hibernate.ejb.AvailableSettings; import org.hibernate.ejb.HibernateEntityManager; import org.hibernate.ejb.HibernateEntityManagerFactory; import org.hibernate.stat.Statistics; +import org.junit.Before; +import org.junit.Test; + +import org.hibernate.testing.TestForIssue; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -56,7 +62,7 @@ import static org.junit.Assert.fail; * @author Gavin King */ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase { - + @Override public Class[] getAnnotatedClasses() { return new Class[] { Item.class, @@ -65,20 +71,27 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase { }; } + @SuppressWarnings( {"unchecked"}) + protected void addConfigOptions(Map options) { + options.put( Environment.GENERATE_STATISTICS, "true" ); + } + + @Override public Map getCachedClasses() { Map result = new HashMap(); result.put( Item.class, "read-write" ); return result; } + @Override public Map getCachedCollections() { Map result = new HashMap(); result.put( Item.class.getName() + ".distributors", "read-write, RegionName" ); return result; } + @Test public void testEntityManager() { - Item item = new Item( "Mouse", "Micro$oft mouse" ); EntityManager em = getOrCreateEntityManager(); @@ -121,16 +134,16 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase { em.getTransaction().commit(); em.close(); - } + @Test public void testConfiguration() throws Exception { Item item = new Item( "Mouse", "Micro$oft mouse" ); Distributor res = new Distributor(); res.setName( "Bruce" ); item.setDistributors( new HashSet() ); item.getDistributors().add( res ); - Statistics stats = ( ( HibernateEntityManagerFactory ) factory ).getSessionFactory().getStatistics(); + Statistics stats = ( ( HibernateEntityManagerFactory ) entityManagerFactory() ).getSessionFactory().getStatistics(); stats.clear(); stats.setStatisticsEnabled( true ); @@ -169,6 +182,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase { stats.setStatisticsEnabled( false ); } + @Test public void testContains() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -201,6 +215,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testClear() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -216,6 +231,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testFlushMode() throws Exception { EntityManager em = getOrCreateEntityManager(); em.setFlushMode( FlushModeType.COMMIT ); @@ -225,6 +241,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testPersistNoneGenerator() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -242,6 +259,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testSerializableException() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -284,6 +302,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase { assertNotNull( e.getCause() ); } + @Test public void testIsOpen() throws Exception { EntityManager em = getOrCreateEntityManager(); assertTrue( em.isOpen() ); @@ -294,7 +313,8 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase { assertFalse( em.isOpen() ); } - //EJB-9 + @Test + @TestForIssue( jiraKey = "EJB-9" ) public void testGet() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -315,6 +335,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase { } } + @Test public void testGetProperties() throws Exception { EntityManager em = getOrCreateEntityManager(); Map properties = em.getProperties(); @@ -330,6 +351,7 @@ public class EntityManagerTest extends BaseEntityManagerFunctionalTestCase { assertTrue( properties.containsKey( AvailableSettings.FLUSH_MODE ) ); } + @Test public void testSetProperty() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/association/AssociationTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/association/AssociationTest.java index 7900cc2ad7..80ff0cccad 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/association/AssociationTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/association/AssociationTest.java @@ -1,12 +1,16 @@ -//$Id$ package org.hibernate.ejb.test.association; + import javax.persistence.EntityManager; + import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + /** * @author Emmanuel Bernard */ public class AssociationTest extends BaseEntityManagerFunctionalTestCase { + @Test public void testBidirOneToOne() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -20,13 +24,16 @@ public class AssociationTest extends BaseEntityManagerFunctionalTestCase { em.persist( i ); } em.getTransaction().commit(); - em.clear(); + em.close(); + + em = getOrCreateEntityManager(); em.getTransaction().begin(); em.remove( em.find(Incident.class, id) ); em.getTransaction().commit(); em.close(); } + @Test public void testMergeAndBidirOneToOne() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -36,16 +43,23 @@ public class AssociationTest extends BaseEntityManagerFunctionalTestCase { em.persist( kitchen ); kitchen.setOven( oven ); oven.setKitchen( kitchen ); - em.flush(); - em.clear(); - //oven = em.find(Oven.class, oven.getId() ); - oven = em.merge( oven ); - em.flush(); + em.getTransaction().commit(); + em.close(); - em.getTransaction().rollback(); + em = getOrCreateEntityManager(); + em.getTransaction().begin(); + oven = em.merge( oven ); + em.getTransaction().commit(); + em.close(); + + em = getOrCreateEntityManager(); + em.getTransaction().begin(); + em.remove( em.find( Oven.class, oven.getId() ) ); + em.getTransaction().commit(); em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[]{ Incident.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java index b321b87b98..0546bae827 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java @@ -1,16 +1,46 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.beanvalidation; -import java.math.BigDecimal; + import javax.persistence.EntityManager; import javax.persistence.RollbackException; import javax.validation.ConstraintViolationException; +import java.math.BigDecimal; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * @author Emmanuel Bernard */ public class BeanValidationTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testBeanValidationIntegrationOnFlush() { CupHolder ch = new CupHolder(); ch.setRadius( new BigDecimal( "12" ) ); @@ -32,6 +62,7 @@ public class BeanValidationTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testBeanValidationIntegrationOnCommit() { CupHolder ch = new CupHolder(); ch.setRadius( new BigDecimal( "9" ) ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/cachemodes/SharedCacheModesTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/cachemodes/SharedCacheModesTest.java index bacbaa3710..a16a9a3fbb 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/cachemodes/SharedCacheModesTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cacheable/cachemodes/SharedCacheModesTest.java @@ -22,10 +22,12 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.test.cacheable.cachemodes; + import javax.persistence.CacheRetrieveMode; import javax.persistence.CacheStoreMode; import javax.persistence.EntityManager; import javax.persistence.Query; + import org.hibernate.CacheMode; import org.hibernate.Session; import org.hibernate.ejb.AvailableSettings; @@ -34,9 +36,11 @@ import org.hibernate.ejb.HibernateQuery; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.impl.AbstractQueryImpl; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + /** - * TODO : javadoc - * * @author Steve Ebersole */ public class SharedCacheModesTest extends BaseEntityManagerFunctionalTestCase { @@ -45,8 +49,7 @@ public class SharedCacheModesTest extends BaseEntityManagerFunctionalTestCase { return new Class[] { SimpleEntity.class }; } - // this is all i can do for now testing-wise since I did not implement @Cacheable first ;) - + @Test public void testEntityManagerCacheModes() { EntityManager em; @@ -82,6 +85,7 @@ public class SharedCacheModesTest extends BaseEntityManagerFunctionalTestCase { assertEquals( CacheMode.REFRESH, session.getCacheMode() ); } + @Test public void testQueryCacheModes() { EntityManager em = getOrCreateEntityManager(); Query jpaQuery = em.createQuery( "from SimpleEntity" ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/callbacks/CallbackAndDirtyTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/callbacks/CallbackAndDirtyTest.java index be3e56b554..f09fc18881 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/callbacks/CallbackAndDirtyTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/callbacks/CallbackAndDirtyTest.java @@ -1,15 +1,44 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.callbacks; + +import javax.persistence.EntityManager; import java.util.Iterator; import java.util.List; -import javax.persistence.EntityManager; + import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + /** * @author Emmanuel Bernard */ public class CallbackAndDirtyTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testDirtyButNotDirty() throws Exception { EntityManager manager = getOrCreateEntityManager(); manager.getTransaction().begin(); @@ -81,6 +110,7 @@ public class CallbackAndDirtyTest extends BaseEntityManagerFunctionalTestCase { manager.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[]{ Customer.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/callbacks/CallbacksTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/callbacks/CallbacksTest.java index e6873a4308..ef95fcb929 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/callbacks/CallbacksTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/callbacks/CallbacksTest.java @@ -1,20 +1,30 @@ -//$Id$ package org.hibernate.ejb.test.callbacks; + +import javax.persistence.EntityManager; import java.util.ArrayList; import java.util.Date; import java.util.List; -import javax.persistence.EntityManager; + +import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.ejb.test.Cat; import org.hibernate.ejb.test.Kitten; -import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; + +import org.junit.Test; + import org.hibernate.testing.FailureExpected; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * @author Emmanuel Bernard */ @SuppressWarnings("unchecked") public class CallbacksTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testCallbackMethod() throws Exception { EntityManager em = getOrCreateEntityManager(); Cat c = new Cat(); @@ -37,6 +47,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testEntityListener() throws Exception { EntityManager em = getOrCreateEntityManager(); Cat c = new Cat(); @@ -63,7 +74,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase { em.close(); } - + @Test public void testPostPersist() throws Exception { EntityManager em = getOrCreateEntityManager(); Cat c = new Cat(); @@ -103,6 +114,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase { } } + @Test public void testPrePersistOnCascade() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -118,6 +130,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testCallBackListenersHierarchy() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -133,6 +146,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase { assertTrue( tv.isLast ); } + @Test public void testException() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -154,6 +168,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase { } + @Test public void testIdNullSetByPrePersist() throws Exception { Plant plant = new Plant(); plant.setName( "Origuna plantula gigantic" ); @@ -165,6 +180,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test @FailureExpected(message = "collection change does not trigger an event", jiraKey = "EJB-288") public void testPostUpdateCollection() throws Exception { // create a cat @@ -220,6 +236,7 @@ public class CallbacksTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[]{ Cat.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/CascadeTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/CascadeTest.java index 9eabcb9e97..e040e3d527 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/CascadeTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/CascadeTest.java @@ -1,23 +1,45 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.cascade; + import javax.persistence.EntityManager; import javax.persistence.EntityTransaction; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; /** * @author Max Rydahl Andersen */ public class CascadeTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testCascade() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); - Teacher teacher = null; - - teacher = new Teacher(); + Teacher teacher = new Teacher(); Student student = new Student(); @@ -46,10 +68,9 @@ public class CascadeTest extends BaseEntityManagerFunctionalTestCase { em.getTransaction().commit(); // here *alot* of flushes occur on an object graph that has *Zero* changes. em.close(); - - } + @Test public void testNoCascadeAndMerge() throws Exception { Song e1 = new Song(); Author e2 = new Author(); @@ -67,7 +88,6 @@ public class CascadeTest extends BaseEntityManagerFunctionalTestCase { em = getOrCreateEntityManager(); e1 = em.find(Song.class, e1.getId()); - e2 = null; tx = em.getTransaction(); @@ -76,10 +96,9 @@ public class CascadeTest extends BaseEntityManagerFunctionalTestCase { //em.refresh(e1); tx.commit(); em.close(); - } - + @Override public Class[] getAnnotatedClasses() { return new Class[]{ Teacher.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/DeleteOrphanTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/DeleteOrphanTest.java index 3d2794d382..b3fcdfd663 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/DeleteOrphanTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/DeleteOrphanTest.java @@ -1,5 +1,28 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.cascade; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -11,10 +34,14 @@ import javax.persistence.EntityTransaction; import org.hibernate.Hibernate; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Assert; +import org.junit.Test; + /** * @author Emmanuel Bernard */ public class DeleteOrphanTest extends BaseEntityManagerFunctionalTestCase { + @Test public void testDeleteOrphan() throws Exception { EntityTransaction tx; @@ -41,7 +68,7 @@ public class DeleteOrphanTest extends BaseEntityManagerFunctionalTestCase { Soldier soldier = troop.getSoldiers().iterator().next(); troop.getSoldiers().remove( soldier ); - troop = (Troop) unserialize( serialize( troop ) ); + troop = (Troop) deserialize( serialize( troop ) ); em = getOrCreateEntityManager(); tx = em.getTransaction(); @@ -54,13 +81,14 @@ public class DeleteOrphanTest extends BaseEntityManagerFunctionalTestCase { tx = em.getTransaction(); tx.begin(); soldier = em.find( Soldier.class, mickey.getId() ); - assertNull( "delete-orphan should work", soldier ); + Assert.assertNull( "delete-orphan should work", soldier ); troop = em.find( Troop.class, disney.getId() ); em.remove( troop ); tx.commit(); em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[]{ Troop.class, @@ -78,7 +106,7 @@ public class DeleteOrphanTest extends BaseEntityManagerFunctionalTestCase { return serialized; } - private Object unserialize(byte[] serialized) throws IOException, ClassNotFoundException { + private Object deserialize(byte[] serialized) throws IOException, ClassNotFoundException { ByteArrayInputStream byteIn = new ByteArrayInputStream( serialized ); ObjectInputStream in = new ObjectInputStream( byteIn ); Object result = in.readObject(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/DetachAndContainsTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/DetachAndContainsTest.java index a0cdb018e3..cbf200ccdc 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/DetachAndContainsTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/DetachAndContainsTest.java @@ -1,21 +1,52 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.cascade; -import static javax.persistence.CascadeType.DETACH; -import static javax.persistence.CascadeType.REMOVE; -import java.util.ArrayList; -import java.util.Collection; + import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import java.util.ArrayList; +import java.util.Collection; + import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static javax.persistence.CascadeType.DETACH; +import static javax.persistence.CascadeType.REMOVE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + /** * @author Emmanuel Bernard */ public class DetachAndContainsTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testDetach() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -49,6 +80,7 @@ public class DetachAndContainsTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[] { Mouth.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/FetchTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/FetchTest.java index 079d225843..cd6cc86c47 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/FetchTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/FetchTest.java @@ -1,19 +1,48 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.cascade; -import java.util.ArrayList; -import java.util.Date; + import javax.persistence.EntityManager; import javax.persistence.EntityTransaction; import javax.persistence.Query; +import java.util.ArrayList; +import java.util.Date; + import org.hibernate.Hibernate; import org.hibernate.ejb.HibernateEntityManager; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * @author Emmanuel Bernard */ public class FetchTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testCascadeAndFetchCollection() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -43,6 +72,7 @@ public class FetchTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testCascadeAndFetchEntity() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -71,6 +101,7 @@ public class FetchTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testTwoLevelDeepPersist() throws Exception { EntityTransaction tx; @@ -108,6 +139,7 @@ public class FetchTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testTwoLevelDeepPersistOnManyToOne() throws Exception { EntityTransaction tx; EntityManager em = getOrCreateEntityManager(); @@ -131,6 +163,7 @@ public class FetchTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testPerfCascadeAndFetchEntity() throws Exception { EntityManager em = getOrCreateEntityManager(); //init data @@ -198,7 +231,7 @@ public class FetchTest extends BaseEntityManagerFunctionalTestCase { em.close(); } - + @Override public Class[] getAnnotatedClasses() { return new Class[]{ Troop.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/FetchTest2.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/FetchTest2.java index a081d9ba1c..0ad169bac1 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/FetchTest2.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/cascade/FetchTest2.java @@ -1,12 +1,40 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.cascade; + import javax.persistence.EntityManager; + import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.fail; + public class FetchTest2 extends BaseEntityManagerFunctionalTestCase { - + @Test public void testProxyTransientStuff() throws Exception { - - EntityManager em = factory.createEntityManager(); + EntityManager em = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); Troop2 disney = new Troop2(); @@ -22,7 +50,7 @@ public class FetchTest2 extends BaseEntityManagerFunctionalTestCase { em.getTransaction().commit(); em.close(); - em = factory.createEntityManager(); + em = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); Soldier2 soldier = em.find( Soldier2.class, mickey.getId() ); @@ -37,7 +65,7 @@ public class FetchTest2 extends BaseEntityManagerFunctionalTestCase { em.getTransaction().commit(); em.close(); - em = factory.createEntityManager(); + em = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); //load troop wo a proxy @@ -56,6 +84,7 @@ public class FetchTest2 extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[]{ Troop2.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ejb3configuration/EntityManagerSerializationTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ejb3configuration/EntityManagerSerializationTest.java index ab8bc3a4b5..595b09ec7c 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ejb3configuration/EntityManagerSerializationTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ejb3configuration/EntityManagerSerializationTest.java @@ -1,13 +1,37 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.ejb3configuration; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Date; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; + import org.hibernate.ejb.HibernateEntityManager; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.ejb.test.Cat; @@ -16,15 +40,17 @@ import org.hibernate.ejb.test.Item; import org.hibernate.ejb.test.Kitten; import org.hibernate.ejb.test.Wallet; +import org.junit.Test; + /** * @author Emmanuel Bernard */ public class EntityManagerSerializationTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testSerialization() throws Exception { ByteArrayOutputStream stream = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream( stream ); - out.writeObject( factory ); + out.writeObject( entityManagerFactory() ); out.close(); byte[] serialized = stream.toByteArray(); stream.close(); @@ -79,6 +105,7 @@ public class EntityManagerSerializationTest extends BaseEntityManagerFunctionalT em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[]{ Item.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/FlushModeTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/FlushModeTest.java index 168f22ec27..c30045085e 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/FlushModeTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/FlushModeTest.java @@ -1,4 +1,3 @@ -//$Id$ /* * Hibernate, Relational Persistence for Idiomatic Java * @@ -23,16 +22,20 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.test.emops; + import java.util.HashMap; import java.util.Map; import javax.persistence.EntityManager; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Assert; +import org.junit.Test; + /** * @author Emmanuel Bernard */ public class FlushModeTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testCreateEMFlushMode() throws Exception { Map properties = new HashMap(); properties.put( "org.hibernate.flushMode", "manual" ); @@ -45,11 +48,12 @@ public class FlushModeTest extends BaseEntityManagerFunctionalTestCase { em.clear(); - assertNull( em.find( Dress.class, dress.name ) ); + Assert.assertNull( em.find( Dress.class, dress.name ) ); em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[] { Race.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/FlushTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/FlushTest.java index 9aa6069538..8505b95495 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/FlushTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/FlushTest.java @@ -1,5 +1,28 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.emops; + import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -10,19 +33,37 @@ import javax.persistence.Query; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Assert; +import org.junit.Test; + +import org.hibernate.testing.TestForIssue; + /** * @author Emmanuel Bernard */ public class FlushTest extends BaseEntityManagerFunctionalTestCase { - private static Set names= new HashSet(); - static { + private static Set names = namesSet(); + private static Set namesSet() { + HashSet names = new HashSet(); names.add("Toonses"); names.add("Sox"); names.add("Winnie"); names.add("Junior"); + return names; } - //Test for EJBTHREE-722 + @Override + public Class[] getAnnotatedClasses() { + return new Class[] { + Pet.class, + Dog.class, + Cat.class, + Decorate.class + }; + } + + @Test + @TestForIssue( jiraKey = "EJBTHREE-722" ) public void testFlushOnDetached() throws Exception { EntityManager manager = getOrCreateEntityManager( ); @@ -55,22 +96,21 @@ public class FlushTest extends BaseEntityManagerFunctionalTestCase { manager.flush(); manager.clear(); for (Object o : l) { - assertTrue( names.contains( ( (Pet) o).getName() ) ); + Assert.assertTrue( names.contains( ((Pet) o).getName() ) ); } Collection founds = getDecorate(manager); manager.flush(); manager.clear(); for (Decorate value : founds) { - assertTrue( names.contains( value.getPet().getName() ) ); + Assert.assertTrue( names.contains( value.getPet().getName() ) ); } manager.getTransaction().rollback(); manager.close(); - } - public Dog createDog(String name, double weight, int bones, EntityManager manager) { + private Dog createDog(String name, double weight, int bones, EntityManager manager) { Dog dog = new Dog(); dog.setName(name); dog.setWeight(weight); @@ -79,7 +119,7 @@ public class FlushTest extends BaseEntityManagerFunctionalTestCase { return dog; } - public Cat createCat(String name, double weight, int lives, EntityManager manager) { + private Cat createCat(String name, double weight, int lives, EntityManager manager) { Cat cat = new Cat(); cat.setName(name); cat.setWeight(weight); @@ -88,13 +128,13 @@ public class FlushTest extends BaseEntityManagerFunctionalTestCase { return cat; } - public List findByWeight(double weight, EntityManager manager) { + private List findByWeight(double weight, EntityManager manager) { return manager.createQuery( "select p from Pet p where p.weight < :weight").setParameter( "weight", weight).getResultList(); } - public Decorate createDecorate(String name, Pet pet, EntityManager manager) { + private Decorate createDecorate(String name, Pet pet, EntityManager manager) { Decorate dec = new Decorate(); dec.setName(name); dec.setPet(pet); @@ -102,7 +142,7 @@ public class FlushTest extends BaseEntityManagerFunctionalTestCase { return dec; } - public Collection getDecorate(EntityManager manager) { + private Collection getDecorate(EntityManager manager) { Collection founds = new ArrayList(); Query query = manager.createQuery("SELECT o FROM Decorate o"); List list = query.getResultList(); @@ -116,12 +156,4 @@ public class FlushTest extends BaseEntityManagerFunctionalTestCase { return founds; } - public Class[] getAnnotatedClasses() { - return new Class[] { - Pet.class, - Dog.class, - Cat.class, - Decorate.class - }; - } } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/GetReferenceTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/GetReferenceTest.java index 604f34e67a..7ec0e8f506 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/GetReferenceTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/GetReferenceTest.java @@ -1,18 +1,44 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.emops; + import javax.persistence.EntityManager; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.fail; /** * @author Emmanuel Bernard */ public class GetReferenceTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testWrongIdType() throws Exception { EntityManager em = getOrCreateEntityManager(); try { - Competitor c = em.getReference( Competitor.class, new String("30") ); + em.getReference( Competitor.class, "30" ); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { @@ -23,7 +49,7 @@ public class GetReferenceTest extends BaseEntityManagerFunctionalTestCase { } try { - Mail c = em.getReference( Mail.class, 1 ); + em.getReference( Mail.class, 1 ); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { @@ -35,6 +61,7 @@ public class GetReferenceTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[] { Competitor.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/MergeTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/MergeTest.java index 0252e16b0d..6fda66a2ca 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/MergeTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/MergeTest.java @@ -1,14 +1,44 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.emops; + +import javax.persistence.EntityManager; import java.util.ArrayList; import java.util.List; -import javax.persistence.EntityManager; + import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + /** * @author Emmanuel Bernard */ public class MergeTest extends BaseEntityManagerFunctionalTestCase { + @Test public void testMergeWithIndexColumn() { Race race = new Race(); race.competitors.add( new Competitor( "Name" ) ); @@ -33,6 +63,7 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testMergeManyToMany() { Competition competition = new Competition(); competition.getCompetitors().add( new Competitor( "Name" ) ); @@ -65,6 +96,7 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testMergeManyToManyWithDeference() { Competition competition = new Competition(); competition.getCompetitors().add( new Competitor( "Name" ) ); @@ -98,6 +130,7 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testRemoveAndMerge() { Race race = new Race(); EntityManager em = getOrCreateEntityManager(); @@ -122,6 +155,7 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testConcurrentMerge() { Race race = new Race(); race.name = "Derby"; @@ -154,6 +188,7 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testMergeUnidirectionalOneToMany() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -173,6 +208,7 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[] { Race.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/RefreshTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/RefreshTest.java index b1c7b25466..3834a77a6a 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/RefreshTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/RefreshTest.java @@ -1,13 +1,41 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.emops; + import javax.persistence.EntityManager; + import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.fail; + /** * @author Emmanuel Bernard */ public class RefreshTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testRefreshNonManaged() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -28,6 +56,7 @@ public class RefreshTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[] { Race.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/RemoveTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/RemoveTest.java index 947529e641..dd6b500014 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/RemoveTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/RemoveTest.java @@ -1,5 +1,28 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.emops; + import static org.hibernate.testing.TestLogger.LOG; import java.util.Map; import javax.persistence.EntityManager; @@ -7,11 +30,14 @@ import javax.persistence.OptimisticLockException; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Assert; +import org.junit.Test; + /** * @author Emmanuel Bernard */ public class RemoveTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testRemove() { Race race = new Race(); race.competitors.add( new Competitor() ); @@ -27,17 +53,19 @@ public class RemoveTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testRemoveAndFind() { Race race = new Race(); EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); em.persist( race ); em.remove( race ); - assertNull( em.find( Race.class, race.id ) ); + Assert.assertNull( em.find( Race.class, race.id ) ); em.getTransaction().rollback(); em.close(); } + @Test public void testUpdatedAndRemove() throws Exception { Music music = new Music(); music.setName( "Classical" ); @@ -48,12 +76,13 @@ public class RemoveTest extends BaseEntityManagerFunctionalTestCase { em.clear(); - EntityManager em2 = factory.createEntityManager(); + EntityManager em2 = entityManagerFactory().createEntityManager(); try { em2.getTransaction().begin(); //read music from 2nd EM music = em2.find( Music.class, music.getId() ); - } catch (Exception e) { + } + catch (Exception e) { em2.getTransaction().rollback(); em2.close(); throw e; @@ -68,9 +97,8 @@ public class RemoveTest extends BaseEntityManagerFunctionalTestCase { try { em2.remove( music ); //remove changed music em2.flush(); - fail("should have an optimistic lock exception"); + Assert.fail( "should have an optimistic lock exception" ); } - catch( OptimisticLockException e ) { LOG.debug("success"); } @@ -97,9 +125,8 @@ public class RemoveTest extends BaseEntityManagerFunctionalTestCase { @Override - public Map getConfig() { - Map cfg = super.getConfig(); - cfg.put( "hibernate.jdbc.batch_size", "0"); - return cfg; + @SuppressWarnings( {"unchecked"}) + protected void addConfigOptions(Map options) { + options.put( "hibernate.jdbc.batch_size", "0" ); } } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java index 1fa3c9ddc5..07454bc6f4 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java @@ -1,15 +1,43 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.emops.cascade; + import javax.persistence.EntityManager; + import org.hibernate.Session; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.stat.Statistics; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + /** * @author Emmanuel Bernard */ public class CascadePersistTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testLazyCollectionsStayLazyOnPersist() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -81,6 +109,7 @@ public class CascadePersistTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[]{ A.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/exception/ExceptionTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/exception/ExceptionTest.java index 44f6763cc3..789b3203dd 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/exception/ExceptionTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/exception/ExceptionTest.java @@ -1,24 +1,56 @@ -// $Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.exception; -import static org.hibernate.testing.TestLogger.LOG; -import java.util.Map; + import javax.persistence.EntityManager; import javax.persistence.EntityNotFoundException; import javax.persistence.OptimisticLockException; import javax.persistence.PersistenceException; +import java.util.Map; + import org.hibernate.cfg.Environment; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.exception.ConstraintViolationException; +import org.junit.Test; + +import org.hibernate.testing.TestForIssue; + +import static org.hibernate.testing.TestLogger.LOG; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * @author Emmanuel Bernard */ @SuppressWarnings("unchecked") public class ExceptionTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testOptimisticLockingException() throws Exception { EntityManager em = getOrCreateEntityManager(); - EntityManager em2 = factory.createEntityManager(); + EntityManager em2 = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); Music music = new Music(); music.setName( "Old Country" ); @@ -59,6 +91,7 @@ public class ExceptionTest extends BaseEntityManagerFunctionalTestCase { } } + @Test public void testEntityNotFoundException() throws Exception { EntityManager em = getOrCreateEntityManager(); Music music = em.getReference( Music.class, -1 ); @@ -74,6 +107,7 @@ public class ExceptionTest extends BaseEntityManagerFunctionalTestCase { } } + @Test public void testConstraintViolationException() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -102,7 +136,8 @@ public class ExceptionTest extends BaseEntityManagerFunctionalTestCase { } } - // HHH-4676 + @Test + @TestForIssue( jiraKey = "HHH-4676" ) public void testInterceptor() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -119,10 +154,8 @@ public class ExceptionTest extends BaseEntityManagerFunctionalTestCase { } @Override - public Map getConfig() { - Map config = super.getConfig(); - config.put( Environment.BATCH_VERSIONED_DATA, "false" ); - return config; + protected void addConfigOptions(Map options) { + options.put( Environment.BATCH_VERSIONED_DATA, "false" ); } @Override diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/inheritance/InheritanceTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/inheritance/InheritanceTest.java index 9742732ef0..bd4ef613e2 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/inheritance/InheritanceTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/inheritance/InheritanceTest.java @@ -1,13 +1,41 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.inheritance; + import javax.persistence.EntityManager; + import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + /** * @author Emmanuel Bernard */ public class InheritanceTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testFind() throws Exception { EntityManager firstSession = getOrCreateEntityManager( ); Strawberry u = new Strawberry(); @@ -30,6 +58,8 @@ public class InheritanceTest extends BaseEntityManagerFunctionalTestCase { firstSession.getTransaction().commit(); firstSession.close(); } + + @Override public Class[] getAnnotatedClasses() { return new Class[] { Fruit.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lob/BlobTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lob/BlobTest.java index 3511d518d7..54438147b6 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lob/BlobTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lob/BlobTest.java @@ -1,4 +1,3 @@ - /* * Hibernate, Relational Persistence for Idiomatic Java * @@ -34,6 +33,8 @@ import java.util.Map; import org.hibernate.Session; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + import org.hibernate.testing.DialectChecks; import org.hibernate.testing.RequiresDialectFeature; @@ -44,7 +45,7 @@ import static org.junit.Assert.assertTrue; */ @RequiresDialectFeature( DialectChecks.SupportsExpectedLobUsagePattern.class ) public class BlobTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testBlobSerialization() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -69,6 +70,7 @@ public class BlobTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[] { ImageReader.class }; } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java index 9eb9eb3d88..3e3c1a7bca 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java @@ -1,6 +1,34 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.lock; -import static org.hibernate.testing.TestLogger.LOG; + +import javax.persistence.EntityManager; +import javax.persistence.LockModeType; +import javax.persistence.LockTimeoutException; +import javax.persistence.OptimisticLockException; +import javax.persistence.Query; +import javax.persistence.QueryTimeoutException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -8,22 +36,25 @@ import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; -import javax.persistence.EntityManager; -import javax.persistence.LockModeType; -import javax.persistence.LockTimeoutException; -import javax.persistence.OptimisticLockException; -import javax.persistence.Query; -import javax.persistence.QueryTimeoutException; + import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.Oracle10gDialect; import org.hibernate.ejb.AvailableSettings; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.hibernate.testing.TestLogger.LOG; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * @author Emmanuel Bernard */ public class LockTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testFindWithTimeoutHint() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -49,6 +80,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testLockRead() throws Exception { Lock lock = new Lock(); lock.setName( "name" ); @@ -72,6 +104,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testLockOptimistic() throws Exception { Lock lock = new Lock(); lock.setName( "name" ); @@ -95,6 +128,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testLockWrite() throws Exception { Lock lock = new Lock(); lock.setName( "second" ); @@ -121,6 +155,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testLockWriteOnUnversioned() throws Exception { UnversionedLock lock = new UnversionedLock(); lock.setName( "second" ); @@ -153,6 +188,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testLockPessimisticForceIncrement() throws Exception { Lock lock = new Lock(); lock.setName( "force" ); @@ -179,6 +215,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testLockOptimisticForceIncrement() throws Exception { Lock lock = new Lock(); lock.setName( "force" ); @@ -205,30 +242,31 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase { em.close(); } - public void testLockOptimisticForceIncrementDifferentEm() throws Exception { - Lock lock = new Lock(); - lock.setName( "force" ); - EntityManager em1 = createIsolatedEntityManager(); - em1.getTransaction().begin(); - em1.persist( lock ); - em1.getTransaction().commit(); - em1.close(); + @Test + public void testLockOptimisticForceIncrementDifferentEm() throws Exception { + Lock lock = new Lock(); + lock.setName( "force" ); + EntityManager em1 = createIsolatedEntityManager(); + em1.getTransaction().begin(); + em1.persist( lock ); + em1.getTransaction().commit(); + em1.close(); - EntityManager em2 = createIsolatedEntityManager(); - em2.getTransaction().begin(); - lock = em2.find( Lock.class, lock.getId(), LockModeType.OPTIMISTIC ); - assertEquals( "lock mode should be OPTIMISTIC ", LockModeType.OPTIMISTIC, em2.getLockMode(lock) ); - em2.lock( lock, LockModeType.OPTIMISTIC_FORCE_INCREMENT ); - assertEquals( "lock mode should be OPTIMISTIC_FORCE_INCREMENT ", LockModeType.OPTIMISTIC_FORCE_INCREMENT, em2.getLockMode(lock) ); - em2.getTransaction().commit(); - em2.getTransaction().begin(); - em2.remove( lock ); - em2.getTransaction().commit(); - em2.close(); + EntityManager em2 = createIsolatedEntityManager(); + em2.getTransaction().begin(); + lock = em2.find( Lock.class, lock.getId(), LockModeType.OPTIMISTIC ); + assertEquals( "lock mode should be OPTIMISTIC ", LockModeType.OPTIMISTIC, em2.getLockMode(lock) ); + em2.lock( lock, LockModeType.OPTIMISTIC_FORCE_INCREMENT ); + assertEquals( "lock mode should be OPTIMISTIC_FORCE_INCREMENT ", LockModeType.OPTIMISTIC_FORCE_INCREMENT, em2.getLockMode(lock) ); + em2.getTransaction().commit(); + em2.getTransaction().begin(); + em2.remove( lock ); + em2.getTransaction().commit(); + em2.close(); } + @Test public void testContendedPessimisticLock() throws Exception { - EntityManager em = getOrCreateEntityManager(); final EntityManager em2 = createIsolatedEntityManager(); // TODO: replace dialect instanceof test with a Dialect.hasCapability (e.g. supportsPessimisticWriteLock) @@ -300,8 +338,8 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase { } } + @Test public void testContendedPessimisticReadLockTimeout() throws Exception { - EntityManager em = getOrCreateEntityManager(); final EntityManager em2 = createIsolatedEntityManager(); // TODO: replace dialect instanceof test with a Dialect.hasCapability (e.g. supportsPessimisticLockTimeout) @@ -385,6 +423,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase { } } + @Test public void testContendedPessimisticWriteLockTimeout() throws Exception { EntityManager em = getOrCreateEntityManager(); @@ -470,6 +509,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase { } } + @Test public void testContendedPessimisticWriteLockNoWait() throws Exception { EntityManager em = getOrCreateEntityManager(); @@ -555,6 +595,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase { } } + @Test public void testQueryTimeout() throws Exception { EntityManager em = getOrCreateEntityManager(); @@ -644,6 +685,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase { } } + @Test public void testQueryTimeoutEMProps() throws Exception { // TODO: replace dialect instanceof test with a Dialect.hasCapability if ( ! (getDialect() instanceof Oracle10gDialect)) { @@ -734,6 +776,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase { } + @Test public void testLockTimeoutEMProps() throws Exception { EntityManager em = getOrCreateEntityManager(); @@ -819,7 +862,7 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase { } } - + @Override public Class[] getAnnotatedClasses() { return new Class[]{ Lock.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lock/QueryLockingTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lock/QueryLockingTest.java index 1008f1e22f..0017ec16aa 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lock/QueryLockingTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/lock/QueryLockingTest.java @@ -22,23 +22,30 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.test.lock; -import java.util.Map; + import javax.persistence.EntityManager; import javax.persistence.LockModeType; +import java.util.Map; + import org.hibernate.LockMode; -import org.hibernate.cfg.AnnotationConfiguration; +import org.hibernate.cfg.Configuration; import org.hibernate.ejb.AvailableSettings; import org.hibernate.ejb.QueryImpl; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.impl.SessionImpl; +import org.junit.Test; + +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.assertTrue; + /** - * TODO : javadoc - * * @author Steve Ebersole */ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase { - @Override protected Class[] getAnnotatedClasses() { return new Class[] { Lockable.class }; @@ -47,9 +54,10 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase { @Override @SuppressWarnings({ "unchecked" }) protected void addConfigOptions(Map options) { - options.put( AnnotationConfiguration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" ); + options.put( Configuration.USE_NEW_ID_GENERATOR_MAPPINGS, "true" ); } + @Test public void testOverallLockMode() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -75,6 +83,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testPessimisticForcedIncrementOverall() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -99,6 +108,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testPessimisticForcedIncrementSpecific() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -125,6 +135,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testOptimisticForcedIncrementOverall() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -150,6 +161,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testOptimisticForcedIncrementSpecific() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -177,6 +189,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testOptimisticOverall() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -205,6 +218,7 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testOptimisticSpecific() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/mapping/QuotingTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/mapping/QuotingTest.java index 4415c33835..af1a912e03 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/mapping/QuotingTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/mapping/QuotingTest.java @@ -1,11 +1,37 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.mapping; + import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + /** * @author Emmanuel Bernard */ public class QuotingTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testQuote() { // the configuration was failing } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java index a44b482938..bba4879251 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java @@ -22,7 +22,7 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.test.metadata; -import java.util.Set; + import javax.persistence.EntityManagerFactory; import javax.persistence.metamodel.Attribute; import javax.persistence.metamodel.Bindable; @@ -36,44 +36,58 @@ import javax.persistence.metamodel.PluralAttribute; import javax.persistence.metamodel.SetAttribute; import javax.persistence.metamodel.SingularAttribute; import javax.persistence.metamodel.Type; -import org.hibernate.cfg.AnnotationConfiguration; +import java.util.Set; + +import org.hibernate.cfg.Configuration; import org.hibernate.ejb.metamodel.MetamodelImpl; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.engine.SessionFactoryImplementor; +import org.junit.Test; + +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.assertTrue; +import static org.junit.Assert.fail; + /** * @author Emmanuel Bernard */ public class MetadataTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testBaseOfService() throws Exception { - EntityManagerFactory emf = factory; + EntityManagerFactory emf = entityManagerFactory(); assertNotNull( emf.getMetamodel() ); final EntityType entityType = emf.getMetamodel().entity( Fridge.class ); assertNotNull( entityType ); } + @Test @SuppressWarnings({ "unchecked" }) public void testBuildingMetamodelWithParameterizedCollection() { - AnnotationConfiguration cfg = new AnnotationConfiguration( ); - configure( cfg ); + Configuration cfg = new Configuration( ); +// configure( cfg ); cfg.addAnnotatedClass( WithGenericCollection.class ); cfg.buildMappings(); - SessionFactoryImplementor sfi = (SessionFactoryImplementor) cfg.buildSessionFactory( getServiceRegistry() ); + SessionFactoryImplementor sfi = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry() ); MetamodelImpl.buildMetamodel( cfg.getClassMappings(), sfi ); } + @Test public void testLogicalManyToOne() throws Exception { - final EntityType entityType = factory.getMetamodel().entity( JoinedManyToOneOwner.class ); + final EntityType entityType = entityManagerFactory().getMetamodel().entity( JoinedManyToOneOwner.class ); final SingularAttribute attr = entityType.getDeclaredSingularAttribute( "house" ); assertEquals( Attribute.PersistentAttributeType.MANY_TO_ONE, attr.getPersistentAttributeType() ); assertEquals( House.class, attr.getBindableJavaType() ); - final EntityType houseType = factory.getMetamodel().entity( House.class ); + final EntityType houseType = entityManagerFactory().getMetamodel().entity( House.class ); assertEquals( houseType.getBindableJavaType(), attr.getBindableJavaType() ); } + @Test public void testEntity() throws Exception { - final EntityType fridgeType = factory.getMetamodel().entity( Fridge.class ); + final EntityType fridgeType = entityManagerFactory().getMetamodel().entity( Fridge.class ); assertEquals( Fridge.class, fridgeType.getBindableJavaType() ); assertEquals( Bindable.BindableType.ENTITY_TYPE, fridgeType.getBindableType() ); SingularAttribute wrapped = fridgeType.getDeclaredSingularAttribute( "temperature", Integer.class ); @@ -103,7 +117,7 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase { assertEquals( 3, fridgeType.getDeclaredAttributes().size() ); - final EntityType houseType = factory.getMetamodel().entity( House.class ); + final EntityType houseType = entityManagerFactory().getMetamodel().entity( House.class ); assertEquals( "org.hibernate.ejb.test.metadata.House", houseType.getName() ); assertTrue( houseType.hasSingleIdAttribute() ); final SingularAttribute houseId = houseType.getDeclaredId( House.Key.class ); @@ -111,7 +125,7 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase { assertTrue( houseId.isId() ); assertEquals( Attribute.PersistentAttributeType.EMBEDDED, houseId.getPersistentAttributeType() ); - final EntityType personType = factory.getMetamodel().entity( Person.class ); + final EntityType personType = entityManagerFactory().getMetamodel().entity( Person.class ); assertEquals( "Homo", personType.getName() ); assertFalse( personType.hasSingleIdAttribute() ); final Set> ids = personType.getIdClassAttributes(); @@ -121,7 +135,7 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase { assertTrue( localId.isId() ); } - final EntityType foodType = factory.getMetamodel().entity( FoodItem.class ); + final EntityType foodType = entityManagerFactory().getMetamodel().entity( FoodItem.class ); assertTrue( foodType.hasVersionAttribute() ); final SingularAttribute version = foodType.getVersion( Long.class ); assertNotNull( version ); @@ -130,8 +144,9 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase { } + @Test public void testBasic() throws Exception { - final EntityType entityType = factory.getMetamodel().entity( Fridge.class ); + final EntityType entityType = entityManagerFactory().getMetamodel().entity( Fridge.class ); final SingularAttribute singularAttribute = entityType.getDeclaredSingularAttribute( "temperature", Integer.class @@ -165,8 +180,9 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase { assertTrue( found ); } + @Test public void testEmbeddable() throws Exception { - final EntityType entityType = factory.getMetamodel().entity( House.class ); + final EntityType entityType = entityManagerFactory().getMetamodel().entity( House.class ); final SingularAttribute address = entityType.getDeclaredSingularAttribute( "address", Address.class @@ -181,21 +197,23 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase { assertTrue( addressType.getDeclaredSingularAttribute( "address1" ).isOptional() ); assertFalse( addressType.getDeclaredSingularAttribute( "address2" ).isOptional() ); - final EmbeddableType
directType = factory.getMetamodel().embeddable( Address.class ); + final EmbeddableType
directType = entityManagerFactory().getMetamodel().embeddable( Address.class ); assertNotNull( directType ); assertEquals( Type.PersistenceType.EMBEDDABLE, directType.getPersistenceType() ); } + @Test public void testCollection() throws Exception { - final EntityType entiytype = factory.getMetamodel().entity( Garden.class ); + final EntityType entiytype = entityManagerFactory().getMetamodel().entity( Garden.class ); final Set> attributes = entiytype.getPluralAttributes(); assertEquals( 1, attributes.size() ); PluralAttribute flowers = attributes.iterator().next(); assertTrue( flowers instanceof ListAttribute ); } + @Test public void testElementCollection() throws Exception { - final EntityType entityType = factory.getMetamodel().entity( House.class ); + final EntityType entityType = entityManagerFactory().getMetamodel().entity( House.class ); final SetAttribute rooms = entityType.getDeclaredSet( "rooms", Room.class ); assertNotNull( rooms ); assertTrue( rooms.isAssociation() ); @@ -222,8 +240,9 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase { assertEquals( PluralAttribute.CollectionType.LIST, roomsBySize.getCollectionType() ); } + @Test public void testHierarchy() { - final EntityType cat = factory.getMetamodel().entity( Cat.class ); + final EntityType cat = entityManagerFactory().getMetamodel().entity( Cat.class ); assertNotNull( cat ); assertEquals( 7, cat.getAttributes().size() ); assertEquals( 1, cat.getDeclaredAttributes().size() ); @@ -287,14 +306,15 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase { assertNull( thing.getSupertype() ); } + @Test public void testBackrefAndGenerics() throws Exception { - final EntityType parent = factory.getMetamodel().entity( Parent.class ); + final EntityType parent = entityManagerFactory().getMetamodel().entity( Parent.class ); assertNotNull( parent ); final SetAttribute children = parent.getSet( "children" ); assertNotNull( children ); assertEquals( 1, parent.getPluralAttributes().size() ); assertEquals( 4, parent.getAttributes().size() ); - final EntityType child = factory.getMetamodel().entity( Child.class ); + final EntityType child = entityManagerFactory().getMetamodel().entity( Child.class ); assertNotNull( child ); assertEquals( 2, child.getAttributes().size() ); final SingularAttribute attribute = parent.getSingularAttribute( diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java index 1a3ffd0f13..51a195e900 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/metadata/SecondMetadataTest.java @@ -1,15 +1,43 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.metadata; + import javax.persistence.EntityManagerFactory; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + /** * @author Emmanuel Bernard */ public class SecondMetadataTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testBaseOfService() throws Exception { - EntityManagerFactory emf = factory; + EntityManagerFactory emf = entityManagerFactory(); assertNotNull( emf.getMetamodel() ); assertNotNull( emf.getMetamodel().entity( DeskWithRawType.class ) ); assertNotNull( emf.getMetamodel().entity( EmployeeWithRawType.class ) ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/metadata/StaticMetadataTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/metadata/StaticMetadataTest.java index c7f30cae65..4a6261d67c 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/metadata/StaticMetadataTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/metadata/StaticMetadataTest.java @@ -22,20 +22,28 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.test.metadata; -import java.util.Set; + import javax.persistence.metamodel.Attribute; import javax.persistence.metamodel.Bindable; import javax.persistence.metamodel.EmbeddableType; import javax.persistence.metamodel.PluralAttribute; import javax.persistence.metamodel.Type; +import java.util.Set; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + /** * @author Steve Ebersole */ public class StaticMetadataTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testInjections() throws Exception { // Address (embeddable) assertNotNull( Address_.address1 ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/FindTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/FindTest.java index 2f46870705..1efbb5186e 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/FindTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/FindTest.java @@ -1,13 +1,39 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.ops; + import javax.persistence.EntityManager; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Assert; +import org.junit.Test; + /** * @author Emmanuel Bernard */ public class FindTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testSubclassWrongId() throws Exception { Mammal mammal = new Mammal(); mammal.setMamalNbr( 2 ); @@ -16,11 +42,12 @@ public class FindTest extends BaseEntityManagerFunctionalTestCase { em.getTransaction().begin(); em.persist( mammal ); em.flush(); - assertNull( em.find(Reptile.class, 1l) ); + Assert.assertNull( em.find( Reptile.class, 1l ) ); em.getTransaction().rollback(); em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[] { Mammal.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/GetLoadTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/GetLoadTest.java index fd94dc1d27..e04c717b17 100755 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/GetLoadTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/GetLoadTest.java @@ -21,23 +21,30 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ - -//$Id$ package org.hibernate.ejb.test.ops; -import java.util.Map; + import javax.persistence.EntityManager; +import java.util.Map; + import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.cfg.Environment; import org.hibernate.ejb.EntityManagerFactoryImpl; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + /** * @author Gavin King * @author Hardy Ferentschik */ public class GetLoadTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testGetLoad() { clearCounts(); @@ -106,27 +113,24 @@ public class GetLoadTest extends BaseEntityManagerFunctionalTestCase { } private void clearCounts() { - ( ( EntityManagerFactoryImpl ) factory ).getSessionFactory().getStatistics().clear(); + ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory().getStatistics().clear(); } private void assertFetchCount(int count) { - int fetches = ( int ) ( ( EntityManagerFactoryImpl ) factory ).getSessionFactory() + int fetches = ( int ) ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory() .getStatistics() .getEntityFetchCount(); assertEquals( count, fetches ); } @Override + @SuppressWarnings( {"unchecked"}) protected void addConfigOptions(Map options) { options.put( Environment.GENERATE_STATISTICS, "true" ); options.put( Environment.STATEMENT_BATCH_SIZE, "0" ); } @Override - protected Class[] getAnnotatedClasses() { - return new Class[0]; - } - protected String[] getMappings() { return new String[] { "org/hibernate/ejb/test/ops/Node.hbm.xml", diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/MergeNewTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/MergeNewTest.java index af6a05437c..58c0187476 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/MergeNewTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/MergeNewTest.java @@ -1,14 +1,41 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.ops; + import javax.persistence.EntityManager; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + /** * @author Emmanuel Bernard */ public class MergeNewTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testMergeNew() throws Exception { Workload load = new Workload(); load.name = "Cleaning"; @@ -23,6 +50,7 @@ public class MergeNewTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testMergeAfterRemove() throws Exception { Workload load = new Workload(); load.name = "Cleaning"; @@ -48,8 +76,9 @@ public class MergeNewTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Override public Class[] getAnnotatedClasses() { - return new Class[]{ + return new Class[] { Workload.class }; } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/MergeTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/MergeTest.java index ea21c0bbbc..68311b6f5d 100755 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/MergeTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/MergeTest.java @@ -21,20 +21,23 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -//$Id$ package org.hibernate.ejb.test.ops; + import java.util.Map; import javax.persistence.EntityManager; import org.hibernate.cfg.Environment; import org.hibernate.ejb.EntityManagerFactoryImpl; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Assert; +import org.junit.Test; + /** * @author Gavin King * @author Hardy Ferentschik */ public class MergeTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testMergeTree() { clearCounts(); @@ -100,24 +103,25 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase { } private void clearCounts() { - ( ( EntityManagerFactoryImpl ) factory ).getSessionFactory().getStatistics().clear(); + ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory().getStatistics().clear(); } private void assertInsertCount(int count) { - int inserts = ( int ) ( ( EntityManagerFactoryImpl ) factory ).getSessionFactory() + int inserts = ( int ) ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory() .getStatistics() .getEntityInsertCount(); - assertEquals( count, inserts ); + Assert.assertEquals( count, inserts ); } private void assertUpdateCount(int count) { - int updates = ( int ) ( ( EntityManagerFactoryImpl ) factory ).getSessionFactory() + int updates = ( int ) ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory() .getStatistics() .getEntityUpdateCount(); - assertEquals( count, updates ); + Assert.assertEquals( count, updates ); } @Override + @SuppressWarnings( {"unchecked"}) protected void addConfigOptions(Map options) { options.put( Environment.GENERATE_STATISTICS, "true" ); options.put( Environment.STATEMENT_BATCH_SIZE, "0" ); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/PersistTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/PersistTest.java index 7c8f94f4db..aa2c137425 100755 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/PersistTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/ops/PersistTest.java @@ -23,22 +23,31 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.ejb.test.ops; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; + import javax.persistence.EntityManager; import javax.persistence.PersistenceException; import javax.persistence.RollbackException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + import org.hibernate.cfg.Environment; import org.hibernate.ejb.EntityManagerFactoryImpl; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + /** * @author Gavin King * @author Hardy Ferentschik */ public class PersistTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testCreateTree() { clearCounts(); @@ -56,7 +65,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase { em = getOrCreateEntityManager(); em.getTransaction().begin(); - root = ( Node ) em.find( Node.class, "root" ); + root = em.find( Node.class, "root" ); Node child2 = new Node( "child2" ); root.addChild( child2 ); em.getTransaction().commit(); @@ -66,6 +75,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase { assertUpdateCount( 0 ); } + @Test public void testCreateTreeWithGeneratedId() { clearCounts(); @@ -83,7 +93,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase { em = getOrCreateEntityManager(); em.getTransaction().begin(); - root = ( NumberedNode ) em.find( NumberedNode.class, root.getId() ); + root = em.find( NumberedNode.class, root.getId() ); NumberedNode child2 = new NumberedNode( "child2" ); root.addChild( child2 ); em.getTransaction().commit(); @@ -93,6 +103,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase { assertUpdateCount( 0 ); } + @Test public void testCreateException() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -130,6 +141,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testCreateExceptionWithGeneratedId() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -167,6 +179,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testBasic() throws Exception { EntityManager em = getOrCreateEntityManager(); @@ -185,7 +198,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase { em = getOrCreateEntityManager(); em.getTransaction().begin(); - er = ( Employer ) em.find( Employer.class, er.getId() ); + er = em.find( Employer.class, er.getId() ); assertNotNull( er ); assertNotNull( er.getEmployees() ); assertEquals( 1, er.getEmployees().size() ); @@ -196,23 +209,25 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase { } private void clearCounts() { - ( ( EntityManagerFactoryImpl ) factory ).getSessionFactory().getStatistics().clear(); + ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory().getStatistics().clear(); } private void assertInsertCount(int count) { - int inserts = ( int ) ( ( EntityManagerFactoryImpl ) factory ).getSessionFactory() + int inserts = ( int ) ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory() .getStatistics() .getEntityInsertCount(); assertEquals( count, inserts ); } private void assertUpdateCount(int count) { - int updates = ( int ) ( ( EntityManagerFactoryImpl ) factory ).getSessionFactory() + int updates = ( int ) ( ( EntityManagerFactoryImpl ) entityManagerFactory() ).getSessionFactory() .getStatistics() .getEntityUpdateCount(); assertEquals( count, updates ); } + @Override + @SuppressWarnings( {"unchecked"}) protected void addConfigOptions(Map options) { options.put( Environment.GENERATE_STATISTICS, "true" ); options.put( Environment.STATEMENT_BATCH_SIZE, "0" ); @@ -223,6 +238,7 @@ public class PersistTest extends BaseEntityManagerFunctionalTestCase { return new Class[] { Node.class }; } + @Override protected String[] getMappings() { return new String[] { "org/hibernate/ejb/test/ops/Node.hbm.xml", diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/query/ComponentJoinsTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/query/ComponentJoinsTest.java index b457a09b81..4447c2d2e7 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/query/ComponentJoinsTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/query/ComponentJoinsTest.java @@ -22,20 +22,26 @@ * Boston, MA 02110-1301 USA\ */ package org.hibernate.ejb.test.query; + import javax.persistence.EntityManager; + import org.hibernate.ejb.criteria.components.Client; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + /** * Tests related to specifying joins on components (embedded values). * * @author Steve Ebersole */ public class ComponentJoinsTest extends BaseEntityManagerFunctionalTestCase { + @Override public Class[] getAnnotatedClasses() { return new Class[] { Client.class }; } + @Test public void testComponentJoins() { // Just checking proper query construction and syntax checking via database query parser... EntityManager em = getOrCreateEntityManager(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/query/QueryTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/query/QueryTest.java index a5baddbe00..3d17820564 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/query/QueryTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/query/QueryTest.java @@ -1,23 +1,53 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.query; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; import javax.persistence.EntityManager; import javax.persistence.Query; import javax.persistence.TemporalType; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + import org.hibernate.Hibernate; +import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.ejb.test.Distributor; import org.hibernate.ejb.test.Item; -import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.ejb.test.Wallet; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * @author Emmanuel Bernard */ public class QueryTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testPagedQuery() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -37,6 +67,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testAggregationReturnType() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -51,6 +82,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testParameterList() throws Exception { final Item item = new Item( "Mouse", "Micro$oft mouse" ); final Item item2 = new Item( "Computer", "Dell computer" ); @@ -99,6 +131,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testParameterListInExistingParens() throws Exception { final Item item = new Item( "Mouse", "Micro$oft mouse" ); final Item item2 = new Item( "Computer", "Dell computer" ); @@ -150,39 +183,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { em.close(); } -// public void testDistinct() throws Exception { -// Item item = new Item("Mouse", "Micro_oft mouse"); -// Distributor fnac = new Distributor(); -// fnac.setName("Fnac"); -// item.addDistributor(fnac); -// Distributor auchan = new Distributor(); -// auchan.setName("Auchan"); -// item.addDistributor(auchan); -// -// EntityManager em = getOrCreateEntityManager(); -// em.getTransaction().begin(); -// em.persist(fnac); -// em.persist(auchan); -// em.persist(item); -// em.getTransaction().commit(); -// -// em.getTransaction().begin(); -// Query q = em.createQuery("select distinct item from Item item join fetch item.distributors"); -// List result = q.getResultList(); -// assertNotNull(result); -// assertEquals( 1, result.size() ); -// item = (Item) result.get(0); -// item.getDistributors().clear(); -// em.flush(); -// int deleted = em.createQuery("delete from Item").executeUpdate(); -// assertEquals( 1, deleted ); -// deleted = em.createQuery("delete from Distributor").executeUpdate(); -// assertEquals( 2, deleted ); -// em.getTransaction().commit(); -// -// em.close(); -// } - + @Test public void testEscapeCharacter() throws Exception { final Item item = new Item( "Mouse", "Micro_oft mouse" ); final Item item2 = new Item( "Computer", "Dell computer" ); @@ -206,8 +207,8 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testNativeQueryByEntity() { - Item item = new Item( "Mouse", "Micro$oft mouse" ); EntityManager em = getOrCreateEntityManager(); @@ -227,8 +228,8 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { } + @Test public void testNativeQueryByResultSet() { - Item item = new Item( "Mouse", "Micro$oft mouse" ); EntityManager em = getOrCreateEntityManager(); @@ -249,6 +250,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { } + @Test public void testExplicitPositionalParameter() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -274,6 +276,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testPositionalParameterForms() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -308,6 +311,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testPositionalParameterWithUserError() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -335,6 +339,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { } } + @Test public void testNativeQuestionMarkParameter() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -354,8 +359,8 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testNativeQueryWithPositionalParameter() { - Item item = new Item( "Mouse", "Micro$oft mouse" ); EntityManager em = getOrCreateEntityManager(); @@ -382,6 +387,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { } + @Test public void testDistinct() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -410,6 +416,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testIsNull() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -443,8 +450,8 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testUpdateQuery() { - Item item = new Item( "Mouse", "Micro$oft mouse" ); EntityManager em = getOrCreateEntityManager(); @@ -469,6 +476,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { } + @Test public void testUnavailableNamedQuery() throws Exception { Item item = new Item( "Mouse", "Micro$oft mouse" ); @@ -493,6 +501,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { } + @Test public void testTypedNamedNativeQuery() { Item item = new Item( "Mouse", "Micro$oft mouse" ); @@ -513,6 +522,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[]{ Item.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java index 1a733df9e9..46c371cb43 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java @@ -1,21 +1,53 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.transaction; -import java.util.List; + import javax.persistence.EntityManager; import javax.persistence.LockModeType; import javax.persistence.OptimisticLockException; import javax.persistence.PersistenceException; import javax.persistence.RollbackException; import javax.persistence.TransactionRequiredException; +import java.util.List; + import org.hibernate.Session; import org.hibernate.ejb.HibernateEntityManagerFactory; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.stat.Statistics; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * @author Emmanuel Bernard */ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase { + @Test public void testAlwaysTransactionalOperations() throws Exception { Book book = new Book(); book.name = "Le petit prince"; @@ -43,39 +75,12 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase em.close(); } -// public void testTransactionalOperationsWhenTransactional() throws Exception { -// Book book = new Book(); -// book.name = "Le petit prince"; -// EntityManager em = getEntityManager( PersistenceContextType.TRANSACTION ); -// try { -// em.persist( book ); -// fail("flush has to be inside a Tx"); -// } -// catch (TransactionRequiredException e) { -// //success -// } -// try { -// em.refresh( book ); -// fail("refresh has to be inside a Tx"); -// } -// catch (TransactionRequiredException e) { -// //success -// } -// try { -// em.remove( book ); -// fail("refresh has to be inside a Tx"); -// } -// catch (TransactionRequiredException e) { -// //success -// } -// em.close(); -// } - + @Test public void testTransactionalOperationsWhenExtended() throws Exception { Book book = new Book(); book.name = "Le petit prince"; EntityManager em = getOrCreateEntityManager(); - Statistics stats = ( ( HibernateEntityManagerFactory ) factory ).getSessionFactory().getStatistics(); + Statistics stats = ( ( HibernateEntityManagerFactory ) entityManagerFactory() ).getSessionFactory().getStatistics(); stats.clear(); stats.setStatisticsEnabled( true ); @@ -114,11 +119,12 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase stats.setStatisticsEnabled( false ); } + @Test public void testMergeWhenExtended() throws Exception { Book book = new Book(); book.name = "Le petit prince"; EntityManager em = getOrCreateEntityManager(); - Statistics stats = ( ( HibernateEntityManagerFactory ) factory ).getSessionFactory().getStatistics(); + Statistics stats = ( ( HibernateEntityManagerFactory ) entityManagerFactory() ).getSessionFactory().getStatistics(); em.getTransaction().begin(); em.persist( book ); @@ -157,6 +163,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase stats.setStatisticsEnabled( false ); } + @Test public void testCloseAndTransaction() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -175,6 +182,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase } } + @Test public void testTransactionCommitDoesNotFlush() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -192,6 +200,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase em.close(); } + @Test public void testTransactionAndContains() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -211,6 +220,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase em.close(); } + @Test public void testRollbackOnlyOnPersistenceException() throws Exception { Book book = new Book(); book.name = "Stolen keys"; @@ -243,9 +253,9 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase finally { em.close(); } - } + @Test public void testRollbackExceptionOnOptimisticLockException() throws Exception { Book book = new Book(); book.name = "Stolen keys"; @@ -277,6 +287,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase } + @Test public void testRollbackClearPC() throws Exception { Book book = new Book(); book.name = "Stolen keys"; @@ -292,6 +303,7 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[] { Book.class diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/util/GetIdentifierTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/util/GetIdentifierTest.java index e27861ec7a..cda3c41f02 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/util/GetIdentifierTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/util/GetIdentifierTest.java @@ -1,14 +1,43 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.util; + import javax.persistence.EntityManager; + import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + /** * @author Emmanuel Bernard */ public class GetIdentifierTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testSimpleId() { - EntityManager em = factory.createEntityManager(); + EntityManager em = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); Book book = new Book(); em.persist( book ); @@ -18,8 +47,9 @@ public class GetIdentifierTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testEmbeddedId() { - EntityManager em = factory.createEntityManager(); + EntityManager em = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); Umbrella umbrella = new Umbrella(); umbrella.setId( new Umbrella.PK() ); @@ -32,8 +62,9 @@ public class GetIdentifierTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test public void testIdClass() { - EntityManager em = factory.createEntityManager(); + EntityManager em = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); Sickness sick = new Sickness(); @@ -49,6 +80,7 @@ public class GetIdentifierTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[] { Book.class, diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/util/IsLoadedTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/util/IsLoadedTest.java index 2f99424e22..6732bdd814 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/util/IsLoadedTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/util/IsLoadedTest.java @@ -1,14 +1,44 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.util; + import javax.persistence.EntityManager; + import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * @author Emmanuel Bernard */ public class IsLoadedTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testIsLoadedOnPrivateSuperclassProperty() { - EntityManager em = factory.createEntityManager(); + EntityManager em = entityManagerFactory().createEntityManager(); em.getTransaction().begin(); Author a = new Author(); Book book = new Book(a); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/CounterListener.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/CounterListener.java index 0d5ef0250f..f87e7708a5 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/CounterListener.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/CounterListener.java @@ -1,5 +1,28 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.xml; + import javax.persistence.PrePersist; import javax.persistence.PreRemove; import javax.persistence.PreUpdate; diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/XmlAttributeOverrideTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/XmlAttributeOverrideTest.java index 20f0d53890..22a1caa8de 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/XmlAttributeOverrideTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/XmlAttributeOverrideTest.java @@ -1,13 +1,41 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.xml; + import javax.persistence.EntityManager; + import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + /** * @author Emmanuel Bernard */ public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testAttributeOverriding() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -26,6 +54,7 @@ public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCas em.close(); } + @Test public void testDefaultEventListener() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -63,10 +92,6 @@ public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCas assertEquals( 1, CounterListener.delete ); } - public Class[] getAnnotatedClasses() { - return new Class[0]; - } - @Override public String[] getEjb3DD() { return new String[] { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/XmlTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/XmlTest.java index 163f45d801..c421f418ee 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/XmlTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/XmlTest.java @@ -1,18 +1,45 @@ -//$Id$ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.xml; + import javax.persistence.EntityManager; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + /** * @author Emmanuel Bernard */ public class XmlTest extends BaseEntityManagerFunctionalTestCase { + @Test public void testXmlMappingCorrectness() throws Exception { EntityManager em = getOrCreateEntityManager(); em.close(); } + @Override public Class[] getAnnotatedClasses() { return new Class[0]; } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/sequences/XmlAttributeOverrideTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/sequences/XmlAttributeOverrideTest.java index 49f830514c..3753d57556 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/sequences/XmlAttributeOverrideTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/ejb/test/xml/sequences/XmlAttributeOverrideTest.java @@ -1,13 +1,38 @@ -//$Id: $ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, 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.ejb.test.xml.sequences; + import javax.persistence.EntityManager; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Test; + /** * @author Emmanuel Bernard */ public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCase { - + @Test public void testAttributeOverriding() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -26,10 +51,6 @@ public class XmlAttributeOverrideTest extends BaseEntityManagerFunctionalTestCas em.close(); } - public Class[] getAnnotatedClasses() { - return new Class[0]; - } - @Override public String[] getEjb3DD() { return new String[] {