added tests for service factory feature

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@942921 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyService.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyService.java
new file mode 100644
index 0000000..b786a12
--- /dev/null
+++ b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyService.java
@@ -0,0 +1,83 @@
+/*
+ * 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.bundle.annotation.factory;
+
+import java.util.Dictionary;
+
+import org.apache.felix.dm.annotation.api.Property;
+import org.apache.felix.dm.annotation.api.Service;
+import org.apache.felix.dm.annotation.api.Start;
+import org.apache.felix.dm.annotation.api.Stop;
+import org.apache.felix.dm.annotation.api.dependency.ServiceDependency;
+import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
+
+@Service(factory = "MyServiceFactory", factoryConfigure = "configure", properties = { @Property(name = "foo", value = "bar") })
+public class MyService implements MyServiceInterface
+{
+    @ServiceDependency
+    Sequencer m_sequencer;
+
+    @SuppressWarnings("unchecked")
+    Dictionary m_configuration;
+
+    public void configure(Dictionary<?, ?> configuration)
+    {
+        if (m_configuration == null)
+        {
+            m_configuration = configuration;
+        }
+        else
+        {
+            m_sequencer.step(5);
+        }
+    }
+
+    @Start
+    public void start()
+    {
+        m_sequencer.step(2);
+    }
+
+    @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);
+    }
+}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyServiceFactory.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyServiceFactory.java
new file mode 100644
index 0000000..b0b3433
--- /dev/null
+++ b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyServiceFactory.java
@@ -0,0 +1,83 @@
+/*
+ * 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.bundle.annotation.factory;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.apache.felix.dm.annotation.api.Service;
+import org.apache.felix.dm.annotation.api.Start;
+import org.apache.felix.dm.annotation.api.dependency.ServiceDependency;
+import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
+
+@SuppressWarnings("unchecked")
+@Service
+public class MyServiceFactory
+{
+    @ServiceDependency(filter = "(dm.factory.name=MyServiceFactory)")
+    Set<Dictionary> m_myServiceFactory;
+
+    @ServiceDependency
+    Sequencer m_sequencer;
+
+    Hashtable m_conf;
+
+    @Start
+    void start()
+    {
+        m_sequencer.step(1);
+        // create a service instance with this configuration
+        m_conf = new Hashtable();
+        m_conf.put("instance.id", "instance");
+        m_conf.put(".private.param", "private");
+        Assert.assertTrue(m_myServiceFactory.add(m_conf));
+    }
+
+    @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"));
+
+        // update the service instance
+        m_conf.put("instance.modified", "true");
+        Assert.assertFalse(m_myServiceFactory.add(m_conf));
+    }
+
+    void update(Map serviceProperties, MyServiceInterface service)
+    {
+        m_sequencer.step(6);
+        service.changed((String) serviceProperties.get("instance.modified"));
+
+        // remove instance
+        Assert.assertTrue(m_myServiceFactory.remove(m_conf));
+    }
+
+    void removed(MyServiceInterface service)
+    {
+        m_sequencer.step(8);
+        service.removed();
+    }
+}
diff --git a/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyServiceInterface.java b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyServiceInterface.java
new file mode 100644
index 0000000..75a051e
--- /dev/null
+++ b/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/factory/MyServiceInterface.java
@@ -0,0 +1,26 @@
+/*
+ * 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.bundle.annotation.factory;
+
+public interface MyServiceInterface
+{
+    public void added(String instanceId);
+    public void changed(String modified);
+    public void removed();
+}