added new testcase regarding annotations and dependencymanager service factories
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@899462 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/Factory.java b/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/Factory.java
new file mode 100644
index 0000000..0e7bba5
--- /dev/null
+++ b/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/Factory.java
@@ -0,0 +1,23 @@
+/*
+ * 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.dm.test.annotation;
+
+/**
+ * Class used to instantiate various components unsing Dependency Manager Factories.
+ */
+public class Factory
+{
+ public FactoryTest createFactoryTest()
+ {
+ return new FactoryTest("factory");
+ }
+}
diff --git a/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/FactoryTest.java b/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/FactoryTest.java
new file mode 100644
index 0000000..a5ca145
--- /dev/null
+++ b/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/FactoryTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.dm.test.annotation;
+
+import org.apache.felix.dm.annotation.api.Service;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.annotation.api.Start;
+
+/**
+ * Validate DependencyManager Factories declarared with annotations.
+ */
+@Service(factory=Factory.class, factoryMethod="createFactoryTest")
+public class FactoryTest
+{
+ String m_id;
+
+ @ServiceDependency(filter="(test=factory)")
+ Sequencer m_sequencer;
+
+ public FactoryTest(String id)
+ {
+ m_id = id;
+ }
+
+ @Start
+ void start() {
+ if (! "factory".equals(m_id)) {
+ throw new IllegalStateException();
+ }
+ m_sequencer.next(1);
+ }
+}
diff --git a/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/ServiceProvider.java b/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/ServiceProvider.java
index 11cb104..ad75ff4 100644
--- a/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/ServiceProvider.java
+++ b/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/ServiceProvider.java
@@ -19,7 +19,7 @@
@Service(properties = { "foo=bar" })
public class ServiceProvider implements ServiceInterface
{
- @ServiceDependency
+ @ServiceDependency(filter="(test=simple)")
Sequencer m_sequencer;
@ServiceDependency(removed="unbind")
diff --git a/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/ServiceProvider2.java b/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/ServiceProvider2.java
index 68e8c71..11de5a7 100644
--- a/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/ServiceProvider2.java
+++ b/dependencymanager/test/annotation/src/main/java/org/apache/felix/dm/test/annotation/ServiceProvider2.java
@@ -26,7 +26,7 @@
@ServiceDependency(required=false, filter="(foo=bar)")
Runnable m_runnable;
- @ServiceDependency(service=Sequencer.class)
+ @ServiceDependency(service=Sequencer.class, filter="(test=simple)")
void bind(Sequencer seq)
{
m_sequencer = seq;
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AnnotationTest.java b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AnnotationTest.java
index d69fc3f..bc41b4d 100644
--- a/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AnnotationTest.java
+++ b/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AnnotationTest.java
@@ -22,6 +22,9 @@
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.provision;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.test.annotation.Sequencer;
import org.junit.Test;
@@ -33,6 +36,7 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+@SuppressWarnings({ "unchecked", "serial" })
@RunWith(JUnit4TestRunner.class)
public class AnnotationTest implements Sequencer
{
@@ -54,7 +58,8 @@
m_ensure = new Ensure();
DependencyManager m = new DependencyManager(context);
// We provide ourself as a "Sequencer" service: this will active the "org.apache.felix.dependencymanager.test.annotation" bundle
- m.add(m.createService().setImplementation(this).setInterface(Sequencer.class.getName(), null));
+ Dictionary props = new Hashtable() {{ put("test", "simple"); }};
+ m.add(m.createService().setImplementation(this).setInterface(Sequencer.class.getName(), props));
// Check if the test.annotation components have been initialized orderly
m_ensure.waitForStep(7, 10000);
// Stop the test.annotation bundle
@@ -82,6 +87,18 @@
m_ensure.waitForStep(11, 10000);
}
+ @Test
+ public void testFactoryAnnotation(BundleContext context)
+ {
+ m_ensure = new Ensure();
+ DependencyManager m = new DependencyManager(context);
+ // We provide ourself as a "Sequencer" service: this will active the "org.apache.felix.dependencymanager.test.annotation" bundle
+ Dictionary props = new Hashtable() {{ put("test", "factory"); }};
+ m.add(m.createService().setImplementation(this).setInterface(Sequencer.class.getName(), props));
+ // Check if the test.annotation components have been initialized orderly
+ m_ensure.waitForStep(1, 10000);
+ }
+
// The test.annotation bundle will call back us here
public void next(int step)
{