felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1564995 [12/17] - in /felix/sandbox/pderop/dependencymanager: ./ core/ core/.externalToolBuilders/ core/.settings/ core/src/ core/src/main/ core/src/main/java/ core/src/main/java/org/ core/src/main/java/org/apache/ core/src/main/java/org/a...
Date Wed, 05 Feb 2014 23:22:36 GMT
Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/CompositeAnnotationsTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/CompositeAnnotationsTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/CompositeAnnotationsTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/CompositeAnnotationsTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,53 @@
+/*
+* 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.integration.annotations;
+
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.components.CompositeAnnotations.C1;
+import org.apache.felix.dm.test.components.CompositeAnnotations.Dependency1;
+import org.apache.felix.dm.test.components.CompositeAnnotations.Dependency2;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Use case: Verify Composite annotated services.
+ */
+@RunWith(PaxExam.class)
+public class CompositeAnnotationsTest extends TestBase {
+    public CompositeAnnotationsTest() {
+        super(true /* start test components bundle */);
+    }
+
+    @Test
+    public void testComposite() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr1 = register(e, C1.ENSURE);
+        ServiceRegistration sr2 = register(e, Dependency1.ENSURE);
+        ServiceRegistration sr3 = register(e, Dependency2.ENSURE);
+        e.waitForStep(4, 10000);
+        stopTestBundle();
+        e.waitForStep(12, 10000);
+        sr3.unregister();
+        sr2.unregister();
+        sr1.unregister();
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/ExtraServicePropertiesTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/ExtraServicePropertiesTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/ExtraServicePropertiesTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/ExtraServicePropertiesTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,84 @@
+/*
+ * 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.integration.annotations;
+
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.components.ExtraAdapterServiceProperties;
+import org.apache.felix.dm.test.components.ExtraAspectServiceProperties;
+import org.apache.felix.dm.test.components.ExtraFactoryServiceProperties;
+import org.apache.felix.dm.test.components.ExtraServiceProperties;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Use case: Verify the a Service may provide its service properties dynamically from its start method.
+ */
+@RunWith(PaxExam.class)
+public class ExtraServicePropertiesTest extends TestBase {
+    public ExtraServicePropertiesTest() {
+        super(true /* start test components bundle */);
+    }
+
+    /**
+     * Tests if a Service can provide its service properties from its start method.
+     */
+    @Test
+    public void testExtraServiceProperties() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, ExtraServiceProperties.ENSURE);
+        e.waitForStep(2, 10000);
+        sr.unregister();
+    }
+
+    /**
+     * Tests if a Service instantiated by a Factory can provide its service properties from its start method.
+     */
+    @Test
+    public void testExtraFactoryServiceProperties() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, ExtraFactoryServiceProperties.ENSURE);
+        e.waitForStep(3, 10000);
+        sr.unregister();
+    }
+
+    /**
+     * Tests if an AdapterService can provide its service properties from its start method.
+     */
+    @Test
+    public void testExtraAdapterServiceProperties() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, ExtraAdapterServiceProperties.ENSURE);
+        e.waitForStep(3, 10000);
+        sr.unregister();
+    }
+
+    /**
+     * Tests if an AspectService can provide its service properties from its start method.
+     */
+    @Test
+    public void testExtraAspectServiceProperties() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, ExtraAspectServiceProperties.ENSURE);
+        e.waitForStep(3, 10000);
+        sr.unregister();
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/FactoryConfigurationAdapterAnnotationTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/FactoryConfigurationAdapterAnnotationTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/FactoryConfigurationAdapterAnnotationTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/FactoryConfigurationAdapterAnnotationTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,80 @@
+/*
+* 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.integration.annotations;
+
+import java.io.IOException;
+import java.util.Hashtable;
+
+import junit.framework.Assert;
+
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.components.FactoryConfigurationAdapterAnnotation.ServiceProvider;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+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(PaxExam.class)
+public class FactoryConfigurationAdapterAnnotationTest extends TestBase {
+    public FactoryConfigurationAdapterAnnotationTest() {
+        super(true /* start test components bundle */);
+    }
+
+    @Test
+    public void testFactoryConfigurationAdapterAnnotation() throws Throwable {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, ServiceProvider.ENSURE);
+        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");
+                }
+            });
+            // Wait for the ServiceProvider activation.
+            e.waitForStep(2, 10000);
+            // Update conf
+            cf.update(new Hashtable() {
+                {
+                    put("foo2", "bar2_modified");
+                }
+            });
+            // Wait for effective update
+            e.waitForStep(4, 10000);
+            // Remove configuration.
+            cf.delete();
+            // Check if ServiceProvider has been stopped.
+            e.waitForStep(6, 1000);
+            e.ensure();
+            sr.unregister();
+        } catch (IOException err) {
+            err.printStackTrace();
+            Assert.fail("can't create factory configuration");
+        }
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/Felix4050Test.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/Felix4050Test.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/Felix4050Test.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/Felix4050Test.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,51 @@
+/*
+ * 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.integration.annotations;
+
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.components.Felix4050;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Test for FELIX-4050 issue: It validates that component state calculation does not mess up
+ * when an @Init method adds an available dependency using the API, and also returns a Map for
+ * configuring a named dependency.
+ */
+@RunWith(PaxExam.class)
+public class Felix4050Test extends TestBase {
+    public Felix4050Test() {
+        super(true /* start test components bundle */);
+    }
+
+    @Test
+    public void testFelix4050() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, Felix4050.ENSURE);
+        // wait for S to be started
+        e.waitForStep(3, 10000);
+        // remove our sequencer: this will stop S
+        sr.unregister();
+        // ensure that S is stopped and destroyed
+        e.waitForStep(5, 10000);
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/Felix4357Test.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/Felix4357Test.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/Felix4357Test.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/Felix4357Test.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,48 @@
+/*
+ * 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.integration.annotations;
+
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.components.Felix4357;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Test for FELIX-4357 issue: It validates the types of some service component properties
+ * defined with @Property annotation.
+ */
+@RunWith(PaxExam.class)
+public class Felix4357Test extends TestBase {
+    public Felix4357Test() {
+        super(true /* start test components bundle */);
+    }
+
+    @Test
+    public void testPropertiesWithTypes() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, Felix4357.ENSURE);
+        // wait for S to be started
+        e.waitForStep(30, 10000);
+        // remove our sequencer: this will stop S
+        sr.unregister();
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/MultipleAnnotationsTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/MultipleAnnotationsTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/MultipleAnnotationsTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/MultipleAnnotationsTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,48 @@
+/*
+* 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.integration.annotations;
+
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.components.MultipleAnnotations;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Use case: Verify complex Annotation usage.
+ */
+@RunWith(PaxExam.class)
+public class MultipleAnnotationsTest extends TestBase {
+    public MultipleAnnotationsTest() {
+        super(true /* start test components bundle */);
+    }
+
+    @Test
+    public void testMultipleAnnotations() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, MultipleAnnotations.ENSURE);
+        e.waitForStep(7, 10000);
+        stopTestBundle();
+        // And check if the test.annotation bundle has been deactivated orderly
+        e.waitForStep(11, 10000);
+        sr.unregister();
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/PropagateAnnotationTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/PropagateAnnotationTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/PropagateAnnotationTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/PropagateAnnotationTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,45 @@
+/*
+ * 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.integration.annotations;
+
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.components.PropagateAnnotation;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Use case: Verify that dependency "propagate" option is properly propagating properties to provided service.
+ */
+@RunWith(PaxExam.class)
+public class PropagateAnnotationTest extends TestBase {
+    public PropagateAnnotationTest() {
+        super(true /* start test components bundle */);
+    }
+
+    @Test
+    public void testServiceDependencyPropagate() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, PropagateAnnotation.ENSURE);
+        e.waitForStep(3, 10000);
+        sr.unregister();
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/PublisherAnnotationTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/PublisherAnnotationTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/PublisherAnnotationTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/PublisherAnnotationTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,106 @@
+/*
+ * 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.integration.annotations;
+
+import org.apache.felix.dm.test.components.AdapterServiceTestWithPublisher;
+import org.apache.felix.dm.test.components.BundleAdapterServiceTestWithPublisher;
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.components.FactoryConfigurationAdapterServiceTestWithPublisher;
+import org.apache.felix.dm.test.components.FactoryServiceTestWthPublisher;
+import org.apache.felix.dm.test.components.ResourceAdapterServiceTestWithPublisher;
+import org.apache.felix.dm.test.components.ServiceTestWthPublisher;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
+
+@RunWith(PaxExam.class)
+public class PublisherAnnotationTest extends TestBase {
+    public PublisherAnnotationTest() {
+        super(true /* start test components bundle */);
+    }
+
+    /**
+     * A Service that just registers/unregisters its service, using the @ServiceLifecycle annotation.
+     */
+    @Test
+    public void testServiceWithPublisher() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, ServiceTestWthPublisher.ENSURE);
+        e.waitForStep(4, 10000);
+        sr.unregister();
+    }
+
+    /**
+     * A Service instantiated from a FactorySet, and which registers/unregisters its service,
+     * using the @ServiceLifecycle annotation.
+     */
+    @Test
+    public void testFactoryServiceWithPublisher() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, FactoryServiceTestWthPublisher.ENSURE);
+        e.waitForStep(5, 10000);
+        sr.unregister();
+    }
+
+    /**
+     * Test an AdapterService which provides its interface using a @ServiceLifecycle.
+     */
+    @Test
+    public void testAdapterServiceWithPublisher() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, AdapterServiceTestWithPublisher.ENSURE);
+        e.waitForStep(6, 10000);
+        sr.unregister();
+    }
+
+    /**
+     * Test a BundleAdapterService which provides its interface using a @ServiceLifecycle.
+     */
+    @Test
+    public void testBundleAdapterServiceWithPublisher() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, BundleAdapterServiceTestWithPublisher.ENSURE);
+        e.waitForStep(5, 10000);
+        sr.unregister();
+    }
+
+    /**
+     * Test a ResourceAdapterService which provides its interface using a @ServiceLifecycle.
+     */
+    @Test
+    public void TestResourceAdapterServiceWithPublisher() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, ResourceAdapterServiceTestWithPublisher.ENSURE);
+        e.waitForStep(5, 10000);
+        sr.unregister();
+    }
+
+    /**
+     * Test a FactoryConfigurationAdapterService which provides its interface using a @ServiceLifecycle.
+     */
+    @Test
+    public void testFactoryAdapterServiceWithPublisher() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, FactoryConfigurationAdapterServiceTestWithPublisher.ENSURE);
+        e.waitForStep(5, 10000);
+        sr.unregister();
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/ResourceAnnotationTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/ResourceAnnotationTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/ResourceAnnotationTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/ResourceAnnotationTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,82 @@
+/*
+* 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.integration.annotations;
+
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.components.ResourceAnnotation;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Use case: Verify Bundle Dependency annotations usage.
+ */
+@RunWith(PaxExam.class)
+public class ResourceAnnotationTest extends TestBase {
+    public ResourceAnnotationTest() {
+        super(true /* start test components bundle */);
+    }
+
+    /**
+     * Tests a simple ResourceConsumer
+     * @param context
+     */
+    @Test
+    public void testResourceAnnotation() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, ResourceAnnotation.ENSURE_RESOURCE);
+        ServiceRegistration sr2 = register(e, ResourceAnnotation.ENSURE_PROVIDER);
+        stopTestBundle();
+        e.waitForStep(1, 10000);
+        sr.unregister();
+        sr2.unregister();
+    }
+
+    /**
+     * Tests a simple ResourceConsumer using a class field for resource injection
+     */
+    @Test
+    public void testResourceAnnotationAutoConfig() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, ResourceAnnotation.ENSURE_FIELD);
+        ServiceRegistration sr2 = register(e, ResourceAnnotation.ENSURE_PROVIDER);
+        stopTestBundle();
+        e.waitForStep(1, 10000);
+        sr.unregister();
+        sr2.unregister();
+    }
+
+    /**
+      * Tests a ResourceAdapter
+      * @param context
+      */
+    @Test
+    public void testResourceAdapterAnnotation() throws Throwable {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, ResourceAnnotation.ENSURE_ADAPTER);
+        ServiceRegistration sr2 = register(e, ResourceAnnotation.ENSURE_PROVIDER);
+        stopTestBundle();
+        e.waitForStep(2, 10000);
+        e.ensure();
+        sr.unregister();
+        sr2.unregister();
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/ServiceFactoryAnnotationTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/ServiceFactoryAnnotationTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/ServiceFactoryAnnotationTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/ServiceFactoryAnnotationTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,78 @@
+/*
+ * 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.integration.annotations;
+
+import java.util.Hashtable;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.components.ServiceFactoryAnnotation;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
+
+@RunWith(PaxExam.class)
+public class ServiceFactoryAnnotationTest extends TestBase {
+    public ServiceFactoryAnnotationTest() {
+        super(true /* start test components bundle */);
+    }
+
+    private final Ensure m_ensure = new Ensure();
+    @Test
+    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 + "=" + 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) {
+        // create a service instance with this configuration
+        Hashtable conf = new Hashtable();
+        conf.put("instance.id", "instance");
+        conf.put(".private.param", "private");
+        Assert.assertTrue(factory.add(conf));
+        m_ensure.waitForStep(4, 5000);
+
+        // update the service instance
+        conf.put("instance.modified", "true");
+        Assert.assertFalse(factory.add(conf));
+        m_ensure.waitForStep(7, 5000);
+
+        // remove instance
+        Assert.assertTrue(factory.remove(conf));
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/SimpleAnnotationsTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/SimpleAnnotationsTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/SimpleAnnotationsTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/SimpleAnnotationsTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,54 @@
+/*
+* 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.integration.annotations;
+
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.components.SimpleAnnotations.Consumer;
+import org.apache.felix.dm.test.components.SimpleAnnotations.Producer;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Use case: Ensure that a Provider can be injected into a Consumer, using simple DM annotations.
+ */
+@RunWith(PaxExam.class)
+public class SimpleAnnotationsTest extends TestBase {
+    public SimpleAnnotationsTest() {
+        super(true /* start test components bundle */);
+    }
+
+    @Test
+    public void testSimpleAnnotations() throws Throwable {
+        Ensure e = new Ensure();
+        ServiceRegistration er = register(e, Producer.ENSURE);
+        e.waitForStep(3, 10000); // Producer registered
+        ServiceRegistration er2 = register(e, Consumer.ENSURE);
+
+        er2.unregister(); // stop consumer
+        er.unregister(); // stop provider
+
+        // And check if components have been deactivated orderly.
+        e.waitForStep(10, 10000);
+        e.ensure();
+        stopTestBundle();
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/TemporalAnnotationsTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/TemporalAnnotationsTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/TemporalAnnotationsTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/annotations/TemporalAnnotationsTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,66 @@
+/*
+* 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.integration.annotations;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.components.TemporalAnnotations;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Use case: Verify Temporal Service dependency Annotations usage.
+ */
+@RunWith(PaxExam.class)
+public class TemporalAnnotationsTest extends TestBase {
+    public TemporalAnnotationsTest() {
+        super(true /* start test components bundle */);
+    }
+
+    @Test
+    public void testTemporalServiceDependency() {
+        Ensure ensure = new Ensure();
+        ServiceRegistration ensureReg = register(ensure, TemporalAnnotations.ENSURE);
+        Dictionary props = new Hashtable() {
+            {
+                put("test", "temporal");
+            }
+        };
+        Runnable r = Ensure.createRunnableStep(ensure, 1);
+        ServiceRegistration sr = context.registerService(Runnable.class.getName(), r, props);
+        ensure.waitForStep(1, 15000);
+        System.out.println("unregistering R");
+        sr.unregister();
+        ensure.step(2);
+        sleep(500);
+        r = Ensure.createRunnableStep(ensure, 3);
+        sr = context.registerService(Runnable.class.getName(), r, props);
+        ensure.waitForStep(3, 15000);
+        sr.unregister();
+        ensure.step(4);
+        sleep(1500);
+        ensure.waitForStep(5, 15000);
+        ensureReg.unregister();
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AbstractServiceDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AbstractServiceDependencyTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AbstractServiceDependencyTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AbstractServiceDependencyTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,109 @@
+/*
+ * 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.integration.api;
+
+import junit.framework.Assert;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+@RunWith(PaxExam.class)
+public class AbstractServiceDependencyTest extends TestBase {
+
+   @Test
+   public void testAbstractClassDependency() {
+       DependencyManager m = new DependencyManager(context);
+       // helper class that ensures certain steps get executed in sequence
+       Ensure e = new Ensure();
+       // create a service provider and consumer
+       Component sp = m.createComponent()
+           .setInterface(ServiceAbstract.class.getName(), null)
+           .setImplementation(new ServiceProvider(e))
+           ;
+       Component sc = m.createComponent()
+           .setImplementation(new ServiceConsumer(e))
+           .add(m.createServiceDependency()
+               .setService(ServiceAbstract.class)
+               .setRequired(true)
+               .setCallbacks("bind", "unbind")
+               );
+       m.add(sp);
+       m.add(sc);
+       m.remove(sp);
+       // ensure we executed all steps inside the component instance
+       e.step(8);
+   }
+
+   static abstract class ServiceAbstract {
+       public abstract void invoke();
+   }
+
+   static class ServiceProvider extends ServiceAbstract {
+       private final Ensure m_ensure;
+       public ServiceProvider(Ensure e) {
+           m_ensure = e;
+       }
+
+       public void start() {
+           m_ensure.step(1);
+       }
+
+       public void invoke() {
+           m_ensure.step(4);
+       }
+
+       public void stop() {
+           m_ensure.step(7);
+       }
+   }
+
+   static class ServiceConsumer {
+       private volatile ServiceAbstract m_service;
+       private final Ensure m_ensure;
+
+       public ServiceConsumer(Ensure e) {
+           m_ensure = e;
+       }
+
+       public void bind(ServiceAbstract service) {
+           m_ensure.step(2);
+           m_service = service;
+       }
+
+       public void start() {
+           m_ensure.step(3);
+           m_service.invoke();
+       }
+
+       public void stop() {
+           m_ensure.step(5);
+       }
+
+       public void unbind(ServiceAbstract service) {
+           System.out.println("UNBINDDDDDDDDDDDDDDDDDDDDDDDDDDD");
+           Assert.assertEquals(m_service, service);
+           m_ensure.step(6);
+       }
+   }
+}
\ No newline at end of file

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterAndConsumerTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterAndConsumerTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterAndConsumerTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterAndConsumerTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,115 @@
+/*
+ * 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.integration.api;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+@RunWith(PaxExam.class)
+public class AdapterAndConsumerTest extends TestBase {
+    
+    @Test
+    public void testServiceWithAdapterAndConsumer() {
+        DependencyManager m = new DependencyManager(context);
+        // helper class that ensures certain steps get executed in sequence
+        Ensure e = new Ensure();
+
+        Component provider = m.createComponent()
+            .setInterface(OriginalService.class.getName(), null)
+            .setImplementation(new ServiceProvider(e));
+
+        Component consumer = m.createComponent()
+            .setImplementation(new ServiceConsumer(e))
+            .add(m.createServiceDependency()
+                .setService(AdaptedService.class)
+                .setRequired(true)
+            );
+
+        Component adapter = m.createAdapterService(OriginalService.class, null)
+            .setInterface(AdaptedService.class.getName(), null)
+            .setImplementation(ServiceAdapter.class);
+        
+        // add the provider and the adapter
+        m.add(provider);
+        m.add(adapter);
+        // add a consumer that will invoke the adapter
+        // which will in turn invoke the original provider
+        m.add(consumer);
+        // now validate that both have been invoked in the right order
+        e.waitForStep(2, 5000);
+        // remove the provider again
+        m.remove(provider);
+        // ensure that the consumer is stopped
+        e.waitForStep(3, 5000);
+        // remove adapter and consumer
+        m.remove(adapter);
+        m.remove(consumer);
+    }
+
+    static interface OriginalService {
+        public void invoke();
+    }
+    
+    static interface AdaptedService {
+        public void invoke();
+    }
+    
+    static class ServiceProvider implements OriginalService {
+        private final Ensure m_ensure;
+        public ServiceProvider(Ensure e) {
+            m_ensure = e;
+        }
+        public void invoke() {
+            m_ensure.step(2);
+        }
+    }
+    
+    public static class ServiceAdapter implements AdaptedService {
+        private volatile OriginalService m_originalService;
+        
+        public void start() { System.out.println("start"); }
+        public void stop() { System.out.println("stop"); }
+        public void invoke() {
+            m_originalService.invoke();
+        }
+    }
+
+    static class ServiceConsumer {
+        private volatile AdaptedService m_service;
+        private final Ensure m_ensure;
+        
+        public ServiceConsumer(Ensure e) {
+            m_ensure = e;
+        }
+        public void start() {
+            m_ensure.step(1);
+            m_service.invoke();
+        }
+        public void stop() {
+            m_ensure.step(3);
+        }
+    }
+}
+
+

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithAspectCallbacksTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithAspectCallbacksTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithAspectCallbacksTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithAspectCallbacksTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,249 @@
+/*
+ * 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.integration.api;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceReference;
+
+@RunWith(PaxExam.class)
+public class AdapterWithAspectCallbacksTest extends TestBase {
+    @Test
+    public void testAdapterWithAspectMultipleTimes() {
+        DependencyManager m = new DependencyManager(context);
+        // helper class that ensures certain steps get executed in sequence
+        Ensure e = new Ensure();
+
+        Component aspect1 = m.createAspectService(OriginalService.class, null, 10, null)
+	            .setImplementation(ServiceAspect.class);
+	        
+	    Component aspect2 = m.createAspectService(OriginalService.class, null, 15, null)
+	            .setImplementation(ServiceAspect.class);
+	    
+        Component adapter = m.createAdapterService(OriginalService.class, null, "add", null, "remove", "swap")
+	            .setInterface(AdaptedService.class.getName(), null)
+	            .setImplementation(ServiceAdapter.class);
+        
+        m.add(adapter);
+        m.add(aspect1);
+        
+        List originals = new ArrayList();
+        List consumers = new ArrayList();
+        int count = 100;
+        for (int i = 0; i < count; i++) {
+	        // create a service provider and consumer
+        	Dictionary props = new Hashtable();
+        	props.put("number", "" + i);
+	        Component original = m.createComponent()
+	            .setImplementation(new ServiceProvider("" + i, e))
+	            .setInterface(OriginalService.class.getName(), props);
+	        
+	        Component consumer = m.createComponent()
+	            .setImplementation(new ServiceConsumer(e, "" + i))
+	            .add(m.createServiceDependency()
+	                .setService(AdaptedService.class, "(number=" + i + ")")
+	                .setCallbacks("add", null, "remove", "swap")
+	                .setRequired(true)
+	            );
+	        
+	        m.add(original);
+	        e.waitForStep(1 + i, 15000);	        
+	        originals.add(original);
+//	        m.add(consumer);
+	        consumers.add(consumer);
+        }
+        
+        m.add(aspect2);
+        e.waitForStep(2 + count, 15000);
+        // dumpComponents(m)
+        
+        for (int i = 0; i < 1; i++) {
+        	for (Object original : originals) {
+        		m.remove((Component)original);
+        	}
+        	for (Object consumer : consumers) {
+        		m.remove((Component)consumer);
+        	}
+        }
+        m.remove(aspect1);
+        m.remove(adapter);
+        
+        e.waitForStep(count * 3, 15000);
+        m.remove(aspect2);
+        e.step(count * 3 + 1);
+        m.clear();
+    }
+        
+    static interface OriginalService {
+        public void invoke();
+
+		public String getMessage();
+
+		public Ensure getEnsure();
+    }
+    
+    static interface AdaptedService {
+        public void invoke();
+
+		public String getMessage();
+    }
+    
+    static class ServiceProvider implements OriginalService {
+    	private final String message;
+    	private final Ensure m_ensure;
+    	
+		public ServiceProvider(String message, Ensure e) {
+			this.message = message;
+			this.m_ensure = e;
+    	}
+        public void start() {
+            System.out.println("...original starting");
+        }
+        public void invoke() {
+        }
+        
+        @Override
+        public String toString() {
+            return "Original " + message;
+        }
+		public String getMessage() {
+			return message;
+		}
+		public Ensure getEnsure() {
+			return m_ensure;
+		}
+    }
+    
+    public static class ServiceAdapter implements AdaptedService {
+        private volatile OriginalService m_originalService;
+		private int m_nr;
+        
+		public ServiceAdapter() {
+			
+		}
+
+        public void init() {
+        }
+        public void start() {
+            System.out.println("...adapter starting");
+        }
+        public void invoke() {
+            m_originalService.invoke();
+        }
+        public void stop() {
+        	System.out.println("...adapter stopping");
+        }
+        
+        void add(ServiceReference ref, OriginalService originalService) {
+        	m_originalService = originalService;
+        	System.out.println("adapter add: " + originalService + " (" + System.identityHashCode(this) + ")");
+        	m_originalService.getEnsure().step();
+        }
+        
+        void remove(ServiceReference ref, OriginalService originalService) {
+        	System.out.println("adapter rem: " + originalService + " (" + System.identityHashCode(this) + ")");
+        	m_originalService = null;
+        }
+        
+        void swap(ServiceReference oldRef, OriginalService oldService, ServiceReference newRef, OriginalService newService) {
+        	m_originalService = newService;
+        	System.out.println("adapter swp: " + newService + " (" + System.identityHashCode(this) + ")");
+        	m_originalService.getEnsure().step();
+        	System.out.println("ensure: " + m_originalService.getEnsure());
+        }
+        
+        @Override
+        public String toString() {
+            return "Adapter on " + m_originalService;
+        }
+		public String getMessage() {
+			return m_originalService.getMessage();
+		}
+	
+    }
+    
+    
+    public static class ServiceAspect implements OriginalService {
+        volatile OriginalService m_service;
+        
+        public void start() {
+            System.out.println("...aspect starting: " + toString());
+        }
+        
+        public void invoke() {
+            m_service.invoke();
+        }
+        
+        @Override
+        public String toString() {
+            return "Aspect on " + m_service;
+        }
+
+		public String getMessage() {
+			return m_service.getMessage();
+		}
+
+		public Ensure getEnsure() {
+			return m_service.getEnsure();
+		}
+    }
+
+    public static class ServiceConsumer {
+        Ensure m_ensure;
+        volatile AdaptedService service;
+		private final String expectedMessage;
+        
+        public ServiceConsumer(Ensure e, String expectedMessage) {
+            m_ensure = e;
+			this.expectedMessage = expectedMessage;
+        }
+        
+        public void start() {
+            String message = service.getMessage();
+            Assert.assertEquals(expectedMessage, message);
+        }
+        
+        public void stop() {
+        }
+        
+        public void add(ServiceReference ref, AdaptedService service) {
+        	this.service = service;
+        }
+        public void remove(ServiceReference ref, AdaptedService service) {
+        	this.service = null;
+        }
+        public void swap(ServiceReference oldRef, AdaptedService oldService, ServiceReference newRef, AdaptedService newService) {
+        	this.service = newService;
+        }
+        
+    }
+}
+
+

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithAspectTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithAspectTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithAspectTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithAspectTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,231 @@
+/*
+ * 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.integration.api;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.ServiceReference;
+
+@RunWith(PaxExam.class)
+public class AdapterWithAspectTest extends TestBase {
+    
+    @Test
+    public void testAdapterWithAspectMultipleTimes() {
+        // TODO this test is broken, it assumes that the order in which listeners are added to the BundleContext will also
+        // be the order in which they're invoked (which from a spec point of view is not true)
+        
+        
+        DependencyManager m = new DependencyManager(context);
+        // helper class that ensures certain steps get executed in sequence
+        Ensure e = new Ensure();
+        
+        // create a service provider and consumer
+        Component provider = m.createComponent()
+            .setImplementation(new ServiceProvider())
+            .setInterface(OriginalService.class.getName(), null);
+
+        Component consumer = m.createComponent()
+            .setImplementation(new ServiceConsumer(e))
+            .add(m.createServiceDependency()
+                .setService(AdaptedService.class)
+                .setCallbacks("add", null, "remove", "swap")
+            );
+        Component adapter = m.createAdapterService(OriginalService.class, null, "add", null, "remove", "swap")
+            .setInterface(AdaptedService.class.getName(), null)
+            .setImplementation(new ServiceAdapter(e,1));
+        
+        Component adapter2 = m.createAdapterService(OriginalService.class, null, "add", null, "remove", "swap")
+            .setInterface(AdaptedService.class.getName(), null)
+            .setImplementation(new ServiceAdapter(e,2));
+        
+        Component aspect = m.createAspectService(OriginalService.class, null, 10, null)
+            .setImplementation(ServiceAspect.class);
+        
+        m.add(provider);
+
+        int stepsInLoop = 10;
+        int loops = 10;
+        for (int loop = 0; loop < loops; loop++) {
+            int offset = stepsInLoop * loop;
+            
+            System.out.println("add adapter");
+            m.add(adapter);
+            System.out.println("add consumer");
+            m.add(consumer);
+            e.waitForStep(1 + offset, 5000);
+            System.out.println("add aspect");
+            m.add(aspect);
+            // a swap is expected on the adapter
+            e.waitForStep(2 + offset, 5000);
+            System.out.println("add adapter2");
+            m.add(adapter2);
+            // another aspect adapter will appear
+            e.waitForStep(4 + offset, 5000);
+            System.out.println("remove provider");
+            m.remove(provider);
+            // two times:
+            // the aspect adapter will disappear
+            // the original adapter will (briefly) appear
+            // the original adapter will disappear
+            
+            // TODO the test will fail somewhere here most of the time
+            
+            e.waitForStep(8 + offset, 5000);
+            System.out.println("remove consumer");
+            m.remove(consumer);
+            
+            // nothing should happen, all consumed services were already gone
+            System.out.println("add provider");
+            m.add(provider);
+            // still nothing should happen
+            System.out.println("remove adapter");
+            m.remove(adapter);
+            System.out.println("remove adapter2");
+            m.remove(adapter2);
+            System.out.println("remove aspect");
+            m.remove(aspect);
+        }
+        m.remove(provider);
+        e.waitForStep(stepsInLoop * loops, 5000);
+    }
+    
+    static interface OriginalService {
+        public void invoke();
+    }
+    
+    static interface AdaptedService {
+        public void invoke();
+    }
+    
+    static class ServiceProvider implements OriginalService {
+        public void start() {
+            System.out.println("...provider started");
+        }
+        public void invoke() {
+        }
+        
+        @Override
+        public String toString() {
+            return "Provider";
+        }
+    }
+    
+    public static class ServiceAdapter implements AdaptedService {
+        private volatile OriginalService m_originalService;
+		private final Ensure m_ensure;
+		private final int m_nr;
+        
+        public ServiceAdapter(Ensure e, int nr) {
+			this.m_ensure = e;
+			this.m_nr = nr;
+        }
+        public void init() {
+        }
+        public void start() {
+            System.out.println("...adapter started");
+        }
+        public void invoke() {
+            m_originalService.invoke();
+        }
+        public void stop() {
+        }
+        
+        void add(ServiceReference ref, OriginalService originalService) {
+        	m_originalService = originalService;
+        	m_ensure.step();
+        	System.out.println("adapter" + m_nr + " add: " + originalService);
+        }
+        
+        void remove(ServiceReference ref, OriginalService originalService) {
+        	System.out.println("adapter" + m_nr + " rem: " + originalService);
+        	m_originalService = null;
+        }
+        
+        void swap(ServiceReference oldRef, OriginalService oldService, ServiceReference newRef, OriginalService newService) {
+        	m_originalService = newService;
+        	m_ensure.step();
+        	System.out.println("adapter" + m_nr + " swp: " + newService);
+        }
+        
+        @Override
+        public String toString() {
+            return "Adapter on " + m_originalService;
+        }
+    }
+    
+    public static class ServiceAspect implements OriginalService {
+        volatile OriginalService m_service;
+        
+        public void start() {
+            System.out.println("...aspect started");
+        }
+        
+        public void invoke() {
+            m_service.invoke();
+        }
+        
+        @Override
+        public String toString() {
+            return "Aspect on " + m_service;
+        }
+    }
+
+    public static class ServiceConsumer {
+        Ensure m_ensure;
+        
+        public ServiceConsumer(Ensure e) {
+            m_ensure = e;
+        }
+        
+//        public void init() {
+//            Thread t = new Thread(this);
+//            t.start();
+//        }
+        public void start() {
+            System.out.println("Consumer starting...");
+        }
+        
+        int counter = 0;
+        public void add(ServiceReference ref, AdaptedService service) {
+            counter++;
+            System.out.println("consumer add: " + counter + " " + service);
+            m_ensure.step();
+        }
+        public void remove(ServiceReference ref, AdaptedService service) {
+            counter--;
+            System.out.println("consumer rem: " + counter + " " + service);
+            m_ensure.step();
+        }
+        public void swap(ServiceReference oldRef, AdaptedService oldService, ServiceReference newRef, AdaptedService newService) {
+        	System.out.println("consumer swp: " + counter + " " + newService);
+        	m_ensure.step();
+        }
+        
+//        public void run() {
+//            m_service.invoke();
+//        }
+    }
+}
+
+

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithExtraDependenciesTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithExtraDependenciesTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithExtraDependenciesTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithExtraDependenciesTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,106 @@
+/*
+ * 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.integration.api;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+@RunWith(PaxExam.class)
+public class AdapterWithExtraDependenciesTest extends TestBase {
+    @Test
+    public void testAdapterWithExtraDependenciesAndCallbacks() {
+        DependencyManager m = new DependencyManager(context);
+        // helper class that ensures certain steps get executed in sequence
+        Ensure e = new Ensure();
+        
+        // create a service adapter that adapts to services S1 and has an optional dependency on services S2
+        Component sa = m.createAdapterService(S1.class, null)
+            .setImplementation(SA.class)
+            .add(m.createServiceDependency().setService(S2.class).setCallbacks("add", "remove"));
+        m.add(sa);
+        
+        // create a service S1, which triggers the creation of the first adapter instance (A1)
+        Component s1 = m.createComponent().setInterface(S1.class.getName(), null).setImplementation(new S1Impl());
+        m.add(s1);
+        
+        // create a service S2, which will be added to A1
+        Component s2 = m.createComponent().setInterface(S2.class.getName(), null).setImplementation(new S2Impl(e));
+        m.add(s2);
+        
+        // create a second service S1, which triggers the creation of the second adapter instance (A2)
+        Component s1b = m.createComponent().setInterface(S1.class.getName(), null).setImplementation(new S1Impl());
+        m.add(s1b);
+        
+        // observe that S2 is also added to A2
+        e.waitForStep(2, 5000);
+        
+        // remove S2 again
+        m.remove(s2);
+        
+        // make sure both adapters have their "remove" callbacks invoked
+        e.waitForStep(4, 5000);
+        
+        m.remove(s1);
+        m.remove(sa);
+    }
+    
+    static interface S1 {
+    }
+    static interface S2 {
+        public void invoke();
+    }
+    static class S1Impl implements S1 {
+    }
+    static class S2Impl implements S2 {
+
+        private final Ensure m_e;
+
+        public S2Impl(Ensure e) {
+            m_e = e;
+        }
+
+        public void invoke() {
+            m_e.step();
+        }
+    }
+    
+    public static class SA {
+        volatile S2 s2;
+        
+        public SA() {
+            System.out.println("Adapter created");
+        }
+        public void init() {
+            System.out.println("Adapter init " + s2);
+        }
+        public void add(S2 s) {
+            System.out.println("adding " + s);
+            s.invoke();
+        }
+        public void remove(S2 s) {
+            System.out.println("removing " + s);
+            s.invoke();
+        }
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithInstanceBoundDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithInstanceBoundDependencyTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithInstanceBoundDependencyTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithInstanceBoundDependencyTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,138 @@
+/*
+ * 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.integration.api;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+@RunWith(PaxExam.class)
+public class AdapterWithInstanceBoundDependencyTest extends TestBase {
+    @Test
+    public void testInstanceBoundDependency() {
+        DependencyManager m = new DependencyManager(context);
+        // helper class that ensures certain steps get executed in sequence
+        Ensure e = new Ensure();
+        // create a service provider and consumer
+        Component sp = m.createComponent()
+            .setInterface(ServiceInterface.class.getName(), null)
+            .setImplementation(new ServiceProvider(e));
+        Component sp2 = m.createComponent()
+        .setInterface(ServiceInterface2.class.getName(), null)
+            .setImplementation(new ServiceProvider2(e));
+        Component sc = m.createComponent()
+            .setImplementation(new ServiceConsumer())
+            .add(m.createServiceDependency()
+                .setService(ServiceInterface3.class)
+                .setRequired(true));
+        Component sa = m.createAdapterService(ServiceInterface.class, null)
+            .setInterface(ServiceInterface3.class.getName(), null)
+            .setImplementation(new ServiceAdapter(e));
+        m.add(sc);
+        m.add(sp);
+        m.add(sp2);
+        m.add(sa);
+        e.waitForStep(5, 15000);
+        m.remove(sa);
+        m.remove(sp2);
+        m.remove(sp);
+        m.remove(sc);
+    }
+    
+    static interface ServiceInterface {
+        public void invoke();
+    }
+    
+    static interface ServiceInterface2 {
+        public void invoke();
+    }
+    
+    static interface ServiceInterface3 {
+        public void invoke();
+    }
+    
+    static class ServiceProvider2 implements ServiceInterface2 {
+        private final Ensure m_ensure;
+
+        public ServiceProvider2(Ensure ensure) {
+            m_ensure = ensure;
+        }
+
+        public void invoke() {
+            m_ensure.step(4);
+        }
+    }
+
+    static class ServiceProvider implements ServiceInterface {
+        private final Ensure m_ensure;
+        public ServiceProvider(Ensure e) {
+            m_ensure = e;
+        }
+        public void invoke() {
+            m_ensure.step(5);
+        }
+    }
+    
+    static class ServiceAdapter implements ServiceInterface3 {
+        private Ensure m_ensure;
+        private volatile ServiceInterface m_originalService;
+        private volatile ServiceInterface2 m_injectedService;
+        private volatile Component m_service;
+        private volatile DependencyManager m_manager;
+        
+        public ServiceAdapter(Ensure e) {
+            m_ensure = e;
+        }
+        public void init() {
+            m_ensure.step(1);
+            m_service.add(m_manager.createServiceDependency().setInstanceBound(true).setRequired(true).setService(ServiceInterface2.class));
+        }
+        public void start() {
+            m_ensure.step(2);
+        }
+        public void invoke() {
+            m_ensure.step(3);
+            m_injectedService.invoke();
+            m_originalService.invoke();
+        }
+        
+        public void stop() {
+            m_ensure.step(6);
+        }
+    }
+
+    static class ServiceConsumer implements Runnable {
+        private volatile ServiceInterface3 m_service;
+        
+        public void init() {
+            Thread t = new Thread(this);
+            t.start();
+        }
+        
+        public void run() {
+            m_service.invoke();
+        }
+    }
+}
+
+

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithModifiedInstanceBoundDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithModifiedInstanceBoundDependencyTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithModifiedInstanceBoundDependencyTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithModifiedInstanceBoundDependencyTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,159 @@
+/*
+ * 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.integration.api;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+/**
+ * Test for FELIX-4334 issue.
+ * 
+ * Three components: A, B and C
+ * 
+ * - A provided with property foo=bar
+ * - B adapts A, B has no filters on A, and B.init() method adds an instance bound required dependency to C.
+ * - C depends on A(foo=bar)
+ * - Now someone modifies the service properties of A: foo=bar2
+ * - As a result of that, C becomes unavailable and is unbound from B.
+ * - Since B has an instance bound required dependency to C: B should not be destroyed: it should be called in B.stop(), B.remove(C), B.change(A, "foo=bar2))
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@RunWith(PaxExam.class)
+public class AdapterWithModifiedInstanceBoundDependencyTest extends TestBase {
+    public static interface A {
+    }
+    
+    static class AImpl implements A {
+        final Ensure m_e;
+        AImpl(Ensure e) {
+            m_e = e;
+        }        
+    }
+    
+    public static interface C {
+    }
+
+    static class CImpl implements C {
+        volatile A m_a;
+    }
+    
+    public static interface B {
+    }
+    
+    static class BImpl implements B {
+        final Ensure m_e;
+        volatile A m_a;
+        volatile C m_c;
+        
+        BImpl(Ensure e) {
+            m_e = e;
+        }
+        
+        public void add(A a) {
+            m_e.step(1);
+        }
+
+        void init(Component c) {
+            m_e.step(2);
+            DependencyManager dm = c.getDependencyManager();
+            c.add(dm.createServiceDependency().setService(C.class).setRequired(true).setInstanceBound(true).setCallbacks("add", "remove"));
+        }      
+        
+        public void add(C c) {
+            m_e.step(3);
+        }
+        
+        public void start() {
+            m_e.step(4);            
+        }
+        
+        public void stop() { // C becomes unsatisfied when A properties are changed to foo=bar2
+            m_e.step(5);
+        }
+
+        public void remove(C c) {
+            m_e.step(6);
+        }
+
+        public void change(Map properties, A a) {
+            Assert.assertEquals("bar2", properties.get("foo"));
+            m_e.step(7);
+        }
+        
+        public void destroy() {
+            m_e.step(8);
+        }
+
+        public void remove(A a) {   
+            m_e.step(9);
+        }                    
+    }
+    
+    @Test
+    public void testAdapterWithChangedInstanceBoundDependency() {
+        DependencyManager m = new DependencyManager(context);
+        Ensure e = new Ensure();
+
+        Dictionary props = new Hashtable();
+        props.put("foo", "bar");
+        Component a = m.createComponent()
+                .setImplementation(new AImpl(e))
+                .setInterface(A.class.getName(), props);
+        
+        Component b = m.createAdapterService(A.class, null, "add", "change", "remove")
+                .setInterface(B.class.getName(), null)
+                .setImplementation(new BImpl(e));                
+        
+        Component c = m.createComponent()
+                .setImplementation(new CImpl())
+                .setInterface(C.class.getName(), null)
+                .add(m.createServiceDependency().setService(A.class, "(foo=bar)").setRequired(true));                     
+              
+        m.add(a);
+        m.add(c);
+        m.add(b);
+        
+        e.waitForStep(4, 5000);
+        
+        System.out.println("changing A props ...");
+        props = new Hashtable();
+        props.put("foo", "bar2");
+        a.setServiceProperties(props);
+        
+        e.waitForStep(7, 5000);                
+        
+        m.remove(c);
+        m.remove(a);
+        m.remove(b);
+        
+        e.waitForStep(9, 5000);                
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithPropagationTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithPropagationTest.java?rev=1564995&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithPropagationTest.java (added)
+++ felix/sandbox/pderop/dependencymanager/test/src/test/java/org/apache/felix/dm/test/integration/api/AdapterWithPropagationTest.java Wed Feb  5 23:22:32 2014
@@ -0,0 +1,137 @@
+/*
+ * 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.integration.api;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.test.components.Ensure;
+import org.apache.felix.dm.test.integration.common.TestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+/**
+ * Checks if a service adapter propagates its service properties, if 
+ * the adapted service properties are changed:
+ * 
+ * S1Impl provides S
+ * S1Adapter adapts S1Impl(S) to S2
+ * S3 depends on S2
+ * 
+ * So, when S1Impl service properties are changed, S1Adapter shall propagate the changed properties to S3.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@RunWith(PaxExam.class)
+public class AdapterWithPropagationTest extends TestBase {
+    public static interface S1 {}
+    
+    static class S1Impl implements S1 {
+        private Ensure m_ensure;
+        public S1Impl(Ensure e) {
+            m_ensure = e;
+        }
+        
+        public void start() {
+            m_ensure.step(1);
+        }
+    }
+    
+    public static interface S2 {}
+
+    static class S1Adapter implements S2 {
+        private Ensure m_ensure;
+        public S1Adapter(Ensure e) {
+            m_ensure = e;
+        }
+        
+        public void add(Map properties, S1 s1) {
+            Assert.assertTrue("bar".equals(properties.get("foo")));
+            m_ensure.step(2);
+        }
+        
+        public void change(Map properties, S1 s1) {   
+            Assert.assertTrue("bar2".equals(properties.get("foo")));
+            m_ensure.step(4);
+        }
+    }
+
+    static class S3 {
+        private final Ensure m_ensure;
+
+        public S3(Ensure e) {
+            m_ensure = e;
+        }
+                        
+        public void add(Map properties, S2 s2) {
+            Assert.assertTrue("bar".equals(properties.get("foo")));
+            m_ensure.step(3);
+        }
+        
+        public void change(Map properties, S2 s2) {
+            Assert.assertTrue("bar2".equals(properties.get("foo")));
+            m_ensure.step(5);
+        }
+    }
+    
+    @Test
+    public void testAdapterWithPropagation() {
+        DependencyManager m = new DependencyManager(context);
+        // helper class that ensures certain steps get executed in sequence
+        Ensure e = new Ensure(); 
+        
+        Dictionary s1Properties = new Hashtable();
+        s1Properties.put("foo", "bar");
+        Component s1 = m.createComponent()
+                .setImplementation(new S1Impl(e))
+                .setInterface(S1.class.getName(), s1Properties);
+        
+        Component s1Adapter = m.createAdapterService(S1.class, null, "add", "change", null)
+                .setInterface(S2.class.getName(), null)
+                .setImplementation(new S1Adapter(e));
+        
+        Component s3 = m.createComponent()
+                .setImplementation(new S3(e))
+                .add(m.createServiceDependency()
+                     .setService(S2.class)
+                     .setRequired(true)
+                     .setCallbacks("add", "change", null));
+                     
+              
+        m.add(s1);
+        m.add(s1Adapter);
+        m.add(s3);
+        
+        e.waitForStep(3, 5000);
+        
+        s1Properties = new Hashtable();
+        s1Properties.put("foo", "bar2");
+        s1.setServiceProperties(s1Properties);
+        
+        e.waitForStep(5, 5000);
+
+        m.clear();
+    }
+}



Mime
View raw message