Repository: deltaspike Updated Branches: refs/heads/master 944d13aef -> 63f15665c
DELTASPIKE-1007 transactional tests on Java EE 7 using both JTA @Transactional and DS @Transactional Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/63f15665 Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/63f15665 Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/63f15665 Branch: refs/heads/master Commit: 63f15665c05c338a9daae7dec0df9afc31a200a3 Parents: 944d13a Author: Harald Wellmann <[email protected]> Authored: Sat Dec 19 16:36:46 2015 +0100 Committer: Harald Wellmann <[email protected]> Committed: Sat Dec 19 16:36:46 2015 +0100 ---------------------------------------------------------------------- deltaspike/modules/data/pom.xml | 1 + deltaspike/modules/data/test-ee7/pom.xml | 216 +++++++++++++++++++ .../data/test/ee7/domain/EmbeddedSimple.java | 39 ++++ .../deltaspike/data/test/ee7/domain/Simple.java | 147 +++++++++++++ .../data/test/ee7/domain/SuperSimple.java | 38 ++++ ...taSpikeTransactionalRepositoryInterface.java | 44 ++++ .../JtaTransactionalRepositoryInterface.java | 44 ++++ .../ee7/tx/DeltaSpikeTransactionalTest.java | 138 ++++++++++++ .../data/test/ee7/tx/JtaTransactionalTest.java | 139 ++++++++++++ .../ee7/tx/TransactionalQueryRunnerWrapper.java | 66 ++++++ .../deltaspike/data/test/ee7/util/Logging.java | 43 ++++ .../data/test/ee7/util/TestDeployments.java | 62 ++++++ .../resources-glassfish/test-persistence.xml | 30 +++ .../resources-weblogic/test-persistence.xml | 31 +++ .../test/resources-wildfly/test-persistence.xml | 27 +++ .../src/test/resources/logging.properties | 32 +++ 16 files changed, 1097 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/pom.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/pom.xml b/deltaspike/modules/data/pom.xml index 00dab33..24e3a00 100755 --- a/deltaspike/modules/data/pom.xml +++ b/deltaspike/modules/data/pom.xml @@ -33,6 +33,7 @@ <modules> <module>api</module> <module>impl</module> + <module>test-ee7</module> </modules> <properties> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/pom.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/pom.xml b/deltaspike/modules/data/test-ee7/pom.xml new file mode 100644 index 0000000..e36f9e4 --- /dev/null +++ b/deltaspike/modules/data/test-ee7/pom.xml @@ -0,0 +1,216 @@ +<?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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>data-module-project</artifactId> + <version>1.5.3-SNAPSHOT</version> + </parent> + + <artifactId>deltaspike-data-module-test-ee7</artifactId> + <packaging>jar</packaging> + + <name>Apache DeltaSpike Data-Module Tests on Java EE 7</name> + + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <argLine>-Xms128m -Xmx1024m -XX:MaxPermSize=256m</argLine> + </configuration> + </plugin> + </plugins> + </pluginManagement> + <plugins> + <plugin> + <groupId>org.bsc.maven</groupId> + <artifactId>maven-processor-plugin</artifactId> + <version>2.0.7</version> + <executions> + <execution> + <id>process-test</id> + <goals> + <goal>process-test</goal> + </goals> + <phase>generate-test-sources</phase> + </execution> + </executions> + <configuration> + <processors> + <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor> + </processors> + </configuration> + <dependencies> + <!-- this part of Hibernate is Apache License 2.0, thus O.K. for us. --> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-jpamodelgen</artifactId> + <version>1.2.0.Final</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> + + <dependencies> + + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jpa_2.1_spec</artifactId> + <version>1.0-alpha-1</version> + </dependency> + + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jta_1.2_spec</artifactId> + <version>1.0-alpha-1</version> + </dependency> + + <dependency> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>deltaspike-data-module-api</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>deltaspike-data-module-impl</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.deltaspike.core</groupId> + <artifactId>deltaspike-core-impl</artifactId> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>deltaspike-partial-bean-module-impl</artifactId> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.deltaspike.modules</groupId> + <artifactId>deltaspike-jpa-module-impl</artifactId> + <scope>compile</scope> + </dependency> + + <!-- Tests --> + + <dependency> + <groupId>org.jboss.shrinkwrap.resolver</groupId> + <artifactId>shrinkwrap-resolver-impl-maven</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.jboss.shrinkwrap.descriptors</groupId> + <artifactId>shrinkwrap-descriptors-impl-javaee</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + + <profiles> + <profile> + <id>wildfly-build-managed</id> + <build> + <testResources> + <testResource> + <directory>src/test/resources</directory> + </testResource> + <testResource> + <directory>src/test/resources-wildfly</directory> + </testResource> + </testResources> + </build> + </profile> + <profile> + <id>wildfly-managed</id> + <build> + <testResources> + <testResource> + <directory>src/test/resources</directory> + </testResource> + <testResource> + <directory>src/test/resources-wildfly</directory> + </testResource> + </testResources> + </build> + </profile> + <profile> + <id>wildfly-remote</id> + <build> + <testResources> + <testResource> + <directory>src/test/resources</directory> + </testResource> + <testResource> + <directory>src/test/resources-wildfly</directory> + </testResource> + </testResources> + </build> + </profile> + <profile> + <id>glassfish-build-managed-4</id> + <build> + <testResources> + <testResource> + <directory>src/test/resources</directory> + </testResource> + <testResource> + <directory>src/test/resources-glassfish</directory> + </testResource> + </testResources> + </build> + </profile> + <profile> + <id>wls-remote-12c</id> + <build> + <testResources> + <testResource> + <directory>src/test/resources</directory> + </testResource> + <testResource> + <directory>src/test/resources-weblogic</directory> + </testResource> + </testResources> + </build> + </profile> + <profile> + <id>wls-managed-12c</id> + <build> + <testResources> + <testResource> + <directory>src/test/resources</directory> + </testResource> + <testResource> + <directory>src/test/resources-weblogic</directory> + </testResource> + </testResources> + </build> + </profile> + </profiles> + +</project> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/domain/EmbeddedSimple.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/domain/EmbeddedSimple.java b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/domain/EmbeddedSimple.java new file mode 100644 index 0000000..516f245 --- /dev/null +++ b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/domain/EmbeddedSimple.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.data.test.ee7.domain; + +import javax.persistence.Embeddable; + +@Embeddable +public class EmbeddedSimple +{ + + private String embedd; + + public String getEmbedd() + { + return embedd; + } + + public void setEmbedd(String embedd) + { + this.embedd = embedd; + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/domain/Simple.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/domain/Simple.java b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/domain/Simple.java new file mode 100755 index 0000000..44cf969 --- /dev/null +++ b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/domain/Simple.java @@ -0,0 +1,147 @@ +/* + * 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.data.test.ee7.domain; + +import java.util.Date; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@NamedQueries({ + @NamedQuery(name = Simple.BY_NAME_LIKE, + query = "select e from Simple e where e.name like ?1"), + @NamedQuery(name = Simple.BY_NAME_ENABLED, + query = "select s from Simple s where s.name = ?1 and s.enabled = ?2 order by s.id asc"), + @NamedQuery(name = Simple.BY_ID, + query = "select s from Simple s where s.id = :id and s.enabled = :enabled") +}) +@Table(name = "SIMPLE_TABLE") +public class Simple extends SuperSimple +{ + + public static final String BY_NAME_LIKE = "simple.byNameLike"; + public static final String BY_NAME_ENABLED = "simple.byNameAndEnabled"; + public static final String BY_ID = "simple.byId"; + + @Id + @GeneratedValue + private Long id; + + private String name; + private String camelCase; + private Boolean enabled = Boolean.TRUE; + private Integer counter = Integer.valueOf(0); + @Temporal(TemporalType.TIMESTAMP) + private Date temporal; + private EmbeddedSimple embedded; + + protected Simple() + { + } + + public Simple(String name) + { + this.name = name; + } + + public Long getId() + { + return id; + } + + public void setId(Long id) + { + this.id = id; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public Boolean getEnabled() + { + return enabled; + } + + public void setEnabled(Boolean enabled) + { + this.enabled = enabled; + } + + public Integer getCounter() + { + return counter; + } + + public void setCounter(Integer counter) + { + this.counter = counter; + } + + public String getCamelCase() + { + return camelCase; + } + + public void setCamelCase(String camelCase) + { + this.camelCase = camelCase; + } + + public Date getTemporal() + { + return temporal; + } + + public void setTemporal(Date temporal) + { + this.temporal = temporal; + } + + public EmbeddedSimple getEmbedded() + { + return embedded; + } + + public void setEmbedded(EmbeddedSimple embedded) + { + this.embedded = embedded; + } + + @Override + public String toString() + { + return "Simple [id=" + id + ", name=" + name + ", camelCase=" + camelCase + ", enabled=" + enabled + + ", counter=" + counter + ", temporal=" + temporal + ", embedded=" + embedded + "]"; + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/domain/SuperSimple.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/domain/SuperSimple.java b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/domain/SuperSimple.java new file mode 100644 index 0000000..10af87b --- /dev/null +++ b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/domain/SuperSimple.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.data.test.ee7.domain; + +import javax.persistence.MappedSuperclass; + +@MappedSuperclass +public class SuperSimple +{ + private String superName; + + public String getSuperName() + { + return superName; + } + + public void setSuperName(String superName) + { + this.superName = superName; + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/service/DeltaSpikeTransactionalRepositoryInterface.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/service/DeltaSpikeTransactionalRepositoryInterface.java b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/service/DeltaSpikeTransactionalRepositoryInterface.java new file mode 100644 index 0000000..32f642a --- /dev/null +++ b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/service/DeltaSpikeTransactionalRepositoryInterface.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.data.test.ee7.service; + +import static javax.persistence.LockModeType.PESSIMISTIC_READ; + +import org.apache.deltaspike.data.api.EntityManagerDelegate; +import org.apache.deltaspike.data.api.EntityRepository; +import org.apache.deltaspike.data.api.Modifying; +import org.apache.deltaspike.data.api.Query; +import org.apache.deltaspike.data.api.Repository; +import org.apache.deltaspike.data.test.ee7.domain.Simple; + +@Repository [email protected] +public interface DeltaSpikeTransactionalRepositoryInterface extends EntityRepository<Simple, Long>, EntityManagerDelegate<Simple> +{ + + @Query(lock = PESSIMISTIC_READ) + Simple findByName(String name); + + @Query(named = Simple.BY_NAME_LIKE) + Simple findByNameNoLock(String name); + + @Modifying @Query("delete from Simple") + int deleteAll(); + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/service/JtaTransactionalRepositoryInterface.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/service/JtaTransactionalRepositoryInterface.java b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/service/JtaTransactionalRepositoryInterface.java new file mode 100755 index 0000000..e28a011 --- /dev/null +++ b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/service/JtaTransactionalRepositoryInterface.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.data.test.ee7.service; + +import static javax.persistence.LockModeType.PESSIMISTIC_READ; + +import org.apache.deltaspike.data.api.EntityManagerDelegate; +import org.apache.deltaspike.data.api.EntityRepository; +import org.apache.deltaspike.data.api.Modifying; +import org.apache.deltaspike.data.api.Query; +import org.apache.deltaspike.data.api.Repository; +import org.apache.deltaspike.data.test.ee7.domain.Simple; + +@Repository [email protected] +public interface JtaTransactionalRepositoryInterface extends EntityRepository<Simple, Long>, EntityManagerDelegate<Simple> +{ + + @Query(lock = PESSIMISTIC_READ) + Simple findByName(String name); + + @Query(named = Simple.BY_NAME_LIKE) + Simple findByNameNoLock(String name); + + @Modifying @Query("delete from Simple") + int deleteAll(); + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/tx/DeltaSpikeTransactionalTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/tx/DeltaSpikeTransactionalTest.java b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/tx/DeltaSpikeTransactionalTest.java new file mode 100644 index 0000000..18b0817 --- /dev/null +++ b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/tx/DeltaSpikeTransactionalTest.java @@ -0,0 +1,138 @@ +/* + * 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.data.test.ee7.tx; + +import static org.apache.deltaspike.data.test.ee7.util.TestDeployments.initDeployment; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import javax.enterprise.inject.Produces; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import org.apache.deltaspike.data.test.ee7.domain.Simple; +import org.apache.deltaspike.data.test.ee7.service.DeltaSpikeTransactionalRepositoryInterface; +import org.apache.deltaspike.test.category.WebEE7ProfileCategory; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.junit.InSequence; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +@Category(WebEE7ProfileCategory.class) +@RunWith(Arquillian.class) +public class DeltaSpikeTransactionalTest +{ + + public static String DS_PROPERTIES_WITH_ENV_AWARE_TX_STRATEGY + = "globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy=" + + "org.apache.deltaspike.jpa.impl.transaction.EnvironmentAwareTransactionStrategy"; + + private static final String NAME = "should_run_in_transaction"; + + @Deployment + public static Archive<?> deployment() + { + return initDeployment() + .addClasses(DeltaSpikeTransactionalRepositoryInterface.class) + .addClass(TransactionalQueryRunnerWrapper.class) + .addPackage(Simple.class.getPackage()) + .addAsWebInfResource(new StringAsset(DS_PROPERTIES_WITH_ENV_AWARE_TX_STRATEGY), + "classes/META-INF/apache-deltaspike.properties"); + } + + @Inject + private DeltaSpikeTransactionalRepositoryInterface repository; + + @Produces + @PersistenceContext + private EntityManager entityManager; + + @Inject + private TransactionalQueryRunnerWrapper wrapper; + + @Test + @InSequence(1) + public void should_run_modifying_in_transaction() throws Exception + { + // when + repository.deleteAll(); + + // then + assertTrue(wrapper.isRunInTx()); + } + + @Test + @InSequence(2) + public void should_save_in_transaction() throws Exception + { + // given + Simple simple = new Simple(NAME); + + // when + simple = repository.save(simple); + + // then + assertNotNull(simple.getId()); + assertTrue(wrapper.isRunInTx()); + } + + @Test + @InSequence(3) + public void should_find_with_lockmode_in_transaction() throws Exception + { + // when + Simple simple = repository.findByName(NAME); + + // then + assertNotNull(simple); + assertTrue(wrapper.isRunInTx()); + } + + @Test + @InSequence(4) + public void should_find_no_lock_without_transaction() throws Exception + { + // when + Simple simple = repository.findByNameNoLock(NAME); + + // then + assertNotNull(simple); + assertTrue(wrapper.isRunInNonTx()); + } + + @Test + @InSequence(10) + public void should_cleanup() throws Exception + { + repository.deleteAll(); + } + + @Before + public void init() + { + wrapper.reset(); + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/tx/JtaTransactionalTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/tx/JtaTransactionalTest.java b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/tx/JtaTransactionalTest.java new file mode 100644 index 0000000..2dee1e6 --- /dev/null +++ b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/tx/JtaTransactionalTest.java @@ -0,0 +1,139 @@ +/* + * 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.data.test.ee7.tx; + +import static org.apache.deltaspike.data.test.ee7.util.TestDeployments.initDeployment; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import javax.enterprise.inject.Produces; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import org.apache.deltaspike.data.test.ee7.domain.Simple; +import org.apache.deltaspike.data.test.ee7.service.JtaTransactionalRepositoryInterface; +import org.apache.deltaspike.test.category.WebEE7ProfileCategory; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.junit.InSequence; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +@Category(WebEE7ProfileCategory.class) +@RunWith(Arquillian.class) +public class JtaTransactionalTest +{ + + public static String DS_PROPERTIES_WITH_CMT_STRATEGY + = "globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy=" + + "org.apache.deltaspike.jpa.impl.transaction.ContainerManagedTransactionStrategy"; + + private static final String NAME = "should_run_in_transaction"; + + @Deployment + public static Archive<?> deployment() + { + return initDeployment() + .addClasses(JtaTransactionalRepositoryInterface.class) + .addClass(TransactionalQueryRunnerWrapper.class) + .addPackage(Simple.class.getPackage()) + .addAsWebInfResource(new StringAsset(DS_PROPERTIES_WITH_CMT_STRATEGY), + "classes/META-INF/apache-deltaspike.properties"); + + } + + @Inject + private JtaTransactionalRepositoryInterface repository; + + @Produces + @PersistenceContext + private EntityManager entityManager; + + @Inject + private TransactionalQueryRunnerWrapper wrapper; + + @Test + @InSequence(1) + public void should_run_modifying_in_transaction() throws Exception + { + // when + repository.deleteAll(); + + // then + assertTrue(wrapper.isRunInTx()); + } + + @Test + @InSequence(2) + public void should_save_in_transaction() throws Exception + { + // given + Simple simple = new Simple(NAME); + + // when + simple = repository.save(simple); + + // then + assertNotNull(simple.getId()); + assertTrue(wrapper.isRunInTx()); + } + + @Test + @InSequence(3) + public void should_find_with_lockmode_in_transaction() throws Exception + { + // when + Simple simple = repository.findByName(NAME); + + // then + assertNotNull(simple); + assertTrue(wrapper.isRunInTx()); + } + + @Test + @InSequence(4) + public void should_find_no_lock_without_transaction() throws Exception + { + // when + Simple simple = repository.findByNameNoLock(NAME); + + // then + assertNotNull(simple); + assertTrue(wrapper.isRunInNonTx()); + } + + @Test + @InSequence(10) + public void should_cleanup() throws Exception + { + repository.deleteAll(); + } + + @Before + public void init() + { + wrapper.reset(); + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/tx/TransactionalQueryRunnerWrapper.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/tx/TransactionalQueryRunnerWrapper.java b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/tx/TransactionalQueryRunnerWrapper.java new file mode 100644 index 0000000..328b660 --- /dev/null +++ b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/tx/TransactionalQueryRunnerWrapper.java @@ -0,0 +1,66 @@ +/* + * 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.data.test.ee7.tx; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Specializes; + +import org.apache.deltaspike.data.impl.builder.QueryBuilder; +import org.apache.deltaspike.data.impl.handler.CdiQueryInvocationContext; +import org.apache.deltaspike.data.impl.tx.TransactionalQueryRunner; + +@Specializes +@ApplicationScoped +public class TransactionalQueryRunnerWrapper extends TransactionalQueryRunner +{ + + private boolean runInTx = false; + private boolean runInNonTx = false; + + public void reset() + { + runInTx = false; + runInNonTx = false; + } + + @Override + protected Object executeNonTransactional(QueryBuilder builder, CdiQueryInvocationContext context) + { + runInNonTx = true; + return super.executeNonTransactional(builder, context); + } + + @Override + protected Object executeTransactional(QueryBuilder builder, CdiQueryInvocationContext context) throws Exception + { + runInTx = true; + return super.executeTransactional(builder, context); + } + + public boolean isRunInTx() + { + return runInTx; + } + + public boolean isRunInNonTx() + { + return runInNonTx; + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/util/Logging.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/util/Logging.java b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/util/Logging.java new file mode 100755 index 0000000..51dedad --- /dev/null +++ b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/util/Logging.java @@ -0,0 +1,43 @@ +/* + * 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.data.test.ee7.util; + +import java.io.InputStream; +import java.util.logging.LogManager; + +public class Logging +{ + + private Logging() + { + } + + public static void reconfigure() + { + try + { + InputStream loggingProperties = Logging.class.getClassLoader().getResourceAsStream("logging.properties"); + LogManager.getLogManager().readConfiguration(loggingProperties); + } + catch (Exception e) + { + throw new RuntimeException("Failed to reconfigure Java Logging.", e); + } + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/util/TestDeployments.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/util/TestDeployments.java b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/util/TestDeployments.java new file mode 100755 index 0000000..2198a05 --- /dev/null +++ b/deltaspike/modules/data/test-ee7/src/test/java/org/apache/deltaspike/data/test/ee7/util/TestDeployments.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.data.test.ee7.util; + +import java.io.File; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.maven.Maven; + +public abstract class TestDeployments { + + /** + * Create a basic deployment with dependencies, beans.xml and persistence descriptor. + * + * @return Basic web archive. + */ + public static WebArchive initDeployment() + { + Logging.reconfigure(); + + WebArchive archive = ShrinkWrap + .create(WebArchive.class, "test.war") + .addAsLibraries(getDeltaSpikeDataWithDependencies()) + .addAsWebInfResource("test-persistence.xml", "classes/META-INF/persistence.xml") + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + + return archive; + } + + public static File[] getDeltaSpikeDataWithDependencies() + { + return Maven.resolver().loadPomFromFile("pom.xml").resolve( + "org.apache.deltaspike.core:deltaspike-core-api", + "org.apache.deltaspike.core:deltaspike-core-impl", + "org.apache.deltaspike.modules:deltaspike-partial-bean-module-api", + "org.apache.deltaspike.modules:deltaspike-partial-bean-module-impl", + "org.apache.deltaspike.modules:deltaspike-jpa-module-api", + "org.apache.deltaspike.modules:deltaspike-jpa-module-impl", + "org.apache.deltaspike.modules:deltaspike-data-module-api", + "org.apache.deltaspike.modules:deltaspike-data-module-impl") + .withTransitivity() + .asFile(); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/src/test/resources-glassfish/test-persistence.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/src/test/resources-glassfish/test-persistence.xml b/deltaspike/modules/data/test-ee7/src/test/resources-glassfish/test-persistence.xml new file mode 100644 index 0000000..f615141 --- /dev/null +++ b/deltaspike/modules/data/test-ee7/src/test/resources-glassfish/test-persistence.xml @@ -0,0 +1,30 @@ +<?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. +--> +<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> + <persistence-unit name="test"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>jdbc/__default</jta-data-source> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="FINE"/> + <property name="eclipselink.logging.parameters" value="true" /> + </properties> + </persistence-unit> +</persistence> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/src/test/resources-weblogic/test-persistence.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/src/test/resources-weblogic/test-persistence.xml b/deltaspike/modules/data/test-ee7/src/test/resources-weblogic/test-persistence.xml new file mode 100644 index 0000000..b809d70 --- /dev/null +++ b/deltaspike/modules/data/test-ee7/src/test/resources-weblogic/test-persistence.xml @@ -0,0 +1,31 @@ +<?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. +--> +<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"> + <persistence-unit name="test"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <jta-data-source>TestDS</jta-data-source> + <properties> + <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> + <property name="eclipselink.logging.level" value="FINE"/> + <property name="eclipselink.logging.parameters" value="true" /> + <property name="eclipselink.deploy-on-startup" value="true" /> + </properties> + </persistence-unit> +</persistence> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/src/test/resources-wildfly/test-persistence.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/src/test/resources-wildfly/test-persistence.xml b/deltaspike/modules/data/test-ee7/src/test/resources-wildfly/test-persistence.xml new file mode 100644 index 0000000..bd3f4a5 --- /dev/null +++ b/deltaspike/modules/data/test-ee7/src/test/resources-wildfly/test-persistence.xml @@ -0,0 +1,27 @@ +<?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. +--> +<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> + <persistence-unit name="test"> + <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> + <properties> + <property name="hibernate.hbm2ddl.auto" value="create-drop"/> + </properties> + </persistence-unit> +</persistence> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/63f15665/deltaspike/modules/data/test-ee7/src/test/resources/logging.properties ---------------------------------------------------------------------- diff --git a/deltaspike/modules/data/test-ee7/src/test/resources/logging.properties b/deltaspike/modules/data/test-ee7/src/test/resources/logging.properties new file mode 100755 index 0000000..9a4f080 --- /dev/null +++ b/deltaspike/modules/data/test-ee7/src/test/resources/logging.properties @@ -0,0 +1,32 @@ +##################################################################################### +# 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. +##################################################################################### + +handlers=java.util.logging.ConsoleHandler +.level=SEVERE + +java.util.logging.FileHandler.pattern=%h/java%u.log +java.util.logging.FileHandler.limit=50000 +java.util.logging.FileHandler.count=1 +java.util.logging.FileHandler.formatter=java.util.logging.XMLFormatter + +java.util.logging.ConsoleHandler.level=ALL +java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter + +#org.glassfish.level=SEVERE +#com.sun.enterprise.level=INFO
