From 7fc5d3e85647a4ede4a4c11a65a8c41b1bf2073f Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Mon, 11 Dec 2017 13:56:28 -0600 Subject: [PATCH] HHH-12098 - prep 5.3 --- hibernate-core/hibernate-core.gradle | 8 +- .../org/hibernate/cfg/AvailableSettings.java | 2 +- .../hibernate/jpa/test/cdi/BasicCdiTest.java | 131 ++++++++++-------- ...ationalPersistenceContextExtendedTest.java | 2 + ...ationalPersistenceContextExtendedTest.java | 2 + ...ationalPersistenceContextExtendedTest.java | 2 + .../emf/DdlInWildFlyUsingBmtAndEmfTest.java | 2 + .../bmt/sf/DdlInWildFlyUsingBmtAndSfTest.java | 2 + .../emf/DdlInWildFlyUsingBmtAndEmfTest.java | 2 + .../cmt/sf/DdlInWildFlyUsingCmtAndSfTest.java | 2 + .../hibernate/testing/FailureExpected.java | 2 + .../org/hibernate/testing/junit4/Helper.java | 2 +- libraries.gradle | 7 +- 13 files changed, 98 insertions(+), 68 deletions(-) diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index 0d3ad6266c..bd7b4bf2ce 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -67,7 +67,7 @@ dependencies { provided( libraries.jacc ) provided( libraries.validation ) provided( libraries.ant ) - provided( "javax.enterprise:cdi-api:${cdiVersion}" ) + provided( libraries.cdi ) testCompile( project(':hibernate-testing') ) testCompile( libraries.shrinkwrap_api ) @@ -79,9 +79,8 @@ dependencies { testCompile( libraries.mockito ) testCompile( libraries.mockito_inline ) testCompile( 'joda-time:joda-time:2.3' ) -// testCompile( "org.jboss.weld:weld-core:2.3.4.Final" ) -// testCompile( "org.jboss.arquillian.container:arquillian-weld-ee-embedded-1.1:1.0.0.CR9" ) - testCompile( "javax.enterprise:cdi-api:${cdiVersion}" ) { + + testCompile( libraries.cdi ) { // we need to force it to make sure we influence the one coming from arquillian force=true } @@ -100,6 +99,7 @@ dependencies { testRuntime( 'jaxen:jaxen:1.1' ) testRuntime( libraries.javassist ) testRuntime( libraries.byteBuddy ) + testRuntime( libraries.weld ) testCompile( project( ':hibernate-jpamodelgen' ) ) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java index 3abbd5d8df..8beba873d1 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -24,7 +24,7 @@ import org.hibernate.tool.schema.SourceType; /** * @author Steve Ebersole */ -public interface AvailableSettings { +public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // JPA defined settings diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/BasicCdiTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/BasicCdiTest.java index 6bf5e74189..c9708a0951 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/BasicCdiTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/BasicCdiTest.java @@ -10,92 +10,101 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; -import javax.annotation.Resource; -import javax.inject.Inject; +import javax.enterprise.inject.se.SeContainer; +import javax.enterprise.inject.se.SeContainerInitializer; import javax.persistence.Entity; import javax.persistence.EntityListeners; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; import javax.persistence.Id; -import javax.persistence.PersistenceUnit; import javax.persistence.PrePersist; import javax.persistence.Table; -import javax.transaction.TransactionManager; -import javax.transaction.UserTransaction; + +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.BootstrapServiceRegistry; +import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.jpa.event.spi.JpaIntegrator; +import org.hibernate.tool.schema.Action; import org.junit.Test; -import org.junit.runner.RunWith; - -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.jboss.shrinkwrap.api.asset.StringAsset; -import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.jboss.shrinkwrap.descriptor.api.Descriptors; -import org.jboss.shrinkwrap.descriptor.api.persistence21.PersistenceDescriptor; +import static org.hibernate.testing.transaction.TransactionUtil2.inTransaction; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; /** * @author Steve Ebersole */ -@RunWith(Arquillian.class) public class BasicCdiTest { - @Deployment - public static Archive buildDeployment() { - return ShrinkWrap.create( JavaArchive.class, "test.jar" ) - .addClass( MyEntity.class ) - .addClass( EventQueue.class ) - .addClass( Event.class ) - .addClass( Monitor.class ) - .addAsManifestResource( EmptyAsset.INSTANCE, "beans.xml" ) - .addAsManifestResource( new StringAsset( persistenceXml().exportAsString() ), "persistence.xml" ); - } - - private static PersistenceDescriptor persistenceXml() { - return Descriptors.create( PersistenceDescriptor.class ) - .createPersistenceUnit().name( "pu-cdi-basic" ) - .clazz( MyEntity.class.getName() ) - .excludeUnlistedClasses( true ) - .nonJtaDataSource( "java:jboss/datasources/ExampleDS" ) - .getOrCreateProperties().createProperty().name( "jboss.as.jpa.providerModule" ).value( "org.hibernate:5.3" ).up().up() - .getOrCreateProperties().createProperty().name( "hibernate.delay_cdi_access" ).value( "true" ).up().up() - .getOrCreateProperties().createProperty().name( "hibernate.hbm2ddl.auto" ).value( "create-drop" ).up().up().up(); - } - - @PersistenceUnit - EntityManagerFactory emf; - - @Resource - private UserTransaction utx; - private static int count; @Test @SuppressWarnings("unchecked") - public void testIt() throws Exception { + public void testIt() { + final SeContainerInitializer cdiInitializer = SeContainerInitializer.newInstance() + .disableDiscovery() + .addBeanClasses( Monitor.class, EventQueue.class, Event.class ); + count = 0; - utx.begin(); - EntityManager em = emf.createEntityManager(); - em.persist( new MyEntity( 1 ) ); - utx.commit(); + try ( final SeContainer cdiContainer = cdiInitializer.initialize() ) { + BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder() + .applyIntegrator( new JpaIntegrator() ) + .build(); - assertEquals( 1, count ); + final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr ) + .applySetting( AvailableSettings.CDI_BEAN_MANAGER, cdiContainer.getBeanManager() ) + .applySetting( AvailableSettings.DELAY_CDI_ACCESS, "true" ) + .applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP ) + .build(); - utx.begin(); - em = emf.createEntityManager(); - MyEntity it = em.find( MyEntity.class, 1 ); - assertNotNull( it ); - em.remove( it ); - utx.commit(); + final SessionFactoryImplementor sessionFactory; + + try { + sessionFactory = (SessionFactoryImplementor) new MetadataSources( ssr ) + .addAnnotatedClass( MyEntity.class ) + .buildMetadata() + .getSessionFactoryBuilder() + .build(); + } + catch ( Exception e ) { + StandardServiceRegistryBuilder.destroy( ssr ); + throw e; + } + + try { + inTransaction( + sessionFactory, + session -> session.persist( new MyEntity( 1 ) ) + ); + + assertEquals( 1, count ); + + inTransaction( + sessionFactory, + session -> { + MyEntity it = session.find( MyEntity.class, 1 ); + assertNotNull( it ); + } + ); + } + finally { + inTransaction( + sessionFactory, + session -> { + session.createQuery( "delete MyEntity" ).executeUpdate(); + } + ); + + sessionFactory.close(); + } + } } - @Entity + @Entity( name = "MyEntity" ) @EntityListeners( Monitor.class ) @Table(name = "my_entity") public static class MyEntity { @@ -132,7 +141,7 @@ public class BasicCdiTest { public void addEvent(Event anEvent) { if ( events == null ) { - events = new ArrayList(); + events = new ArrayList<>(); } events.add( anEvent ); count++; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/extended/ConversationalPersistenceContextExtendedTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/extended/ConversationalPersistenceContextExtendedTest.java index 162ed88233..915769c6c5 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/extended/ConversationalPersistenceContextExtendedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/extended/ConversationalPersistenceContextExtendedTest.java @@ -10,6 +10,7 @@ import javax.ejb.EJB; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,6 +30,7 @@ import static org.junit.Assert.assertEquals; * @author Vlad Mihalcea */ @RunWith(Arquillian.class) +@Ignore( "WildFly has not released a version supporting JPA 2.2 and CDI 2.0" ) public class ConversationalPersistenceContextExtendedTest { @Deployment diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/extended/ManualFlushConversationalPersistenceContextExtendedTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/extended/ManualFlushConversationalPersistenceContextExtendedTest.java index a8214bdf6c..657c3b22c4 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/extended/ManualFlushConversationalPersistenceContextExtendedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/extended/ManualFlushConversationalPersistenceContextExtendedTest.java @@ -11,6 +11,7 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.hibernate.testing.TestForIssue; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,6 +31,7 @@ import static org.junit.Assert.assertEquals; * @author Vlad Mihalcea */ @RunWith(Arquillian.class) +@Ignore( "WildFly has not released a version supporting JPA 2.2 and CDI 2.0" ) public class ManualFlushConversationalPersistenceContextExtendedTest { @Deployment diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/extended/NonConversationalPersistenceContextExtendedTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/extended/NonConversationalPersistenceContextExtendedTest.java index bb6ae15bf3..1b4bc502c9 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/extended/NonConversationalPersistenceContextExtendedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/cdi/extended/NonConversationalPersistenceContextExtendedTest.java @@ -10,6 +10,7 @@ import javax.ejb.EJB; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,6 +30,7 @@ import static org.junit.Assert.assertEquals; * @author Vlad Mihalcea */ @RunWith(Arquillian.class) +@Ignore( "WildFly has not released a version supporting JPA 2.2 and CDI 2.0" ) public class NonConversationalPersistenceContextExtendedTest { @Deployment diff --git a/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/bmt/emf/DdlInWildFlyUsingBmtAndEmfTest.java b/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/bmt/emf/DdlInWildFlyUsingBmtAndEmfTest.java index 8f793642f4..d761fc1d4d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/bmt/emf/DdlInWildFlyUsingBmtAndEmfTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/bmt/emf/DdlInWildFlyUsingBmtAndEmfTest.java @@ -24,6 +24,7 @@ import org.hibernate.jpa.boot.internal.PersistenceXmlParser; import org.hibernate.jpa.boot.spi.Bootstrap; import org.hibernate.test.wf.ddl.WildFlyDdlEntity; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -43,6 +44,7 @@ import static org.junit.Assert.assertNotNull; * @author Steve Ebersole */ @RunWith( Arquillian.class ) +@Ignore( "WildFly has not released a version supporting JPA 2.2 and CDI 2.0" ) public class DdlInWildFlyUsingBmtAndEmfTest { public static final String PERSISTENCE_XML_RESOURCE_NAME = "pu-wf-ddl/persistence.xml"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/bmt/sf/DdlInWildFlyUsingBmtAndSfTest.java b/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/bmt/sf/DdlInWildFlyUsingBmtAndSfTest.java index 6685d2b12f..823dd3cb2a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/bmt/sf/DdlInWildFlyUsingBmtAndSfTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/bmt/sf/DdlInWildFlyUsingBmtAndSfTest.java @@ -8,6 +8,7 @@ package org.hibernate.test.wf.ddl.bmt.sf; import org.hibernate.testing.TestForIssue; import org.hibernate.test.wf.ddl.WildFlyDdlEntity; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -22,6 +23,7 @@ import org.jboss.shrinkwrap.api.spec.WebArchive; */ @RunWith(Arquillian.class) @TestForIssue(jiraKey = "HHH-11024") +@Ignore( "WildFly has not released a version supporting JPA 2.2 and CDI 2.0" ) public class DdlInWildFlyUsingBmtAndSfTest { public static final String ARCHIVE_NAME = BmtSfStatefulBean.class.getSimpleName(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/cmt/emf/DdlInWildFlyUsingBmtAndEmfTest.java b/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/cmt/emf/DdlInWildFlyUsingBmtAndEmfTest.java index 2c4b68d0fe..5a0555db3c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/cmt/emf/DdlInWildFlyUsingBmtAndEmfTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/cmt/emf/DdlInWildFlyUsingBmtAndEmfTest.java @@ -22,6 +22,7 @@ import org.hibernate.jpa.boot.internal.PersistenceXmlParser; import org.hibernate.jpa.boot.spi.Bootstrap; import org.hibernate.test.wf.ddl.WildFlyDdlEntity; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -41,6 +42,7 @@ import static org.junit.Assert.assertNotNull; * @author Steve Ebersole */ @RunWith( Arquillian.class ) +@Ignore( "WildFly has not released a version supporting JPA 2.2 and CDI 2.0" ) public class DdlInWildFlyUsingBmtAndEmfTest { public static final String PERSISTENCE_XML_RESOURCE_NAME = "pu-wf-ddl/persistence.xml"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/cmt/sf/DdlInWildFlyUsingCmtAndSfTest.java b/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/cmt/sf/DdlInWildFlyUsingCmtAndSfTest.java index 8d833db3a7..30675c9df2 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/cmt/sf/DdlInWildFlyUsingCmtAndSfTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/wf/ddl/cmt/sf/DdlInWildFlyUsingCmtAndSfTest.java @@ -8,6 +8,7 @@ package org.hibernate.test.wf.ddl.cmt.sf; import org.hibernate.testing.TestForIssue; import org.hibernate.test.wf.ddl.WildFlyDdlEntity; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -22,6 +23,7 @@ import org.jboss.shrinkwrap.api.spec.WebArchive; */ @RunWith(Arquillian.class) @TestForIssue(jiraKey = "HHH-11024") +@Ignore( "WildFly has not released a version supporting JPA 2.2 and CDI 2.0" ) public class DdlInWildFlyUsingCmtAndSfTest { public static final String ARCHIVE_NAME = CmtSfStatefulBean.class.getSimpleName(); diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpected.java b/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpected.java index cfc123eb2f..220343db4d 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpected.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpected.java @@ -20,6 +20,8 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD, ElementType.TYPE }) public @interface FailureExpected { + String VALIDATE_FAILURE_EXPECTED = "hibernate.test.validatefailureexpected"; + /** * The key of a JIRA issue which covers this expected failure. * @return The jira issue key diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/Helper.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/Helper.java index 815648f73d..391d12c8ba 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/Helper.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/Helper.java @@ -26,7 +26,7 @@ import org.junit.runners.model.TestClass; * @author Steve Ebersole */ public final class Helper { - public static final String VALIDATE_FAILURE_EXPECTED = "hibernate.test.validatefailureexpected"; + public static final String VALIDATE_FAILURE_EXPECTED = FailureExpected.VALIDATE_FAILURE_EXPECTED; private Helper() { } diff --git a/libraries.gradle b/libraries.gradle index 71b56cffe3..83127808f5 100644 --- a/libraries.gradle +++ b/libraries.gradle @@ -15,7 +15,9 @@ ext { infinispanVersion = '8.2.5.Final' jnpVersion = '5.0.6.CR1' elVersion = '2.2.4' - cdiVersion = '1.1' + + cdiVersion = '2.0' + weldVersion = '3.0.0.Final' javassistVersion = '3.22.0-GA' byteBuddyVersion = '1.6.14' // Improved JDK9 compatibility @@ -130,6 +132,9 @@ ext { proxool: "proxool:proxool:0.8.3", hikaricp: "com.zaxxer:HikariCP:2.5.1", + cdi: "javax.enterprise:cdi-api:${cdiVersion}", + weld: "org.jboss.weld.se:weld-se-shaded:${weldVersion}", + // Arquillian/Shrinkwrap arquillian_junit_container: "org.jboss.arquillian.junit:arquillian-junit-container:${arquillianVersion}", arquillian_protocol_servlet: "org.jboss.arquillian.protocol:arquillian-protocol-servlet:${arquillianVersion}",