You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2009/12/05 19:14:58 UTC

svn commit: r887567 - /felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AbstractServiceDependencyTest.java

Author: pderop
Date: Sat Dec  5 18:14:58 2009
New Revision: 887567

URL: http://svn.apache.org/viewvc?rev=887567&view=rev
Log:
added new test to show up a regression regarding ServiceImpl.unconfigureServices() method

Added:
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AbstractServiceDependencyTest.java

Added: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AbstractServiceDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AbstractServiceDependencyTest.java?rev=887567&view=auto
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AbstractServiceDependencyTest.java (added)
+++ felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/AbstractServiceDependencyTest.java Sat Dec  5 18:14:58 2009
@@ -0,0 +1,112 @@
+/*
+ * 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;
+
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import junit.framework.Assert;
+
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.service.Service;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.BundleContext;
+
+@RunWith(JUnit4TestRunner.class)
+public class AbstractServiceDependencyTest {
+    @Configuration
+    public static Option[] configuration() {
+        return options(
+            provision(
+                mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").version("4.2.0"),
+                mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject()
+            )
+        );
+    }    
+    
+    @Test
+    public void testAbstractClassDependency(BundleContext context) {
+        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
+        Service sp = m.createService().setImplementation(new ServiceProvider(e)).setInterface(ServiceAbstract.class.getName(), null);
+        Service sc = m.createService().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) {
+            Assert.assertEquals(m_service, service);
+            m_ensure.step(6);
+        }
+    }
+}