HHH-5942 - Migrate to JUnit 4

This commit is contained in:
Steve Ebersole 2011-03-14 12:51:04 -05:00
parent df4df47b95
commit 9ad55dc4bd
60 changed files with 1663 additions and 585 deletions

View File

@ -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 ?
}
}
}
}

View File

@ -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 <b>when</b> 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<String> xmlFiles = (Collection<String>) workingVars.get(
AvailableSettings.XML_FILE_NAMES
);
Collection<String> xmlFiles = (Collection<String>) 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;
}

View File

@ -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<String,Object> 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<String, Object> propertyMap, Properties properties) {

View File

@ -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;
/**

View File

@ -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> 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;
}

View File

@ -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();

View File

@ -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()

View File

@ -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();

View File

@ -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();

View File

@ -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<Order> orderCriteria = builder.createQuery( Order.class );
Root<Order> orderRoot = orderCriteria.from( Order.class );
@ -66,9 +74,14 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
List<Order> 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<Order> orderCriteria = builder.createQuery( Order.class );
Root<Order> orderRoot = orderCriteria.from( Order.class );
@ -78,12 +91,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
List<Order> 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<Order> orderCriteria = builder.createQuery( Order.class );
Root<Order> orderRoot = orderCriteria.from( Order.class );
@ -92,12 +110,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
List<Order> 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<Order> orderCriteria = builder.createQuery( Order.class );
Root<Order> 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<Order> orderCriteria = builder.createQuery( Order.class );
Root<Order> orderRoot = orderCriteria.from( Order.class );
@ -127,12 +155,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
List<Order> 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<Order> orderCriteria = builder.createQuery( Order.class );
Root<Order> orderRoot = orderCriteria.from( Order.class );
@ -143,20 +176,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
List<Order> 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<Order> orderCriteria = builder.createQuery( Order.class );
Root<Order> orderRoot = orderCriteria.from( Order.class );
@ -166,12 +196,17 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
List<Order> 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<Order> orderCriteria = builder.createQuery( Order.class );
Root<Order> orderRoot = orderCriteria.from( Order.class );
@ -181,6 +216,8 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
List<Order> orders = em.createQuery( orderCriteria ).getResultList();
assertTrue( orders.size() == 0 );
em.getTransaction().commit();
em.close();
}

View File

@ -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<Client> root = cq.from(Client.class);
cq.where(cb.equal(root.get("name").get("firstName"), client.getName().getFirstName()));
List<Client> 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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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<Object[]> 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<Tuple> 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();

View File

@ -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 {

View File

@ -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<VersionedEntity> metadata = em.getMetamodel().entity( VersionedEntity.class );
assertNotNull( metadata.getDeclaredVersion( int.class ) );

View File

@ -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<EntityManager> isolatedEms = new ArrayList<EntityManager>();
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<Class, String> 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<String, String> 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<String> dds = new ArrayList<String>();
@ -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<Class, String> getCachedClasses() {
return new HashMap<Class, String>();
}
protected String[] getOrmXmlFiles() {
return NO_MAPPINGS;
public Map<String, String> getCachedCollections() {
return new HashMap<String, String>();
}
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<Class, String> getCachedClasses() {
return new HashMap<Class, String>();
}
public Map<String, String> getCachedCollections() {
return new HashMap<String, String>();
}
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;
}
}

View File

@ -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<Class, String> getCachedClasses() {
Map<Class, String> result = new HashMap<Class, String>();
result.put( Item.class, "read-write" );
return result;
}
@Override
public Map<String, String> getCachedCollections() {
Map<String, String> result = new HashMap<String, String>();
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<Distributor>() );
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<String, Object> 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();

View File

@ -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,

View File

@ -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" ) );

View File

@ -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" );

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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();

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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<String, String> properties = new HashMap<String, String>();
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,

View File

@ -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<String> names= new HashSet<String>();
static {
private static Set<String> names = namesSet();
private static Set<String> namesSet() {
HashSet<String> names = new HashSet<String>();
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<Decorate> 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<Decorate> getDecorate(EntityManager manager) {
private Collection<Decorate> getDecorate(EntityManager manager) {
Collection<Decorate> founds = new ArrayList<Decorate>();
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
};
}
}

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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" );
}
}

View File

@ -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,

View File

@ -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

View File

@ -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,

View File

@ -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 };
}

View File

@ -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,

View File

@ -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();

View File

@ -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
}

View File

@ -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<Fridge> 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<JoinedManyToOneOwner> entityType = factory.getMetamodel().entity( JoinedManyToOneOwner.class );
final EntityType<JoinedManyToOneOwner> 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<House> houseType = factory.getMetamodel().entity( House.class );
final EntityType<House> houseType = entityManagerFactory().getMetamodel().entity( House.class );
assertEquals( houseType.getBindableJavaType(), attr.getBindableJavaType() );
}
@Test
public void testEntity() throws Exception {
final EntityType<Fridge> fridgeType = factory.getMetamodel().entity( Fridge.class );
final EntityType<Fridge> fridgeType = entityManagerFactory().getMetamodel().entity( Fridge.class );
assertEquals( Fridge.class, fridgeType.getBindableJavaType() );
assertEquals( Bindable.BindableType.ENTITY_TYPE, fridgeType.getBindableType() );
SingularAttribute<Fridge,Integer> wrapped = fridgeType.getDeclaredSingularAttribute( "temperature", Integer.class );
@ -103,7 +117,7 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
assertEquals( 3, fridgeType.getDeclaredAttributes().size() );
final EntityType<House> houseType = factory.getMetamodel().entity( House.class );
final EntityType<House> houseType = entityManagerFactory().getMetamodel().entity( House.class );
assertEquals( "org.hibernate.ejb.test.metadata.House", houseType.getName() );
assertTrue( houseType.hasSingleIdAttribute() );
final SingularAttribute<House, House.Key> 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<Person> personType = factory.getMetamodel().entity( Person.class );
final EntityType<Person> personType = entityManagerFactory().getMetamodel().entity( Person.class );
assertEquals( "Homo", personType.getName() );
assertFalse( personType.hasSingleIdAttribute() );
final Set<SingularAttribute<? super Person,?>> ids = personType.getIdClassAttributes();
@ -121,7 +135,7 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
assertTrue( localId.isId() );
}
final EntityType<FoodItem> foodType = factory.getMetamodel().entity( FoodItem.class );
final EntityType<FoodItem> foodType = entityManagerFactory().getMetamodel().entity( FoodItem.class );
assertTrue( foodType.hasVersionAttribute() );
final SingularAttribute<? super FoodItem, Long> version = foodType.getVersion( Long.class );
assertNotNull( version );
@ -130,8 +144,9 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
}
@Test
public void testBasic() throws Exception {
final EntityType<Fridge> entityType = factory.getMetamodel().entity( Fridge.class );
final EntityType<Fridge> entityType = entityManagerFactory().getMetamodel().entity( Fridge.class );
final SingularAttribute<? super Fridge,Integer> 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<House> entityType = factory.getMetamodel().entity( House.class );
final EntityType<House> entityType = entityManagerFactory().getMetamodel().entity( House.class );
final SingularAttribute<? super House,Address> 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<Address> directType = factory.getMetamodel().embeddable( Address.class );
final EmbeddableType<Address> directType = entityManagerFactory().getMetamodel().embeddable( Address.class );
assertNotNull( directType );
assertEquals( Type.PersistenceType.EMBEDDABLE, directType.getPersistenceType() );
}
@Test
public void testCollection() throws Exception {
final EntityType<Garden> entiytype = factory.getMetamodel().entity( Garden.class );
final EntityType<Garden> entiytype = entityManagerFactory().getMetamodel().entity( Garden.class );
final Set<PluralAttribute<? super Garden, ?, ?>> attributes = entiytype.getPluralAttributes();
assertEquals( 1, attributes.size() );
PluralAttribute<? super Garden, ?, ?> flowers = attributes.iterator().next();
assertTrue( flowers instanceof ListAttribute );
}
@Test
public void testElementCollection() throws Exception {
final EntityType<House> entityType = factory.getMetamodel().entity( House.class );
final EntityType<House> entityType = entityManagerFactory().getMetamodel().entity( House.class );
final SetAttribute<House,Room> 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> cat = factory.getMetamodel().entity( Cat.class );
final EntityType<Cat> 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> parent = factory.getMetamodel().entity( Parent.class );
final EntityType<Parent> parent = entityManagerFactory().getMetamodel().entity( Parent.class );
assertNotNull( parent );
final SetAttribute<? super Parent, ?> children = parent.getSet( "children" );
assertNotNull( children );
assertEquals( 1, parent.getPluralAttributes().size() );
assertEquals( 4, parent.getAttributes().size() );
final EntityType<Child> child = factory.getMetamodel().entity( Child.class );
final EntityType<Child> child = entityManagerFactory().getMetamodel().entity( Child.class );
assertNotNull( child );
assertEquals( 2, child.getAttributes().size() );
final SingularAttribute<? super Parent, Parent.Relatives> attribute = parent.getSingularAttribute(

View File

@ -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 ) );

View File

@ -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 );

View File

@ -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,

View File

@ -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",

View File

@ -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
};
}

View File

@ -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" );

View File

@ -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",

View File

@ -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();

View File

@ -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,

View File

@ -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

View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -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[] {

View File

@ -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];
}

View File

@ -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[] {