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/15 00:39:49 UTC
svn commit: r1532119 - in /felix/trunk/dependencymanager/test2: ./
src/main/java/org/apache/felix/dependencymanager/test2/components/
src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/
Author: pderop
Date: Mon Oct 14 22:39:49 2013
New Revision: 1532119
URL: http://svn.apache.org/r1532119
Log:
pax exam 3.0.0 migration ...
Added:
felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ResourceAnnotation.java
felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ServiceFactoryAnnotation.java
felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/ResourceAnnotationTest.java
- copied, changed from r1531934, felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ResourceAnnotationTest.java
felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/ServiceFactoryAnnotationTest.java
- copied, changed from r1531934, felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ServiceFactoryAnnotationTest.java
Modified:
felix/trunk/dependencymanager/test2/pom.xml
felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ResourceAdapterServiceTestWithPublisher.java
Modified: felix/trunk/dependencymanager/test2/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test2/pom.xml?rev=1532119&r1=1532118&r2=1532119&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test2/pom.xml (original)
+++ felix/trunk/dependencymanager/test2/pom.xml Mon Oct 14 22:39:49 2013
@@ -205,7 +205,7 @@
you can specify a given test below: for example:
<include>**/integration/**/AspectBaseTest.java</include>
-->
- <include>**/integration/**/*.java</include>
+ <include>**/integration/**/ResourceAdapterTest.java</include>
</includes>
</configuration>
</execution>
Modified: felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ResourceAdapterServiceTestWithPublisher.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ResourceAdapterServiceTestWithPublisher.java?rev=1532119&r1=1532118&r2=1532119&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ResourceAdapterServiceTestWithPublisher.java (original)
+++ felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ResourceAdapterServiceTestWithPublisher.java Mon Oct 14 22:39:49 2013
@@ -81,6 +81,9 @@ public class ResourceAdapterServiceTestW
@Component
public static class ResourceProvider {
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
+
@Inject
private volatile BundleContext m_context;
private final Map m_handlers = new HashMap();
Added: felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ResourceAnnotation.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ResourceAnnotation.java?rev=1532119&view=auto
==============================================================================
--- felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ResourceAnnotation.java (added)
+++ felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ResourceAnnotation.java Mon Oct 14 22:39:49 2013
@@ -0,0 +1,287 @@
+/*
+* 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.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import junit.framework.Assert;
+
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.ResourceHandler;
+import org.apache.felix.dm.ResourceUtil;
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.Destroy;
+import org.apache.felix.dm.annotation.api.Init;
+import org.apache.felix.dm.annotation.api.Inject;
+import org.apache.felix.dm.annotation.api.Property;
+import org.apache.felix.dm.annotation.api.ResourceAdapterService;
+import org.apache.felix.dm.annotation.api.ResourceDependency;
+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;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+
+public class ResourceAnnotation {
+ public final static String ENSURE_RESOURCE = "ResourceAnnotation.resource";
+ public final static String ENSURE_FIELD = "ResourceAnnotation.field";
+ public final static String ENSURE_ADAPTER = "ResourceAnnotation.adapter";
+ public final static String ENSURE_PROVIDER = "ResourceAnnotation.provider";
+
+ /**
+ * A Service provided the ServiceProvider, which is a ResourceAdapter.
+ */
+ public interface ServiceInterface extends Runnable {
+ }
+
+ /**
+ * A Component which has a resource dependency.
+ */
+ @Component
+ public static class ResourceConsumer {
+ @ServiceDependency(required = true, filter = "(name=" + ENSURE_RESOURCE + ")")
+ volatile Ensure m_sequencer;
+
+ private volatile int m_resourcesSeen;
+
+ @Start
+ void start() {
+ System.out.println("ResourceConsumer.start: sequencer=" + m_sequencer);
+ }
+
+ @ResourceDependency(required = false, filter = "(&(path=/path/to/*.txt)(host=localhost))")
+ public void add(URL resource) {
+ System.out.println("ResourceConsumer.add: resource=" + resource + ", m_sequencer=" + m_sequencer);
+ if (match(resource, "file://localhost/path/to/test1.txt")) {
+ m_resourcesSeen++;
+ return;
+ }
+
+ if (match(resource, "file://localhost/path/to/test2.txt")) {
+ m_resourcesSeen++;
+ return;
+ }
+
+ Assert.fail("Got unexpected resource: " + resource);
+ }
+
+ private boolean match(URL resource, String url) {
+ return url.equals(resource.toString());
+ }
+
+ @Stop
+ void stop() {
+ System.out.println("ResourceConsumer.stop: m_sequencer=" + m_sequencer);
+ Assert.assertEquals(2, m_resourcesSeen);
+ m_sequencer.step(1);
+ }
+ }
+
+ /**
+ * A Component which as a resource dependency, using a class field.
+ */
+ @Component
+ public static class ResourceConsumerField {
+ @ServiceDependency(required = true, filter = "(name=" + ENSURE_FIELD + ")")
+ volatile Ensure m_sequencer;
+
+ @ResourceDependency(filter = "(&(path=*/test1.txt)(host=localhost))")
+ URL m_resource;
+
+ @Init
+ void init() {
+ if (m_resource != null) {
+ Assert.assertTrue("file://localhost/path/to/test1.txt".equals(m_resource.toString()));
+ m_sequencer.step(1);
+ }
+ }
+ }
+
+ /**
+ * Provides some simple resources.
+ */
+ @Component
+ public static class ResourceProvider {
+ @ServiceDependency(required = true, filter = "(name=" + ENSURE_PROVIDER + ")")
+ volatile Ensure m_sequencer;
+
+ @Inject
+ private volatile BundleContext m_context;
+ private final Map m_handlers = new HashMap();
+ private final URL[] m_resources;
+
+ public ResourceProvider() throws Exception {
+ m_resources = new URL[]{
+ new URL("file://localhost/path/to/test1.txt"),
+ new URL("file://localhost/path/to/test2.txt"),
+ new URL("file://localhost/path/to/README.doc")};
+ }
+
+ /**
+ * Handles a new Resource consumer
+ * @param serviceProperties
+ * @param handler
+ */
+ @ServiceDependency(removed = "remove", required = false)
+ public void add(Map serviceProperties, ResourceHandler handler) {
+ System.out.println("ResourceProvider.addResourceHandler " + handler);
+ String filterString = (String) serviceProperties.get("filter");
+ Filter filter = null;
+ if (filterString != null) {
+ try {
+ filter = m_context.createFilter(filterString);
+ } catch (InvalidSyntaxException e) {
+ Assert.fail("Could not create filter for resource handler: " + e);
+ return;
+ }
+ }
+ synchronized (m_handlers) {
+ m_handlers.put(handler, filter);
+ }
+ for (int i = 0; i < m_resources.length; i++) {
+ if (filter == null || filter.match(ResourceUtil.createProperties(m_resources[i]))) {
+ System.out.println("ResourceProvider: calling handled.added(" + m_resources[i] + ")");
+ handler.added(m_resources[i], null);
+ }
+ }
+ }
+
+ /**
+ * Remove a Resource consumer.
+ * @param handler
+ */
+ public void remove(ResourceHandler handler) {
+ System.out.println("ResourceProvider.removeResourceHandler " + handler);
+
+ Filter filter;
+ synchronized (m_handlers) {
+ filter = (Filter) m_handlers.remove(handler);
+ }
+ removeResources(handler, filter);
+ }
+
+ private void removeResources(ResourceHandler handler, Filter filter) {
+ for (int i = 0; i < m_resources.length; i++) {
+ if (filter == null || filter.match(ResourceUtil.createProperties(m_resources[i]))) {
+ handler.removed(m_resources[i], null);
+ }
+ }
+ }
+
+ /**
+ * Our component is being destroyed: notify all our registered Resource consumers that we don't
+ * provide our Resources anymore.
+ */
+ @Destroy
+ public void destroy() {
+ Entry[] handlers;
+ synchronized (m_handlers) {
+ handlers = (Entry[]) m_handlers.entrySet().toArray(new Entry[m_handlers.size()]);
+ }
+ for (int i = 0; i < handlers.length; i++) {
+ removeResources((ResourceHandler) handlers[i].getKey(), (Filter) handlers[i].getValue());
+ }
+ }
+ }
+
+ /**
+ * Our ServiceInterface provider, which service is activated by a ResourceAdapter.
+ */
+ @ResourceAdapterService(filter = "(&(path=/path/to/test1.txt)(host=localhost))", properties = {@Property(name = "foo", value = "bar")}, propagate = true)
+ public static class ServiceProvider implements ServiceInterface {
+ // Injected by reflection
+ URL m_resource;
+
+ @ServiceDependency(filter = "(name=" + ENSURE_ADAPTER + ")")
+ Ensure m_sequencer;
+
+ // Check auto config injections
+ @Inject
+ BundleContext m_bc;
+ BundleContext m_bcNotInjected;
+
+ @Inject
+ DependencyManager m_dm;
+ DependencyManager m_dmNotInjected;
+
+ @Inject
+ org.apache.felix.dm.Component m_component;
+ org.apache.felix.dm.Component m_componentNotInjected;
+
+ public void run() {
+ checkInjectedFields();
+ Assert.assertNotNull("Resource has not been injected in the adapter", m_resource);
+ Assert.assertEquals("ServiceProvider did not get expected resource", "file://localhost/path/to/test1.txt",
+ m_resource.toString());
+ m_sequencer.step(2);
+ }
+
+ 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;
+ }
+ }
+ }
+
+ /**
+ * A Component with a dependency over the ServiceInterface, which is actually provided
+ * by a ResourceAdapter.
+ */
+ @Component
+ public static class ServiceConsumer {
+ @ServiceDependency
+ ServiceInterface m_serviceInterface;
+
+ @ServiceDependency(filter = "(name=" + ENSURE_ADAPTER + ")")
+ Ensure m_sequencer;
+
+ @Start
+ void start() {
+ m_sequencer.step(1);
+ m_serviceInterface.run();
+ }
+ }
+}
Added: felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ServiceFactoryAnnotation.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ServiceFactoryAnnotation.java?rev=1532119&view=auto
==============================================================================
--- felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ServiceFactoryAnnotation.java (added)
+++ felix/trunk/dependencymanager/test2/src/main/java/org/apache/felix/dependencymanager/test2/components/ServiceFactoryAnnotation.java Mon Oct 14 22:39:49 2013
@@ -0,0 +1,176 @@
+/*
+* 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.HashMap;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.Init;
+import org.apache.felix.dm.annotation.api.Property;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.annotation.api.Start;
+import org.apache.felix.dm.annotation.api.Stop;
+
+public class ServiceFactoryAnnotation {
+ public final static String FACTORY = "ServiceFactoryAnnotation.Factory";
+ public final static String ENSURE = "ServiceFactoryAnnotation.Ensure";
+
+ public interface MyServiceInterface {
+ public void added(String instanceId);
+
+ public void changed(String modified);
+
+ public void removed();
+ }
+
+ @Component(properties = @Property(name = "foo", value = "bar"))
+ public static class ExtraDependency1 implements Runnable {
+ public void run() {
+ }
+ }
+
+ @Component(properties = @Property(name = "foo", value = "bar2"))
+ public static class ExtraDependency2 implements Runnable {
+ public void run() {
+ System.out.println("ExtraDependency2.run()");
+ }
+ }
+
+ /**
+ * This service is instantiated using a "factory set" from the
+ * ServiceFactoryAnnotationTest class.
+ *
+ * @see org.apache.felix.dm.test.annotation.ServiceFactoryAnnotationTest
+ */
+ @Component(factorySet = FACTORY, factoryConfigure = "configure", properties = {@Property(name = "foo", value = "bar")})
+ public static class MyService implements MyServiceInterface {
+ /**
+ * The configuration provided by MyServiceFactory
+ */
+ @SuppressWarnings("unchecked")
+ volatile Dictionary m_configuration;
+
+ /**
+ * Our sequencer.
+ */
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
+
+ /**
+ * An extra dependency (we'll dynamically configure the filter from our
+ * init() method).
+ */
+ @ServiceDependency(name = "extra")
+ Runnable m_extra;
+
+ /**
+ * This is the first method called: we are provided with the
+ * MyServiceFactory configuration.
+ */
+ public void configure(Dictionary<?, ?> configuration) {
+ if (m_configuration == null) {
+ m_configuration = configuration;
+ } else {
+ m_sequencer.step(5);
+ }
+ }
+
+ /**
+ * Initialize our Service: we'll dynamically configure our dependency whose
+ * name is "extra".
+ */
+ @Init
+ Map init() {
+ return new HashMap() {
+ {
+ put("extra.filter", "(foo=bar2)");
+ put("extra.required", "true");
+ }
+ };
+ }
+
+ /**
+ * our Service is starting: at this point, all required dependencies have
+ * been injected.
+ */
+ @Start
+ public void start() {
+ Assert.assertNotNull("Extra dependency not injected", m_extra);
+ m_extra.run();
+ m_sequencer.step(2);
+ }
+
+ /**
+ * Our service is stopping.
+ */
+ @Stop
+ public void stop() {
+ m_sequencer.step(10);
+ }
+
+ public void added(String instanceId) {
+ if (instanceId.equals(m_configuration.get("instance.id"))) {
+ m_sequencer.step(4);
+ }
+ }
+
+ public void changed(String modified) {
+ if (modified.equals(m_configuration.get("instance.modified"))) {
+ m_sequencer.step(7);
+ }
+ }
+
+ public void removed() {
+ m_sequencer.step(9);
+ }
+ }
+
+ @Component
+ public static class MyServiceClient {
+ @ServiceDependency(filter = "(name=" + ENSURE + ")")
+ volatile Ensure m_sequencer;
+
+ @Start
+ void start() {
+ m_sequencer.step(1);
+ }
+
+ @ServiceDependency(required = false, changed = "update", removed = "removed")
+ void bind(Map serviceProperties, MyServiceInterface service) {
+ m_sequencer.step(3);
+ Assert.assertEquals("bar", serviceProperties.get("foo"));
+ Assert.assertNull(serviceProperties.get(".private.param"));
+ service.added((String) serviceProperties.get("instance.id"));
+ }
+
+ void update(Map serviceProperties, MyServiceInterface service) {
+ m_sequencer.step(6);
+ service.changed((String) serviceProperties.get("instance.modified"));
+ }
+
+ void removed(MyServiceInterface service) {
+ m_sequencer.step(8);
+ service.removed();
+ }
+ }
+}
Copied: felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/ResourceAnnotationTest.java (from r1531934, felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ResourceAnnotationTest.java)
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/ResourceAnnotationTest.java?p2=felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/ResourceAnnotationTest.java&p1=felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ResourceAnnotationTest.java&r1=1531934&r2=1532119&rev=1532119&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ResourceAnnotationTest.java (original)
+++ felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/ResourceAnnotationTest.java Mon Oct 14 22:39:49 2013
@@ -16,91 +16,63 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.dm.test.annotation;
+package org.apache.felix.dependencymanager.test2.integration.annotations;
-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;
-
-import java.util.Properties;
-
-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.components.ResourceAnnotation;
+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;
/**
* Use case: Verify Bundle Dependency annotations usage.
*/
-@RunWith(JUnit4TestRunner.class)
-public class ResourceAnnotationTest 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.dependencymanager").versionAsInProject(),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager.runtime").versionAsInProject()),
- provision(
- new BundleGenerator()
- .set(Constants.BUNDLE_SYMBOLICNAME, "ResourceTest")
- .set("Export-Package", "org.apache.felix.dm.test.bundle.annotation.sequencer")
- .set("Private-Package", "org.apache.felix.dm.test.bundle.annotation.resource")
- .set("Import-Package", "*")
- .set("-plugin", "org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin")
- .build()));
- }
-
+@RunWith(PaxExam.class)
+public class ResourceAnnotationTest extends TestBase {
/**
* Tests a simple ResourceConsumer
* @param context
*/
@Test
- public void testResourceAnnotation(BundleContext context)
- {
- DependencyManager m = new DependencyManager(context);
- Properties props = new Properties() {{ put("test", "resource"); }};
- m.add(m.createComponent().setImplementation(this).setInterface(Sequencer.class.getName(), props));
- super.stopBundle("ResourceTest", context);
- m_ensure.waitForStep(1, 10000);
+ public void testResourceAnnotation() {
+ Ensure e = new Ensure();
+ ServiceRegistration sr = register(e, ResourceAnnotation.ENSURE_RESOURCE);
+ ServiceRegistration sr2 = register(e, ResourceAnnotation.ENSURE_PROVIDER);
+ stopTestComponentsBundle();
+ e.waitForStep(1, 10000);
+ sr.unregister();
+ sr2.unregister();
}
/**
* Tests a simple ResourceConsumer using a class field for resource injection
*/
@Test
- public void testResourceAnnotationAutoConfig(BundleContext context)
- {
- DependencyManager m = new DependencyManager(context);
- Properties props = new Properties() {{ put("test", "resourceField"); }};
- m.add(m.createComponent().setImplementation(this).setInterface(Sequencer.class.getName(), props));
- super.stopBundle("ResourceTest", context);
- m_ensure.waitForStep(1, 10000);
+ public void testResourceAnnotationAutoConfig() {
+ Ensure e = new Ensure();
+ ServiceRegistration sr = register(e, ResourceAnnotation.ENSURE_FIELD);
+ ServiceRegistration sr2 = register(e, ResourceAnnotation.ENSURE_PROVIDER);
+ stopTestComponentsBundle();
+ e.waitForStep(1, 10000);
+ sr.unregister();
+ sr2.unregister();
}
- /**
- * Tests a ResourceAdapter
- * @param context
- */
+ /**
+ * Tests a ResourceAdapter
+ * @param context
+ */
@Test
- public void testResourceAdapterAnnotation(BundleContext context) throws Throwable
- {
- DependencyManager m = new DependencyManager(context);
- Properties props = new Properties() {{ put("test", "adapter"); }};
- m.add(m.createComponent().setImplementation(this).setInterface(Sequencer.class.getName(), props));
- super.stopBundle("ResourceTest", context);
- m_ensure.waitForStep(2, 10000);
- m_ensure.ensure();
+ public void testResourceAdapterAnnotation() throws Throwable {
+ Ensure e = new Ensure();
+ ServiceRegistration sr = register(e, ResourceAnnotation.ENSURE_ADAPTER);
+ ServiceRegistration sr2 = register(e, ResourceAnnotation.ENSURE_PROVIDER);
+ stopTestComponentsBundle();
+ e.waitForStep(2, 10000);
+ e.ensure();
+ sr.unregister();
+ sr2.unregister();
}
}
Copied: felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/ServiceFactoryAnnotationTest.java (from r1531934, felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ServiceFactoryAnnotationTest.java)
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/ServiceFactoryAnnotationTest.java?p2=felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/ServiceFactoryAnnotationTest.java&p1=felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ServiceFactoryAnnotationTest.java&r1=1531934&r2=1532119&rev=1532119&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/annotation/ServiceFactoryAnnotationTest.java (original)
+++ felix/trunk/dependencymanager/test2/src/test/java/org/apache/felix/dependencymanager/test2/integration/annotations/ServiceFactoryAnnotationTest.java Mon Oct 14 22:39:49 2013
@@ -16,74 +16,42 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.dm.test.annotation;
+package org.apache.felix.dependencymanager.test2.integration.annotations;
-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;
-
-import java.util.Dictionary;
import java.util.Hashtable;
-import java.util.Map;
import java.util.Set;
import junit.framework.Assert;
+import org.apache.felix.dependencymanager.test2.components.Ensure;
+import org.apache.felix.dependencymanager.test2.components.ServiceFactoryAnnotation;
+import org.apache.felix.dependencymanager.test2.integration.common.TestBase;
import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.annotation.api.Component;
-import org.apache.felix.dm.test.Base;
-import org.apache.felix.dm.test.BundleGenerator;
-import org.apache.felix.dm.test.bundle.annotation.factory.MyService;
-import org.apache.felix.dm.test.bundle.annotation.factory.MyServiceInterface;
-import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
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;
-
-@RunWith(JUnit4TestRunner.class)
-public class ServiceFactoryAnnotationTest 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.dependencymanager").versionAsInProject(),
- mavenBundle().groupId("org.apache.felix")
- .artifactId("org.apache.felix.dependencymanager.runtime")
- .versionAsInProject()),
- provision(new BundleGenerator()
- .set(Constants.BUNDLE_SYMBOLICNAME, "ServiceFactoryAnnotationTest")
- .set("Export-Package", "org.apache.felix.dm.test.bundle.annotation.sequencer")
- .set("Private-Package", "org.apache.felix.dm.test.bundle.annotation.factory")
- .set("Import-Package", "*")
- .set("-plugin", "org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin").build()));
- }
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
+@RunWith(PaxExam.class)
+public class ServiceFactoryAnnotationTest extends TestBase {
+ private final Ensure m_ensure = new Ensure();
@Test
- public void testServiceFactory(BundleContext context) {
- DependencyManager m = new DependencyManager(context);
-
- // We provide ourself as a "Sequencer" service to the annotated bundles.
- m.add(m.createComponent().setImplementation(ServiceFactoryAnnotationTest.this)
- .setInterface(Sequencer.class.getName(), null));
+ public void testServiceFactory() {
+ ServiceRegistration sr = register(m_ensure, ServiceFactoryAnnotation.ENSURE);
+ DependencyManager m = new DependencyManager(context);
// Wait for the factory.
m.add(m.createComponent()
.setImplementation(this)
.add(m.createServiceDependency()
- .setService(Set.class, "(" + Component.FACTORY_NAME + "=MyServiceFactory)")
+ .setService(Set.class, "(" + Component.FACTORY_NAME + "=" + ServiceFactoryAnnotation.FACTORY + ")")
.setRequired(true).setCallbacks("bindFactory", null)));
// Check if the test.annotation components have been initialized orderly
m_ensure.waitForStep(10, 5000);
+ m.clear();
+ sr.unregister();
}
void bindFactory(Set factory) {