You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2012/05/19 05:45:46 UTC
[2/5] DELTASPIKE-175 and DELTASPIKE-178
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/context/TransactionContextExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/context/TransactionContextExtension.java b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/context/TransactionContextExtension.java
new file mode 100644
index 0000000..292f1e9
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/context/TransactionContextExtension.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.jpa.impl.transaction.context;
+
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.core.util.ClassDeactivationUtils;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+
+/**
+ * CDI Extension which registers and manages the {@link TransactionContext}.
+ */
+public class TransactionContextExtension implements Extension, Deactivatable
+{
+ private Boolean isActivated = null;
+
+ protected void init(@Observes BeforeBeanDiscovery afterBeanDiscovery)
+ {
+ initActivation();
+ }
+
+ /**
+ * Register the TransactionContext as a CDI Context
+ *
+ * @param afterBeanDiscovery after-bean-discovery event
+ */
+ protected void registerTransactionContext(@Observes AfterBeanDiscovery afterBeanDiscovery)
+ {
+ if (!isActivated)
+ {
+ return;
+ }
+
+ TransactionContext transactionContext = new TransactionContext();
+ afterBeanDiscovery.addContext(transactionContext);
+ }
+
+ protected void initActivation()
+ {
+ if (isActivated == null)
+ {
+ isActivated = ClassDeactivationUtils.isActivated(getClass());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/main/resources/META-INF/beans.xml b/deltaspike/modules/jpa/impl/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..0f736c4
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+ <interceptors>
+ <class>org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor</class>
+ </interceptors>
+</beans>
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/deltaspike/modules/jpa/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
new file mode 100644
index 0000000..abbfce7
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
@@ -0,0 +1,20 @@
+#####################################################################################
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#####################################################################################
+
+org.apache.deltaspike.jpa.impl.transaction.context.TransactionContextExtension
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/First.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/First.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/First.java
new file mode 100644
index 0000000..f7c854a
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/First.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.shared;
+
+import javax.inject.Qualifier;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Target({ FIELD, METHOD, PARAMETER })
+@Retention(RUNTIME)
+@Documented
+
+//cdi annotations
+@Qualifier
+public @interface First
+{
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/Second.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/Second.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/Second.java
new file mode 100644
index 0000000..b1a1a1f
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/Second.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.shared;
+
+import javax.inject.Qualifier;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Target({ FIELD, METHOD, PARAMETER })
+@Retention(RUNTIME)
+@Documented
+
+//cdi annotations
+@Qualifier
+public @interface Second
+{
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/TestEntityManager.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/TestEntityManager.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/TestEntityManager.java
new file mode 100644
index 0000000..f23e89c
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/TestEntityManager.java
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.shared;
+
+import javax.enterprise.inject.Typed;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.FlushModeType;
+import javax.persistence.LockModeType;
+import javax.persistence.Query;
+import javax.persistence.TypedQuery;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.metamodel.Metamodel;
+import java.util.Map;
+
+@Typed()
+public class TestEntityManager implements EntityManager
+{
+ private EntityTransaction entityTransaction = new TestEntityTransaction();
+
+ private boolean open = true;
+ private boolean flushed = false;
+
+ @Override
+ public void persist(Object entity)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public <T> T merge(T entity)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public void remove(Object entity)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public <T> T find(Class<T> entityClass, Object primaryKey)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public <T> T find(Class<T> entityClass, Object primaryKey, Map<String, Object> properties)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockMode)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockMode, Map<String, Object> properties)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public <T> T getReference(Class<T> entityClass, Object primaryKey)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public void flush()
+ {
+ this.flushed = true;
+ }
+
+ @Override
+ public void setFlushMode(FlushModeType flushMode)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public FlushModeType getFlushMode()
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public void lock(Object entity, LockModeType lockMode)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public void lock(Object entity, LockModeType lockMode, Map<String, Object> properties)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public void refresh(Object entity)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public void refresh(Object entity, Map<String, Object> properties)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public void refresh(Object entity, LockModeType lockMode)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public void refresh(Object entity, LockModeType lockMode, Map<String, Object> properties)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public void clear()
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public void detach(Object entity)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public boolean contains(Object entity)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public LockModeType getLockMode(Object entity)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public void setProperty(String propertyName, Object value)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Map<String, Object> getProperties()
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Query createQuery(String qlString)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public <T> TypedQuery<T> createQuery(String qlString, Class<T> resultClass)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Query createNamedQuery(String name)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public <T> TypedQuery<T> createNamedQuery(String name, Class<T> resultClass)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Query createNativeQuery(String sqlString)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Query createNativeQuery(String sqlString, Class resultClass)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Query createNativeQuery(String sqlString, String resultSetMapping)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public void joinTransaction()
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public <T> T unwrap(Class<T> cls)
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Object getDelegate()
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public void close()
+ {
+ if (!this.open)
+ {
+ throw new IllegalStateException("entity manager is closed already");
+ }
+ this.open = false;
+ }
+
+ @Override
+ public boolean isOpen()
+ {
+ return this.open;
+ }
+
+ @Override
+ public EntityTransaction getTransaction()
+ {
+ return this.entityTransaction;
+ }
+
+ @Override
+ public EntityManagerFactory getEntityManagerFactory()
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public CriteriaBuilder getCriteriaBuilder()
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public Metamodel getMetamodel()
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ public boolean isFlushed()
+ {
+ return flushed;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/TestEntityTransaction.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/TestEntityTransaction.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/TestEntityTransaction.java
new file mode 100644
index 0000000..79cafb8
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/TestEntityTransaction.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.shared;
+
+import javax.persistence.EntityTransaction;
+
+public class TestEntityTransaction implements EntityTransaction
+{
+ private boolean started = false;
+ private boolean committed = false;
+ private boolean rolledBack = false;
+
+ @Override
+ public void begin()
+ {
+ if (this.started)
+ {
+ throw new IllegalStateException("transaction started already");
+ }
+
+ this.started = true;
+ }
+
+ @Override
+ public void commit()
+ {
+ this.committed = true;
+ }
+
+ @Override
+ public void rollback()
+ {
+ this.rolledBack = true;
+ }
+
+ @Override
+ public void setRollbackOnly()
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public boolean getRollbackOnly()
+ {
+ throw new IllegalStateException("not implemented");
+ }
+
+ @Override
+ public boolean isActive()
+ {
+ return this.started && !(this.committed || this.rolledBack);
+ }
+
+ public boolean isStarted()
+ {
+ return started;
+ }
+
+ public boolean isCommitted()
+ {
+ return committed;
+ }
+
+ public boolean isRolledBack()
+ {
+ return rolledBack;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/TestException.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/TestException.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/TestException.java
new file mode 100644
index 0000000..0b0a168
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/shared/TestException.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.shared;
+
+public class TestException extends RuntimeException
+{
+ private static final long serialVersionUID = -3719932856173828526L;
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/DefaultEntityManagerInjectionTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/DefaultEntityManagerInjectionTest.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/DefaultEntityManagerInjectionTest.java
new file mode 100644
index 0000000..e75bc38
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/DefaultEntityManagerInjectionTest.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.defaultinjection;
+
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
+import org.apache.deltaspike.jpa.impl.transaction.context.TransactionContextExtension;
+import org.apache.deltaspike.test.jpa.api.shared.TestEntityManager;
+import org.apache.deltaspike.test.jpa.api.shared.TestEntityTransaction;
+import org.apache.deltaspike.test.jpa.api.shared.TestException;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.Extension;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+@RunWith(Arquillian.class)
+public class DefaultEntityManagerInjectionTest
+{
+ @Inject
+ private TransactionalBean transactionalBean;
+
+ @Inject
+ @Failed
+ private TransactionalBean failedTransactionalBean;
+
+ @Inject
+ private FailedFlushTransactionalBean failedFlushTransactionalBean;
+
+ @Inject
+ private TestEntityManagerProducer entityManagerProducer;
+
+ @Deployment
+ public static WebArchive deploy()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "defaultInjectionTest.jar")
+ .addPackage(ArchiveUtils.SHARED_PACKAGE)
+ .addPackage(DefaultEntityManagerInjectionTest.class.getPackage().getName())
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+
+ return ShrinkWrap.create(WebArchive.class)
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndJpaArchive())
+ .addAsLibraries(testJar)
+ .addAsServiceProvider(Extension.class, TransactionContextExtension.class)
+ .addAsWebInfResource(ArchiveUtils.getBeansXml(), "beans.xml");
+ }
+
+ @Test
+ public void defaultEntityManagerInjection()
+ {
+ EntityManager injectedEntityManager = this.entityManagerProducer.getDefaultEntityManager();
+
+ Assert.assertNotNull(injectedEntityManager);
+ Assert.assertTrue(injectedEntityManager instanceof TestEntityManager);
+ TestEntityTransaction testTransaction = (TestEntityTransaction) (injectedEntityManager).getTransaction();
+
+ Assert.assertEquals(false, ((TestEntityManager) injectedEntityManager).isFlushed());
+ Assert.assertEquals(false, testTransaction.isActive());
+ Assert.assertEquals(false, testTransaction.isStarted());
+ Assert.assertEquals(false, testTransaction.isCommitted());
+ Assert.assertEquals(false, testTransaction.isRolledBack());
+
+ this.transactionalBean.executeInTransaction();
+
+ Assert.assertEquals(true, ((TestEntityManager) injectedEntityManager).isFlushed());
+ Assert.assertEquals(false, testTransaction.isActive());
+ Assert.assertEquals(true, testTransaction.isStarted());
+ Assert.assertEquals(true, testTransaction.isCommitted());
+ Assert.assertEquals(false, testTransaction.isRolledBack());
+ }
+
+ @Test
+ public void defaultEntityManagerInjectionFailedTransaction()
+ {
+ EntityManager injectedEntityManager = this.entityManagerProducer.getDefaultEntityManager();
+
+ Assert.assertNotNull(injectedEntityManager);
+ Assert.assertTrue(injectedEntityManager instanceof TestEntityManager);
+ TestEntityTransaction testTransaction = (TestEntityTransaction) (injectedEntityManager).getTransaction();
+
+ Assert.assertEquals(false, ((TestEntityManager) injectedEntityManager).isFlushed());
+ Assert.assertEquals(false, testTransaction.isActive());
+ Assert.assertEquals(false, testTransaction.isStarted());
+ Assert.assertEquals(false, testTransaction.isCommitted());
+ Assert.assertEquals(false, testTransaction.isRolledBack());
+
+ try
+ {
+ this.failedTransactionalBean.executeInTransaction();
+ Assert.fail(TestException.class.getName() + " expected!");
+ }
+ catch (TestException e)
+ {
+ //expected
+ }
+
+ Assert.assertEquals(false, ((TestEntityManager) injectedEntityManager).isFlushed());
+ Assert.assertEquals(false, testTransaction.isActive());
+ Assert.assertEquals(true, testTransaction.isStarted());
+ Assert.assertEquals(false, testTransaction.isCommitted());
+ Assert.assertEquals(true, testTransaction.isRolledBack());
+ }
+
+ @Test
+ public void defaultEntityManagerInjectionFailedFlush()
+ {
+ EntityManager injectedEntityManager = this.entityManagerProducer.getFailedFlushEntityManager();
+
+ Assert.assertNotNull(injectedEntityManager);
+ Assert.assertTrue(injectedEntityManager instanceof TestEntityManager);
+ TestEntityTransaction testTransaction = (TestEntityTransaction) (injectedEntityManager).getTransaction();
+
+ Assert.assertEquals(false, ((TestEntityManager) injectedEntityManager).isFlushed());
+ Assert.assertEquals(false, testTransaction.isActive());
+ Assert.assertEquals(false, testTransaction.isStarted());
+ Assert.assertEquals(false, testTransaction.isCommitted());
+ Assert.assertEquals(false, testTransaction.isRolledBack());
+
+ try
+ {
+ this.failedFlushTransactionalBean.executeInTransaction();
+ Assert.fail(TestException.class.getName() + " expected!");
+ }
+ catch (TestException e)
+ {
+ //expected
+ }
+
+ Assert.assertEquals(false, ((TestEntityManager) injectedEntityManager).isFlushed());
+ Assert.assertEquals(false, testTransaction.isActive());
+ Assert.assertEquals(true, testTransaction.isStarted());
+ Assert.assertEquals(false, testTransaction.isCommitted());
+ Assert.assertEquals(true, testTransaction.isRolledBack());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/Failed.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/Failed.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/Failed.java
new file mode 100644
index 0000000..4b9f69d
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/Failed.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.defaultinjection;
+
+import javax.inject.Qualifier;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Target({ FIELD, METHOD, TYPE })
+@Retention(RUNTIME)
+@Documented
+
+//cdi annotations
+@Qualifier
+public @interface Failed
+{
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/FailedFlushTransactionalBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/FailedFlushTransactionalBean.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/FailedFlushTransactionalBean.java
new file mode 100644
index 0000000..4da6ede
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/FailedFlushTransactionalBean.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.defaultinjection;
+
+import org.apache.deltaspike.jpa.api.Transactional;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+@ApplicationScoped
+public class FailedFlushTransactionalBean
+{
+ @Inject
+ @Failed
+ private EntityManager entityManager;
+
+ @Transactional
+ public void executeInTransaction()
+ {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/FailedTransactionalBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/FailedTransactionalBean.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/FailedTransactionalBean.java
new file mode 100644
index 0000000..dbc6280
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/FailedTransactionalBean.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.defaultinjection;
+
+import org.apache.deltaspike.jpa.api.Transactional;
+import org.apache.deltaspike.test.jpa.api.shared.TestException;
+
+import javax.enterprise.context.ApplicationScoped;
+
+@Failed
+@ApplicationScoped
+public class FailedTransactionalBean extends TransactionalBean
+{
+ @Override
+ @Transactional
+ public void executeInTransaction()
+ {
+ throw new TestException();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/TestEntityManagerProducer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/TestEntityManagerProducer.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/TestEntityManagerProducer.java
new file mode 100644
index 0000000..8d15805
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/TestEntityManagerProducer.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.defaultinjection;
+
+import org.apache.deltaspike.test.jpa.api.shared.TestEntityManager;
+import org.apache.deltaspike.test.jpa.api.shared.TestException;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+import javax.persistence.EntityManager;
+
+@RequestScoped
+public class TestEntityManagerProducer
+{
+ private TestEntityManager defaultEntityManager = new TestEntityManager();
+ private TestEntityManager failedFlushEntityManager = new TestEntityManager() {
+ @Override
+ public void flush()
+ {
+ throw new TestException();
+ }
+ };
+
+ @Produces
+ protected EntityManager defaultEntityManager()
+ {
+ return this.defaultEntityManager;
+ }
+
+ @Produces
+ @Failed
+ protected EntityManager failedFlushEntityManager()
+ {
+ return this.failedFlushEntityManager;
+ }
+
+ public TestEntityManager getDefaultEntityManager()
+ {
+ return defaultEntityManager;
+ }
+
+ public TestEntityManager getFailedFlushEntityManager()
+ {
+ return failedFlushEntityManager;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/TransactionalBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/TransactionalBean.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/TransactionalBean.java
new file mode 100644
index 0000000..81125a8
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultinjection/TransactionalBean.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.defaultinjection;
+
+import org.apache.deltaspike.jpa.api.Transactional;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+@ApplicationScoped
+public class TransactionalBean
+{
+ @Inject
+ private EntityManager entityManager;
+
+ @Transactional
+ public void executeInTransaction()
+ {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/DefaultNestedTransactionTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/DefaultNestedTransactionTest.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/DefaultNestedTransactionTest.java
new file mode 100644
index 0000000..59c0e1e
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/DefaultNestedTransactionTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.defaultnested;
+
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
+import org.apache.deltaspike.jpa.impl.transaction.context.TransactionContextExtension;
+import org.apache.deltaspike.test.jpa.api.shared.TestEntityManager;
+import org.apache.deltaspike.test.jpa.api.shared.TestEntityTransaction;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.Extension;
+import javax.inject.Inject;
+
+@RunWith(Arquillian.class)
+public class DefaultNestedTransactionTest
+{
+ @Inject
+ private FirstLevelTransactionBean firstLevelTransactionBean;
+
+ @Inject
+ private TestEntityManagerProducer entityManagerProducer;
+
+ @Deployment
+ public static WebArchive deploy()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "defaultNestedTransactionTest.jar")
+ .addPackage(ArchiveUtils.SHARED_PACKAGE)
+ .addPackage(DefaultNestedTransactionTest.class.getPackage().getName())
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+
+ return ShrinkWrap.create(WebArchive.class)
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndJpaArchive())
+ .addAsLibraries(testJar)
+ .addAsServiceProvider(Extension.class, TransactionContextExtension.class)
+ .addAsWebInfResource(ArchiveUtils.getBeansXml(), "beans.xml");
+ }
+
+ @Test
+ public void defaultNestedTransaction()
+ {
+ TestEntityManager firstEntityManager = this.entityManagerProducer.getFirstEntityManager();
+
+ Assert.assertNotNull(firstEntityManager);
+ TestEntityTransaction firstTransaction = (TestEntityTransaction) (firstEntityManager).getTransaction();
+
+ Assert.assertEquals(false, firstEntityManager.isFlushed());
+ Assert.assertEquals(false, firstTransaction.isActive());
+ Assert.assertEquals(false, firstTransaction.isStarted());
+ Assert.assertEquals(false, firstTransaction.isCommitted());
+ Assert.assertEquals(false, firstTransaction.isRolledBack());
+
+ this.firstLevelTransactionBean.executeInTransaction();
+
+ Assert.assertEquals(true, firstEntityManager.isFlushed());
+ Assert.assertEquals(false, firstTransaction.isActive());
+ Assert.assertEquals(true, firstTransaction.isStarted());
+ Assert.assertEquals(true, firstTransaction.isCommitted());
+ Assert.assertEquals(false, firstTransaction.isRolledBack());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/FirstLevelTransactionBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/FirstLevelTransactionBean.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/FirstLevelTransactionBean.java
new file mode 100644
index 0000000..7d74128
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/FirstLevelTransactionBean.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.defaultnested;
+
+import org.apache.deltaspike.jpa.api.Transactional;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+@ApplicationScoped
+public class FirstLevelTransactionBean
+{
+ @Inject
+ private EntityManager entityManager;
+
+ @Inject
+ private NestedTransactionBean nestedTransactionBean;
+
+ @Transactional
+ public void executeInTransaction()
+ {
+ this.nestedTransactionBean.executeInTransaction();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/NestedTransactionBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/NestedTransactionBean.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/NestedTransactionBean.java
new file mode 100644
index 0000000..baf62ef
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/NestedTransactionBean.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.defaultnested;
+
+import org.apache.deltaspike.jpa.api.Transactional;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+@ApplicationScoped
+public class NestedTransactionBean
+{
+ @Inject
+ private EntityManager entityManager;
+
+ @Transactional
+ public void executeInTransaction()
+ {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/TestEntityManagerProducer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/TestEntityManagerProducer.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/TestEntityManagerProducer.java
new file mode 100644
index 0000000..f89ad34
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/defaultnested/TestEntityManagerProducer.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.defaultnested;
+
+import org.apache.deltaspike.test.jpa.api.shared.TestEntityManager;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+import javax.persistence.EntityManager;
+
+@RequestScoped
+public class TestEntityManagerProducer
+{
+ private TestEntityManager firstEntityManager = new TestEntityManager();
+
+ @Produces
+ protected EntityManager firstEntityManager()
+ {
+ return this.firstEntityManager;
+ }
+
+ public TestEntityManager getFirstEntityManager()
+ {
+ return firstEntityManager;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/FirstLevelTransactionBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/FirstLevelTransactionBean.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/FirstLevelTransactionBean.java
new file mode 100644
index 0000000..ccc7cb0
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/FirstLevelTransactionBean.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.exception.catched.multipleinjection.nested;
+
+import org.apache.deltaspike.jpa.api.Transactional;
+import org.apache.deltaspike.test.jpa.api.shared.First;
+import org.apache.deltaspike.test.jpa.api.shared.TestException;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+@ApplicationScoped
+public class FirstLevelTransactionBean
+{
+ @Inject
+ private @First EntityManager firstEntityManager;
+
+ @Inject
+ private NestedTransactionBean nestedTransactionBean;
+
+ @Transactional
+ public void executeInTransaction()
+ {
+ try
+ {
+ this.nestedTransactionBean.executeInTransaction();
+ }
+ catch (TestException e)
+ {
+ //expected -> do nothing
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/NestedMultiTransactionCatchedExceptionTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/NestedMultiTransactionCatchedExceptionTest.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/NestedMultiTransactionCatchedExceptionTest.java
new file mode 100644
index 0000000..ca902ba
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/NestedMultiTransactionCatchedExceptionTest.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.exception.catched.multipleinjection.nested;
+
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
+import org.apache.deltaspike.jpa.impl.transaction.context.TransactionContextExtension;
+import org.apache.deltaspike.test.jpa.api.shared.TestEntityManager;
+import org.apache.deltaspike.test.jpa.api.shared.TestEntityTransaction;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.Extension;
+import javax.inject.Inject;
+
+@RunWith(Arquillian.class)
+public class NestedMultiTransactionCatchedExceptionTest
+{
+ @Inject
+ private FirstLevelTransactionBean firstLevelTransactionBean;
+
+ @Inject
+ private TestEntityManagerProducer entityManagerProducer;
+
+ @Deployment
+ public static WebArchive deploy()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "nestedMultiTransactionCatchedExceptionTest.jar")
+ .addPackage(ArchiveUtils.SHARED_PACKAGE)
+ .addPackage(NestedMultiTransactionCatchedExceptionTest.class.getPackage().getName())
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+
+ return ShrinkWrap.create(WebArchive.class)
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndJpaArchive())
+ .addAsLibraries(testJar)
+ .addAsServiceProvider(Extension.class, TransactionContextExtension.class)
+ .addAsWebInfResource(ArchiveUtils.getBeansXml(), "beans.xml");
+ }
+
+ @Test
+ public void nestedMultiTransactionCatchedExceptionTest()
+ {
+ TestEntityManager firstEntityManager = this.entityManagerProducer.getFirstEntityManager();
+ TestEntityManager secondEntityManager = this.entityManagerProducer.getSecondEntityManager();
+
+ Assert.assertNotNull(firstEntityManager);
+ TestEntityTransaction firstTransaction = (TestEntityTransaction) (firstEntityManager).getTransaction();
+
+ Assert.assertEquals(false, firstEntityManager.isFlushed());
+ Assert.assertEquals(false, firstTransaction.isActive());
+ Assert.assertEquals(false, firstTransaction.isStarted());
+ Assert.assertEquals(false, firstTransaction.isCommitted());
+ Assert.assertEquals(false, firstTransaction.isRolledBack());
+
+ Assert.assertNotNull(secondEntityManager);
+ TestEntityTransaction secondTransaction = (TestEntityTransaction) (secondEntityManager).getTransaction();
+
+ Assert.assertEquals(false, secondEntityManager.isFlushed());
+ Assert.assertEquals(false, secondTransaction.isActive());
+ Assert.assertEquals(false, secondTransaction.isStarted());
+ Assert.assertEquals(false, secondTransaction.isCommitted());
+ Assert.assertEquals(false, secondTransaction.isRolledBack());
+
+ this.firstLevelTransactionBean.executeInTransaction();
+
+ Assert.assertEquals(true, firstEntityManager.isFlushed());
+ Assert.assertEquals(false, firstTransaction.isActive());
+ Assert.assertEquals(true, firstTransaction.isStarted());
+ Assert.assertEquals(true, firstTransaction.isCommitted());
+ Assert.assertEquals(false, firstTransaction.isRolledBack());
+
+ Assert.assertEquals(true, secondEntityManager.isFlushed());
+ Assert.assertEquals(false, secondTransaction.isActive());
+ Assert.assertEquals(true, secondTransaction.isStarted());
+ Assert.assertEquals(true, secondTransaction.isCommitted());
+ Assert.assertEquals(false, secondTransaction.isRolledBack());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/NestedTransactionBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/NestedTransactionBean.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/NestedTransactionBean.java
new file mode 100644
index 0000000..cd5779e
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/NestedTransactionBean.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.exception.catched.multipleinjection.nested;
+
+import org.apache.deltaspike.jpa.api.Transactional;
+import org.apache.deltaspike.test.jpa.api.shared.Second;
+import org.apache.deltaspike.test.jpa.api.shared.TestException;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+@ApplicationScoped
+public class NestedTransactionBean
+{
+ @Inject
+ private @Second EntityManager secondEntityManager;
+
+ @Transactional
+ public void executeInTransaction()
+ {
+ throw new TestException();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/TestEntityManagerProducer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/TestEntityManagerProducer.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/TestEntityManagerProducer.java
new file mode 100644
index 0000000..81ed6db
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/multipleinjection/nested/TestEntityManagerProducer.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.exception.catched.multipleinjection.nested;
+
+import org.apache.deltaspike.test.jpa.api.shared.First;
+import org.apache.deltaspike.test.jpa.api.shared.Second;
+import org.apache.deltaspike.test.jpa.api.shared.TestEntityManager;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+import javax.persistence.EntityManager;
+
+@RequestScoped
+public class TestEntityManagerProducer
+{
+ private TestEntityManager firstEntityManager = new TestEntityManager();
+
+ private TestEntityManager secondEntityManager = new TestEntityManager();
+
+ @Produces
+ @First
+ protected EntityManager firstEntityManager()
+ {
+ return this.firstEntityManager;
+ }
+
+ @Produces
+ @Second
+ protected EntityManager secondEntityManager()
+ {
+ return this.secondEntityManager;
+ }
+
+ public TestEntityManager getFirstEntityManager()
+ {
+ return firstEntityManager;
+ }
+
+ public TestEntityManager getSecondEntityManager()
+ {
+ return secondEntityManager;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/FirstLevelTransactionBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/FirstLevelTransactionBean.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/FirstLevelTransactionBean.java
new file mode 100644
index 0000000..4410998
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/FirstLevelTransactionBean.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.exception.catched.nested;
+
+import org.apache.deltaspike.jpa.api.Transactional;
+import org.apache.deltaspike.test.jpa.api.shared.First;
+import org.apache.deltaspike.test.jpa.api.shared.TestException;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+@ApplicationScoped
+public class FirstLevelTransactionBean
+{
+ @Inject
+ private @First EntityManager firstEntityManager;
+
+ @Inject
+ private NestedTransactionBean nestedTransactionBean;
+
+ @Transactional
+ public void executeInTransaction()
+ {
+ try
+ {
+ this.nestedTransactionBean.executeInTransaction();
+ }
+ catch (TestException e)
+ {
+ //catch to test that the transaction doesn't get rolled back
+ //do nothing
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/NestedTransactionBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/NestedTransactionBean.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/NestedTransactionBean.java
new file mode 100644
index 0000000..edde5fc
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/NestedTransactionBean.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.exception.catched.nested;
+
+import org.apache.deltaspike.jpa.api.Transactional;
+import org.apache.deltaspike.test.jpa.api.shared.First;
+import org.apache.deltaspike.test.jpa.api.shared.TestException;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+@ApplicationScoped
+public class NestedTransactionBean
+{
+ @Inject
+ private @First EntityManager firstEntityManager;
+
+ @Transactional
+ public void executeInTransaction()
+ {
+ throw new TestException();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/NestedTransactionCatchedExceptionTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/NestedTransactionCatchedExceptionTest.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/NestedTransactionCatchedExceptionTest.java
new file mode 100644
index 0000000..a397195
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/NestedTransactionCatchedExceptionTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.exception.catched.nested;
+
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
+import org.apache.deltaspike.jpa.impl.transaction.context.TransactionContextExtension;
+import org.apache.deltaspike.test.jpa.api.shared.TestEntityManager;
+import org.apache.deltaspike.test.jpa.api.shared.TestEntityTransaction;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.Extension;
+import javax.inject.Inject;
+
+@RunWith(Arquillian.class)
+public class NestedTransactionCatchedExceptionTest
+{
+ @Inject
+ private FirstLevelTransactionBean firstLevelTransactionBean;
+
+ @Inject
+ private TestEntityManagerProducer entityManagerProducer;
+
+ @Deployment
+ public static WebArchive deploy()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "nestedTransactionCatchedExceptionTest.jar")
+ .addPackage(ArchiveUtils.SHARED_PACKAGE)
+ .addPackage(NestedTransactionCatchedExceptionTest.class.getPackage().getName())
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+
+ return ShrinkWrap.create(WebArchive.class)
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndJpaArchive())
+ .addAsLibraries(testJar)
+ .addAsServiceProvider(Extension.class, TransactionContextExtension.class)
+ .addAsWebInfResource(ArchiveUtils.getBeansXml(), "beans.xml");
+ }
+
+ @Test
+ public void nestedTransactionCatchedExceptionTest()
+ {
+ TestEntityManager firstEntityManager = this.entityManagerProducer.getFirstEntityManager();
+
+ Assert.assertNotNull(firstEntityManager);
+ TestEntityTransaction firstTransaction = (TestEntityTransaction) (firstEntityManager).getTransaction();
+
+ Assert.assertEquals(false, firstEntityManager.isFlushed());
+ Assert.assertEquals(false, firstTransaction.isActive());
+ Assert.assertEquals(false, firstTransaction.isStarted());
+ Assert.assertEquals(false, firstTransaction.isCommitted());
+ Assert.assertEquals(false, firstTransaction.isRolledBack());
+
+ this.firstLevelTransactionBean.executeInTransaction();
+
+ Assert.assertEquals(true, firstEntityManager.isFlushed());
+ Assert.assertEquals(false, firstTransaction.isActive());
+ Assert.assertEquals(true, firstTransaction.isStarted());
+ Assert.assertEquals(true, firstTransaction.isCommitted());
+ Assert.assertEquals(false, firstTransaction.isRolledBack());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/TestEntityManagerProducer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/TestEntityManagerProducer.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/TestEntityManagerProducer.java
new file mode 100644
index 0000000..02ea9b8
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/catched/nested/TestEntityManagerProducer.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.exception.catched.nested;
+
+import org.apache.deltaspike.test.jpa.api.shared.First;
+import org.apache.deltaspike.test.jpa.api.shared.TestEntityManager;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+import javax.persistence.EntityManager;
+
+@RequestScoped
+public class TestEntityManagerProducer
+{
+ private TestEntityManager firstEntityManager = new TestEntityManager();
+
+ @Produces
+ @First
+ protected EntityManager firstEntityManager()
+ {
+ return this.firstEntityManager;
+ }
+
+ public TestEntityManager getFirstEntityManager()
+ {
+ return firstEntityManager;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/uncatched/multipleinjection/auto/MultiTransactionBean.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/uncatched/multipleinjection/auto/MultiTransactionBean.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/uncatched/multipleinjection/auto/MultiTransactionBean.java
new file mode 100644
index 0000000..b1fb48f
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/uncatched/multipleinjection/auto/MultiTransactionBean.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.exception.uncatched.multipleinjection.auto;
+
+import org.apache.deltaspike.jpa.api.Transactional;
+import org.apache.deltaspike.test.jpa.api.shared.First;
+import org.apache.deltaspike.test.jpa.api.shared.Second;
+import org.apache.deltaspike.test.jpa.api.shared.TestException;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+@ApplicationScoped
+public class MultiTransactionBean
+{
+ @Inject
+ private EntityManager defaultEntityManager;
+
+ @Inject
+ private @First EntityManager firstEntityManager;
+
+ @Inject
+ private @Second EntityManager secondEntityManager;
+
+ @Transactional
+ public void executeInTransaction()
+ {
+ throw new TestException();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/38960400/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/uncatched/multipleinjection/auto/MultipleEntityManagerInjectionUncatchedExceptionTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/uncatched/multipleinjection/auto/MultipleEntityManagerInjectionUncatchedExceptionTest.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/uncatched/multipleinjection/auto/MultipleEntityManagerInjectionUncatchedExceptionTest.java
new file mode 100644
index 0000000..624acfa
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/api/transactional/exception/uncatched/multipleinjection/auto/MultipleEntityManagerInjectionUncatchedExceptionTest.java
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.test.jpa.api.transactional.exception.uncatched.multipleinjection.auto;
+
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
+import org.apache.deltaspike.jpa.impl.transaction.context.TransactionContextExtension;
+import org.apache.deltaspike.test.jpa.api.shared.TestEntityManager;
+import org.apache.deltaspike.test.jpa.api.shared.TestEntityTransaction;
+import org.apache.deltaspike.test.jpa.api.shared.TestException;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.Extension;
+import javax.inject.Inject;
+
+@RunWith(Arquillian.class)
+public class MultipleEntityManagerInjectionUncatchedExceptionTest
+{
+ @Inject
+ private MultiTransactionBean multiTransactionBean;
+
+ @Inject
+ private TestEntityManagerProducer entityManagerProducer;
+
+ @Deployment
+ public static WebArchive deploy()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "autoInjectionUncatchedExceptionTest.jar")
+ .addPackage(ArchiveUtils.SHARED_PACKAGE)
+ .addPackage(MultipleEntityManagerInjectionUncatchedExceptionTest.class.getPackage().getName())
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+
+ return ShrinkWrap.create(WebArchive.class)
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndJpaArchive())
+ .addAsLibraries(testJar)
+ .addAsServiceProvider(Extension.class, TransactionContextExtension.class)
+ .addAsWebInfResource(ArchiveUtils.getBeansXml(), "beans.xml");
+ }
+
+ @Test
+ public void autoInjectionUncatchedExceptionTest()
+ {
+ TestEntityManager defaultEntityManager = this.entityManagerProducer.getDefaultEntityManager();
+ TestEntityManager firstEntityManager = this.entityManagerProducer.getFirstEntityManager();
+ TestEntityManager secondEntityManager = this.entityManagerProducer.getSecondEntityManager();
+
+ Assert.assertNotNull(defaultEntityManager);
+ TestEntityTransaction defaultTransaction = (TestEntityTransaction) (defaultEntityManager).getTransaction();
+
+ Assert.assertEquals(false, defaultEntityManager.isFlushed());
+ Assert.assertEquals(false, defaultTransaction.isActive());
+ Assert.assertEquals(false, defaultTransaction.isStarted());
+ Assert.assertEquals(false, defaultTransaction.isCommitted());
+ Assert.assertEquals(false, defaultTransaction.isRolledBack());
+
+ Assert.assertNotNull(firstEntityManager);
+ TestEntityTransaction firstTransaction = (TestEntityTransaction) (firstEntityManager).getTransaction();
+
+ Assert.assertEquals(false, firstEntityManager.isFlushed());
+ Assert.assertEquals(false, firstTransaction.isActive());
+ Assert.assertEquals(false, firstTransaction.isStarted());
+ Assert.assertEquals(false, firstTransaction.isCommitted());
+ Assert.assertEquals(false, firstTransaction.isRolledBack());
+
+ Assert.assertNotNull(secondEntityManager);
+ TestEntityTransaction secondTransaction = (TestEntityTransaction) (secondEntityManager).getTransaction();
+
+ Assert.assertEquals(false, secondEntityManager.isFlushed());
+ Assert.assertEquals(false, secondTransaction.isActive());
+ Assert.assertEquals(false, secondTransaction.isStarted());
+ Assert.assertEquals(false, secondTransaction.isCommitted());
+ Assert.assertEquals(false, secondTransaction.isRolledBack());
+
+ try
+ {
+ this.multiTransactionBean.executeInTransaction();
+ Assert.fail(TestException.class.getName() + " expected!");
+ }
+ catch (TestException e)
+ {
+ //expected -> do nothing
+ }
+
+ Assert.assertEquals(false, defaultEntityManager.isFlushed());
+ Assert.assertEquals(false, defaultTransaction.isActive());
+ Assert.assertEquals(true, defaultTransaction.isStarted());
+ Assert.assertEquals(false, defaultTransaction.isCommitted());
+ Assert.assertEquals(true, defaultTransaction.isRolledBack());
+
+ Assert.assertEquals(false, firstEntityManager.isFlushed());
+ Assert.assertEquals(false, firstTransaction.isActive());
+ Assert.assertEquals(true, firstTransaction.isStarted());
+ Assert.assertEquals(false, firstTransaction.isCommitted());
+ Assert.assertEquals(true, firstTransaction.isRolledBack());
+
+ Assert.assertEquals(false, secondEntityManager.isFlushed());
+ Assert.assertEquals(false, secondTransaction.isActive());
+ Assert.assertEquals(true, secondTransaction.isStarted());
+ Assert.assertEquals(false, secondTransaction.isCommitted());
+ Assert.assertEquals(true, secondTransaction.isRolledBack());
+ }
+}