You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2013/10/13 23:15:59 UTC
svn commit: r1531752 - in /felix/trunk/dependencymanager:
test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factoryconfadapter/
test/src/test/java/org/apache/felix/dm/test/annotation/
test2/src/main/java/org/apache/felix/dependencymanager/t...
Author: pderop
Date: Sun Oct 13 21:15:58 2013
New Revision: 1531752
URL: http://svn.apache.org/r1531752
Log:
pax-exam 3.0.0 migration ...
Added:
felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/FactoryConfigurationAdapterAnnotation.java
felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/FactoryConfigurationAdapterAnnotationTest.java
- copied, changed from r1531247, felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/FactoryConfigurationAdapterAnnotationTest.java
Removed:
felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factoryconfadapter/
felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/FactoryConfigurationAdapterAnnotationTest.java
Added: felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/FactoryConfigurationAdapterAnnotation.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/FactoryConfigurationAdapterAnnotation.java?rev=1531752&view=auto
==============================================================================
--- felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/FactoryConfigurationAdapterAnnotation.java (added)
+++ felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/FactoryConfigurationAdapterAnnotation.java Sun Oct 13 21:15:58 2013
@@ -0,0 +1,156 @@
+/*
+* 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.dependencymanager.test2.components;
+
+import java.util.Dictionary;
+import java.util.Map;
+
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.FactoryConfigurationAdapterService;
+import org.apache.felix.dm.annotation.api.Inject;
+import org.apache.felix.dm.annotation.api.Property;
+import org.apache.felix.dm.annotation.api.Registered;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.annotation.api.Start;
+import org.apache.felix.dm.annotation.api.Stop;
+import org.osgi.framework.BundleContext;
+
+public class FactoryConfigurationAdapterAnnotation {
+ public interface ServiceInterface {
+ public void doService();
+ }
+
+ @Component
+ public static class ServiceClient {
+ @ServiceDependency(changed = "changeServiceProvider")
+ void addServiceProvider(Map props, ServiceInterface si) {
+ // props should contain foo=bar, foo2=bar2
+ if (!"bar".equals(props.get("foo"))) {
+ throw new IllegalArgumentException("configuration does not contain foo=bar: " + props);
+ }
+ if (!"bar2".equals(props.get("foo2"))) {
+ throw new IllegalArgumentException("configuration does not contain foo2=bar2: " + props);
+ }
+ si.doService();
+ }
+
+ void changeServiceProvider(Map props, ServiceInterface si) {
+ // props should contain foo=bar, foo2=bar2_modified
+ if (!"bar".equals(props.get("foo"))) {
+ throw new IllegalArgumentException("configuration does not contain foo=bar: " + props);
+ }
+ if (!"bar2_modified".equals(props.get("foo2"))) {
+ throw new IllegalArgumentException("configuration does not contain foo2=bar2: " + props);
+ }
+ si.doService();
+ }
+ }
+
+ /**
+ * This service is instantiated when a factory configuration is created from ConfigAdmin
+ */
+ @FactoryConfigurationAdapterService(factoryPid = "FactoryPidTest", properties = {@Property(name = "foo", value = "bar")}, propagate = true)
+ public static class ServiceProvider implements ServiceInterface {
+ @ServiceDependency(filter="(name=test.FactoryConfigurationAdapterAnnotationTest)")
+ private volatile Ensure m_sequencer;
+
+ private volatile boolean m_started;
+
+ // Check auto config injections
+ @Inject
+ volatile BundleContext m_bc;
+ BundleContext m_bcNotInjected;
+
+ @Inject
+ volatile DependencyManager m_dm;
+ DependencyManager m_dmNotInjected;
+
+ @Inject
+ volatile org.apache.felix.dm.Component m_component;
+ org.apache.felix.dm.Component m_componentNotInjected;
+
+ // Either initial config, or an updated config
+ protected void updated(Dictionary conf) {
+ if (m_started) {
+ // conf should contain foo2=bar2_modified
+ if (!"bar2_modified".equals(conf.get("foo2"))) {
+ m_sequencer.throwable(new Exception("configuration does not contain foo=bar"));
+ }
+ m_sequencer.step(4);
+ } else {
+ // conf should contain foo2=bar2
+ if (!"bar2".equals(conf.get("foo2"))) {
+ throw new IllegalArgumentException("configuration does not contain foo2=bar2: " + conf);
+ }
+ }
+ }
+
+ @Start
+ void start() {
+ checkInjectedFields();
+ m_started = true;
+ m_sequencer.step(1);
+ }
+
+ @Registered
+ void registered() {
+ m_sequencer.step(3);
+ }
+
+ // The ServiceClient is invoking our service
+ public void doService() {
+ m_sequencer.step(); /* 2 or 5 */
+ }
+
+ @Stop
+ void stop() {
+ m_sequencer.step(6);
+ }
+
+ private void checkInjectedFields() {
+ if (m_bc == null) {
+ m_sequencer.throwable(new Exception("Bundle Context not injected"));
+ return;
+ }
+ if (m_bcNotInjected != null) {
+ m_sequencer.throwable(new Exception("Bundle Context must not be injected"));
+ return;
+ }
+
+ if (m_dm == null) {
+ m_sequencer.throwable(new Exception("DependencyManager not injected"));
+ return;
+ }
+ if (m_dmNotInjected != null) {
+ m_sequencer.throwable(new Exception("DependencyManager must not be injected"));
+ return;
+ }
+
+ if (m_component == null) {
+ m_sequencer.throwable(new Exception("Component not injected"));
+ return;
+ }
+ if (m_componentNotInjected != null) {
+ m_sequencer.throwable(new Exception("Component must not be injected"));
+ return;
+ }
+ }
+ }
+}
Copied: felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/FactoryConfigurationAdapterAnnotationTest.java (from r1531247, felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/FactoryConfigurationAdapterAnnotationTest.java)
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/FactoryConfigurationAdapterAnnotationTest.java?p2=felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/FactoryConfigurationAdapterAnnotationTest.java&p1=felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/FactoryConfigurationAdapterAnnotationTest.java&r1=1531247&r2=1531752&rev=1531752&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/FactoryConfigurationAdapterAnnotationTest.java (original)
+++ felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/FactoryConfigurationAdapterAnnotationTest.java Sun Oct 13 21:15:58 2013
@@ -16,85 +16,59 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.dm.test.annotation;
-
-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.CoreOptions.systemProperty;
+package org.apache.felix.dependencymanager.test2.integration.annotations;
import java.io.IOException;
import java.util.Hashtable;
import junit.framework.Assert;
-import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.dm.test.Base;
-import org.apache.felix.dm.test.BundleGenerator;
-import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
+import org.apache.felix.dependencymanager.test2.components.Ensure;
+import org.apache.felix.dependencymanager.test2.integration.common.TestBase;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.Configuration;
-import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ConfigurationAdmin;
/**
* Use case: Verify that an annotated Configuration Factory Adapter Service is properly created when a factory configuration
* is created from Config Admin.
*/
-@RunWith(JUnit4TestRunner.class)
-public class FactoryConfigurationAdapterAnnotationTest extends AnnotationBase
-{
- @Configuration
- public static Option[] configuration()
- {
- return options(
- systemProperty(DMLOG_PROPERTY).value( "true" ),
- provision(
- mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").version(Base.OSGI_SPEC_VERSION),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.configadmin").version("1.2.8"),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject(),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager.runtime").versionAsInProject()),
- provision(
- new BundleGenerator()
- .set(Constants.BUNDLE_SYMBOLICNAME, "FactoryConfigurationAdapterTest")
- .set("Export-Package", "org.apache.felix.dm.test.bundle.annotation.sequencer")
- .set("Private-Package", "org.apache.felix.dm.test.bundle.annotation.factoryconfadapter")
- .set("Import-Package", "*")
- .set("-plugin", "org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin")
- .build()));
- }
-
+@RunWith(PaxExam.class)
+public class FactoryConfigurationAdapterAnnotationTest extends TestBase {
@Test
- public void testFactoryConfigurationAdapterAnnotation(BundleContext context) throws Throwable
- {
- DependencyManager m = new DependencyManager(context);
- // Provide the Sequencer to the adapter bundle service (see main/src/.../factoryconfadapter/*.java).
- m.add(m.createComponent().setImplementation(this).setInterface(Sequencer.class.getName(), null));
- ConfigurationAdmin cm = (ConfigurationAdmin) context.getService(context.getServiceReference(ConfigurationAdmin.class.getName()));
- try
- {
+ public void testFactoryConfigurationAdapterAnnotation() throws Throwable {
+ Ensure e = new Ensure();
+ ServiceRegistration sr = register(e, "test.FactoryConfigurationAdapterAnnotationTest");
+ ConfigurationAdmin cm = (ConfigurationAdmin) context.getService(context
+ .getServiceReference(ConfigurationAdmin.class.getName()));
+ try {
// Create a factory configuration in order to instantiate the ServiceProvider
org.osgi.service.cm.Configuration cf = cm.createFactoryConfiguration("FactoryPidTest", null);
- cf.update(new Hashtable() {{ put("foo2", "bar2"); }});
+ cf.update(new Hashtable() {
+ {
+ put("foo2", "bar2");
+ }
+ });
// Wait for the ServiceProvider activation.
- m_ensure.waitForStep(2, 10000);
+ e.waitForStep(2, 10000);
// Update conf
- cf.update(new Hashtable() {{ put("foo2", "bar2_modified"); }});
+ cf.update(new Hashtable() {
+ {
+ put("foo2", "bar2_modified");
+ }
+ });
// Wait for effective update
- m_ensure.waitForStep(4, 10000);
+ e.waitForStep(4, 10000);
// Remove configuration.
cf.delete();
// Check if ServiceProvider has been stopped.
- m_ensure.waitForStep(6, 1000);
- m_ensure.ensure();
- }
- catch (IOException e)
- {
- e.printStackTrace();
+ e.waitForStep(6, 1000);
+ e.ensure();
+ sr.unregister();
+ } catch (IOException err) {
+ err.printStackTrace();
Assert.fail("can't create factory configuration");
}
}