Commit the Transaction Service (Felix-1012) donated by Guillaume Nodet
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@763278 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/transaction/integration-test/pom.xml b/transaction/integration-test/pom.xml
new file mode 100644
index 0000000..c16b43b
--- /dev/null
+++ b/transaction/integration-test/pom.xml
@@ -0,0 +1,78 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>transaction</artifactId>
+ <version>0.9.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.apache.felix.transaction.itests</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <name>Apache Felix Transaction iTests</name>
+ <version>0.9.0-SNAPSHOT</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicemix.kernel.testing</groupId>
+ <artifactId>org.apache.servicemix.kernel.testing.support</artifactId>
+ <version>1.1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.transaction</artifactId>
+ <version>${pom.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ <version>2.5.6</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+ <execution>
+ <id>generate-depends-file</id>
+ <goals>
+ <goal>generate-depends-file</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/transaction/integration-test/src/test/java/org/apache/felix/transaction/itests/Test.java b/transaction/integration-test/src/test/java/org/apache/felix/transaction/itests/Test.java
new file mode 100644
index 0000000..5669efa
--- /dev/null
+++ b/transaction/integration-test/src/test/java/org/apache/felix/transaction/itests/Test.java
@@ -0,0 +1,108 @@
+/*
+ * 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.transaction.itests;
+
+import javax.transaction.TransactionManager;
+
+import org.apache.servicemix.kernel.testing.support.AbstractIntegrationTest;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Bundle;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+/**
+ */
+public class Test extends AbstractIntegrationTest {
+
+ private static final String PLATFORM_TRANSACTION_MANAGER_CLASS = "org.springframework.transaction.PlatformTransactionManager";
+
+ public void test() throws Exception {
+ ServiceTracker tracker = new ServiceTracker(bundleContext, TransactionManager.class.getName(), null);
+ tracker.open();
+
+ tracker.waitForService(5000L);
+ ServiceReference ref = tracker.getServiceReference();
+ assertNotNull(ref);
+ String[] objClass = (String[]) ref.getProperty(Constants.OBJECTCLASS);
+ assertNotNull(objClass);
+ boolean found = false;
+ for (String clazz : objClass) {
+ found |= PLATFORM_TRANSACTION_MANAGER_CLASS.equals(clazz);
+ }
+ assertFalse(found);
+
+ Bundle bundle = ref.getBundle();
+ bundle.stop();
+ installBundle("org.springframework", "spring-tx", null, "jar");
+ getOsgiService(PackageAdmin.class).refreshPackages(new Bundle[] { bundle });
+ System.err.println("Bundle refreshed");
+ Thread.sleep(500);
+ System.err.println("Starting bundle");
+ bundle.start();
+
+ tracker.waitForService(5000L);
+ ref = tracker.getServiceReference();
+ assertNotNull(ref);
+ objClass = (String[]) ref.getProperty(Constants.OBJECTCLASS);
+ assertNotNull(objClass);
+ found = false;
+ for (String clazz : objClass) {
+ found |= PLATFORM_TRANSACTION_MANAGER_CLASS.equals(clazz);
+ }
+ assertTrue(found);
+
+ tracker.close();
+ }
+
+ //============= Plumbing ==============/
+
+ /**
+ * The manifest to use for the "virtual bundle" created
+ * out of the test classes and resources in this project
+ *
+ * This is actually the boilerplate manifest with one additional
+ * import-package added. We should provide a simpler customization
+ * point for such use cases that doesn't require duplication
+ * of the entire manifest...
+ */
+ protected String getManifestLocation() {
+ return "classpath:org/apache/felix/transaction/MANIFEST.MF";
+ }
+
+ /**
+ * The location of the packaged OSGi bundles to be installed
+ * for this test. Values are Spring resource paths. The bundles
+ * we want to use are part of the same multi-project maven
+ * build as this project is. Hence we use the localMavenArtifact
+ * helper method to find the bundles produced by the package
+ * phase of the maven build (these tests will run after the
+ * packaging phase, in the integration-test phase).
+ *
+ * JUnit, commons-logging, spring-core and the spring OSGi
+ * test bundle are automatically included so do not need
+ * to be specified here.
+ */
+ protected String[] getTestBundlesNames() {
+ return new String[] {
+ getBundle("org.apache.geronimo.specs", "geronimo-jta_1.1_spec"),
+ getBundle("org.apache.geronimo.specs", "geronimo-j2ee-connector_1.5_spec"),
+ getBundle("org.apache.felix", "org.apache.felix.transaction"),
+ };
+ }
+
+}
\ No newline at end of file
diff --git a/transaction/integration-test/src/test/resources/org/apache/felix/transaction/MANIFEST.MF b/transaction/integration-test/src/test/resources/org/apache/felix/transaction/MANIFEST.MF
new file mode 100644
index 0000000..27229b8
--- /dev/null
+++ b/transaction/integration-test/src/test/resources/org/apache/felix/transaction/MANIFEST.MF
@@ -0,0 +1,30 @@
+Manifest-Version: 1.0
+License-00: .
+License-01: Licensed to the Apache Software Foundation (ASF) under one or more
+License-02: contributor license agreements. See the NOTICE file distributed with
+License-03: this work for additional information regarding copyright ownership.
+License-04: The ASF licenses this file to You under the Apache License, Version 2.0
+License-05: (the "License"); you may not use this file except in compliance with
+License-06: the License. You may obtain a copy of the License at
+License-07: .
+License-08: http://www.apache.org/licenses/LICENSE-2.0
+License-09: .
+License-10: Unless required by applicable law or agreed to in writing, software
+License-11: distributed under the License is distributed on an "AS IS" BASIS,
+License-12: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+License-13: See the License for the specific language governing permissions and
+License-14: limitations under the License.
+License-15: .
+Bundle-Name: org.apache.servicemix.testing.itests
+Bundle-SymbolicName: org.apache.servicemix.testing.itests
+Bundle-Vendor: Spring Framework
+Bundle-Activator: org.springframework.osgi.test.JUnitTestActivator
+Import-Package: junit.framework,
+ org.osgi.framework;specification-version="1.3.0",
+ org.apache.commons.logging,
+ org.springframework.core.io,
+ org.springframework.osgi.test,
+ org.apache.servicemix.kernel.testing.support,
+ org.springframework.osgi.util,
+ javax.transaction
+DynamicImport-Package: *