You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2015/11/06 22:40:40 UTC

incubator-tamaya git commit: OSGI: Added first trial of test code.

Repository: incubator-tamaya
Updated Branches:
  refs/heads/master 009360468 -> a465e72ed


OSGI: Added first trial of test code.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/a465e72e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/a465e72e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/a465e72e

Branch: refs/heads/master
Commit: a465e72ed547c948624154e33ee652712ab78357
Parents: 0093604
Author: anatole <an...@apache.org>
Authored: Fri Nov 6 22:40:05 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Fri Nov 6 22:40:05 2015 +0100

----------------------------------------------------------------------
 modules/integration/osgi/felix/pom.xml          |  34 ++++
 .../org.apache.felix.bundlerepository-2.0.6.jar | Bin 0 -> 224471 bytes
 .../org.apache.felix.configadmin-1.8.8.jar      | Bin 0 -> 130990 bytes
 .../org.apache.felix.gogo.command-0.16.0.jar    | Bin 0 -> 52560 bytes
 .../org.apache.felix.gogo.runtime-0.16.2.jar    | Bin 0 -> 125027 bytes
 .../org.apache.felix.gogo.shell-0.10.0.jar      | Bin 0 -> 49004 bytes
 .../container/org.apache.felix.main-5.4.0.jar   | Bin 0 -> 690862 bytes
 .../integration/osgi/felix/Activator.java       |   2 +-
 .../osgi/felix/TestConfigIntegration.java       | 165 +++++++++++++++++++
 .../META-INF/javaconfiguration.properties       |  18 ++
 .../osgi/felix/src/test/resource/arquilian.xml  |  27 +++
 .../felix/src/test/resource/felix.properties    |  18 ++
 12 files changed, 263 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a465e72e/modules/integration/osgi/felix/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/pom.xml b/modules/integration/osgi/felix/pom.xml
index 0443b15..85a7ea9 100644
--- a/modules/integration/osgi/felix/pom.xml
+++ b/modules/integration/osgi/felix/pom.xml
@@ -70,6 +70,40 @@
             <artifactId>org.apache.felix.configadmin</artifactId>
             <version>${felix.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.framework</artifactId>
+            <version>5.4.0</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.arquillian</groupId>
+            <artifactId>arquillian-bom</artifactId>
+            <version>1.1.10.Final</version>
+            <type>pom</type>
+            <scope>import</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.arquillian.junit</groupId>
+            <artifactId>arquillian-junit-container</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <!--<dependency>-->
+            <!--<groupId>org.apache.felix</groupId>-->
+            <!--<artifactId>org.apache.felix.main</artifactId>-->
+            <!--<version>5.4.0</version>-->
+            <!--<scope>test</scope>-->
+        <!--</dependency>-->
+        <dependency>
+            <groupId>org.jboss.arquillian.container</groupId>
+            <artifactId>arquillian-container-felix-embedded</artifactId>
+            <version>2.1.0.CR18</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
     </dependencies>
 
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a465e72e/modules/integration/osgi/felix/src/container/org.apache.felix.bundlerepository-2.0.6.jar
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/container/org.apache.felix.bundlerepository-2.0.6.jar b/modules/integration/osgi/felix/src/container/org.apache.felix.bundlerepository-2.0.6.jar
new file mode 100644
index 0000000..6d8aec3
Binary files /dev/null and b/modules/integration/osgi/felix/src/container/org.apache.felix.bundlerepository-2.0.6.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a465e72e/modules/integration/osgi/felix/src/container/org.apache.felix.configadmin-1.8.8.jar
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/container/org.apache.felix.configadmin-1.8.8.jar b/modules/integration/osgi/felix/src/container/org.apache.felix.configadmin-1.8.8.jar
new file mode 100644
index 0000000..eb7e633
Binary files /dev/null and b/modules/integration/osgi/felix/src/container/org.apache.felix.configadmin-1.8.8.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a465e72e/modules/integration/osgi/felix/src/container/org.apache.felix.gogo.command-0.16.0.jar
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/container/org.apache.felix.gogo.command-0.16.0.jar b/modules/integration/osgi/felix/src/container/org.apache.felix.gogo.command-0.16.0.jar
new file mode 100644
index 0000000..249ed61
Binary files /dev/null and b/modules/integration/osgi/felix/src/container/org.apache.felix.gogo.command-0.16.0.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a465e72e/modules/integration/osgi/felix/src/container/org.apache.felix.gogo.runtime-0.16.2.jar
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/container/org.apache.felix.gogo.runtime-0.16.2.jar b/modules/integration/osgi/felix/src/container/org.apache.felix.gogo.runtime-0.16.2.jar
new file mode 100644
index 0000000..5524532
Binary files /dev/null and b/modules/integration/osgi/felix/src/container/org.apache.felix.gogo.runtime-0.16.2.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a465e72e/modules/integration/osgi/felix/src/container/org.apache.felix.gogo.shell-0.10.0.jar
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/container/org.apache.felix.gogo.shell-0.10.0.jar b/modules/integration/osgi/felix/src/container/org.apache.felix.gogo.shell-0.10.0.jar
new file mode 100644
index 0000000..f74e68e
Binary files /dev/null and b/modules/integration/osgi/felix/src/container/org.apache.felix.gogo.shell-0.10.0.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a465e72e/modules/integration/osgi/felix/src/container/org.apache.felix.main-5.4.0.jar
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/container/org.apache.felix.main-5.4.0.jar b/modules/integration/osgi/felix/src/container/org.apache.felix.main-5.4.0.jar
new file mode 100644
index 0000000..c91e86b
Binary files /dev/null and b/modules/integration/osgi/felix/src/container/org.apache.felix.main-5.4.0.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a465e72e/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/Activator.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/Activator.java b/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/Activator.java
index 636dfa0..9053aa7 100644
--- a/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/Activator.java
+++ b/modules/integration/osgi/felix/src/main/java/org/apache/tamaya/integration/osgi/felix/Activator.java
@@ -45,7 +45,7 @@ public class Activator implements BundleActivator{
         props.put( Constants.SERVICE_PID, tpm.getClass().getName() );
         props.put( Constants.SERVICE_DESCRIPTION, "Apache Tamaya Persistence Manager" );
         props.put( Constants.SERVICE_VENDOR, "Apache Software Foundation" );
-        Integer ranking = Integer.valueOf(Integer.MIN_VALUE + 10);
+        Integer ranking = 10;
         // TODO Make ranking configurable...
         props.put( Constants.SERVICE_RANKING, ranking );
         pmRegistration = bundleContext.registerService( PersistenceManager.class, tpm, props );

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a465e72e/modules/integration/osgi/felix/src/test/java/org/apache/tamaya/integration/osgi/felix/TestConfigIntegration.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/test/java/org/apache/tamaya/integration/osgi/felix/TestConfigIntegration.java b/modules/integration/osgi/felix/src/test/java/org/apache/tamaya/integration/osgi/felix/TestConfigIntegration.java
new file mode 100644
index 0000000..0f31b14
--- /dev/null
+++ b/modules/integration/osgi/felix/src/test/java/org/apache/tamaya/integration/osgi/felix/TestConfigIntegration.java
@@ -0,0 +1,165 @@
+/*
+ * 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.tamaya.integration.osgi.felix;
+
+import org.apache.felix.cm.PersistenceManager;
+import org.apache.tamaya.ConfigurationProvider;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.osgi.metadata.OSGiManifestBuilder;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.Asset;
+import org.jboss.shrinkwrap.api.importer.ZipImporter;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.resolver.api.maven.Maven;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Dictionary;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(Arquillian.class)
+public class TestConfigIntegration{
+
+    private static final String TAMAYA_VERSION = "0.2-incubating-SNAPSHOT";
+
+    @ArquillianResource BundleContext context;
+
+    @Deployment
+    public static JavaArchive createdeployment() {
+        final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "tamaya-config.jar");
+        archive.setManifest(new Asset() {
+            public InputStream openStream() {
+                OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
+                builder.addBundleSymbolicName(archive.getName());
+                builder.addBundleManifestVersion(2);
+                builder.addImportPackages("org.junit", "org.apache.felix.cm.file", "org.apache.tamaya.integration.osgi.felix");
+                builder.addImportPackages(PersistenceManager.class, ConfigurationAdmin.class, ConfigurationProvider.class);
+                builder.addBundleActivator(Activator.class);
+                return builder.openStream();
+            }
+        });
+        archive.addClasses(Activator.class, ConfigurationHandler.class, TamayaPersistenceManager.class)       ;
+        archive.addAsResource("META-INF/javaconfiguration.properties");
+        return archive;
+    }
+
+    @Deployment(name="felix.main")
+    public static JavaArchive deployMain() {
+        return ShrinkWrap.create(ZipImporter.class, "felix.main-5.4.0.jar")
+                .importFrom(new File("src/container/org.apache.felix.main-5.4.0.jar"))
+                .as(JavaArchive.class);
+    }
+
+    @Deployment(name="ConfigAdmin")
+    public static JavaArchive deployConfigAdmin() {
+        return ShrinkWrap.create(ZipImporter.class, "configadmin-1.8.8.jar")
+                .importFrom(new File("src/container/org.apache.felix.configadmin-1.8.8.jar"))
+                .as(JavaArchive.class);
+    }
+
+    @Deployment(name="tamaya-api")
+    public static JavaArchive deployTamayaAPI() {
+        return ShrinkWrap.create(ZipImporter.class, "tamaya-api.jar")
+                .importFrom(getBundleFile("tamaya-api:"+TAMAYA_VERSION))
+                .as(JavaArchive.class);
+    }
+
+    @Deployment(name="tamaya-core")
+    public static JavaArchive deployTamayaCore() {
+        return ShrinkWrap.create(ZipImporter.class, "tamaya-core.jar")
+                .importFrom(getBundleFile("tamaya-core:"+TAMAYA_VERSION))
+                .as(JavaArchive.class);
+    }
+
+    @Deployment(name="javax.annotation")
+    public static JavaArchive deployJavaxAnnotation() {
+        return ShrinkWrap.create(ZipImporter.class, "javax.annotation.jar")
+                .importFrom(Maven.configureResolver()
+                        .withMavenCentralRepo(false)
+                        .withClassPathResolution(true)
+                        .resolve("org.apache.geronimo.specs:geronimo-annotation_1.2_spec:1.0-alpha-1")
+                        .withoutTransitivity().asSingleFile())
+                .as(JavaArchive.class);
+    }
+
+    private static File getBundleFile(String artifactId) {
+        // Check
+        return Maven.configureResolver()
+                .withMavenCentralRepo(false)
+                .withClassPathResolution(true)
+                .resolve("org.apache.tamaya:" + artifactId).withoutTransitivity().asSingleFile();
+    }
+
+    @Before
+    public void startBundles(){
+        for(Bundle bundle:context.getBundles()){
+            try {
+                bundle.start();
+            } catch (BundleException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    @Test @Ignore
+    public void testTamayaPersistenceManagerAvailable(@ArquillianResource Bundle bundle) throws Exception {
+        ServiceReference<PersistenceManager> configRef = context.getServiceReference(PersistenceManager.class);
+        // TODO continue here...
+        assertNotNull(configRef);
+        PersistenceManager pm = context.getService(configRef);
+        assertNotNull(pm);
+        Dictionary tamayaConf = pm.load("tamaya-test");
+        assertNotNull(tamayaConf);
+        assertEquals("success!", tamayaConf.get("tamaya-test-property"));
+    }
+
+    @Test @Ignore
+    public void testTamayaConfigAvailableOnConfig() throws Exception {
+        ServiceReference<ConfigurationAdmin> configRef = context.getServiceReference(ConfigurationAdmin.class);
+        assertNotNull(configRef);
+        ConfigurationAdmin configAdmin = (ConfigurationAdmin)context.getService(configRef);
+        assertNotNull(configRef);
+        Configuration tamayaConf = configAdmin.getConfiguration("tamaya-test");
+        assertNotNull(tamayaConf);
+        assertEquals("success!", tamayaConf.getProperties().get("tamaya-test-property"));
+    }
+
+    @Test
+    public void testBundleContextInjection() throws Exception {
+        assertNotNull("BundleContext injected", context);
+        assertEquals("System Bundle ID", 0, context.getBundle().getBundleId());
+        System.err.println(Arrays.toString(context.getBundles()));
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a465e72e/modules/integration/osgi/felix/src/test/resource/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/test/resource/META-INF/javaconfiguration.properties b/modules/integration/osgi/felix/src/test/resource/META-INF/javaconfiguration.properties
new file mode 100644
index 0000000..b2b0d69
--- /dev/null
+++ b/modules/integration/osgi/felix/src/test/resource/META-INF/javaconfiguration.properties
@@ -0,0 +1,18 @@
+# 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.
+#
+__tamaya-test__.tamaya-test-property=success!
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a465e72e/modules/integration/osgi/felix/src/test/resource/arquilian.xml
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/test/resource/arquilian.xml b/modules/integration/osgi/felix/src/test/resource/arquilian.xml
new file mode 100644
index 0000000..d036dca
--- /dev/null
+++ b/modules/integration/osgi/felix/src/test/resource/arquilian.xml
@@ -0,0 +1,27 @@
+<!--
+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 current 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.
+-->
+<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+
+    <container qualifier="jboss" default="true">
+        <configuration>
+            <property name="frameworkProperties">/felix.properties</property>
+        </configuration>
+    </container>
+</arquillian>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a465e72e/modules/integration/osgi/felix/src/test/resource/felix.properties
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/felix/src/test/resource/felix.properties b/modules/integration/osgi/felix/src/test/resource/felix.properties
new file mode 100644
index 0000000..f81f6bc
--- /dev/null
+++ b/modules/integration/osgi/felix/src/test/resource/felix.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.osgi.framework.bootdelegation=org.osgi.service.cm;org.apache.felix.cm;org.apache.tamaya;org.apache.tamaya.spi;*
\ No newline at end of file