FELIX-3903 - Migrate the transaction handler tests to pax exam 3
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1455460 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/handler/transaction/pom.xml b/ipojo/handler/transaction/pom.xml
index 57679a1..147e2fe 100644
--- a/ipojo/handler/transaction/pom.xml
+++ b/ipojo/handler/transaction/pom.xml
@@ -16,101 +16,100 @@
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">
- <parent>
- <groupId>org.apache.felix</groupId>
- <artifactId>felix-parent</artifactId>
- <version>1.2.1</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <packaging>bundle</packaging>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo.handler.transaction
- </artifactId>
- <version>1.5.0-SNAPSHOT</version>
- <name>Apache Felix iPOJO Transaction Handler</name>
-
- <build>
- <plugins>
- <plugin>
+<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/xsd/maven-4.0.0.xsd">
+ <parent>
<groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>1.4.3</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
- <Private-Package>org.apache.felix.ipojo.transaction</Private-Package>
- <Import-Package>javax.transaction;version=1.1, *</Import-Package>
- </instructions>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-ipojo-plugin</artifactId>
- <version>1.8.4</version>
- <executions>
- <execution>
- <goals>
- <goal>ipojo-bundle</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>rat-maven-plugin</artifactId>
- <configuration>
- <excludeSubProjects>false</excludeSubProjects>
- <useEclipseDefaultExcludes>true</useEclipseDefaultExcludes>
- <useMavenDefaultExcludes>true</useMavenDefaultExcludes>
- <excludes>
- <param>doc/**/*</param>
- <param>maven-eclipse.xml</param>
- <param>.checkstyle</param>
- <param>.externalToolBuilders/*</param>
- <param>LICENSE.asm</param>
- </excludes>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <configuration>
- <enableRulesSummary>false</enableRulesSummary>
- <violationSeverity>warning</violationSeverity>
- <configLocation>
- http://felix.apache.org/ipojo/dev/checkstyle_ipojo.xml
- </configLocation>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <artifactId>felix-parent</artifactId>
+ <version>1.2.1</version>
+ <relativePath>../../../pom/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.apache.felix.ipojo.handler.transaction-handler-project</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ <name>Apache Felix iPOJO Transaction Handler Project</name>
+ <packaging>pom</packaging>
- <dependencies>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo</artifactId>
- <version>1.9.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo.metadata</artifactId>
- <version>1.4.0</version>
- </dependency>
- <dependency>
- <groupId>geronimo-spec</groupId>
- <artifactId>geronimo-spec-jta</artifactId>
- <version>1.0-M1</version>
- </dependency>
- </dependencies>
+ <modules>
+ <module>transaction-handler</module>
+ <module>transaction-handler-it</module>
+ </modules>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ <resource>
+ <directory>.</directory>
+ <targetPath>META-INF</targetPath>
+ <includes>
+ <include>LICENSE*</include>
+ <include>NOTICE*</include>
+ <include>DEPENDENCIES*</include>
+ </includes>
+ </resource>
+ </resources>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>release</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>make-assembly</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <descriptorRefs>
+ <descriptorRef>project</descriptorRef>
+ </descriptorRefs>
+ <!-- we don't want to attach all the assemblies, such as bz2 -->
+ <attach>false</attach>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <!-- only attach the project and bin assemblies, in tar.gz and zip flavors -->
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-assemblies</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attach-artifact</goal>
+ </goals>
+ <configuration>
+ <artifacts>
+ <artifact>
+ <file>
+ ${project.build.directory}/${project.artifactId}-${project.version}-project.tar.gz
+ </file>
+ <classifier>project</classifier>
+ <type>tar.gz</type>
+ </artifact>
+ <artifact>
+ <file>
+ ${project.build.directory}/${project.artifactId}-${project.version}-project.zip
+ </file>
+ <classifier>project</classifier>
+ <type>zip</type>
+ </artifact>
+ </artifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>
diff --git a/ipojo/handler/transaction/transaction-handler-it/pom.xml b/ipojo/handler/transaction/transaction-handler-it/pom.xml
new file mode 100644
index 0000000..b83e9e3
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/pom.xml
@@ -0,0 +1,384 @@
+<!--
+ 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">
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>felix-parent</artifactId>
+ <version>1.2.1</version>
+ <relativePath>../../../../pom/pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>pom</packaging>
+ <name>Apache Felix iPOJO Transaction Handler - Integration Test</name>
+ <artifactId>org.apache.felix.ipojo.handler.transaction-it</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+
+ <properties>
+ <exam.version>3.0.0</exam.version>
+ <url.version>1.5.1</url.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.ow2.chameleon.transaction</groupId>
+ <artifactId>geronimo-transaction-service</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.handler.transaction</artifactId>
+ <version>${project.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>4.2.0</version>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ <version>1.8.6</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-native</artifactId>
+ <version>${exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit4</artifactId>
+ <version>${exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-link-mvn</artifactId>
+ <version>${exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-aether</artifactId>
+ <version>${url.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>0.9.20</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>0.9.20</version>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.ops4j.pax.tinybundles</groupId>
+ <artifactId>tinybundles</artifactId>
+ <version>1.0.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ow2.chameleon.testing</groupId>
+ <artifactId>osgi-helpers</artifactId>
+ <version>0.6.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ow2.chameleon.testing</groupId>
+ <artifactId>tinybundles-ipojo</artifactId>
+ <version>0.3.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.9</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-wrap</artifactId>
+ <version>1.5.2</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ <version>1.2</version>
+ <executions>
+ <execution>
+ <id>generate-config</id>
+ <goals>
+ <goal>generate-depends-file</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.5.1</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>test</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>1.8</version>
+ <configuration>
+ <streamLogs>true</streamLogs>
+ <goals>
+ <goal>clean</goal>
+ <goal>test</goal>
+ </goals>
+ <cloneClean>true</cloneClean>
+ </configuration>
+ <executions>
+ <execution>
+ <id>regular</id>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <profiles>
+ <profile>felix</profile>
+ </profiles>
+ <cloneProjectsTo>${project.build.directory}/regular</cloneProjectsTo>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <!-- no test-all on transaction until we fix all issue on equinox and kf -->
+ <!--
+ <profile>
+ <id>test-all</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>1.8</version>
+ <configuration>
+ <streamLogs>true</streamLogs>
+ <goals>
+ <goal>clean</goal>
+ <goal>test</goal>
+ </goals>
+ <cloneClean>true</cloneClean>
+ </configuration>
+ <executions>
+ <execution>
+ <id>equinox-native</id>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <profiles>
+ <profile>equinox</profile>
+ </profiles>
+ <cloneProjectsTo>${project.build.directory}/equinox-native</cloneProjectsTo>
+
+ </configuration>
+ </execution>
+ <execution>
+ <id>felix-native</id>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <profiles>
+ <profile>felix</profile>
+ </profiles>
+ <cloneProjectsTo>${project.build.directory}/felix-native</cloneProjectsTo>
+ </configuration>
+ </execution>
+ <execution>
+ <id>knopflerfish-native</id>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <profiles>
+ <profile>knopflerfish</profile>
+ </profiles>
+ <cloneProjectsTo>${project.build.directory}/knopflerfish-native</cloneProjectsTo>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ -->
+
+ <profile>
+ <id>knopflerfish</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ <property>
+ <name>pax.exam.framework</name>
+ <value>knopflerfish</value>
+ </property>
+ </activation>
+ <properties>
+ <pax.exam.framework>knopflerfish</pax.exam.framework>
+ </properties>
+ <repositories>
+ <repository>
+ <id>knopflerfish-releases</id>
+ <url>http://www.knopflerfish.org/maven2</url>
+ </repository>
+ </repositories>
+ <dependencies>
+ <dependency>
+ <groupId>org.knopflerfish</groupId>
+ <artifactId>framework</artifactId>
+ <version>5.2.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+
+ <profile>
+ <id>equinox</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ <property>
+ <name>pax.exam.framework</name>
+ <value>equinox</value>
+ </property>
+ </activation>
+ <properties>
+ <pax.exam.framework>equinox</pax.exam.framework>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ <version>3.8.1.v20120830-144521</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+
+ <profile>
+ <id>felix</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ <property>
+ <name>pax.exam.framework</name>
+ <value>felix</value>
+ </property>
+ </activation>
+ <properties>
+ <pax.exam.framework>felix</pax.exam.framework>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>4.2.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+
+ </profiles>
+</project>
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/pom.xml b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/pom.xml
new file mode 100644
index 0000000..177b8ca
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/pom.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.handler.transaction-it</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ <relativePath>../../../pom.xml</relativePath>
+ </parent>
+
+
+ <artifactId>ipojo-transaction-integration-test</artifactId>
+ <name>${project.artifactId}</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>4.2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.annotations</artifactId>
+ <version>1.8.6</version>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/components/ComponentUsingAnnotations.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/components/ComponentUsingAnnotations.java
new file mode 100644
index 0000000..4ef15a9
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/components/ComponentUsingAnnotations.java
@@ -0,0 +1,34 @@
+package org.apache.felix.ipojo.handler.transaction.components;
+
+import org.apache.felix.ipojo.annotations.Component;
+
+import javax.transaction.Transaction;
+
+@Component
+@org.apache.felix.ipojo.transaction.Transaction(field="transaction")
+public class ComponentUsingAnnotations {
+
+ Transaction transaction;
+
+
+ @org.apache.felix.ipojo.transaction.Transactional
+ public void doSomethingBad() throws NullPointerException {
+ }
+
+ @org.apache.felix.ipojo.transaction.Transactional(propagation="required")
+ public void doSomethingBad2() throws UnsupportedOperationException {
+
+ }
+
+ @org.apache.felix.ipojo.transaction.Transactional(propagation="supported", norollbackfor= {"java.lang.Exception"})
+ public void doSomethingGood() {
+
+ }
+
+ @org.apache.felix.ipojo.transaction.Transactional(timeout=1000, exceptiononrollback=true)
+ public void doSomethingLong() {
+
+ }
+
+
+}
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/components/FooDelegator.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/components/FooDelegator.java
new file mode 100644
index 0000000..7d5fd52
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/components/FooDelegator.java
@@ -0,0 +1,77 @@
+package org.apache.felix.ipojo.handler.transaction.components;
+
+import org.apache.felix.ipojo.handler.transaction.services.CheckService;
+import org.apache.felix.ipojo.handler.transaction.services.Foo;
+
+import javax.transaction.Transaction;
+
+public class FooDelegator implements CheckService {
+
+ Transaction transaction;
+ Transaction lastCommitted;
+ Transaction lastRolledback;
+ Transaction current;
+ private Foo foo;
+ private int commit;
+ private int rollback;
+
+ public void onCommit(String method) {
+ commit++;
+ }
+
+ public void onRollback(String method, Exception e) {
+ rollback++;
+ }
+
+ public void doSomethingBad() throws NullPointerException {
+ current = transaction;
+ foo.doSomethingBad();
+ }
+
+ public void doSomethingBad2() throws UnsupportedOperationException {
+ current = transaction;
+ foo.doSomethingBad2();
+
+ }
+
+ public void doSomethingGood() {
+ current = transaction;
+ foo.doSomethingGood();
+ }
+
+ public void doSomethingLong() {
+ current = transaction;
+ foo.doSomethingLong();
+ }
+
+ public Transaction getCurrentTransaction() {
+ return current;
+ }
+
+ public int getNumberOfCommit() {
+ return commit;
+ }
+
+ public int getNumberOfRollback() {
+ return rollback;
+ }
+
+ public Transaction getLastRolledBack() {
+ return lastRolledback;
+ }
+
+ public Transaction getLastCommitted() {
+ return lastCommitted;
+ }
+
+ public void onRollback(Transaction t) {
+ lastRolledback = t;
+ rollback++;
+ }
+
+ public void onCommit(Transaction t) {
+ lastCommitted = t;
+ commit++;
+ }
+
+}
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/components/FooImpl.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/components/FooImpl.java
new file mode 100644
index 0000000..40c6669
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/components/FooImpl.java
@@ -0,0 +1,28 @@
+package org.apache.felix.ipojo.handler.transaction.components;
+
+import org.apache.felix.ipojo.handler.transaction.services.Foo;
+
+public class FooImpl implements Foo {
+
+ public void doSomethingBad() throws NullPointerException {
+ throw new NullPointerException("NULL");
+ }
+
+ public void doSomethingBad2() throws UnsupportedOperationException {
+ throw new UnsupportedOperationException("Expected exception");
+
+ }
+
+ public void doSomethingGood() {
+ // Good...
+ }
+
+ public void doSomethingLong() {
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/services/CheckService.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/services/CheckService.java
new file mode 100644
index 0000000..b06b3eb
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/services/CheckService.java
@@ -0,0 +1,25 @@
+package org.apache.felix.ipojo.handler.transaction.services;
+
+import javax.transaction.Transaction;
+
+public interface CheckService {
+
+ public void doSomethingGood();
+
+ public void doSomethingBad() throws NullPointerException;
+
+ public void doSomethingBad2() throws UnsupportedOperationException;
+
+ public void doSomethingLong();
+
+ public int getNumberOfCommit();
+
+ public int getNumberOfRollback();
+
+ public Transaction getCurrentTransaction();
+
+ public Transaction getLastRolledBack();
+
+ public Transaction getLastCommitted();
+
+}
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/services/Foo.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/services/Foo.java
new file mode 100644
index 0000000..df97492
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/java/org/apache/felix/ipojo/handler/transaction/services/Foo.java
@@ -0,0 +1,13 @@
+package org.apache.felix.ipojo.handler.transaction.services;
+
+public interface Foo {
+
+ public void doSomethingGood();
+
+ public void doSomethingBad() throws NullPointerException;
+
+ public void doSomethingBad2() throws UnsupportedOperationException;
+
+ public void doSomethingLong();
+
+}
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/annotation.xml b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/annotation.xml
new file mode 100644
index 0000000..d1aa123
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/annotation.xml
@@ -0,0 +1,3 @@
+<ipojo xmlns:tr="org.apache.felix.ipojo.transaction">
+
+</ipojo>
\ No newline at end of file
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/foo.xml b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/foo.xml
new file mode 100644
index 0000000..c397a50
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/foo.xml
@@ -0,0 +1,5 @@
+<ipojo>
+ <component classname="org.apache.felix.ipojo.handler.transaction.components.FooImpl">
+ <provides/>
+ </component>
+</ipojo>
\ No newline at end of file
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/mandatory.xml b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/mandatory.xml
new file mode 100644
index 0000000..d242844
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/mandatory.xml
@@ -0,0 +1,25 @@
+<ipojo xmlns:tr="org.apache.felix.ipojo.transaction">
+ <component classname="org.apache.felix.ipojo.handler.transaction.components.FooDelegator" name="mandatory-ok">
+ <provides/>
+ <requires field="foo"/>
+ <tr:transaction field="transaction">
+ <transactional method="doSomethingGood" propagation="mandatory"/>
+ <transactional method="getCurrentTransaction" propagation="mandatory"/>
+ <transactional method="doSomethingBad" propagation="mandatory"/>
+ <transactional method="doSomethingBad2" norollbackfor="java.lang.UnsupportedOperationException" propagation="mandatory"/>
+ <transactional method="doSomethingLong" propagation="mandatory"/>
+ </tr:transaction>
+ </component>
+
+ <component classname="org.apache.felix.ipojo.handler.transaction.components.FooDelegator" name="mandatory-cb">
+ <provides/>
+ <requires field="foo" />
+ <tr:transaction field="transaction" onCommit="onCommit" onRollback="onRollback">
+ <transactional method="doSomethingGood" propagation="mandatory"/>
+ <transactional method="getCurrentTransaction" propagation="mandatory"/>
+ <transactional method="doSomethingBad" propagation="mandatory"/>
+ <transactional method="doSomethingBad2" norollbackfor="java.lang.UnsupportedOperationException" propagation="mandatory"/>
+ <transactional method="doSomethingLong" propagation="mandatory"/>
+ </tr:transaction>
+ </component>
+</ipojo>
\ No newline at end of file
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/never.xml b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/never.xml
new file mode 100644
index 0000000..bb57ef3
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/never.xml
@@ -0,0 +1,25 @@
+<ipojo xmlns:tr="org.apache.felix.ipojo.transaction">
+ <component classname="org.apache.felix.ipojo.handler.transaction.components.FooDelegator" name="never-ok">
+ <provides/>
+ <requires field="foo"/>
+ <tr:transaction field="transaction">
+ <transactional method="doSomethingGood" propagation="never"/>
+ <transactional method="getCurrentTransaction" propagation="never"/>
+ <transactional method="doSomethingBad" propagation="never"/>
+ <transactional method="doSomethingBad2" norollbackfor="java.lang.UnsupportedOperationException" propagation="never"/>
+ <transactional method="doSomethingLong" propagation="never"/>
+ </tr:transaction>
+ </component>
+
+ <component classname="org.apache.felix.ipojo.handler.transaction.components.FooDelegator" name="never-cb">
+ <provides/>
+ <requires field="foo" />
+ <tr:transaction field="transaction" onCommit="onCommit" onRollback="onRollback">
+ <transactional method="doSomethingGood" propagation="never"/>
+ <transactional method="getCurrentTransaction" propagation="never"/>
+ <transactional method="doSomethingBad" propagation="never"/>
+ <transactional method="doSomethingBad2" norollbackfor="java.lang.UnsupportedOperationException" propagation="never"/>
+ <transactional method="doSomethingLong" propagation="never"/>
+ </tr:transaction>
+ </component>
+</ipojo>
\ No newline at end of file
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/notsupported.xml b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/notsupported.xml
new file mode 100644
index 0000000..756b8b1
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/notsupported.xml
@@ -0,0 +1,25 @@
+<ipojo xmlns:tr="org.apache.felix.ipojo.transaction">
+ <component classname="org.apache.felix.ipojo.handler.transaction.components.FooDelegator" name="notsupported-ok">
+ <provides/>
+ <requires field="foo"/>
+ <tr:transaction field="transaction">
+ <transactional method="doSomethingGood" propagation="notsupported"/>
+ <transactional method="getCurrentTransaction" propagation="notsupported"/>
+ <transactional method="doSomethingBad" propagation="notsupported"/>
+ <transactional method="doSomethingBad2" norollbackfor="java.lang.UnsupportedOperationException" propagation="notsupported"/>
+ <transactional method="doSomethingLong" propagation="notsupported"/>
+ </tr:transaction>
+ </component>
+
+ <component classname="org.apache.felix.ipojo.handler.transaction.components.FooDelegator" name="notsupported-cb">
+ <provides/>
+ <requires field="foo" />
+ <tr:transaction field="transaction" onCommit="onCommit" onRollback="onRollback">
+ <transactional method="doSomethingGood" propagation="notsupported"/>
+ <transactional method="getCurrentTransaction" propagation="notsupported"/>
+ <transactional method="doSomethingBad" propagation="notsupported"/>
+ <transactional method="doSomethingBad2" norollbackfor="java.lang.UnsupportedOperationException" propagation="notsupported"/>
+ <transactional method="doSomethingLong" propagation="notsupported"/>
+ </tr:transaction>
+ </component>
+</ipojo>
\ No newline at end of file
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/requires.xml b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/requires.xml
new file mode 100644
index 0000000..d2ef555
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/requires.xml
@@ -0,0 +1,25 @@
+<ipojo xmlns:tr="org.apache.felix.ipojo.transaction">
+ <component classname="org.apache.felix.ipojo.handler.transaction.components.FooDelegator" name="requires-ok">
+ <provides/>
+ <requires field="foo"/>
+ <tr:transaction field="transaction">
+ <transactional method="doSomethingGood"/>
+ <transactional method="getCurrentTransaction"/>
+ <transactional method="doSomethingBad"/>
+ <transactional method="doSomethingBad2" norollbackfor="java.lang.UnsupportedOperationException"/>
+ <transactional method="doSomethingLong"/>
+ </tr:transaction>
+ </component>
+
+ <component classname="org.apache.felix.ipojo.handler.transaction.components.FooDelegator" name="requires-cb">
+ <provides/>
+ <requires field="foo" />
+ <tr:transaction field="transaction" onCommit="onCommit" onRollback="onRollback">
+ <transactional method="doSomethingGood"/>
+ <transactional method="getCurrentTransaction"/>
+ <transactional method="doSomethingBad"/>
+ <transactional method="doSomethingBad2" norollbackfor="java.lang.UnsupportedOperationException"/>
+ <transactional method="doSomethingLong"/>
+ </tr:transaction>
+ </component>
+</ipojo>
\ No newline at end of file
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/requiresnew.xml b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/requiresnew.xml
new file mode 100644
index 0000000..6e62750
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/requiresnew.xml
@@ -0,0 +1,25 @@
+<ipojo xmlns:tr="org.apache.felix.ipojo.transaction">
+ <component classname="org.apache.felix.ipojo.handler.transaction.components.FooDelegator" name="requiresnew-ok">
+ <provides/>
+ <requires field="foo"/>
+ <tr:transaction field="transaction">
+ <transactional method="doSomethingGood" propagation="requiresnew"/>
+ <transactional method="getCurrentTransaction" propagation="requiresnew"/>
+ <transactional method="doSomethingBad" propagation="requiresnew" exceptiononrollback="true"/>
+ <transactional method="doSomethingBad2" norollbackfor="java.lang.UnsupportedOperationException" propagation="requiresnew"/>
+ <transactional method="doSomethingLong" propagation="requiresnew"/>
+ </tr:transaction>
+ </component>
+
+ <component classname="org.apache.felix.ipojo.handler.transaction.components.FooDelegator" name="requiresnew-cb">
+ <provides/>
+ <requires field="foo" />
+ <tr:transaction field="transaction" onCommit="onCommit" onRollback="onRollback">
+ <transactional method="doSomethingGood" propagation="requiresnew"/>
+ <transactional method="getCurrentTransaction" propagation="requiresnew"/>
+ <transactional method="doSomethingBad" propagation="requiresnew"/>
+ <transactional method="doSomethingBad2" norollbackfor="java.lang.UnsupportedOperationException" propagation="requiresnew"/>
+ <transactional method="doSomethingLong" propagation="requiresnew"/>
+ </tr:transaction>
+ </component>
+</ipojo>
\ No newline at end of file
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/supported.xml b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/supported.xml
new file mode 100644
index 0000000..0f68758
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/main/resources/supported.xml
@@ -0,0 +1,25 @@
+<ipojo xmlns:tr="org.apache.felix.ipojo.transaction">
+ <component classname="org.apache.felix.ipojo.handler.transaction.components.FooDelegator" name="supported-ok">
+ <provides/>
+ <requires field="foo"/>
+ <tr:transaction field="transaction">
+ <transactional method="doSomethingGood" propagation="supported"/>
+ <transactional method="getCurrentTransaction" propagation="supported"/>
+ <transactional method="doSomethingBad" propagation="supported"/>
+ <transactional method="doSomethingBad2" norollbackfor="java.lang.UnsupportedOperationException" propagation="supported"/>
+ <transactional method="doSomethingLong" propagation="supported"/>
+ </tr:transaction>
+ </component>
+
+ <component classname="org.apache.felix.ipojo.handler.transaction.components.FooDelegator" name="supported-cb">
+ <provides/>
+ <requires field="foo" />
+ <tr:transaction field="transaction" onCommit="onCommit" onRollback="onRollback">
+ <transactional method="doSomethingGood" propagation="supported"/>
+ <transactional method="getCurrentTransaction" propagation="supported"/>
+ <transactional method="doSomethingBad" propagation="supported"/>
+ <transactional method="doSomethingBad2" norollbackfor="java.lang.UnsupportedOperationException" propagation="supported"/>
+ <transactional method="doSomethingLong" propagation="supported"/>
+ </tr:transaction>
+ </component>
+</ipojo>
\ No newline at end of file
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/Common.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/Common.java
new file mode 100644
index 0000000..9015396
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/Common.java
@@ -0,0 +1,198 @@
+package org.apache.felix.ipojo.handler.transaction.test;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.TrueFileFilter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.options.CompositeOption;
+import org.ops4j.pax.exam.options.DefaultCompositeOption;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerMethod;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.ow2.chameleon.testing.helpers.IPOJOHelper;
+import org.ow2.chameleon.testing.helpers.OSGiHelper;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import static junit.framework.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.*;
+import static org.ops4j.pax.exam.MavenUtils.asInProject;
+
+/**
+ * Bootstrap the test from this project
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerMethod.class)
+public class Common {
+
+ @Inject
+ BundleContext context;
+ OSGiHelper osgiHelper;
+ IPOJOHelper ipojoHelper;
+
+ public static Option junitAndMockitoBundles() {
+ return new DefaultCompositeOption(
+ // Repository required to load harmcrest (OSGi-fied version).
+ repository("http://repository.springsource.com/maven/bundles/external").id(
+ "com.springsource.repository.bundles.external"),
+
+ // Hamcrest with a version matching the range expected by Mockito
+ mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
+
+ // Mockito core does not includes Hamcrest
+ mavenBundle("org.mockito", "mockito-core", "1.9.5"),
+
+ // Objenesis with a version matching the range expected by Mockito
+ wrappedBundle(mavenBundle("org.objenesis", "objenesis", "1.2"))
+ .exports("*;version=1.2"),
+
+ // The default JUnit bundle also exports Hamcrest, but with an (incorrect) version of
+ // 4.9 which does not match the Mockito import. When deployed after the hamcrest bundles, it gets
+ // resolved correctly.
+ CoreOptions.junitBundles(),
+
+ /*
+ * Felix has implicit boot delegation enabled by default. It conflicts with Mockito:
+ * java.lang.LinkageError: loader constraint violation in interface itable initialization:
+ * when resolving method "org.osgi.service.useradmin.User$$EnhancerByMockitoWithCGLIB$$dd2f81dc
+ * .newInstance(Lorg/mockito/cglib/proxy/Callback;)Ljava/lang/Object;" the class loader
+ * (instance of org/mockito/internal/creation/jmock/SearchingClassLoader) of the current class,
+ * org/osgi/service/useradmin/User$$EnhancerByMockitoWithCGLIB$$dd2f81dc, and the class loader
+ * (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for interface
+ * org/mockito/cglib/proxy/Factory have different Class objects for the type org/mockito/cglib/
+ * proxy/Callback used in the signature
+ *
+ * So we disable the bootdelegation. this property has no effect on the other OSGi implementation.
+ */
+ frameworkProperty("felix.bootdelegation.implicit").value("false")
+ );
+ }
+
+ public static CompositeOption ipojoBundles() {
+ return new DefaultCompositeOption(
+ mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
+ mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
+ // The tested handler
+ mavenBundle("org.apache.felix", "org.apache.felix.ipojo.handler.transaction").versionAsInProject()
+ );
+ }
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+ root.setLevel(Level.DEBUG);
+
+ return options(
+ cleanCaches(),
+ ipojoBundles(),
+ junitBundles(),
+ //testedBundle(), // Each test is doing its own deployment.
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN"),
+ provision(
+ mavenBundle().groupId("org.ow2.chameleon.transaction").artifactId("geronimo-transaction-service").version(asInProject())
+ ),
+ systemPackage("javax.transaction;version>=1.1.0")
+ );
+ }
+
+ @Before
+ public void commonSetUp() {
+ osgiHelper = new OSGiHelper(context);
+ ipojoHelper = new IPOJOHelper(context);
+
+ // Dump OSGi Framework information
+ String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
+ if (vendor == null) {
+ vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
+ }
+ String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
+ System.out.println("OSGi Framework : " + vendor + " - " + version);
+ }
+
+ @After
+ public void commonTearDown() {
+ ipojoHelper.dispose();
+ osgiHelper.dispose();
+ }
+
+ public Option testedBundle() throws MalformedURLException {
+ File out = new File("target/tested/bundle.jar");
+
+ TinyBundle tested = TinyBundles.bundle();
+
+ // We look inside target/classes to find the class and resources
+ File classes = new File("target/classes");
+ Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
+ List<File> services = new ArrayList<File>();
+ for (File file : files) {
+ if (file.isDirectory()) {
+ // By convention we export of .services and .service package
+ if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
+ services.add(file);
+ }
+ } else {
+ // We need to compute the path
+ String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
+ tested.add(path, file.toURI().toURL());
+ System.out.println(file.getName() + " added to " + path);
+ }
+ }
+
+ String export = "";
+ for (File file : services) {
+ if (export.length() > 0) {
+ export += ", ";
+ }
+ String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
+ String packageName = path.replace('/', '.');
+ export += packageName;
+ }
+
+ System.out.println("Exported packages : " + export);
+
+ InputStream inputStream = tested
+ .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
+ //.set(Constants.IMPORT_PACKAGE, "*")
+ //.set(Constants.EXPORT_PACKAGE, export) // No export...
+ .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
+
+ try {
+ FileUtils.copyInputStreamToFile(inputStream, out);
+ return bundle(out.toURI().toURL().toExternalForm());
+ } catch (MalformedURLException e) {
+ throw new RuntimeException("Cannot compute the url of the manipulated bundle");
+ } catch (IOException e) {
+ throw new RuntimeException("Cannot write of the manipulated bundle");
+ }
+ }
+
+ public void assertContains(String s, String[] arrays, String object) {
+ for (String suspect : arrays) {
+ if (object.equals(suspect)) {
+ return;
+ }
+ }
+ fail("Assertion failed : " + s);
+ }
+
+
+}
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestAnnotations.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestAnnotations.java
new file mode 100644
index 0000000..331f359
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestAnnotations.java
@@ -0,0 +1,119 @@
+package org.apache.felix.ipojo.handler.transaction.test;
+
+import org.apache.felix.ipojo.handler.transaction.components.ComponentUsingAnnotations;
+import org.apache.felix.ipojo.handler.transaction.components.FooImpl;
+import org.apache.felix.ipojo.handler.transaction.services.CheckService;
+import org.apache.felix.ipojo.handler.transaction.services.Foo;
+import org.apache.felix.ipojo.metadata.Element;
+import org.junit.Assert;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.ow2.chameleon.testing.helpers.IPOJOHelper;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.ops4j.pax.exam.CoreOptions.*;
+import static org.ops4j.pax.exam.MavenUtils.asInProject;
+import static org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy.withiPOJO;
+
+public class TestAnnotations extends Common {
+
+ public static final File TEST = new File("src/main/resources");
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Option[] options = super.config();
+
+ InputStream service = TinyBundles.bundle()
+ .add(CheckService.class)
+ .add(Foo.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Service")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build(TinyBundles.withBnd());
+
+ InputStream fooimpl = TinyBundles.bundle()
+ .add(FooImpl.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Foo Provider")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build(withiPOJO(new File(TEST, "foo.xml")));
+
+ InputStream test = TinyBundles.bundle()
+ .add(ComponentUsingAnnotations.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "TransactionAnnotationTest")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services, javax.transaction;version=1.1")
+ .build(withiPOJO(new File(TEST, "annotation.xml")));
+
+
+ return OptionUtils.combine(
+ options,
+ provision(
+ service,
+ fooimpl,
+ test
+ ),
+ repository("http://maven.ow2.org/maven2-snapshot/")
+ );
+ }
+
+ @Test
+ public void annotations() {
+ Element elem = IPOJOHelper.getMetadata(getBundle(), "org.apache.felix.ipojo.handler.transaction.components.ComponentUsingAnnotations");
+ Assert.assertNotNull(elem);
+
+ Element tr = elem.getElements("transaction", "org.apache.felix.ipojo.transaction")[0];
+ Assert.assertEquals("transaction", tr.getAttribute("field"));
+
+ Assert.assertNull(tr.getAttribute("oncommit"));
+ Assert.assertNull(tr.getAttribute("onrollback"));
+
+ Element[] methods = tr.getElements();
+ Assert.assertEquals(4, methods.length);
+
+ Element m1 = getElementByMethod(methods, "doSomethingBad");
+ Assert.assertNotNull(m1);
+
+ Element m2 = getElementByMethod(methods, "doSomethingBad2");
+ Assert.assertNotNull(m2);
+ Assert.assertEquals("required", m2.getAttribute("propagation"));
+
+ Element m3 = getElementByMethod(methods, "doSomethingGood");
+ Assert.assertNotNull(m3);
+ Assert.assertEquals("supported", m3.getAttribute("propagation"));
+ Assert.assertEquals("{java.lang.Exception}", m3.getAttribute("norollbackfor"));
+
+ Element m4 = getElementByMethod(methods, "doSomethingLong");
+ Assert.assertNotNull(m4);
+ Assert.assertEquals("1000", m4.getAttribute("timeout"));
+ Assert.assertEquals("true", m4.getAttribute("exceptiononrollback"));
+ }
+
+ private Element getElementByMethod(Element[] e, String m) {
+ for (Element elem : e) {
+ if (m.equals(elem.getAttribute("method"))) {
+ return elem;
+ }
+ }
+ Assert.fail("Method " + m + " not found");
+ return null;
+ }
+
+ private Bundle getBundle() {
+ for (Bundle b : context.getBundles()) {
+ System.out.println(b.getSymbolicName());
+ if ("TransactionAnnotationTest".equals(b.getSymbolicName())) {
+ return b;
+ }
+ }
+ Assert.fail("Cannot find the tested bundle");
+ return null;
+ }
+
+
+}
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestInstallation.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestInstallation.java
new file mode 100644
index 0000000..0991376
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestInstallation.java
@@ -0,0 +1,109 @@
+package org.apache.felix.ipojo.handler.transaction.test;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.HandlerFactory;
+import org.apache.felix.ipojo.handler.transaction.components.FooDelegator;
+import org.apache.felix.ipojo.handler.transaction.components.FooImpl;
+import org.apache.felix.ipojo.handler.transaction.services.CheckService;
+import org.apache.felix.ipojo.handler.transaction.services.Foo;
+import org.junit.Assert;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+import javax.transaction.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.exam.MavenUtils.asInProject;
+import static org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy.withiPOJO;
+
+public class TestInstallation extends Common {
+
+ public static final File TEST = new File("src/main/resources");
+
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Option[] options = super.config();
+
+ InputStream service = TinyBundles.bundle()
+ .add(CheckService.class)
+ .add(Foo.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Service")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build();
+
+ InputStream fooimpl = TinyBundles.bundle()
+ .add(FooImpl.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Foo Provider")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build(withiPOJO(new File(TEST, "foo.xml")));
+
+ InputStream test = TinyBundles.bundle()
+ .add(FooDelegator.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "RequiredTransactionPropagation")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services, javax.transaction;version=1.1")
+ .build(withiPOJO(new File(TEST, "requires.xml")));
+
+
+ return OptionUtils.combine(
+ options,
+ provision(
+ service,
+ fooimpl,
+ test
+ ));
+ }
+
+ @Test
+ public void install() throws NotSupportedException, SystemException, IllegalStateException,
+ SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException, InvalidSyntaxException {
+ Bundle[] bundles = context.getBundles();
+ for (Bundle b : bundles) {
+ System.out.println("Bundle : " + b.getSymbolicName() + " - " + b.getState());
+ Assert.assertTrue(b.getSymbolicName(), b.getState() == Bundle.ACTIVE);
+ }
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ // Transaction Service available
+ osgiHelper.isServiceAvailable(TransactionManager.class.getName());
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Assert.assertNotNull(tm.getTransaction());
+ tm.commit();
+
+ tm.begin();
+ Assert.assertNotNull(tm.getTransaction());
+ tm.rollback();
+
+ // Handler exposed
+ ServiceReference ref = osgiHelper.getServiceReference(HandlerFactory.class.getName(), "(&(handler.name=transaction)(handler.namespace=org.apache.felix.ipojo.transaction))");
+ Assert.assertNotNull(ref);
+
+ // Create an install of the components
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference[] refs = context.getAllServiceReferences(CheckService.class.getName(), "(instance.name=" + under.getInstanceName() + ")");
+
+// ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(refs);
+
+ ((CheckService) osgiHelper.getServiceObject(refs[0])).doSomethingGood();
+ }
+
+}
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestInvalidation.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestInvalidation.java
new file mode 100644
index 0000000..a311fa0
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestInvalidation.java
@@ -0,0 +1,102 @@
+package org.apache.felix.ipojo.handler.transaction.test;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.handler.transaction.components.FooDelegator;
+import org.apache.felix.ipojo.handler.transaction.components.FooImpl;
+import org.apache.felix.ipojo.handler.transaction.services.CheckService;
+import org.apache.felix.ipojo.handler.transaction.services.Foo;
+import org.junit.Assert;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+import javax.transaction.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy.withiPOJO;
+
+public class TestInvalidation extends Common {
+
+ public static final File TEST = new File("src/main/resources");
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Option[] options = super.config();
+
+ InputStream service = TinyBundles.bundle()
+ .add(CheckService.class)
+ .add(Foo.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Service")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build();
+
+ InputStream fooimpl = TinyBundles.bundle()
+ .add(FooImpl.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Foo Provider")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build(withiPOJO(new File(TEST, "foo.xml")));
+
+ InputStream test = TinyBundles.bundle()
+ .add(FooDelegator.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "RequiredTransactionPropagation")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services, javax.transaction;version=1.1")
+ .build(withiPOJO(new File(TEST, "requires.xml")));
+
+
+ return OptionUtils.combine(
+ options,
+ provision(
+ service,
+ fooimpl,
+ test
+ ));
+ }
+
+ @Test
+ public void testInvalidation() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ final ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+
+ Thread thread = new Thread(new Runnable() {
+ public void run() {
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ prov.dispose();
+ }
+ });
+
+ thread.start();
+
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ cs.doSomethingLong(); // 5s, so prov should be disposed during this time and under becomes invalid
+
+ Assert.assertEquals(ComponentInstance.INVALID, under.getState());
+
+ Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, t.getStatus());
+
+ t.rollback();
+ }
+
+
+}
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestMandatory.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestMandatory.java
new file mode 100644
index 0000000..af671d9
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestMandatory.java
@@ -0,0 +1,378 @@
+package org.apache.felix.ipojo.handler.transaction.test;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.handler.transaction.components.FooDelegator;
+import org.apache.felix.ipojo.handler.transaction.components.FooImpl;
+import org.apache.felix.ipojo.handler.transaction.services.CheckService;
+import org.apache.felix.ipojo.handler.transaction.services.Foo;
+import org.junit.Assert;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+import javax.transaction.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy.withiPOJO;
+
+
+public class TestMandatory extends Common {
+
+
+ public static final File TEST = new File("src/main/resources");
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Option[] options = super.config();
+
+
+ InputStream service = TinyBundles.bundle()
+ .add(CheckService.class)
+ .add(Foo.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Service")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build();
+
+ InputStream fooimpl = TinyBundles.bundle()
+ .add(FooImpl.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Foo Provider")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build(withiPOJO(new File(TEST, "foo.xml")));
+
+ InputStream test = TinyBundles.bundle()
+ .add(FooDelegator.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "MandatoryTransactionPropagation")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services, javax.transaction;version=1.1")
+ .build(withiPOJO(new File(TEST, "mandatory.xml")));
+
+
+ return OptionUtils.combine(
+ options,
+ provision(
+ service,
+ fooimpl,
+ test
+ ));
+
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testOkOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingGood(); // Fail !
+ }
+
+ @Test
+ public void testOkInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ cs.doSomethingGood();
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ t.commit();
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testExceptionOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad(); // Fail, RTE thrown before the other exception
+ }
+
+ @Test(expected = RollbackException.class)
+ public void testExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad();
+ Assert.fail("NullPointerException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NullPointerException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, t.getStatus());
+
+ t.commit(); // Throws a rollback exception.
+ }
+
+ @Test
+ public void testExceptionInsideTransactionRB() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad();
+ Assert.fail("NullPointerException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NullPointerException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, t.getStatus());
+
+ t.rollback();
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testExpectedExceptionOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad2(); // Throws a RTE
+ }
+
+ @Test
+ public void testExpectedExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad2();
+ Assert.fail("UnsupportedOperationException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnsupportedOperationException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
+
+ t.commit();
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testOkOutsideTransactionWithCallback() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+
+ cs.doSomethingGood(); // Throws a RTE.
+
+ }
+
+ @Test
+ public void testOkInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ cs.doSomethingGood();
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ t.commit();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNotNull(cs.getLastCommitted());
+ Assert.assertEquals(1, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+
+ Assert.assertSame(t, cs.getLastCommitted());
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testExceptionOutsideTransactionWithCallback() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+
+ cs.doSomethingBad(); // Thows a RTE.
+
+ }
+
+ @Test
+ public void testExceptionInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad();
+ Assert.fail("NullPointerException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NullPointerException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, t.getStatus());
+
+ try {
+ t.commit(); // Throw a rollback exception.
+ } catch (RollbackException e) {
+ // Expected
+ } catch (Throwable e) {
+ Assert.fail(e.getMessage()); // Unexpected
+ }
+
+ Assert.assertNotNull(cs.getLastRolledBack());
+ Assert.assertNull(cs.getLastCommitted());
+ Assert.assertEquals(0, cs.getNumberOfCommit());
+ Assert.assertEquals(1, cs.getNumberOfRollback());
+
+ Assert.assertSame(t, cs.getLastRolledBack());
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testExpectedExceptionOutsideTransactionWithCallback() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+
+ cs.doSomethingBad2();
+
+
+ }
+
+ @Test
+ public void testExpectedExceptionInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("mandatory-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad2();
+ Assert.fail("UnsupportedOperationException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnsupportedOperationException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
+
+ t.commit();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNotNull(cs.getLastCommitted());
+ Assert.assertEquals(1, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+
+ Assert.assertSame(t, cs.getLastCommitted());
+ }
+
+
+}
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestNever.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestNever.java
new file mode 100644
index 0000000..5b496e7
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestNever.java
@@ -0,0 +1,150 @@
+package org.apache.felix.ipojo.handler.transaction.test;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.handler.transaction.components.FooDelegator;
+import org.apache.felix.ipojo.handler.transaction.components.FooImpl;
+import org.apache.felix.ipojo.handler.transaction.services.CheckService;
+import org.apache.felix.ipojo.handler.transaction.services.Foo;
+import org.junit.Assert;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+import javax.transaction.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy.withiPOJO;
+
+public class TestNever extends Common {
+
+ public static final File TEST = new File("src/main/resources");
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Option[] options = super.config();
+
+
+ InputStream service = TinyBundles.bundle()
+ .add(CheckService.class)
+ .add(Foo.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Service")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build();
+
+ InputStream fooimpl = TinyBundles.bundle()
+ .add(FooImpl.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Foo Provider")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build(withiPOJO(new File(TEST, "foo.xml")));
+
+ InputStream test = TinyBundles.bundle()
+ .add(FooDelegator.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "NeverTransactionPropagation")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services, javax.transaction;version=1.1")
+ .build(withiPOJO(new File(TEST, "never.xml")));
+
+ return OptionUtils.combine(
+ options,
+ provision(
+ service,
+ fooimpl,
+ test
+ ));
+ }
+
+ @Test
+ public void testOkOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("never-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingGood();
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testOkInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("never-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ cs.doSomethingGood(); // Fail
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testExceptionOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("never-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad(); // Throws an NPE
+ }
+
+ @Test
+ public void testExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("never-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad(); // Fail
+ Assert.fail("RuntimeException expected");
+ } catch (RuntimeException e) {
+ // Ok :-)
+ }
+ Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
+
+ t.rollback();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testExpectedExceptionOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("never-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad2();
+ }
+
+
+}
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestNotSupported.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestNotSupported.java
new file mode 100644
index 0000000..92c338b
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestNotSupported.java
@@ -0,0 +1,384 @@
+package org.apache.felix.ipojo.handler.transaction.test;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.handler.transaction.components.FooDelegator;
+import org.apache.felix.ipojo.handler.transaction.components.FooImpl;
+import org.apache.felix.ipojo.handler.transaction.services.CheckService;
+import org.apache.felix.ipojo.handler.transaction.services.Foo;
+import org.junit.Assert;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+import javax.transaction.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy.withiPOJO;
+
+@ExamReactorStrategy(PerClass.class)
+public class TestNotSupported extends Common {
+
+
+ public static final File TEST = new File("src/main/resources");
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Option[] options = super.config();
+
+ InputStream service = TinyBundles.bundle()
+ .add(CheckService.class)
+ .add(Foo.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Service")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build();
+
+ InputStream fooimpl = TinyBundles.bundle()
+ .add(FooImpl.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Foo Provider")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build(withiPOJO(new File(TEST, "foo.xml")));
+
+ InputStream test = TinyBundles.bundle()
+ .add(FooDelegator.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "NotSupportedTransactionPropagation")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services, javax.transaction;version=1.1")
+ .build(withiPOJO(new File(TEST, "notsupported.xml")));
+
+ return OptionUtils.combine(
+ options,
+ provision(
+ service,
+ fooimpl,
+ test
+ ));
+ }
+
+ @Test
+ public void testOkOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ CheckService cs = ((CheckService) osgiHelper.getServiceObject(ref));
+ cs.doSomethingGood();
+ // No transaction.
+ }
+
+ @Test
+ public void testOkInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ cs.doSomethingGood();
+ Transaction t2 = cs.getCurrentTransaction(); // Is executed in the transaction despite it's not supported.
+ Assert.assertSame(t2, t);
+ t.commit();
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testExceptionOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad();
+ }
+
+ @Test
+ public void testExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad();
+ Assert.fail("NullPointerException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NullPointerException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus()); // No impact on the transaction.
+
+ t.commit(); // Ok.
+ }
+
+ @Test
+ public void testExceptionInsideTransactionRB() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad();
+ Assert.fail("NullPointerException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NullPointerException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus()); // No impact on the transaction.
+
+ t.rollback(); // Ok.
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testExpectedExceptionOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad2();
+ }
+
+ @Test
+ public void testExpectedExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad2();
+ Assert.fail("UnsupportedOperationException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnsupportedOperationException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
+
+ t.commit();
+ }
+
+ @Test
+ public void testOkOutsideTransactionWithCallback() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+
+ cs.doSomethingGood();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNull(cs.getLastCommitted());
+ Assert.assertEquals(0, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+ }
+
+ @Test
+ public void testOkInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ cs.doSomethingGood();
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ t.commit();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNull(cs.getLastCommitted());
+ Assert.assertEquals(0, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testExceptionOutsideTransactionWithCallback() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+
+ cs.doSomethingBad();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNull(cs.getLastCommitted());
+ Assert.assertEquals(0, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+ }
+
+ @Test
+ public void testExceptionInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad();
+ Assert.fail("NullPointerException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NullPointerException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus()); // No effect on the transaction
+
+ try {
+ t.commit(); // Throw a rollback exception.
+ } catch (RollbackException e) {
+ // Expected
+ } catch (Throwable e) {
+ Assert.fail(e.getMessage()); // Unexpected
+ }
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNull(cs.getLastCommitted());
+ Assert.assertEquals(0, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testExpectedExceptionOutsideTransactionWithCallback() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+
+ cs.doSomethingBad2();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNull(cs.getLastCommitted());
+ Assert.assertEquals(0, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+ }
+
+ @Test
+ public void testExpectedExceptionInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("notsupported-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad2();
+ Assert.fail("UnsupportedOperationException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnsupportedOperationException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
+
+ t.commit();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNull(cs.getLastCommitted());
+ Assert.assertEquals(0, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+ }
+
+
+}
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestRequires.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestRequires.java
new file mode 100644
index 0000000..8d447c7
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestRequires.java
@@ -0,0 +1,387 @@
+package org.apache.felix.ipojo.handler.transaction.test;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.handler.transaction.components.FooDelegator;
+import org.apache.felix.ipojo.handler.transaction.components.FooImpl;
+import org.apache.felix.ipojo.handler.transaction.services.CheckService;
+import org.apache.felix.ipojo.handler.transaction.services.Foo;
+import org.junit.Assert;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+import javax.transaction.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy.withiPOJO;
+
+public class TestRequires extends Common {
+
+
+ public static final File TEST = new File("src/main/resources");
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Option[] options = super.config();
+
+
+ InputStream service = TinyBundles.bundle()
+ .add(CheckService.class)
+ .add(Foo.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Service")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build();
+
+ InputStream fooimpl = TinyBundles.bundle()
+ .add(FooImpl.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Foo Provider")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build(withiPOJO(new File(TEST, "foo.xml")));
+
+ InputStream test = TinyBundles.bundle()
+ .add(FooDelegator.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "RequiresTransactionPropagation")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services, javax.transaction;version=1.1")
+ .build(withiPOJO(new File(TEST, "requires.xml")));
+
+ return OptionUtils.combine(
+ options,
+ provision(
+ service,
+ fooimpl,
+ test
+ ));
+
+ }
+
+ @Test
+ public void testOkOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingGood();
+ }
+
+ @Test
+ public void testOkInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ cs.doSomethingGood();
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ t.commit();
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testExceptionOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad();
+ }
+
+ @Test(expected = RollbackException.class)
+ public void testExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad();
+ Assert.fail("NullPointerException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NullPointerException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, t.getStatus());
+
+ t.commit(); // Throw a rollback exception.
+ }
+
+ @Test
+ public void testExceptionInsideTransactionRB() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad();
+ Assert.fail("NullPointerException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NullPointerException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, t.getStatus());
+
+ t.rollback();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testExpectedExceptionOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad2();
+ }
+
+ @Test
+ public void testExpectedExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad2();
+ Assert.fail("UnsupportedOperationException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnsupportedOperationException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
+
+ t.commit();
+ }
+
+ @Test
+ public void testOkOutsideTransactionWithCallback() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+
+ cs.doSomethingGood();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNotNull(cs.getLastCommitted());
+ Assert.assertEquals(1, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+ }
+
+ @Test
+ public void testOkInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ cs.doSomethingGood();
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ t.commit();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNotNull(cs.getLastCommitted());
+ Assert.assertEquals(1, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+
+ Assert.assertSame(t, cs.getLastCommitted());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testExceptionOutsideTransactionWithCallback() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+
+ cs.doSomethingBad();
+
+ Assert.assertNotNull(cs.getLastRolledBack());
+ Assert.assertNull(cs.getLastCommitted());
+ Assert.assertEquals(0, cs.getNumberOfCommit());
+ Assert.assertEquals(1, cs.getNumberOfRollback());
+ }
+
+ @Test
+ public void testExceptionInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad();
+ Assert.fail("NullPointerException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NullPointerException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, t.getStatus());
+
+ try {
+ t.commit(); // Throw a rollback exception.
+ } catch (RollbackException e) {
+ // Expected
+ } catch (Throwable e) {
+ Assert.fail(e.getMessage()); // Unexpected
+ }
+
+ Assert.assertNotNull(cs.getLastRolledBack());
+ Assert.assertNull(cs.getLastCommitted());
+ Assert.assertEquals(0, cs.getNumberOfCommit());
+ Assert.assertEquals(1, cs.getNumberOfRollback());
+
+ Assert.assertSame(t, cs.getLastRolledBack());
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testExpectedExceptionOutsideTransactionWithCallback() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+
+ cs.doSomethingBad2();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNotNull(cs.getLastCommitted());
+ Assert.assertEquals(1, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+ }
+
+ @Test
+ public void testExpectedExceptionInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requires-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad2();
+ Assert.fail("UnsupportedOperationException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnsupportedOperationException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
+
+ t.commit();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNotNull(cs.getLastCommitted());
+ Assert.assertEquals(1, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+
+ Assert.assertSame(t, cs.getLastCommitted());
+ }
+
+
+}
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestRequiresNew.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestRequiresNew.java
new file mode 100644
index 0000000..30b1f95
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestRequiresNew.java
@@ -0,0 +1,200 @@
+package org.apache.felix.ipojo.handler.transaction.test;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.handler.transaction.components.FooDelegator;
+import org.apache.felix.ipojo.handler.transaction.components.FooImpl;
+import org.apache.felix.ipojo.handler.transaction.services.CheckService;
+import org.apache.felix.ipojo.handler.transaction.services.Foo;
+import org.junit.Assert;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+import javax.transaction.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy.withiPOJO;
+
+public class TestRequiresNew extends Common {
+
+
+ public static final File TEST = new File("src/main/resources");
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Option[] options = super.config();
+
+ InputStream service = TinyBundles.bundle()
+ .add(CheckService.class)
+ .add(Foo.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Service")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build();
+
+ InputStream fooimpl = TinyBundles.bundle()
+ .add(FooImpl.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Foo Provider")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build(withiPOJO(new File(TEST, "foo.xml")));
+
+ InputStream test = TinyBundles.bundle()
+ .add(FooDelegator.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "RequiresNewTransactionPropagation")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services, javax.transaction;version=1.1")
+ .build(withiPOJO(new File(TEST, "requiresnew.xml")));
+
+ return OptionUtils.combine(
+ options,
+ provision(
+ service,
+ fooimpl,
+ test
+ )
+ );
+
+
+ }
+
+ @Test
+ public void testOkOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requiresnew-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingGood(); // Ok
+ }
+
+ @Test
+ public void testOkInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requiresnew-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ cs.doSomethingGood();
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertNotSame(t2, t); // Two different transactions
+ // Check that t2 is commited => no transaction
+ Assert.assertEquals(Status.STATUS_NO_TRANSACTION, t2.getStatus());
+ t.commit();
+ }
+
+ @Test
+ public void testExceptionOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requiresnew-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ try {
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad(); // throws an exception on rollback
+ Assert.fail("Exception expected on rollback");
+ } catch (IllegalStateException e) {
+ // Ok.
+ } catch (Exception e) {
+ Assert.fail("IllegalStateException expected on rollback");
+ }
+ }
+
+ @Test
+ public void testExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requiresnew-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad();
+ Assert.fail("IllegalStateException expected"); // throws an exception on rollback
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof IllegalStateException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertNotSame(t2, t);
+ // Check that t2 is rolledback
+ Assert.assertEquals(Status.STATUS_NO_TRANSACTION, t2.getStatus());
+ Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
+
+ t.commit();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testExpectedExceptionOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requiresnew-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad2();
+ }
+
+ @Test
+ public void testExpectedExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("requiresnew-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad2();
+ Assert.fail("UnsupportedOperationException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnsupportedOperationException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertNotSame(t2, t);
+ Assert.assertEquals(Status.STATUS_NO_TRANSACTION, t2.getStatus());
+ Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
+
+ t.commit();
+ }
+}
diff --git a/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestSupported.java b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestSupported.java
new file mode 100644
index 0000000..780b187
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler-it/src/it/transaction-it/src/test/java/org/apache/felix/ipojo/handler/transaction/test/TestSupported.java
@@ -0,0 +1,392 @@
+package org.apache.felix.ipojo.handler.transaction.test;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.handler.transaction.components.FooDelegator;
+import org.apache.felix.ipojo.handler.transaction.components.FooImpl;
+import org.apache.felix.ipojo.handler.transaction.services.CheckService;
+import org.apache.felix.ipojo.handler.transaction.services.Foo;
+import org.junit.Assert;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.spi.reactors.PerMethod;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+import javax.transaction.*;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy.withiPOJO;
+
+@ExamReactorStrategy(PerClass.class)
+public class TestSupported extends Common {
+
+
+ public static final File TEST = new File("src/main/resources");
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Option[] options = super.config();
+
+
+ InputStream service = TinyBundles.bundle()
+ .add(CheckService.class)
+ .add(Foo.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Service")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build();
+
+ InputStream fooimpl = TinyBundles.bundle()
+ .add(FooImpl.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "Foo Provider")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services")
+ .build(withiPOJO(new File(TEST, "foo.xml")));
+
+ InputStream test = TinyBundles.bundle()
+ .add(FooDelegator.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "SupportedTransactionPropagation")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.handler.transaction.services, javax.transaction;version=1.1")
+ .build(withiPOJO(new File(TEST, "supported.xml")));
+
+ return OptionUtils.combine(
+ options,
+ provision(
+ service,
+ fooimpl,
+ test
+ ));
+ }
+
+ @Test
+ public void testOkOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("supported-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ CheckService cs = ((CheckService) osgiHelper.getServiceObject(ref));
+ cs.doSomethingGood();
+ // No transaction.
+ }
+
+ @Test
+ public void testOkInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("supported-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ cs.doSomethingGood();
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ t.commit();
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testExceptionOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("supported-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad();
+ }
+
+ @Test(expected = RollbackException.class)
+ public void testExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("supported-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad();
+ Assert.fail("NullPointerException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NullPointerException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, t.getStatus());
+
+ t.commit(); // Throw a rollback exception.
+ }
+
+ @Test
+ public void testExceptionInsideTransactionRB() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("supported-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad();
+ Assert.fail("NullPointerException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NullPointerException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, t.getStatus());
+
+ t.rollback();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testExpectedExceptionOutsideTransaction() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("supported-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ ((CheckService) osgiHelper.getServiceObject(ref)).doSomethingBad2();
+ }
+
+ @Test
+ public void testExpectedExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("supported-ok");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad2();
+ Assert.fail("UnsupportedOperationException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnsupportedOperationException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
+
+ t.commit();
+ }
+
+ @Test
+ public void testOkOutsideTransactionWithCallback() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("supported-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+
+ cs.doSomethingGood();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNull(cs.getLastCommitted());
+ Assert.assertEquals(0, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+ }
+
+ @Test
+ public void testOkInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("supported-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ cs.doSomethingGood();
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ t.commit();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNotNull(cs.getLastCommitted());
+ Assert.assertEquals(1, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+
+ Assert.assertSame(t, cs.getLastCommitted());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testExceptionOutsideTransactionWithCallback() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("supported-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+
+ cs.doSomethingBad();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNull(cs.getLastCommitted());
+ Assert.assertEquals(0, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+ }
+
+ @Test
+ public void testExceptionInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("supported-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad();
+ Assert.fail("NullPointerException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof NullPointerException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, t.getStatus());
+
+ try {
+ t.commit(); // Throw a rollback exception.
+ } catch (RollbackException e) {
+ // Expected
+ } catch (Throwable e) {
+ Assert.fail(e.getMessage()); // Unexpected
+ }
+
+ Assert.assertNotNull(cs.getLastRolledBack());
+ Assert.assertNull(cs.getLastCommitted());
+ Assert.assertEquals(0, cs.getNumberOfCommit());
+ Assert.assertEquals(1, cs.getNumberOfRollback());
+
+ Assert.assertSame(t, cs.getLastRolledBack());
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testExpectedExceptionOutsideTransactionWithCallback() {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("supported-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+
+ cs.doSomethingBad2();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNull(cs.getLastCommitted());
+ Assert.assertEquals(0, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+ }
+
+ @Test
+ public void testExpectedExceptionInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
+ ComponentInstance under = ipojoHelper.createComponentInstance("supported-cb");
+
+ Assert.assertEquals(ComponentInstance.VALID, prov.getState());
+ Assert.assertEquals(ComponentInstance.VALID, under.getState());
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
+ Assert.assertNotNull(ref);
+
+ osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
+ CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+ TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
+ tm.begin();
+ Transaction t = tm.getTransaction();
+ try {
+ cs.doSomethingBad2();
+ Assert.fail("UnsupportedOperationException expected");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnsupportedOperationException);
+ }
+ Transaction t2 = cs.getCurrentTransaction();
+ Assert.assertSame(t2, t);
+ Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
+
+ t.commit();
+
+ Assert.assertNull(cs.getLastRolledBack());
+ Assert.assertNotNull(cs.getLastCommitted());
+ Assert.assertEquals(1, cs.getNumberOfCommit());
+ Assert.assertEquals(0, cs.getNumberOfRollback());
+
+ Assert.assertSame(t, cs.getLastCommitted());
+ }
+
+
+}
diff --git a/ipojo/handler/transaction/transaction-handler/pom.xml b/ipojo/handler/transaction/transaction-handler/pom.xml
new file mode 100644
index 0000000..57679a1
--- /dev/null
+++ b/ipojo/handler/transaction/transaction-handler/pom.xml
@@ -0,0 +1,116 @@
+<!--
+ 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">
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>felix-parent</artifactId>
+ <version>1.2.1</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.handler.transaction
+ </artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ <name>Apache Felix iPOJO Transaction Handler</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.3</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Private-Package>org.apache.felix.ipojo.transaction</Private-Package>
+ <Import-Package>javax.transaction;version=1.1, *</Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-ipojo-plugin</artifactId>
+ <version>1.8.4</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>ipojo-bundle</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>rat-maven-plugin</artifactId>
+ <configuration>
+ <excludeSubProjects>false</excludeSubProjects>
+ <useEclipseDefaultExcludes>true</useEclipseDefaultExcludes>
+ <useMavenDefaultExcludes>true</useMavenDefaultExcludes>
+ <excludes>
+ <param>doc/**/*</param>
+ <param>maven-eclipse.xml</param>
+ <param>.checkstyle</param>
+ <param>.externalToolBuilders/*</param>
+ <param>LICENSE.asm</param>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <enableRulesSummary>false</enableRulesSummary>
+ <violationSeverity>warning</violationSeverity>
+ <configLocation>
+ http://felix.apache.org/ipojo/dev/checkstyle_ipojo.xml
+ </configLocation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.metadata</artifactId>
+ <version>1.4.0</version>
+ </dependency>
+ <dependency>
+ <groupId>geronimo-spec</groupId>
+ <artifactId>geronimo-spec-jta</artifactId>
+ <version>1.0-M1</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/ipojo/handler/transaction/src/main/java/org/apache/felix/ipojo/transaction/TransactionHandler.java b/ipojo/handler/transaction/transaction-handler/src/main/java/org/apache/felix/ipojo/transaction/TransactionHandler.java
similarity index 100%
rename from ipojo/handler/transaction/src/main/java/org/apache/felix/ipojo/transaction/TransactionHandler.java
rename to ipojo/handler/transaction/transaction-handler/src/main/java/org/apache/felix/ipojo/transaction/TransactionHandler.java
diff --git a/ipojo/handler/transaction/src/main/java/org/apache/felix/ipojo/transaction/TransactionalMethod.java b/ipojo/handler/transaction/transaction-handler/src/main/java/org/apache/felix/ipojo/transaction/TransactionalMethod.java
similarity index 100%
rename from ipojo/handler/transaction/src/main/java/org/apache/felix/ipojo/transaction/TransactionalMethod.java
rename to ipojo/handler/transaction/transaction-handler/src/main/java/org/apache/felix/ipojo/transaction/TransactionalMethod.java
diff --git a/ipojo/handler/transaction/src/main/resources/metadata.xml b/ipojo/handler/transaction/transaction-handler/src/main/resources/metadata.xml
similarity index 100%
rename from ipojo/handler/transaction/src/main/resources/metadata.xml
rename to ipojo/handler/transaction/transaction-handler/src/main/resources/metadata.xml