Provide transaction handler annotations
Add test using annotations
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@787003 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/annotations/pom.xml b/ipojo/annotations/pom.xml
index a30fe8a..2c34444 100644
--- a/ipojo/annotations/pom.xml
+++ b/ipojo/annotations/pom.xml
@@ -6,9 +6,9 @@
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
@@ -54,12 +54,13 @@
org.apache.felix.ipojo.handlers.jmx,
org.apache.felix.ipojo.extender,
org.apache.felix.ipojo.whiteboard,
- org.apache.felix.ipojo.handlers.event
+ org.apache.felix.ipojo.handlers.event,
+ org.apache.felix.ipojo.transaction
</Export-Package>
<Include-Resource> META-INF/LICENCE=LICENSE,
META-INF/NOTICE=NOTICE </Include-Resource>
</instructions>
- <obrRepository>NONE</obrRepository>
+ <obrRepository>NONE</obrRepository>
</configuration>
</plugin>
<plugin>
diff --git a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/transaction/Transaction.java b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/transaction/Transaction.java
new file mode 100644
index 0000000..142222a
--- /dev/null
+++ b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/transaction/Transaction.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.transaction;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * Transaction Handler annotation.
+ * Allows the declaration of transactionnal methods
+ * Be aware that despite is it provided in the annotations jar,
+ * it refers to an external handler.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@Target(ElementType.TYPE)
+public @interface Transaction {
+
+ /**
+ * Sets the Transaction field. The specified field must be of the type
+ * Transaction.
+ */
+ String field() default "";
+
+ /**
+ * Sets the method called when a transaction is committed.
+ */
+ String oncommit() default "";
+
+ /**
+ * Sets the method called when a transaction is rolled back.
+ */
+ String onrollback() default "";
+
+
+}
diff --git a/ipojo/annotations/src/main/java/org/apache/felix/ipojo/transaction/Transactionnal.java b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/transaction/Transactionnal.java
new file mode 100644
index 0000000..f705051
--- /dev/null
+++ b/ipojo/annotations/src/main/java/org/apache/felix/ipojo/transaction/Transactionnal.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.transaction;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * Transactionnal Method annotation.
+ * Allows the declaration of transactionnal method.
+ * Be aware that despite is it provided in the annotations jar,
+ * it refers to an external handler.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@Target(ElementType.METHOD)
+public @interface Transactionnal {
+
+ /**
+ * Sets the transaction timeout.
+ */
+ long timeout() default 0;;
+
+ /**
+ * Sets the transaction propagation policy.
+ * Supported values are : requires mandatory, notsupported, never, requiresnew.
+ */
+ String propagation() default "requires";
+
+ /**
+ * Sets the exceptions that do not rollback the current transaction.
+ */
+ String[] norollbackfor() default {};
+
+ /**
+ * Sets if the transaction rollback throws an exception.
+ */
+ boolean exceptiononrollback() default false;
+
+
+}
diff --git a/ipojo/pom.xml b/ipojo/pom.xml
index 54242e2..b3500aa 100644
--- a/ipojo/pom.xml
+++ b/ipojo/pom.xml
@@ -43,6 +43,7 @@
<module>handler/temporal</module>
<module>handler/eventadmin</module>
<module>handler/whiteboard</module>
+ <module>handler/transaction</module>
<module>api</module>
<module>online-manipulator</module>
<module>junit4osgi</module>
diff --git a/ipojo/tests/handler/transaction/pom.xml b/ipojo/tests/handler/transaction/pom.xml
index a7cb2d2..5f49bb0 100644
--- a/ipojo/tests/handler/transaction/pom.xml
+++ b/ipojo/tests/handler/transaction/pom.xml
@@ -1,11 +1,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo.transaction.test</artifactId>
+ <groupId>ipojo.tests</groupId>
+ <artifactId>tests.transactions</artifactId>
<packaging>jar</packaging>
<version>1.3.0-SNAPSHOT</version>
- <name>org.apache.felix.ipojo.transaction.test</name>
+ <name>iPOJO Transaction Handler Test Suite</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
@@ -20,12 +20,17 @@
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.annotations</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.transaction</artifactId>
<version>0.9.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.ipojo.transaction</artifactId>
+ <artifactId>org.apache.felix.ipojo.handler.transaction</artifactId>
<version>1.3.0-SNAPSHOT</version>
</dependency>
<!--
@@ -64,7 +69,7 @@
<type>jar</type>
<scope>test</scope>
</dependency>
-
+
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo.pax.exam.target</artifactId>
@@ -90,9 +95,9 @@
<artifactId>pax-logging-service</artifactId>
<version>1.3.0</version>
</dependency>
-
+
</dependencies>
-
+
<repositories>
<repository>
<id>ops4j.releases</id>
@@ -106,7 +111,7 @@
</snapshots>
</repository>
</repositories>
-
+
<build>
<plugins>
<plugin>
diff --git a/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestAnnotations.java b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestAnnotations.java
new file mode 100644
index 0000000..30aa3e7
--- /dev/null
+++ b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestAnnotations.java
@@ -0,0 +1,166 @@
+package org.apache.felix.ipojo.transaction.test;
+
+import static org.ops4j.pax.exam.CoreOptions.bundle;
+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.ops4j.pax.tinybundles.core.TinyBundles.with;
+
+import java.io.File;
+import java.net.URL;
+
+import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.pax.exam.target.BundleAsiPOJO;
+import org.apache.felix.ipojo.transaction.test.component.ComponentUsingAnnotations;
+import org.apache.felix.ipojo.transaction.test.component.FooImpl;
+import org.apache.felix.ipojo.transaction.test.service.CheckService;
+import org.apache.felix.ipojo.transaction.test.service.Foo;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Inject;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+
+@RunWith( JUnit4TestRunner.class )
+public class TestAnnotations {
+
+ @Inject
+ private BundleContext context;
+
+ private OSGiHelper osgi;
+
+ private IPOJOHelper ipojo;
+
+ public static final File ROOT = new File("target/tmp");
+ public static final File TEST = new File("src/test/resources");
+
+
+ @Before
+ public void init() {
+ osgi = new OSGiHelper(context);
+ ipojo = new IPOJOHelper(context);
+ }
+
+ @After
+ public void stop() {
+ ipojo.dispose();
+ osgi.dispose();
+ }
+
+ @Configuration
+ public static Option[] configure() {
+ ROOT.mkdirs();
+
+ URL service = TinyBundles.newBundle()
+ .addClass(CheckService.class)
+ .addClass(Foo.class)
+ .prepare(
+ with()
+ .set(Constants.BUNDLE_SYMBOLICNAME,"Service")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
+ )
+ .build( TinyBundles.asURL());
+
+ String fooimpl = TinyBundles.newBundle()
+ .addClass(FooImpl.class)
+ .prepare(
+ with()
+ .set(Constants.BUNDLE_SYMBOLICNAME,"Foo Provider")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
+ )
+ .build( new BundleAsiPOJO(new File(ROOT, "FooImpl.jar"), new File(TEST, "foo.xml")) ).toExternalForm();
+
+ String test = TinyBundles.newBundle()
+ .addClass(ComponentUsingAnnotations.class)
+ .prepare(
+ with()
+ .set(Constants.BUNDLE_SYMBOLICNAME,"Transaction Annotation Test")
+ .set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service, javax.transaction")
+ )
+ .build( new BundleAsiPOJO(new File(ROOT, "annotations.jar"), new File(TEST, "annotation.xml")) ).toExternalForm();
+
+
+ Option[] opt = options(
+
+ provision(
+ mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").version(asInProject()),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version(asInProject()),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.handler.transaction").version(asInProject()),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.transaction").version(asInProject()),
+ mavenBundle()
+ .groupId( "org.ops4j.pax.tinybundles" )
+ .artifactId( "pax-tinybundles-core" )
+ .version( "0.5.0-SNAPSHOT" ),
+ bundle(service.toExternalForm()),
+ bundle(fooimpl),
+ bundle(test)
+ )
+ )
+
+ ;
+ return opt;
+ }
+
+ @Test
+ public void annotations() {
+ Element elem = IPOJOHelper.getMetadata(getBundle(), "org.apache.felix.ipojo.transaction.test.component.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()) {
+ if ("Transaction Annotation Test".equals(b.getSymbolicName())) {
+ return b;
+ }
+ }
+ Assert.fail("Cannot find the tested bundle");
+ return null;
+ }
+
+
+}
diff --git a/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestInstallation.java b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestInstallation.java
index 0803abd..e1b3a8d 100644
--- a/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestInstallation.java
+++ b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestInstallation.java
@@ -103,7 +103,7 @@
provision(
mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version(asInProject()),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.transaction").version(asInProject()),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.handler.transaction").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.transaction").version(asInProject()),
mavenBundle()
.groupId( "org.ops4j.pax.tinybundles" )
diff --git a/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestInvalidation.java b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestInvalidation.java
index a57a2a8..490fc9b 100644
--- a/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestInvalidation.java
+++ b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestInvalidation.java
@@ -41,71 +41,71 @@
@RunWith( JUnit4TestRunner.class )
public class TestInvalidation {
-
+
@Inject
private BundleContext context;
-
+
private OSGiHelper osgi;
-
+
private IPOJOHelper ipojo;
-
+
public static final File ROOT = new File("target/tmp");
public static final File TEST = new File("src/test/resources");
-
+
@Before
public void init() {
osgi = new OSGiHelper(context);
ipojo = new IPOJOHelper(context);
}
-
+
@After
public void stop() {
ipojo.dispose();
osgi.dispose();
}
-
+
@Configuration
- public static Option[] configure() {
+ public static Option[] configure() {
ROOT.mkdirs();
-
+
URL service = TinyBundles.newBundle()
.addClass(CheckService.class)
.addClass(Foo.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Service")
.set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
.set(Constants.IMPORT_PACKAGE, "javax.transaction")
)
.build( TinyBundles.asURL());
-
+
String fooimpl = TinyBundles.newBundle()
.addClass(FooImpl.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Foo Provider")
.set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
)
.build( new BundleAsiPOJO(new File(ROOT, "FooImpl.jar"), new File(TEST, "foo.xml")) ).toExternalForm();
-
+
String test = TinyBundles.newBundle()
.addClass(FooDelegator.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Required Transaction Propgatation")
.set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service, javax.transaction")
)
.build( new BundleAsiPOJO(new File(ROOT, "requires.jar"), new File(TEST, "requires.xml")) ).toExternalForm();
-
-
+
+
Option[] opt = options(
-
+
provision(
mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version(asInProject()),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.transaction").version(asInProject()),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.handler.transaction").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.transaction").version(asInProject()),
mavenBundle()
.groupId( "org.ops4j.pax.tinybundles" )
@@ -120,24 +120,24 @@
;
return opt;
}
-
-
-
-
+
+
+
+
@Test
public void testInvalidation() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
final ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requires-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
-
+
Thread thread = new Thread (new Runnable() {
public void run() {
try {
@@ -148,19 +148,19 @@
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/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestMandatory.java b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestMandatory.java
index 66772e2..bc5eef1 100644
--- a/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestMandatory.java
+++ b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestMandatory.java
@@ -41,70 +41,70 @@
@RunWith( JUnit4TestRunner.class )
public class TestMandatory {
-
+
@Inject
private BundleContext context;
-
+
private OSGiHelper osgi;
-
+
private IPOJOHelper ipojo;
-
+
public static final File ROOT = new File("target/tmp");
public static final File TEST = new File("src/test/resources");
-
+
@Before
public void init() {
osgi = new OSGiHelper(context);
ipojo = new IPOJOHelper(context);
}
-
+
@After
public void stop() {
ipojo.dispose();
osgi.dispose();
}
-
+
@Configuration
- public static Option[] configure() {
+ public static Option[] configure() {
ROOT.mkdirs();
URL service = TinyBundles.newBundle()
.addClass(CheckService.class)
.addClass(Foo.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Service")
.set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
.set(Constants.IMPORT_PACKAGE, "javax.transaction")
)
.build( TinyBundles.asURL());
-
+
String fooimpl = TinyBundles.newBundle()
.addClass(FooImpl.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Foo Provider")
.set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
)
.build( new BundleAsiPOJO(new File(ROOT, "FooImpl.jar"), new File(TEST, "foo.xml")) ).toExternalForm();
-
+
String test = TinyBundles.newBundle()
.addClass(FooDelegator.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Mandatory Transaction Propgatation")
.set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service, javax.transaction")
)
.build( new BundleAsiPOJO(new File(ROOT, "mandatory.jar"), new File(TEST, "mandatory.xml")) ).toExternalForm();
-
-
+
+
Option[] opt = options(
-
+
provision(
mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version(asInProject()),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.transaction").version(asInProject()),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.handler.transaction").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.transaction").version(asInProject()),
mavenBundle()
.groupId( "org.ops4j.pax.tinybundles" )
@@ -119,33 +119,33 @@
;
return opt;
}
-
-
+
+
@Test(expected=RuntimeException.class)
public void testOkOutsideTransaction() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("mandatory-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
((CheckService) osgi.getServiceObject(ref)).doSomethingGood(); // Fail !
}
-
+
@Test
public void testOkInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("mandatory-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -155,32 +155,32 @@
Assert.assertSame(t2, t);
t.commit();
}
-
+
@Test(expected=RuntimeException.class)
public void testExceptionOutsideTransaction() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("mandatory-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
((CheckService) osgi.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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("mandatory-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -194,21 +194,21 @@
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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("mandatory-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -222,35 +222,35 @@
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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("mandatory-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
((CheckService) osgi.getServiceObject(ref)).doSomethingBad2(); // Throws a RTE
}
-
+
@Test
public void testExpectedExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("mandatory-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -264,39 +264,39 @@
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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("mandatory-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
cs.doSomethingGood(); // Throws a RTE.
-
+
}
-
+
@Test
public void testOkInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("mandatory-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -305,43 +305,43 @@
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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("mandatory-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
CheckService cs = (CheckService) osgi.getServiceObject(ref);
cs.doSomethingBad(); // Thows a RTE.
-
+
}
-
+
@Test
public void testExceptionInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("mandatory-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -355,7 +355,7 @@
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) {
@@ -363,44 +363,44 @@
} 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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("mandatory-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
CheckService cs = (CheckService) osgi.getServiceObject(ref);
cs.doSomethingBad2();
-
-
+
+
}
-
+
@Test
public void testExpectedExceptionInsideTransactionWithCallback() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("mandatory-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -414,17 +414,17 @@
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/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestNever.java b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestNever.java
index 21d6369..3e38b54 100644
--- a/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestNever.java
+++ b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestNever.java
@@ -41,69 +41,69 @@
@RunWith( JUnit4TestRunner.class )
public class TestNever {
-
+
@Inject
private BundleContext context;
-
+
private OSGiHelper osgi;
-
+
private IPOJOHelper ipojo;
public static final File ROOT = new File("target/tmp");
public static final File TEST = new File("src/test/resources");
-
+
@Before
public void init() {
osgi = new OSGiHelper(context);
ipojo = new IPOJOHelper(context);
}
-
+
@After
public void stop() {
ipojo.dispose();
osgi.dispose();
}
-
+
@Configuration
- public static Option[] configure() {
+ public static Option[] configure() {
ROOT.mkdirs();
URL service = TinyBundles.newBundle()
.addClass(CheckService.class)
.addClass(Foo.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Service")
.set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
.set(Constants.IMPORT_PACKAGE, "javax.transaction")
)
.build( TinyBundles.asURL());
-
+
String fooimpl = TinyBundles.newBundle()
.addClass(FooImpl.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Foo Provider")
.set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
)
.build( new BundleAsiPOJO(new File(ROOT,"FooImpl.jar"), new File(TEST, "foo.xml")) ).toExternalForm();
-
+
String test = TinyBundles.newBundle()
.addClass(FooDelegator.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Mandatory Transaction Propgatation")
.set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service, javax.transaction")
)
.build( new BundleAsiPOJO(new File(ROOT, "never.jar"), new File(TEST, "never.xml")) ).toExternalForm();
-
-
+
+
Option[] opt = options(
-
+
provision(
mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version(asInProject()),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.transaction").version(asInProject()),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.handler.transaction").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.transaction").version(asInProject()),
mavenBundle()
.groupId( "org.ops4j.pax.tinybundles" )
@@ -118,64 +118,64 @@
;
return opt;
}
-
-
+
+
@Test
public void testOkOutsideTransaction() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("never-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
((CheckService) osgi.getServiceObject(ref)).doSomethingGood();
}
-
+
@Test(expected=RuntimeException.class)
public void testOkInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("never-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
cs.doSomethingGood(); // Fail
}
-
+
@Test(expected=NullPointerException.class)
public void testExceptionOutsideTransaction() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("never-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
- ((CheckService) osgi.getServiceObject(ref)).doSomethingBad(); // Throws an NPE
+ ((CheckService) osgi.getServiceObject(ref)).doSomethingBad(); // Throws an NPE
}
-
+
@Test
public void testExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("never-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -187,24 +187,24 @@
Assert.assertTrue(e instanceof RuntimeException);
}
Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
-
- t.rollback();
+
+ t.rollback();
}
-
+
@Test(expected=UnsupportedOperationException.class)
public void testExpectedExceptionOutsideTransaction() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("never-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
- ((CheckService) osgi.getServiceObject(ref)).doSomethingBad2();
+ ((CheckService) osgi.getServiceObject(ref)).doSomethingBad2();
}
-
-
-
+
+
+
}
diff --git a/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestNotSupported.java b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestNotSupported.java
index bd866fc..7c98681 100644
--- a/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestNotSupported.java
+++ b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestNotSupported.java
@@ -41,69 +41,69 @@
@RunWith( JUnit4TestRunner.class )
public class TestNotSupported {
-
+
@Inject
private BundleContext context;
-
+
private OSGiHelper osgi;
-
+
private IPOJOHelper ipojo;
public static final File ROOT = new File("target/tmp");
public static final File TEST = new File("src/test/resources");
-
+
@Before
public void init() {
osgi = new OSGiHelper(context);
ipojo = new IPOJOHelper(context);
}
-
+
@After
public void stop() {
ipojo.dispose();
osgi.dispose();
}
-
+
@Configuration
- public static Option[] configure() {
+ public static Option[] configure() {
ROOT.mkdirs();
URL service = TinyBundles.newBundle()
.addClass(CheckService.class)
.addClass(Foo.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Service")
.set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
.set(Constants.IMPORT_PACKAGE, "javax.transaction")
)
.build( TinyBundles.asURL());
-
+
String fooimpl = TinyBundles.newBundle()
.addClass(FooImpl.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Foo Provider")
.set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
)
.build( new BundleAsiPOJO(new File(ROOT, "FooImpl.jar"), new File(TEST, "foo.xml")) ).toExternalForm();
-
+
String test = TinyBundles.newBundle()
.addClass(FooDelegator.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Required Transaction Propgatation")
.set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service, javax.transaction")
)
.build( new BundleAsiPOJO(new File(ROOT, "notsupported.jar"), new File(TEST, "notsupported.xml")) ).toExternalForm();
-
-
+
+
Option[] opt = options(
-
+
provision(
mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version(asInProject()),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.transaction").version(asInProject()),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.handler.transaction").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.transaction").version(asInProject()),
mavenBundle()
.groupId( "org.ops4j.pax.tinybundles" )
@@ -118,16 +118,16 @@
;
return opt;
}
-
-
+
+
@Test
public void testOkOutsideTransaction() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("notsupported-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
@@ -135,18 +135,18 @@
cs.doSomethingGood();
// No transaction.
}
-
+
@Test
public void testOkInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("notsupported-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -156,32 +156,32 @@
Assert.assertSame(t2, t);
t.commit();
}
-
+
@Test(expected=NullPointerException.class)
public void testExceptionOutsideTransaction() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("notsupported-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
((CheckService) osgi.getServiceObject(ref)).doSomethingBad();
}
-
+
@Test
public void testExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("notsupported-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -195,21 +195,21 @@
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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("notsupported-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -223,35 +223,35 @@
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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("notsupported-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
((CheckService) osgi.getServiceObject(ref)).doSomethingBad2();
}
-
+
@Test
public void testExpectedExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("notsupported-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -265,43 +265,43 @@
Transaction t2 = cs.getCurrentTransaction();
Assert.assertSame(t2, t);
Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
-
+
t.commit();
}
-
+
@Test
public void testOkOutsideTransactionWithCallback() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("notsupported-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("notsupported-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -310,45 +310,45 @@
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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("notsupported-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
CheckService cs = (CheckService) osgi.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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("notsupported-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -362,7 +362,7 @@
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) {
@@ -370,45 +370,45 @@
} 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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("notsupported-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
CheckService cs = (CheckService) osgi.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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("notsupported-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -422,15 +422,15 @@
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/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestRequires.java b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestRequires.java
index 75839a3..781e0dd 100644
--- a/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestRequires.java
+++ b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestRequires.java
@@ -41,70 +41,70 @@
@RunWith( JUnit4TestRunner.class )
public class TestRequires {
-
+
@Inject
private BundleContext context;
-
+
private OSGiHelper osgi;
-
+
private IPOJOHelper ipojo;
-
+
public static final File ROOT = new File("target/tmp");
public static final File TEST = new File("src/test/resources");
-
+
@Before
public void init() {
osgi = new OSGiHelper(context);
ipojo = new IPOJOHelper(context);
}
-
+
@After
public void stop() {
ipojo.dispose();
osgi.dispose();
}
-
+
@Configuration
- public static Option[] configure() {
+ public static Option[] configure() {
ROOT.mkdirs();
URL service = TinyBundles.newBundle()
.addClass(CheckService.class)
.addClass(Foo.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Service")
.set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
.set(Constants.IMPORT_PACKAGE, "javax.transaction")
)
.build( TinyBundles.asURL());
-
+
String fooimpl = TinyBundles.newBundle()
.addClass(FooImpl.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Foo Provider")
.set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
)
.build( new BundleAsiPOJO(new File(ROOT, "FooImpl.jar"), new File(TEST, "foo.xml")) ).toExternalForm();
-
+
String test = TinyBundles.newBundle()
.addClass(FooDelegator.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Required Transaction Propgatation")
.set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service, javax.transaction")
)
.build( new BundleAsiPOJO(new File(ROOT, "requires.jar"), new File(TEST, "requires.xml")) ).toExternalForm();
-
-
+
+
Option[] opt = options(
-
+
provision(
mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version(asInProject()),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.transaction").version(asInProject()),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.handler.transaction").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.transaction").version(asInProject()),
mavenBundle()
.groupId( "org.ops4j.pax.tinybundles" )
@@ -119,33 +119,33 @@
;
return opt;
}
-
-
+
+
@Test
public void testOkOutsideTransaction() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requires-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
((CheckService) osgi.getServiceObject(ref)).doSomethingGood();
}
-
+
@Test
public void testOkInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requires-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -155,32 +155,32 @@
Assert.assertSame(t2, t);
t.commit();
}
-
+
@Test(expected=NullPointerException.class)
public void testExceptionOutsideTransaction() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requires-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
((CheckService) osgi.getServiceObject(ref)).doSomethingBad();
}
-
+
@Test(expected=RollbackException.class)
public void testExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requires-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -194,21 +194,21 @@
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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requires-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -222,35 +222,35 @@
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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requires-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
((CheckService) osgi.getServiceObject(ref)).doSomethingBad2();
}
-
+
@Test
public void testExpectedExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requires-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -264,43 +264,43 @@
Transaction t2 = cs.getCurrentTransaction();
Assert.assertSame(t2, t);
Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
-
+
t.commit();
}
-
+
@Test
public void testOkOutsideTransactionWithCallback() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requires-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requires-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -309,47 +309,47 @@
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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requires-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
CheckService cs = (CheckService) osgi.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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requires-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -363,7 +363,7 @@
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) {
@@ -371,47 +371,47 @@
} 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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requires-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
CheckService cs = (CheckService) osgi.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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requires-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -425,17 +425,17 @@
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/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestRequiresNew.java b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestRequiresNew.java
index 974fca9..00805ed 100644
--- a/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestRequiresNew.java
+++ b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestRequiresNew.java
@@ -41,70 +41,70 @@
@RunWith( JUnit4TestRunner.class )
public class TestRequiresNew {
-
+
@Inject
private BundleContext context;
-
+
private OSGiHelper osgi;
-
+
private IPOJOHelper ipojo;
-
+
public static final File ROOT = new File("target/tmp");
public static final File TEST = new File("src/test/resources");
-
+
@Before
public void init() {
osgi = new OSGiHelper(context);
ipojo = new IPOJOHelper(context);
}
-
+
@After
public void stop() {
ipojo.dispose();
osgi.dispose();
}
-
+
@Configuration
- public static Option[] configure() {
+ public static Option[] configure() {
ROOT.mkdirs();
URL service = TinyBundles.newBundle()
.addClass(CheckService.class)
.addClass(Foo.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Service")
.set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
.set(Constants.IMPORT_PACKAGE, "javax.transaction")
)
.build( TinyBundles.asURL());
-
+
String fooimpl = TinyBundles.newBundle()
.addClass(FooImpl.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Foo Provider")
.set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
)
.build( new BundleAsiPOJO(new File(ROOT, "FooImpl.jar"), new File(TEST, "foo.xml")) ).toExternalForm();
-
+
String test = TinyBundles.newBundle()
.addClass(FooDelegator.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Required Transaction Propgatation")
.set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service, javax.transaction")
)
.build( new BundleAsiPOJO(new File(ROOT, "requiresnew.jar"), new File(TEST, "requiresnew.xml")) ).toExternalForm();
-
-
+
+
Option[] opt = options(
-
+
provision(
mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version(asInProject()),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.transaction").version(asInProject()),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.handler.transaction").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.transaction").version(asInProject()),
mavenBundle()
.groupId( "org.ops4j.pax.tinybundles" )
@@ -119,33 +119,33 @@
;
return opt;
}
-
-
+
+
@Test
public void testOkOutsideTransaction() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requiresnew-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
((CheckService) osgi.getServiceObject(ref)).doSomethingGood(); // Ok
}
-
+
@Test
public void testOkInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requiresnew-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -157,15 +157,15 @@
Assert.assertEquals(Status.STATUS_NO_TRANSACTION, t2.getStatus());
t.commit();
}
-
+
@Test
public void testExceptionOutsideTransaction() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requiresnew-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
@@ -178,18 +178,18 @@
Assert.fail("IllegalStateException expected on rollback");
}
}
-
+
@Test
public void testExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requiresnew-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -205,35 +205,35 @@
// 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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requiresnew-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
((CheckService) osgi.getServiceObject(ref)).doSomethingBad2();
}
-
+
@Test
public void testExpectedExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("requiresnew-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -248,7 +248,7 @@
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/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestSupported.java b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestSupported.java
index 962ab17..7a2e6e2 100644
--- a/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestSupported.java
+++ b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/TestSupported.java
@@ -41,69 +41,69 @@
@RunWith( JUnit4TestRunner.class )
public class TestSupported {
-
+
@Inject
private BundleContext context;
-
+
private OSGiHelper osgi;
-
+
private IPOJOHelper ipojo;
public static final File ROOT = new File("target/tmp");
public static final File TEST = new File("src/test/resources");
-
+
@Before
public void init() {
osgi = new OSGiHelper(context);
ipojo = new IPOJOHelper(context);
}
-
+
@After
public void stop() {
ipojo.dispose();
osgi.dispose();
}
-
+
@Configuration
- public static Option[] configure() {
+ public static Option[] configure() {
ROOT.mkdirs();
URL service = TinyBundles.newBundle()
.addClass(CheckService.class)
.addClass(Foo.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Service")
.set(Constants.EXPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
.set(Constants.IMPORT_PACKAGE, "javax.transaction")
)
.build( TinyBundles.asURL());
-
+
String fooimpl = TinyBundles.newBundle()
.addClass(FooImpl.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Foo Provider")
.set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service")
)
.build( new BundleAsiPOJO(new File(ROOT, "FooImpl.jar"), new File(TEST, "foo.xml")) ).toExternalForm();
-
+
String test = TinyBundles.newBundle()
.addClass(FooDelegator.class)
- .prepare(
+ .prepare(
with()
.set(Constants.BUNDLE_SYMBOLICNAME,"Required Transaction Propgatation")
.set(Constants.IMPORT_PACKAGE, "org.apache.felix.ipojo.transaction.test.service, javax.transaction")
)
.build( new BundleAsiPOJO(new File(ROOT, "supported.jar"), new File(TEST, "supported.xml")) ).toExternalForm();
-
-
+
+
Option[] opt = options(
-
+
provision(
mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo").version(asInProject()),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.transaction").version(asInProject()),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo.handler.transaction").version(asInProject()),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.transaction").version(asInProject()),
mavenBundle()
.groupId( "org.ops4j.pax.tinybundles" )
@@ -118,16 +118,16 @@
;
return opt;
}
-
-
+
+
@Test
public void testOkOutsideTransaction() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("supported-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
@@ -135,18 +135,18 @@
cs.doSomethingGood();
// No transaction.
}
-
+
@Test
public void testOkInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("supported-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -156,32 +156,32 @@
Assert.assertSame(t2, t);
t.commit();
}
-
+
@Test(expected=NullPointerException.class)
public void testExceptionOutsideTransaction() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("supported-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
((CheckService) osgi.getServiceObject(ref)).doSomethingBad();
}
-
+
@Test(expected=RollbackException.class)
public void testExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("supported-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -195,21 +195,21 @@
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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("supported-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -223,35 +223,35 @@
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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("supported-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
((CheckService) osgi.getServiceObject(ref)).doSomethingBad2();
}
-
+
@Test
public void testExpectedExceptionInsideTransaction() throws NotSupportedException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("supported-ok");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -265,43 +265,43 @@
Transaction t2 = cs.getCurrentTransaction();
Assert.assertSame(t2, t);
Assert.assertEquals(Status.STATUS_ACTIVE, t.getStatus());
-
+
t.commit();
}
-
+
@Test
public void testOkOutsideTransactionWithCallback() {
ComponentInstance prov = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("supported-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("supported-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -310,47 +310,47 @@
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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("supported-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
CheckService cs = (CheckService) osgi.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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("supported-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -364,7 +364,7 @@
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) {
@@ -372,47 +372,47 @@
} 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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("supported-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
CheckService cs = (CheckService) osgi.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 = ipojo.createComponentInstance("org.apache.felix.ipojo.transaction.test.component.FooImpl");
ComponentInstance under = ipojo.createComponentInstance("supported-cb");
-
+
Assert.assertEquals(ComponentInstance.VALID, prov.getState());
Assert.assertEquals(ComponentInstance.VALID, under.getState());
-
+
ServiceReference ref = ipojo.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
-
+
CheckService cs = (CheckService) osgi.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgi.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
@@ -426,17 +426,17 @@
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/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/component/ComponentUsingAnnotations.java b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/component/ComponentUsingAnnotations.java
new file mode 100644
index 0000000..a516556
--- /dev/null
+++ b/ipojo/tests/handler/transaction/src/test/java/org/apache/felix/ipojo/transaction/test/component/ComponentUsingAnnotations.java
@@ -0,0 +1,34 @@
+package org.apache.felix.ipojo.transaction.test.component;
+
+import javax.transaction.Transaction;
+
+import org.apache.felix.ipojo.annotations.Component;
+
+@Component
+@org.apache.felix.ipojo.transaction.Transaction(field="transaction")
+public class ComponentUsingAnnotations {
+
+ Transaction transaction;
+
+
+ @org.apache.felix.ipojo.transaction.Transactionnal
+ public void doSomethingBad() throws NullPointerException {
+ }
+
+ @org.apache.felix.ipojo.transaction.Transactionnal(propagation="required")
+ public void doSomethingBad2() throws UnsupportedOperationException {
+
+ }
+
+ @org.apache.felix.ipojo.transaction.Transactionnal(propagation="supported", norollbackfor= {"java.lang.Exception"})
+ public void doSomethingGood() {
+
+ }
+
+ @org.apache.felix.ipojo.transaction.Transactionnal(timeout=1000, exceptiononrollback=true)
+ public void doSomethingLong() {
+
+ }
+
+
+}
diff --git a/ipojo/tests/handler/transaction/src/test/resources/annotation.xml b/ipojo/tests/handler/transaction/src/test/resources/annotation.xml
new file mode 100644
index 0000000..d1aa123
--- /dev/null
+++ b/ipojo/tests/handler/transaction/src/test/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/tests/pom.xml b/ipojo/tests/pom.xml
index 1aa72ed..46830e5 100644
--- a/ipojo/tests/pom.xml
+++ b/ipojo/tests/pom.xml
@@ -62,6 +62,7 @@
<modules>
<module>core/annotations</module>
<module>manipulator/manipulator-java5</module>
+ <module>handler/transaction</module>
</modules>
</profile>
<profile>
@@ -72,6 +73,7 @@
<modules>
<module>core/annotations</module>
<module>manipulator/manipulator-java5</module>
+ <module>handler/transaction</module>
</modules>
</profile>
</profiles>