You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by jo...@apache.org on 2016/04/18 03:47:44 UTC
incubator-tamaya git commit: TAMAYA-148 Working on making OSGi
support work in a testable fashion.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master c9d84a6a1 -> 61ddb3238
TAMAYA-148 Working on making OSGi support work in a testable fashion.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/61ddb323
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/61ddb323
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/61ddb323
Branch: refs/heads/master
Commit: 61ddb3238e8e5f210d6e93cef32df0d0b5fb4200
Parents: c9d84a6
Author: John D. Ament <jo...@apache.org>
Authored: Sun Apr 17 21:47:27 2016 -0400
Committer: John D. Ament <jo...@apache.org>
Committed: Sun Apr 17 21:47:27 2016 -0400
----------------------------------------------------------------------
.../tamaya/events/ConfigEventListener.java | 1 -
.../org.apache.tamaya.events.ConfigListener | 18 --
modules/injection-api/pom.xml | 3 +-
.../tamaya/integration/osgi/HelloService.java | 27 --
.../integration/osgi/HelloServiceImpl.java | 36 ---
.../integration/osgi/TestConfigIntegration.java | 272 -------------------
.../integration/osgi/test/HelloService.java | 35 +++
.../osgi/test/TestConfigIntegration.java | 257 ++++++++++++++++++
.../osgi/src/test/resources/arquillian.xml | 2 +-
.../osgi/src/test/resources/felix.properties | 2 +-
10 files changed, 296 insertions(+), 357 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/61ddb323/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventListener.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventListener.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventListener.java
index de635f8..7fb32c8 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventListener.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventListener.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.events;
/**
* Interface to be implemented for listening on changes on {@link org.apache.tamaya.Configuration} instances.
*/
-//@FunctionalInterface
public interface ConfigEventListener {
/**
* Called if an event occurred.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/61ddb323/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigListener
----------------------------------------------------------------------
diff --git a/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigListener b/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigListener
deleted file mode 100644
index f3199f2..0000000
--- a/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigListener
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# 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.
-#
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/61ddb323/modules/injection-api/pom.xml
----------------------------------------------------------------------
diff --git a/modules/injection-api/pom.xml b/modules/injection-api/pom.xml
index 9b2d580..a2122ad 100644
--- a/modules/injection-api/pom.xml
+++ b/modules/injection-api/pom.xml
@@ -66,7 +66,8 @@ under the License.
<configuration>
<instructions>
<Export-Package>
- org.apache.tamaya.inject.api
+ org.apache.tamaya.inject.api,
+ org.apache.tamaya.inject.spi
</Export-Package>
</instructions>
</configuration>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/61ddb323/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/HelloService.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/HelloService.java b/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/HelloService.java
deleted file mode 100644
index 59ae172..0000000
--- a/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/HelloService.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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;
-
-/**
- * Simple service that says hello.
- */
-public interface HelloService {
-
- String sayHello();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/61ddb323/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/HelloServiceImpl.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/HelloServiceImpl.java b/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/HelloServiceImpl.java
deleted file mode 100644
index 6888822..0000000
--- a/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/HelloServiceImpl.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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;
-
-import org.apache.tamaya.inject.api.Config;
-
-/**
- * Simple service to test injection in OSGI.
- */
-public class HelloServiceImpl implements HelloService{
-
- @Config(value = "example.message", defaultValue = "A Tamaya default.")
- private String message;
-
- @Override
- public String sayHello() {
- System.err.println("HELLO: " + message);
- return message;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/61ddb323/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/TestConfigIntegration.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/TestConfigIntegration.java b/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/TestConfigIntegration.java
deleted file mode 100644
index 79f0965..0000000
--- a/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/TestConfigIntegration.java
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * 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;
-
-import org.apache.log4j.Priority;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.functions.ConfigurationFunctions;
-import org.apache.tamaya.inject.ConfigurationInjection;
-import org.apache.tamaya.spi.ServiceContext;
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.container.test.api.OperateOnDeployment;
-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.*;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.util.tracker.ServiceTracker;
-
-import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-@RunWith(Arquillian.class)
-@Ignore
-public class TestConfigIntegration{
-
- private static final String TAMAYA_VERSION = "0.2-incubating-SNAPSHOT";
-
- static{
- System.setProperty("[bundle:tamaya]systemTestKey", "foo");
- }
-
-
- @ArquillianResource BundleContext context;
-
- //////////////////////////////////////////////////////// Test setup //////////////////////////////////
-
- @Deployment(name="default", order=100)
- public static JavaArchive createdeployment() {
- final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "tamaya-osgi-general.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.tamaya", "org.apache.tamaya.spi",
- "org.apache.tamaya.core", "org.osgi.service.cm");
- builder.addImportPackages(ServiceContext.class, ConfigurationProvider.class, ConfigurationAdmin.class,
- ServiceTracker.class, ConfigurationFunctions.class, ConfigurationInjection.class);
- builder.addBundleActivator(Activator.class);
- return builder.openStream();
- }
- });
- archive.addClasses(Test.class, TestConfigIntegration.class, Priority.class, Activator.class,
- TamayaConfigAdminImpl.class, TamayaConfigurationImpl.class, OSGIConfigRootMapper.class,
- HelloService.class, HelloServiceImpl.class);
- URL config = ClassLoader.getSystemClassLoader().getResource("META-INF/javaconfiguration.properties");
- archive.addAsResource(config, "META-INF/javaconfiguration.properties");
- return archive;
- }
-
- @Deployment(name="felix.main", order=0)
- public static JavaArchive deployMain() {
- return ShrinkWrap.create(ZipImporter.class, "felix.main-5.4.0.jar")
- .importFrom(new File("./test-bundles/org.apache.felix.main-5.4.0.jar"))
- .as(JavaArchive.class);
- }
-
- @Deployment(name="osgi.config", order=0)
- public static JavaArchive deployOSGIConfig() {
- return ShrinkWrap.create(ZipImporter.class, "felix.configadmin-1.8.8.jar")
- .importFrom(new File("./test-bundles/org.apache.felix.configadmin-1.8.8.jar"))
- .as(JavaArchive.class);
- }
-
- @Deployment(name="javax.annotation",order=1)
- 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);
- }
-
- @Deployment(name="tamaya-api", order=5)
- public static JavaArchive deployTamayaAPI() {
- return ShrinkWrap.create(ZipImporter.class, "tamaya-api.jar")
- .importFrom(getBundleFile("org.apache.tamaya:tamaya-api:"+TAMAYA_VERSION))
- .as(JavaArchive.class);
- }
-
- @Deployment(name="tamaya-core", order=6)
- public static JavaArchive deployTamayaCore() {
- return ShrinkWrap.create(ZipImporter.class, "tamaya-core.jar")
- .importFrom(getBundleFile("org.apache.tamaya:tamaya-core:"+TAMAYA_VERSION))
- .as(JavaArchive.class);
- }
-
- @Deployment(name="tamaya-functions",order=7)
- public static JavaArchive deployTamayaFunctions() {
- return ShrinkWrap.create(ZipImporter.class, "tamaya-functions.jar")
- .importFrom(getBundleFile("org.apache.tamaya.ext:tamaya-functions:"+TAMAYA_VERSION))
- .as(JavaArchive.class);
- }
-
- @Deployment(name="java.atInject",order=8)
- public static JavaArchive deployAtInject() {
- return ShrinkWrap.create(ZipImporter.class, "java.atinject.jar")
- .importFrom(Maven.configureResolver()
- .withMavenCentralRepo(false)
- .withClassPathResolution(true)
- .resolve("org.apache.geronimo.specs:geronimo-atinject_1.0_spec:1.0")
- .withoutTransitivity().asSingleFile())
- .as(JavaArchive.class);
- }
-
- @Deployment(name="javax.el",order=9)
- public static JavaArchive deployEL() {
- return ShrinkWrap.create(ZipImporter.class, "javax.el.jar")
- .importFrom(Maven.configureResolver()
- .withMavenCentralRepo(false)
- .withClassPathResolution(true)
- .resolve("org.apache.geronimo.specs:geronimo-el_2.2_spec:1.0.4")
- .withoutTransitivity().asSingleFile())
- .as(JavaArchive.class);
- }
-
- @Deployment(name="javax.interceptor",order=9)
- public static JavaArchive deployInterceptor() {
- return ShrinkWrap.create(ZipImporter.class, "javax.interceptor.jar")
- .importFrom(Maven.configureResolver()
- .withMavenCentralRepo(false)
- .withClassPathResolution(true)
- .resolve("org.apache.geronimo.specs:geronimo-interceptor_1.1_spec:1.0")
- .withoutTransitivity().asSingleFile())
- .as(JavaArchive.class);
- }
-
- @Deployment(name="javax.inject",order=10)
- public static JavaArchive deployCDISpec() {
- return ShrinkWrap.create(ZipImporter.class, "javax.inject.jar")
- .importFrom(Maven.configureResolver()
- .withMavenCentralRepo(false)
- .withClassPathResolution(true)
- .resolve("org.apache.geronimo.specs:geronimo-jcdi_1.1_spec:1.0")
- .withoutTransitivity().asSingleFile())
- .as(JavaArchive.class);
- }
-
- @Deployment(name="tamaya-injection-api",order=11)
- public static JavaArchive deployTamayaInjectionAPI() {
- return ShrinkWrap.create(ZipImporter.class, "tamaya-injection-api.jar")
- .importFrom(getBundleFile("org.apache.tamaya.ext:tamaya-injection-api:"+TAMAYA_VERSION))
- .as(JavaArchive.class);
- }
-
- @Deployment(name="tamaya-events", order=14)
- public static JavaArchive deployTamayaEvents() {
- return ShrinkWrap.create(ZipImporter.class, "tamaya-events.jar")
- .importFrom(getBundleFile("org.apache.tamaya.ext:tamaya-events:"+TAMAYA_VERSION))
- .as(JavaArchive.class);
- }
-
- @Deployment(name="tamaya-injection", order=6)
- public static JavaArchive deployTamayaInjectionSE() {
- return ShrinkWrap.create(ZipImporter.class, "tamaya-injection.jar")
- .importFrom(getBundleFile("org.apache.tamaya.ext:tamaya-injection:"+TAMAYA_VERSION))
- .as(JavaArchive.class);
- }
-
-
-
- private static File getBundleFile(String artifactId) {
- // Check
- return Maven.configureResolver()
- .withMavenCentralRepo(false)
- .withClassPathResolution(true)
- .resolve(artifactId).withoutTransitivity().asSingleFile();
- }
-
-
- //////////////////////////////////////////////////////// Tests //////////////////////////////////
-
-
- @Before
- public void startBundles(){
- for(Bundle bundle:context.getBundles()) {
- try {
- bundle.start();
- } catch (BundleException e) {
- e.printStackTrace();
- }
- }
- }
-
- @OperateOnDeployment("tamaya-core")
- @Test
- public void testTamayaAvailable() throws Exception {
- assertNotNull(ConfigurationProvider.getConfiguration());
- }
-
- @Test
- public void testTamayaConfigAdminAvailable() throws Exception {
- ServiceReference<ConfigurationAdmin> ref = context.getServiceReference(ConfigurationAdmin.class);
- assertNotNull("OSGI ConfigAdmin not loaded.", ref);
- ConfigurationAdmin osgiConfig = context.getService(ref);
- assertNotNull("No config available from Tamaya through OSGI ConfigAdmin.", osgiConfig);
- assertEquals("Override of OSGI ConfigAdmin with Tamaya did not work.", osgiConfig.getClass().getName(), TamayaConfigAdminImpl.class.getName());
- }
-
- @Test
- public void testLoadTamayaConfigFromConfigAdmin() throws Exception {
- ServiceReference<ConfigurationAdmin> ref = context.getServiceReference(ConfigurationAdmin.class);
- assertNotNull("OSGI ConfigAdmin not loaded.", ref);
- ConfigurationAdmin admin = context.getService(ref);
- Configuration osgiConfig = admin.getConfiguration("tamaya");
- assertNotNull("No config available from Tamaya through OSGI ConfigAdmin.", osgiConfig);
- Dictionary<String,Object> config = osgiConfig.getProperties();
- assertNotNull("No config entries loaded from Tamaya.", config);
- assertEquals("Property 'testKey' not loaded from Tamaya.", "foo", config.get("systemTestKey"));
- // TODO: Think on Resource loading in OSGI:
- // this should work with normal resource loading but does not work with OSGI, since this resource is not
- // visible by default, when we have added resource loading as abstraction to the ServiceContext, too.
- // Reason: Resource Loading in OSGI works differently!
-// assertEquals("Property 'testKey' not loaded from Tamaya.", "success!", config.get("my.testProperty"));
- }
-
- @Test
- public void testInjection() throws Exception {
- Dictionary<String,Object> config = new Hashtable<>();
- ServiceRegistration<HelloService> reg = context.registerService(HelloService.class, new HelloServiceImpl(), config);
- assertNotNull(context.getServiceReference(HelloService.class));
- ServiceReference<HelloService> ref = context.getServiceReference(HelloService.class);
- assertNotNull("HelloService not loaded.", ref);
- HelloService helloServ = context.getService(ref);
- assertNotNull("HelloService not referenceable.");
- assertEquals("A Tamaya default.",helloServ.sayHello());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/61ddb323/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/test/HelloService.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/test/HelloService.java b/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/test/HelloService.java
new file mode 100644
index 0000000..06a420f
--- /dev/null
+++ b/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/test/HelloService.java
@@ -0,0 +1,35 @@
+/*
+ * 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.test;
+
+import org.apache.tamaya.inject.api.Config;
+
+/**
+ * Simple service to test injection in OSGI.
+ */
+public class HelloService {
+
+ @Config(value = "example.message", defaultValue = "A Tamaya default.")
+ private String message;
+
+ public String sayHello() {
+ System.err.println("HELLO: " + message);
+ return message;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/61ddb323/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/test/TestConfigIntegration.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/test/TestConfigIntegration.java b/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/test/TestConfigIntegration.java
new file mode 100644
index 0000000..931d0ee
--- /dev/null
+++ b/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/test/TestConfigIntegration.java
@@ -0,0 +1,257 @@
+/*
+ * 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.test;
+
+import org.apache.log4j.Priority;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.integration.osgi.Activator;
+import org.apache.tamaya.integration.osgi.OSGIConfigRootMapper;
+import org.apache.tamaya.integration.osgi.TamayaConfigAdminImpl;
+import org.apache.tamaya.integration.osgi.TamayaConfigurationImpl;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.OperateOnDeployment;
+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.framework.ServiceRegistration;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(Arquillian.class)
+@Ignore
+public class TestConfigIntegration {
+
+ private static final String TAMAYA_VERSION = "0.3-incubating-SNAPSHOT";
+ private static final String DEFAULT = "default";
+
+ static {
+ System.setProperty("[bundle:tamaya]systemTestKey", "foo");
+ System.setProperty("org.osgi.framework.bootdelegation",
+ "org.apache.tamaya,org.apache.tamaya.integration.osgi,org.apache.tamaya.integration.osgi.test");
+ }
+
+ @ArquillianResource
+ BundleContext context;
+
+ //////////////////////////////////////////////////////// Test setup //////////////////////////////////
+
+ @Deployment(name = "felix.main", order = 1)
+ public static JavaArchive deployMain() {
+ return ShrinkWrap.create(ZipImporter.class, "felix.main-5.4.0.jar")
+ .importFrom(getBundleFile("org.apache.felix:org.apache.felix.main:5.4.0"))
+ .as(JavaArchive.class);
+ }
+
+ @Deployment(name = "osgi.config", order = 1)
+ public static JavaArchive deployOSGIConfig() {
+ return ShrinkWrap.create(ZipImporter.class, "felix.configadmin-1.8.8.jar")
+ .importFrom(getBundleFile("org.apache.felix:org.apache.felix.configadmin:1.8.8"))
+ .as(JavaArchive.class);
+ }
+
+ @Deployment(name = "javax.annotation", order = 4)
+ public static JavaArchive deployJavaxAnnotation() {
+ return ShrinkWrap.create(ZipImporter.class, "javax.annotation.jar")
+ .importFrom(getBundleFile("org.apache.geronimo.specs:geronimo-annotation_1.2_spec:1.0-alpha-1"))
+ .as(JavaArchive.class);
+ }
+
+ @Deployment(name = "tamaya-api", order = 5)
+ public static JavaArchive deployTamayaAPI() {
+ return ShrinkWrap.create(ZipImporter.class, "tamaya-api.jar")
+ .importFrom(getBundleFile("org.apache.tamaya:tamaya-api:" + TAMAYA_VERSION))
+ .as(JavaArchive.class);
+ }
+
+ @Deployment(name = "tamaya-core", order = 6)
+ public static JavaArchive deployTamayaCore() {
+ return ShrinkWrap.create(ZipImporter.class, "tamaya-core.jar")
+ .importFrom(getBundleFile("org.apache.tamaya:tamaya-core:" + TAMAYA_VERSION))
+ .as(JavaArchive.class);
+ }
+
+ @Deployment(name = "tamaya-functions", order = 7)
+ public static JavaArchive deployTamayaFunctions() {
+ return ShrinkWrap.create(ZipImporter.class, "tamaya-functions.jar")
+ .importFrom(getBundleFile("org.apache.tamaya.ext:tamaya-functions:" + TAMAYA_VERSION))
+ .as(JavaArchive.class);
+ }
+
+ @Deployment(name = "java.atInject", order = 8)
+ public static JavaArchive deployAtInject() {
+ return ShrinkWrap.create(ZipImporter.class, "java.atinject.jar")
+ .importFrom(getBundleFile("org.apache.geronimo.specs:geronimo-atinject_1.0_spec:1.0"))
+ .as(JavaArchive.class);
+ }
+
+ @Deployment(name = "javax.el", order = 9)
+ public static JavaArchive deployEL() {
+ return ShrinkWrap.create(ZipImporter.class, "javax.el.jar")
+ .importFrom(getBundleFile("org.apache.geronimo.specs:geronimo-el_2.2_spec:1.0.4"))
+ .as(JavaArchive.class);
+ }
+
+ @Deployment(name = "javax.interceptor", order = 9)
+ public static JavaArchive deployInterceptor() {
+ return ShrinkWrap.create(ZipImporter.class, "javax.interceptor.jar")
+ .importFrom(getBundleFile("org.apache.geronimo.specs:geronimo-interceptor_1.1_spec:1.0"))
+ .as(JavaArchive.class);
+ }
+
+ @Deployment(name = "javax.inject", order = 10)
+ public static JavaArchive deployCDISpec() {
+ return ShrinkWrap.create(ZipImporter.class, "javax.inject.jar")
+ .importFrom(getBundleFile("org.apache.geronimo.specs:geronimo-jcdi_1.1_spec:1.0"))
+ .as(JavaArchive.class);
+ }
+
+ @Deployment(name = "tamaya-injection-api", order = 11)
+ public static JavaArchive deployTamayaInjectionAPI() {
+ return ShrinkWrap.create(ZipImporter.class, "tamaya-injection-api.jar")
+ .importFrom(getBundleFile("org.apache.tamaya.ext:tamaya-injection-api:" + TAMAYA_VERSION))
+ .as(JavaArchive.class);
+ }
+
+ @Deployment(name = "tamaya-events", order = 14)
+ public static JavaArchive deployTamayaEvents() {
+ return ShrinkWrap.create(ZipImporter.class, "tamaya-events.jar")
+ .importFrom(getBundleFile("org.apache.tamaya.ext:tamaya-events:" + TAMAYA_VERSION))
+ .as(JavaArchive.class);
+ }
+
+ @Deployment(name = "tamaya-injection", order = 6)
+ public static JavaArchive deployTamayaInjectionSE() {
+ return ShrinkWrap.create(ZipImporter.class, "tamaya-injection.jar")
+ .importFrom(getBundleFile("org.apache.tamaya.ext:tamaya-injection:" + TAMAYA_VERSION))
+ .as(JavaArchive.class);
+ }
+
+ @Deployment(name = DEFAULT, order = 100)
+ public static JavaArchive createdeployment() {
+ final String archiveName = "tamaya-osgi-general.jar";
+ URL config = ClassLoader.getSystemClassLoader().getResource("META-INF/javaconfiguration.properties");
+ return ShrinkWrap.create(JavaArchive.class, archiveName)
+ .setManifest(new Asset() {
+ public InputStream openStream() {
+ return OSGiManifestBuilder.newInstance()
+ .addBundleSymbolicName(archiveName)
+ .addBundleManifestVersion(2)
+ .addExportPackages("org.apache.tamaya.integration.osgi",
+ "org.apache.tamaya.integration.osgi.test")
+ .addImportPackages("org.junit", "org.osgi.service.cm",
+ "org.apache.tamaya", "org.apache.tamaya.functions","org.apache.tamaya.inject",
+ "org.apache.tamaya.spi","org.apache.tamaya.spi", "org.osgi.framework",
+ "org.osgi.util.tracker")
+ .addBundleActivator(Activator.class)
+ .openStream();
+ }
+ })
+ .addClasses(Test.class, TestConfigIntegration.class, Priority.class, Activator.class,
+ TamayaConfigAdminImpl.class, TamayaConfigurationImpl.class, OSGIConfigRootMapper.class,
+ HelloService.class)
+ .addAsResource(config, "META-INF/javaconfiguration.properties");
+ }
+
+ @Before
+ public void startBundles() {
+ for (Bundle bundle : context.getBundles()) {
+ try {
+ bundle.start();
+ } catch (BundleException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+ @Test
+ @OperateOnDeployment(DEFAULT)
+ public void testTamayaAvailable() throws Exception {
+ assertNotNull(ConfigurationProvider.getConfiguration());
+ }
+
+ @Test
+ @OperateOnDeployment(DEFAULT)
+ public void testTamayaConfigAdminAvailable() throws Exception {
+ ServiceReference<ConfigurationAdmin> ref = context.getServiceReference(ConfigurationAdmin.class);
+ assertNotNull("OSGI ConfigAdmin not loaded.", ref);
+ ConfigurationAdmin osgiConfig = context.getService(ref);
+ assertNotNull("No config available from Tamaya through OSGI ConfigAdmin.", osgiConfig);
+ assertEquals("Override of OSGI ConfigAdmin with Tamaya did not work.", osgiConfig.getClass().getName(), TamayaConfigAdminImpl.class.getName());
+ }
+
+ @Test
+ @OperateOnDeployment(DEFAULT)
+ public void testLoadTamayaConfigFromConfigAdmin() throws Exception {
+ ServiceReference<ConfigurationAdmin> ref = context.getServiceReference(ConfigurationAdmin.class);
+ assertNotNull("OSGI ConfigAdmin not loaded.", ref);
+ ConfigurationAdmin admin = context.getService(ref);
+ Configuration osgiConfig = admin.getConfiguration("tamaya");
+ assertNotNull("No config available from Tamaya through OSGI ConfigAdmin.", osgiConfig);
+ Dictionary<String, Object> config = osgiConfig.getProperties();
+ assertNotNull("No config entries loaded from Tamaya.", config);
+ assertEquals("Property 'testKey' not loaded from Tamaya.", "foo", config.get("systemTestKey"));
+ // TODO: Think on Resource loading in OSGI:
+ // this should work with normal resource loading but does not work with OSGI, since this resource is not
+ // visible by default, when we have added resource loading as abstraction to the ServiceContext, too.
+ // Reason: Resource Loading in OSGI works differently!
+// assertEquals("Property 'testKey' not loaded from Tamaya.", "success!", config.get("my.testProperty"));
+ }
+
+ @Test
+ @OperateOnDeployment(DEFAULT)
+ public void testInjection() throws Exception {
+ Dictionary<String, Object> config = new Hashtable<>();
+ ServiceRegistration<HelloService> reg = context.registerService(HelloService.class, new HelloService(), config);
+ ServiceReference<HelloService> serviceReference = reg.getReference();
+ assertNotNull(serviceReference);
+ HelloService helloServ = context.getService(serviceReference);
+ assertNotNull("HelloService not referenceable.", helloServ);
+ assertEquals("A Tamaya default.", helloServ.sayHello());
+ }
+
+ private static File getBundleFile(String artifactId) {
+ return Maven.configureResolver()
+ .withMavenCentralRepo(true)
+ .withClassPathResolution(true)
+ .resolve(artifactId).withoutTransitivity().asSingleFile();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/61ddb323/modules/integration/osgi/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/test/resources/arquillian.xml b/modules/integration/osgi/src/test/resources/arquillian.xml
index 284e964..a4c885a 100644
--- a/modules/integration/osgi/src/test/resources/arquillian.xml
+++ b/modules/integration/osgi/src/test/resources/arquillian.xml
@@ -19,7 +19,7 @@ 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">
+ <container qualifier="osgi" default="true">
<configuration>
<property name="frameworkProperties">src/test/resources/felix.properties</property>
</configuration>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/61ddb323/modules/integration/osgi/src/test/resources/felix.properties
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/test/resources/felix.properties b/modules/integration/osgi/src/test/resources/felix.properties
index 5f3ec1a..de50401 100644
--- a/modules/integration/osgi/src/test/resources/felix.properties
+++ b/modules/integration/osgi/src/test/resources/felix.properties
@@ -16,7 +16,7 @@
# under the License.
#
# org.osgi.service.cm;org.apache.felix.cm;org.apache.tamaya;org.apache.tamaya.spi;
-org.osgi.framework.bootdelegation=org.apache.tamaya.integration.osgi.TestConfigInjection;org.apache.tamaya.integration.osgi.HelloService;org.apache.tamaya.integration.osgi.HelloServiceImpl
+org.osgi.framework.bootdelegation=org.apache.tamaya,org.apache.tamaya.integration.osgi,org.apache.tamaya.integration.osgi.test
felix.log.level=4 #debug logging
# felix.auto.deploy.dir=../test-bundles
org.osgi.framework.storage=target/felix-cache