aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [18/50] [abbrv] aries-rsa git commit: [DOSGI-229] Improve test coverage
Date Fri, 11 Mar 2016 19:43:17 GMT
[DOSGI-229] Improve test coverage


Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/c5ba7e40
Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/c5ba7e40
Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/c5ba7e40

Branch: refs/heads/master
Commit: c5ba7e405715addb385fd523b6c3cdd1ce44a88b
Parents: e5db6fd
Author: Christian Schneider <chris@die-schneider.net>
Authored: Thu Mar 10 19:54:17 2016 +0100
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Thu Mar 10 19:54:17 2016 +0100

----------------------------------------------------------------------
 .../cxf/dosgi/topologymanager/Activator.java    | 17 +----
 .../exporter/EndpointListenerNotifier.java      | 19 +-----
 .../exporter/TopologyManagerExport.java         | 15 +++--
 .../importer/ListenerHookImpl.java              | 15 +++--
 .../dosgi/topologymanager/ActivatorTest.java    | 67 ++++++++++++++++++++
 .../exporter/EndpointListenerNotifierTest.java  | 44 +++++++++++--
 .../exporter/TopologyManagerExportTest.java     | 31 +++++++--
 .../importer/ListenerHookImplTest.java          | 49 +++++++++++---
 .../importer/TopologyManagerImportTest.java     |  5 +-
 9 files changed, 194 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/c5ba7e40/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Activator.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Activator.java
b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Activator.java
index 46f98a7..7c0e035 100644
--- a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Activator.java
+++ b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Activator.java
@@ -28,8 +28,6 @@ import org.apache.cxf.dosgi.topologymanager.exporter.TopologyManagerExport;
 import org.apache.cxf.dosgi.topologymanager.importer.TopologyManagerImport;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.remoteserviceadmin.EndpointListener;
@@ -41,10 +39,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class Activator implements BundleActivator {
-    private static final String DOSGI_SERVICES = "(" + RemoteConstants.SERVICE_EXPORTED_INTERFACES
+ "=*)";
-    private static final String ENDPOINT_LISTENER_FILTER =
-        "(&(" + Constants.OBJECTCLASS + "=" + EndpointListener.class.getName() + ")"
-        + "(" + EndpointListener.ENDPOINT_LISTENER_SCOPE + "=*))";
+    static final String DOSGI_SERVICES = "(" + RemoteConstants.SERVICE_EXPORTED_INTERFACES
+ "=*)";
     private static final Logger LOG = LoggerFactory.getLogger(Activator.class);
 
     private TopologyManagerExport exportManager;
@@ -100,15 +95,7 @@ public class Activator implements BundleActivator {
         importManager.stop();
         rsaTracker.close();
     }
-    
-    public static Filter epListenerFilter(BundleContext bctx) {
-        try {
-            return bctx.createFilter(ENDPOINT_LISTENER_FILTER);
-        } catch (InvalidSyntaxException e) {
-            throw new RuntimeException("Unexpected exception creating filter", e);
-        }
-    }
-    
+
     public void exportExistingServices(BundleContext context) {
         try {
             // cast to String is necessary for compiling against OSGi core version >=
4.3

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/c5ba7e40/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
index 8f33add..cf0da0d 100644
--- a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
+++ b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
@@ -67,9 +67,6 @@ public class EndpointListenerNotifier {
      * @param endpoints the endpoints the listeners should be notified about
      */
     public void notifyListeners(NotifyType type, Collection<EndpointDescription> endpoints)
{
-        if (endpoints.isEmpty()) { // a little optimization to prevent unnecessary processing
-            return;
-        }
         for (EndpointListener listener : listeners.keySet()) {
             notifyListener(type, listener, listeners.get(listener), endpoints);
         }
@@ -97,20 +94,6 @@ public class EndpointListenerNotifier {
         }
     }
 
-    /**
-     * Retrieves an endpoint's properties as a Dictionary.
-     *
-     * @param endpoint an endpoint description
-     * @return endpoint properties (will never return null)
-     */
-    private static Dictionary<String, Object> getEndpointProperties(EndpointDescription
endpoint) {
-        if (endpoint == null || endpoint.getProperties() == null) {
-            return new Hashtable<String, Object>();
-        } else {
-            return new Hashtable<String, Object>(endpoint.getProperties());
-        }
-    }
-
     public static Set<Filter> getFiltersFromEndpointListenerScope(ServiceReference<EndpointListener>
sref) {
         Set<Filter> filters = new HashSet<Filter>();
         String[] scopes = StringPlus.parse(sref.getProperty(EndpointListener.ENDPOINT_LISTENER_SCOPE));
@@ -126,7 +109,7 @@ public class EndpointListenerNotifier {
 
     private static Set<Filter> getMatchingFilters(Set<Filter> filters, EndpointDescription
endpoint) {
         Set<Filter> matchingFilters = new HashSet<Filter>();
-        Dictionary<String, Object> dict = EndpointListenerNotifier.getEndpointProperties(endpoint);
+        Dictionary<String, Object> dict = new Hashtable<String, Object>(endpoint.getProperties());
         for (Filter filter : filters) {
             if (filter.match(dict)) {
                 LOG.debug("Filter {} matches endpoint {}", filter, dict);

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/c5ba7e40/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
index d7db57f..2b1a281 100644
--- a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
+++ b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.concurrent.Executor;
 
+import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.ServiceListener;
 import org.osgi.framework.ServiceReference;
@@ -97,21 +98,17 @@ public class TopologyManagerExport implements ServiceListener {
     public void export(final ServiceReference<?> sref) {
         execService.execute(new Runnable() {
             public void run() {
-                try {
-                    doExportService(sref);
-                } catch (Throwable t) {
-                    LOG.error("export failed", t);
-                }
+                doExport(sref);
             }
         });
     }
 
-    protected void doExportService(final ServiceReference<?> sref) {
+    private void doExport(final ServiceReference<?> sref) {
         LOG.debug("Exporting service {}", sref);
         endpointRepo.addService(sref); // mark for future export even if there are currently
no RSAs
         if (rsaSet.size() == 0) {
             LOG.error("No RemoteServiceAdmin available! Unable to export service from bundle
{}, interfaces: {}",
-                    sref.getBundle().getSymbolicName(),
+                    getSymbolicName(sref.getBundle()),
                     sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS));
             return;
         }
@@ -127,6 +124,10 @@ public class TopologyManagerExport implements ServiceListener {
         }
     }
 
+    private Object getSymbolicName(Bundle bundle) {
+        return bundle == null ? null : bundle.getSymbolicName();
+    }
+
     private void exportServiceUsingRemoteServiceAdmin(final ServiceReference<?> sref,
                                                       final RemoteServiceAdmin remoteServiceAdmin)
{
         // abort if the service was unregistered by the time we got here

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/c5ba7e40/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImpl.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImpl.java
b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImpl.java
index 6d0bee1..03ec9da 100644
--- a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImpl.java
+++ b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImpl.java
@@ -52,12 +52,15 @@ public class ListenerHookImpl implements ListenerHook {
 
     private final BundleContext bctx;
     private final ServiceInterestListener serviceInterestListener;
+    private final String frameworkUUID;
 
     public ListenerHookImpl(BundleContext bc, ServiceInterestListener serviceInterestListener)
{
         this.bctx = bc;
+        this.frameworkUUID = bctx.getProperty(Constants.FRAMEWORK_UUID);
         this.serviceInterestListener = serviceInterestListener;
     }
 
+    @Override
     public void added(Collection<ListenerInfo> listeners) {
         LOG.debug("added listeners {}", listeners);
         for (ListenerInfo listenerInfo : listeners) {
@@ -65,7 +68,7 @@ public class ListenerHookImpl implements ListenerHook {
 
             String className = FilterHelper.getObjectClass(listenerInfo.getFilter());
 
-            if (listenerInfo.getBundleContext().getBundle().equals(bctx.getBundle())) {
+            if (listenerInfo.getBundleContext().equals(bctx)) {
                 LOG.debug("ListenerHookImpl: skipping request from myself");
                 continue;
             }
@@ -79,11 +82,12 @@ public class ListenerHookImpl implements ListenerHook {
                 LOG.debug("Skipping import request for excluded class [{}]", className);
                 continue;
             }
-            String exFilter = extendFilter(listenerInfo.getFilter(), bctx);
+            String exFilter = extendFilter(listenerInfo.getFilter());
             serviceInterestListener.addServiceInterest(exFilter);
         }
     }
 
+    @Override
     public void removed(Collection<ListenerInfo> listeners) {
         LOG.debug("removed listeners {}", listeners);
 
@@ -91,7 +95,7 @@ public class ListenerHookImpl implements ListenerHook {
             LOG.debug("Filter {}", listenerInfo.getFilter());
 
             // TODO: determine if service was handled?
-            String exFilter = extendFilter(listenerInfo.getFilter(), bctx);
+            String exFilter = extendFilter(listenerInfo.getFilter());
             serviceInterestListener.removeServiceInterest(exFilter);
         }
     }
@@ -109,8 +113,7 @@ public class ListenerHookImpl implements ListenerHook {
         return false;
     }
 
-    static String extendFilter(String filter, BundleContext bctx) {
-        String uuid = bctx.getProperty(Constants.FRAMEWORK_UUID);
-        return "(&" + filter + "(!(" + RemoteConstants.ENDPOINT_FRAMEWORK_UUID + "="
+ uuid + ")))";
+    String extendFilter(String filter) {
+        return "(&" + filter + "(!(" + RemoteConstants.ENDPOINT_FRAMEWORK_UUID + "="
+ frameworkUUID + ")))";
     }
 }

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/c5ba7e40/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ActivatorTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ActivatorTest.java
b/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ActivatorTest.java
new file mode 100644
index 0000000..f33199c
--- /dev/null
+++ b/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ActivatorTest.java
@@ -0,0 +1,67 @@
+/**
+ * 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.cxf.dosgi.topologymanager;
+
+import org.apache.cxf.dosgi.topologymanager.exporter.TopologyManagerExport;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+import org.easymock.IMocksControl;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+
+public class ActivatorTest {
+
+    @Test
+    public void testStart() throws Exception {
+        IMocksControl c = EasyMock.createNiceControl();
+        BundleContext context = c.createMock(BundleContext.class);
+        EasyMock.expect(context.getProperty(Constants.FRAMEWORK_UUID)).andReturn("myid");
+        context.addServiceListener(EasyMock.isA(TopologyManagerExport.class));
+        EasyMock.expectLastCall();
+        final Capture<String> filter = EasyMock.newCapture();
+        EasyMock.expect(context.createFilter(EasyMock.capture(filter)))
+            .andAnswer(new IAnswer<Filter>() {
+                public Filter answer() throws Throwable {
+                    return FrameworkUtil.createFilter(filter.getValue());
+                }
+            }).times(2);
+        ServiceReference<?> sref = c.createMock(ServiceReference.class);
+        Bundle bundle = c.createMock(Bundle.class);
+        EasyMock.expect(sref.getBundle()).andReturn(bundle).anyTimes();
+        EasyMock.expect(context.getServiceReferences((String)null, Activator.DOSGI_SERVICES))
+            .andReturn(new ServiceReference[]{sref});
+
+        c.replay();
+        Activator activator = new Activator();
+        activator.start(context);
+        c.verify();
+        
+        c.reset();
+        c.replay();
+        activator.stop(context);
+        c.verify();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/c5ba7e40/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java
b/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java
index 0e60d3e..95d35d9 100644
--- a/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java
+++ b/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java
@@ -18,8 +18,6 @@
  */
 package org.apache.cxf.dosgi.topologymanager.exporter;
 
-
-
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Dictionary;
@@ -30,6 +28,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import static java.util.Arrays.asList;
+
 import org.apache.cxf.dosgi.topologymanager.exporter.EndpointListenerNotifier.NotifyType;
 import org.easymock.EasyMock;
 import org.junit.Assert;
@@ -52,24 +52,54 @@ import static org.junit.Assert.assertThat;
 public class EndpointListenerNotifierTest {
 
     @Test
-    public void testNotifyListenersOfRemovalIfAppropriate() throws InvalidSyntaxException
{
+    public void testNotifyListener() throws InvalidSyntaxException {
         EndpointDescription endpoint1 = createEndpoint("myClass");
         EndpointDescription endpoint2 = createEndpoint("notMyClass");
 
         // Expect listener to be called for endpoint1 but not for endpoint2 
-        EndpointListener epl = EasyMock.createMock(EndpointListener.class);
-        epl.endpointRemoved(EasyMock.eq(endpoint1), EasyMock.eq("(objectClass=myClass)"));
-        EasyMock.expectLastCall().once();
-        EasyMock.replay(epl);
+        EndpointListener epl = listenerExpects(endpoint1, "(objectClass=myClass)");
 
         EndpointRepository exportRepository = new EndpointRepository();
         EndpointListenerNotifier tm = new EndpointListenerNotifier(exportRepository);
 
+        EasyMock.replay(epl);
         List<EndpointDescription> endpoints = Arrays.asList(endpoint1, endpoint2);
         Set<Filter> filters = new HashSet<Filter>();
         filters.add(FrameworkUtil.createFilter("(objectClass=myClass)"));
+        tm.notifyListener(NotifyType.ADDED, epl, filters, endpoints);
         tm.notifyListener(NotifyType.REMOVED, epl, filters, endpoints);
+        EasyMock.verify(epl);
+    }
 
+    private EndpointListener listenerExpects(EndpointDescription endpoint, String filter)
{
+        EndpointListener epl = EasyMock.createStrictMock(EndpointListener.class);
+        epl.endpointAdded(EasyMock.eq(endpoint), EasyMock.eq(filter));
+        EasyMock.expectLastCall().once();
+        epl.endpointRemoved(EasyMock.eq(endpoint), EasyMock.eq(filter));
+        EasyMock.expectLastCall().once();
+        return epl;
+    }
+    
+    @Test
+    public void testNotifyListeners() throws InvalidSyntaxException {
+        EndpointDescription endpoint1 = createEndpoint("myClass");
+        
+        EndpointListener epl = EasyMock.createStrictMock(EndpointListener.class);
+        epl.endpointAdded(EasyMock.eq(endpoint1), EasyMock.eq("(objectClass=myClass)"));
+        EasyMock.expectLastCall().once();
+        epl.endpointRemoved(EasyMock.eq(endpoint1), EasyMock.eq("(objectClass=myClass)"));
+        EasyMock.expectLastCall().once();
+
+        EndpointRepository exportRepository = new EndpointRepository();
+        EndpointListenerNotifier tm = new EndpointListenerNotifier(exportRepository);
+
+        EasyMock.replay(epl);
+        Set<Filter> filters = new HashSet<Filter>();
+        filters.add(FrameworkUtil.createFilter("(objectClass=myClass)"));
+        tm.add(epl, filters);
+        tm.notifyListeners(NotifyType.ADDED, asList(endpoint1));
+        tm.notifyListeners(NotifyType.REMOVED, asList(endpoint1));
+        tm.remove(epl);
         EasyMock.verify(epl);
     }
     

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/c5ba7e40/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExportTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExportTest.java
b/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExportTest.java
index cb9dc36..1355925 100644
--- a/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExportTest.java
+++ b/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExportTest.java
@@ -18,11 +18,15 @@
  */
 package org.apache.cxf.dosgi.topologymanager.exporter;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.Executor;
 
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
+
 import org.apache.cxf.dosgi.topologymanager.exporter.EndpointListenerNotifier.NotifyType;
 import org.easymock.EasyMock;
 import org.easymock.IMocksControl;
@@ -37,6 +41,9 @@ import org.osgi.service.remoteserviceadmin.ExportRegistration;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
 import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin;
 
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expectLastCall;
+
 @SuppressWarnings({"rawtypes", "unchecked"})
 public class TopologyManagerExportTest {
 
@@ -50,13 +57,14 @@ public class TopologyManagerExportTest {
     public void testServiceExportUnexport() throws Exception {
         IMocksControl c = EasyMock.createControl();
         RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);
-        final EndpointListenerNotifier mockEpListenerNotifier = c.createMock(EndpointListenerNotifier.class);
+        final EndpointListenerNotifier notifier = c.createMock(EndpointListenerNotifier.class);
         final ServiceReference sref = createUserService(c);
         EndpointDescription epd = createEndpoint();
-        expectServiceExported(c, rsa, mockEpListenerNotifier, sref, epd);
+        expectServiceExported(c, rsa, notifier, sref, epd);
+        
         c.replay();
         EndpointRepository endpointRepo = new EndpointRepository();
-        endpointRepo.setNotifier(mockEpListenerNotifier);
+        endpointRepo.setNotifier(notifier);
         Executor executor = syncExecutor();
         TopologyManagerExport exportManager = new TopologyManagerExport(endpointRepo, executor);
         exportManager.add(rsa);
@@ -64,12 +72,23 @@ public class TopologyManagerExportTest {
         c.verify();
         
         c.reset();
-        mockEpListenerNotifier.notifyListeners(EasyMock.eq(NotifyType.REMOVED), 
-                                               EasyMock.eq(Collections.singletonList(epd)));
-        EasyMock.expectLastCall().once();
+        notifier.notifyListeners(eq(NotifyType.REMOVED), eq(singletonList(epd)));
+        expectLastCall().once();
         c.replay();
         exportManager.serviceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, sref));
         c.verify();
+        
+        c.reset();
+        c.replay();
+        exportManager.serviceChanged(new ServiceEvent(ServiceEvent.MODIFIED, sref));
+        c.verify();
+        
+        c.reset();
+        notifier.notifyListeners(eq(NotifyType.REMOVED), eq((Collection)emptyList()));
+        expectLastCall().once();
+        c.replay();
+        exportManager.remove(rsa);
+        c.verify();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/c5ba7e40/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImplTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImplTest.java
b/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImplTest.java
index e61b453..1e2f90c 100644
--- a/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImplTest.java
+++ b/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/ListenerHookImplTest.java
@@ -18,15 +18,19 @@
  */
 package org.apache.cxf.dosgi.topologymanager.importer;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Hashtable;
 
 import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
 import org.junit.Test;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.hooks.service.ListenerHook.ListenerInfo;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
 
 import static org.junit.Assert.assertFalse;
@@ -35,22 +39,51 @@ import static org.junit.Assert.assertTrue;
 public class ListenerHookImplTest {
 
     @Test
-    public void testUUIDFilterExtension() throws InvalidSyntaxException {
+    public void testExtendFilter() throws InvalidSyntaxException {
         String filter = "(a=b)";
-
-        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.expect(bc.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn("MyUUID").atLeastOnce();
-        EasyMock.replay(bc);
-
-        filter = ListenerHookImpl.extendFilter(filter, bc);
+        BundleContext bc = createBundleContext();
+        filter = new ListenerHookImpl(bc, null).extendFilter(filter);
 
         Filter f = FrameworkUtil.createFilter(filter);
 
         Dictionary<String, String> m = new Hashtable<String, String>();
         m.put("a", "b");
-
         assertTrue(filter + " filter must match as uuid is missing", f.match(m));
         m.put(RemoteConstants.ENDPOINT_FRAMEWORK_UUID, "MyUUID");
         assertFalse(filter + " filter must NOT match as uuid is the local one", f.match(m));
     }
+    
+    @Test
+    public void testAddedRemoved() throws InvalidSyntaxException {
+        IMocksControl c = EasyMock.createControl();
+        String filter = "(objectClass=My)";
+        BundleContext bc = createBundleContext();
+        BundleContext listenerBc = createBundleContext();
+        ServiceInterestListener serviceInterestListener = c.createMock(ServiceInterestListener.class);
+        ListenerHookImpl listenerHook = new ListenerHookImpl(bc, serviceInterestListener);
+
+        ListenerInfo listener = c.createMock(ListenerInfo.class);
+        EasyMock.expect(listener.getBundleContext()).andReturn(listenerBc);
+        EasyMock.expect(listener.getFilter()).andReturn(filter).atLeastOnce();
+        
+        // Main assertions
+        serviceInterestListener.addServiceInterest(listenerHook.extendFilter(filter));
+        EasyMock.expectLastCall();
+        serviceInterestListener.removeServiceInterest(listenerHook.extendFilter(filter));
+        EasyMock.expectLastCall();
+
+        Collection<ListenerInfo> listeners = Collections.singletonList(listener);
+        
+        c.replay();
+        listenerHook.added(listeners);
+        listenerHook.removed(listeners);
+        c.verify();
+    }
+
+    private BundleContext createBundleContext() {
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.expect(bc.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn("MyUUID").atLeastOnce();
+        EasyMock.replay(bc);
+        return bc;
+    }
 }

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/c5ba7e40/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImportTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImportTest.java
b/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImportTest.java
index 01a9600..00be969 100644
--- a/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImportTest.java
+++ b/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/importer/TopologyManagerImportTest.java
@@ -27,6 +27,7 @@ import org.easymock.IAnswer;
 import org.easymock.IMocksControl;
 import org.junit.Test;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 import org.osgi.service.remoteserviceadmin.ImportReference;
@@ -48,13 +49,15 @@ public class TopologyManagerImportTest {
 
         final Semaphore sema = new Semaphore(0);
 
-        BundleContext bc = c.createMock(BundleContext.class);
         ServiceRegistration sreg = c.createMock(ServiceRegistration.class);
         sreg.unregister();
         EasyMock.expectLastCall().once();
+        
+        BundleContext bc = c.createMock(BundleContext.class);
         EasyMock.expect(bc.registerService(EasyMock.anyObject(Class.class),
                                            EasyMock.anyObject(),
                                            (Dictionary)EasyMock.anyObject())).andReturn(sreg).anyTimes();
+        EasyMock.expect(bc.getProperty(Constants.FRAMEWORK_UUID)).andReturn("myid");
 
         EndpointDescription endpoint = c.createMock(EndpointDescription.class);
         RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);


Mime
View raw message