You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2016/03/12 13:46:23 UTC

aries-rsa git commit: Improve test

Repository: aries-rsa
Updated Branches:
  refs/heads/master 4eebdd6e5 -> 60e9ab9b3


Improve test


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

Branch: refs/heads/master
Commit: 60e9ab9b30d97db68deb7cb4a8692f6873d4f69b
Parents: 4eebdd6
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Sat Mar 12 13:46:16 2016 +0100
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Sat Mar 12 13:46:16 2016 +0100

----------------------------------------------------------------------
 .../dosgi/discovery/zookeeper/Activator.java    |   2 +-
 .../discovery/zookeeper/ZooKeeperDiscovery.java |  62 ++++++++----
 .../PublishingEndpointListenerFactory.java      |  13 ++-
 .../subscribe/InterfaceMonitorManager.java      |   8 +-
 .../dosgi/discovery/zookeeper/util/Utils.java   |  56 ----------
 .../zookeeper/ZookeeperDiscoveryTest.java       |  52 ++++++++++
 .../subscribe/InterfaceMonitorManagerTest.java  | 101 +++++++------------
 .../discovery/zookeeper/util/UtilsTest.java     |  24 -----
 8 files changed, 144 insertions(+), 174 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/60e9ab9b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java
----------------------------------------------------------------------
diff --git a/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java
index cbbea58..1e6c551 100644
--- a/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java
+++ b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java
@@ -33,7 +33,7 @@ public class Activator implements BundleActivator {
     public synchronized void start(BundleContext bc) throws Exception {
         zkd = new ZooKeeperDiscovery(bc);
         Dictionary<String, String> props = new Hashtable<String, String>();
-        props.put(Constants.SERVICE_PID, "org.apache.cxf.dosgi.discovery.zookeeper");
+        props.put(Constants.SERVICE_PID, "org.apache.aries.rsa.discovery.zookeeper");
         bc.registerService(ManagedService.class.getName(), zkd, props);
     }
 

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/60e9ab9b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
----------------------------------------------------------------------
diff --git a/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
index 33e2da4..6157d2a 100644
--- a/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
+++ b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
@@ -20,11 +20,13 @@ package org.apache.cxf.dosgi.discovery.zookeeper;
 
 import java.io.IOException;
 import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.cxf.dosgi.discovery.zookeeper.publish.PublishingEndpointListenerFactory;
 import org.apache.cxf.dosgi.discovery.zookeeper.subscribe.EndpointListenerTracker;
 import org.apache.cxf.dosgi.discovery.zookeeper.subscribe.InterfaceMonitorManager;
-import org.apache.cxf.dosgi.discovery.zookeeper.util.Utils;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
@@ -57,26 +59,16 @@ public class ZooKeeperDiscovery implements Watcher, ManagedService {
         this.bctx = bctx;
     }
 
-    private void setDefaults(Dictionary<String, String> configuration) {
-        Utils.setDefault(configuration, "zookeeper.host", "localhost");
-        Utils.setDefault(configuration, "zookeeper.port", "2181");
-        Utils.setDefault(configuration, "zookeeper.timeout", "3000");
-    }
-
-    @SuppressWarnings("unchecked")
     public synchronized void updated(Dictionary<String, ?> configuration) throws ConfigurationException {
         LOG.debug("Received configuration update for Zookeeper Discovery: {}", configuration);
-        if (configuration != null) {
-            setDefaults((Dictionary<String, String>)configuration);
-        }
         // make changes only if config actually changed, to prevent unnecessary ZooKeeper reconnections
-        if (!Utils.toMap(configuration).equals(Utils.toMap(curConfiguration))) {
+        if (!ZooKeeperDiscovery.toMap(configuration).equals(ZooKeeperDiscovery.toMap(curConfiguration))) {
             stop(false);
             curConfiguration = configuration;
             // config is null if it doesn't exist, is being deleted or has not yet been loaded
             // in which case we just stop running
-            if (configuration != null) {
-                createZooKeeper(configuration);
+            if (!closed && configuration != null) {
+                createZookeeper(configuration);
             }
         }
     }
@@ -123,13 +115,7 @@ public class ZooKeeperDiscovery implements Watcher, ManagedService {
         }
     }
 
-    private synchronized void createZooKeeper(Dictionary<String, ?> configuration) {
-        if (closed) {
-            return;
-        }
-        String host = configuration.get("zookeeper.host").toString();
-        String port = configuration.get("zookeeper.port").toString();
-        int timeout = Integer.parseInt(configuration.get("zookeeper.timeout").toString());
+    protected void createZooKeeper(String host, String port, int timeout) {
         LOG.debug("ZooKeeper configuration: connecting to {}:{} with timeout {}",
                 new Object[]{host, port, timeout});
         try {
@@ -153,7 +139,7 @@ public class ZooKeeperDiscovery implements Watcher, ManagedService {
         case Expired:
             LOG.info("Connection to ZooKeeper expired. Trying to create a new connection");
             stop(false);
-            createZooKeeper(curConfiguration);
+            createZookeeper(curConfiguration);
             break;
 
         default:
@@ -161,4 +147,36 @@ public class ZooKeeperDiscovery implements Watcher, ManagedService {
             break;
         }
     }
+
+    private void createZookeeper(Dictionary<String, ?> config) {
+        String host = (String)getWithDefault(config, "zookeeper.host", "localhost");
+        String port = (String)getWithDefault(config, "zookeeper.port", "2181");
+        int timeout = Integer.parseInt((String)getWithDefault(config, "zookeeper.timeout", "3000"));
+        createZooKeeper(host, port, timeout);
+    }
+    
+    public Object getWithDefault(Dictionary<String, ?> config, String key, Object defaultValue) {
+        Object value = config.get(key);
+        return value != null ? value : defaultValue;
+    }
+    
+    /**
+     * Converts the given Dictionary to a Map.
+     *
+     * @param dict a dictionary
+     * @param <K> the key type
+     * @param <V> the value type
+     * @return the converted map, or an empty map if the given dictionary is null
+     */
+    public static <K, V> Map<K, V> toMap(Dictionary<K, V> dict) {
+        Map<K, V> map = new HashMap<K, V>();
+        if (dict != null) {
+            Enumeration<K> keys = dict.keys();
+            while (keys.hasMoreElements()) {
+                K key = keys.nextElement();
+                map.put(key, dict.get(key));
+            }
+        }
+        return map;
+    }
 }

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/60e9ab9b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListenerFactory.java
----------------------------------------------------------------------
diff --git a/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListenerFactory.java b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListenerFactory.java
index 76d79eb..bbb72d7 100644
--- a/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListenerFactory.java
+++ b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/publish/PublishingEndpointListenerFactory.java
@@ -24,7 +24,6 @@ import java.util.Hashtable;
 import java.util.List;
 
 import org.apache.cxf.dosgi.discovery.zookeeper.ZooKeeperDiscovery;
-import org.apache.cxf.dosgi.discovery.zookeeper.util.Utils;
 import org.apache.zookeeper.ZooKeeper;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -74,13 +73,13 @@ public class PublishingEndpointListenerFactory implements ServiceFactory<Publish
 
     public synchronized void start() {
         Dictionary<String, String> props = new Hashtable<String, String>();
-        props.put(EndpointListener.ENDPOINT_LISTENER_SCOPE,
-                  "(&(" + Constants.OBJECTCLASS + "=*)(" + RemoteConstants.ENDPOINT_FRAMEWORK_UUID
-                  + "=" + Utils.getUUID(bctx) + "))");
+        props.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, 
+                  String.format("(&(%s=*)(%s=))", Constants.OBJECTCLASS, 
+                                RemoteConstants.ENDPOINT_FRAMEWORK_UUID, getUUID(bctx)));
         props.put(ZooKeeperDiscovery.DISCOVERY_ZOOKEEPER_ID, "true");
         serviceRegistration = bctx.registerService(EndpointListener.class.getName(), this, props);
     }
-
+    
     public synchronized void stop() {
         if (serviceRegistration != null) {
             serviceRegistration.unregister();
@@ -93,6 +92,10 @@ public class PublishingEndpointListenerFactory implements ServiceFactory<Publish
             listeners.clear();
         }
     }
+    
+    private String getUUID(BundleContext bc) {
+        return bc.getProperty(Constants.FRAMEWORK_UUID);
+    }
 
     /**
      * Only for the test case!

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/60e9ab9b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitorManager.java
----------------------------------------------------------------------
diff --git a/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitorManager.java b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitorManager.java
index 7da98de..1a23a93 100644
--- a/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitorManager.java
+++ b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitorManager.java
@@ -27,7 +27,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CopyOnWriteArrayList;
 
-
+import org.apache.aries.rsa.util.StringPlus;
 import org.apache.cxf.dosgi.discovery.zookeeper.ZooKeeperDiscovery;
 import org.apache.cxf.dosgi.discovery.zookeeper.util.Utils;
 import org.apache.zookeeper.ZooKeeper;
@@ -79,7 +79,7 @@ public class InterfaceMonitorManager {
         if (LOG.isDebugEnabled()) {
             LOG.debug("updated EndpointListener properties: {}", Utils.getProperties(endpointListener));
         }
-        for (String scope : Utils.getScopes(endpointListener)) {
+        for (String scope : getScopes(endpointListener)) {
             String objClass = Utils.getObjectClass(scope);
             LOG.debug("Adding interest in scope {}, objectClass {}", scope, objClass);
             addInterest(endpointListener, scope, objClass);
@@ -231,4 +231,8 @@ public class InterfaceMonitorManager {
     protected synchronized Map<ServiceReference<EndpointListener>, List<String>> getEndpointListenerScopes() {
         return endpointListenerScopes;
     }
+
+    protected List<String> getScopes(ServiceReference<?> sref) {
+        return Utils.removeEmpty(StringPlus.normalize(sref.getProperty(EndpointListener.ENDPOINT_LISTENER_SCOPE)));
+    }
 }

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/60e9ab9b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/util/Utils.java
----------------------------------------------------------------------
diff --git a/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/util/Utils.java b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/util/Utils.java
index 62f2268..d732a62 100644
--- a/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/util/Utils.java
+++ b/discovery/zookeeper/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/util/Utils.java
@@ -19,19 +19,13 @@
 package org.apache.cxf.dosgi.discovery.zookeeper.util;
 
 import java.util.ArrayList;
-import java.util.Dictionary;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.UUID;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.aries.rsa.util.StringPlus;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
-import org.osgi.service.remoteserviceadmin.EndpointListener;
 
 public final class Utils {
 
@@ -63,56 +57,6 @@ public final class Utils {
         return result;
     }
 
-    public static List<String> getScopes(ServiceReference<?> sref) {
-        return removeEmpty(StringPlus.normalize(sref.getProperty(EndpointListener.ENDPOINT_LISTENER_SCOPE)));
-    }
-
-    // copied from the DSW OSGiUtils class
-    public static String getUUID(BundleContext bc) {
-        synchronized ("org.osgi.framework.uuid") {
-            String uuid = bc.getProperty("org.osgi.framework.uuid");
-            if (uuid == null) {
-                uuid = UUID.randomUUID().toString();
-                System.setProperty("org.osgi.framework.uuid", uuid);
-            }
-            return uuid;
-        }
-    }
-
-    /**
-     * Puts the given key-value pair in the given dictionary if the key does not
-     * already exist in it or if its existing value is null.
-     *
-     * @param dict a dictionary
-     * @param key the key
-     * @param value the default value to set
-     */
-    public static void setDefault(Dictionary<String, String> dict, String key, String value) {
-        if (dict.get(key) == null) {
-            dict.put(key, value);
-        }
-    }
-
-    /**
-     * Converts the given Dictionary to a Map.
-     *
-     * @param dict a dictionary
-     * @param <K> the key type
-     * @param <V> the value type
-     * @return the converted map, or an empty map if the given dictionary is null
-     */
-    public static <K, V> Map<K, V> toMap(Dictionary<K, V> dict) {
-        Map<K, V> map = new HashMap<K, V>();
-        if (dict != null) {
-            Enumeration<K> keys = dict.keys();
-            while (keys.hasMoreElements()) {
-                K key = keys.nextElement();
-                map.put(key, dict.get(key));
-            }
-        }
-        return map;
-    }
-
     public static String getObjectClass(String scope) {
         Matcher m = OBJECTCLASS_PATTERN.matcher(scope);
         return m.matches() ? m.group(1) : null;

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/60e9ab9b/discovery/zookeeper/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ZookeeperDiscoveryTest.java
----------------------------------------------------------------------
diff --git a/discovery/zookeeper/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ZookeeperDiscoveryTest.java b/discovery/zookeeper/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ZookeeperDiscoveryTest.java
new file mode 100644
index 0000000..6fd0aa1
--- /dev/null
+++ b/discovery/zookeeper/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ZookeeperDiscoveryTest.java
@@ -0,0 +1,52 @@
+package org.apache.cxf.dosgi.discovery.zookeeper;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+import org.junit.Assert;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ConfigurationException;
+
+
+public class ZookeeperDiscoveryTest {
+
+    @Test
+    public void testDefaults() throws ConfigurationException {
+        IMocksControl c = EasyMock.createControl();
+        BundleContext bctx = c.createMock(BundleContext.class);
+        ZooKeeperDiscovery zkd = new ZooKeeperDiscovery(bctx) {
+            @Override
+            protected void createZooKeeper(String host, String port, int timeout) {
+                Assert.assertEquals("localhost", host);
+                Assert.assertEquals("2181", port);
+                Assert.assertEquals(3000, timeout);
+            }  
+        };
+        
+        Dictionary<String, Object> configuration = new Hashtable<String, Object>();
+        zkd.updated(configuration);
+    }
+    
+    @Test
+    public void testConfig() throws ConfigurationException {
+        IMocksControl c = EasyMock.createControl();
+        BundleContext bctx = c.createMock(BundleContext.class);
+        ZooKeeperDiscovery zkd = new ZooKeeperDiscovery(bctx) {
+            @Override
+            protected void createZooKeeper(String host, String port, int timeout) {
+                Assert.assertEquals("myhost", host);
+                Assert.assertEquals("1", port);
+                Assert.assertEquals(1000, timeout);
+            }  
+        };
+        
+        Dictionary<String, Object> configuration = new Hashtable<String, Object>();
+        configuration.put("zookeeper.host", "myhost");
+        configuration.put("zookeeper.port", "1");
+        configuration.put("zookeeper.timeout", "1000");
+        zkd.updated(configuration);
+    }
+}

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/60e9ab9b/discovery/zookeeper/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitorManagerTest.java
----------------------------------------------------------------------
diff --git a/discovery/zookeeper/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitorManagerTest.java b/discovery/zookeeper/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitorManagerTest.java
index 5e5cb63..01aea63 100644
--- a/discovery/zookeeper/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitorManagerTest.java
+++ b/discovery/zookeeper/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/InterfaceMonitorManagerTest.java
@@ -18,7 +18,8 @@
  */
 package org.apache.cxf.dosgi.discovery.zookeeper.subscribe;
 
-import java.util.ArrayList;
+import static org.junit.Assert.assertEquals;
+
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -32,108 +33,80 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.remoteserviceadmin.EndpointListener;
 
-import static org.junit.Assert.assertEquals;
-
 public class InterfaceMonitorManagerTest {
 
     @Test
     public void testEndpointListenerTrackerCustomizer() {
         IMocksControl c = EasyMock.createNiceControl();
-
         BundleContext ctx = c.createMock(BundleContext.class);
+        ServiceReference<EndpointListener> sref = createService(c);
+        ServiceReference<EndpointListener> sref2 = createService(c);
         ZooKeeper zk = c.createMock(ZooKeeper.class);
-
-        @SuppressWarnings("unchecked")
-        ServiceReference<EndpointListener> sref = c.createMock(ServiceReference.class);
-        @SuppressWarnings("unchecked")
-        ServiceReference<EndpointListener> sref2 = c.createMock(ServiceReference.class);
-
-        final Map<String, ?> p = new HashMap<String, Object>();
-
-        EasyMock.expect(sref.getPropertyKeys()).andAnswer(new IAnswer<String[]>() {
-            public String[] answer() throws Throwable {
-                return p.keySet().toArray(new String[p.size()]);
-            }
-        }).anyTimes();
-
-        EasyMock.expect(sref.getProperty((String)EasyMock.anyObject())).andAnswer(new IAnswer<Object>() {
-            public Object answer() throws Throwable {
-                String key = (String)(EasyMock.getCurrentArguments()[0]);
-                return p.get(key);
-            }
-        }).anyTimes();
-
-        EasyMock.expect(sref2.getPropertyKeys()).andAnswer(new IAnswer<String[]>() {
-            public String[] answer() throws Throwable {
-                return p.keySet().toArray(new String[p.size()]);
-            }
-        }).anyTimes();
-
-        EasyMock.expect(sref2.getProperty((String)EasyMock.anyObject())).andAnswer(new IAnswer<Object>() {
-            public Object answer() throws Throwable {
-                String key = (String)(EasyMock.getCurrentArguments()[0]);
-                return p.get(key);
-            }
-        }).anyTimes();
-
-        final List<IMocksControl> controls = new ArrayList<IMocksControl>();
-
         InterfaceMonitorManager eltc = new InterfaceMonitorManager(ctx, zk);
 
         c.replay();
 
         // sref has no scope -> nothing should happen
-
         assertEquals(0, eltc.getEndpointListenerScopes().size());
         assertEquals(0, eltc.getInterests().size());
 
-        //p.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, );
-
         eltc.addInterest(sref, "(objectClass=mine)", "mine");
-
+        assertScopeIncludes(sref, eltc);
         assertEquals(1, eltc.getEndpointListenerScopes().size());
-        assertEquals(1, eltc.getEndpointListenerScopes().get(sref).size());
-        assertEquals("(objectClass=mine)", eltc.getEndpointListenerScopes().get(sref).get(0));
         assertEquals(1, eltc.getInterests().size());
 
         eltc.addInterest(sref, "(objectClass=mine)", "mine");
-
+        assertScopeIncludes(sref, eltc);
         assertEquals(1, eltc.getEndpointListenerScopes().size());
-        assertEquals(1, eltc.getEndpointListenerScopes().get(sref).size());
-        assertEquals("(objectClass=mine)", eltc.getEndpointListenerScopes().get(sref).get(0));
         assertEquals(1, eltc.getInterests().size());
 
         eltc.addInterest(sref2, "(objectClass=mine)", "mine");
-
+        assertScopeIncludes(sref, eltc);
+        assertScopeIncludes(sref2, eltc);
         assertEquals(2, eltc.getEndpointListenerScopes().size());
-        assertEquals(1, eltc.getEndpointListenerScopes().get(sref).size());
-        assertEquals(1, eltc.getEndpointListenerScopes().get(sref2).size());
-        assertEquals("(objectClass=mine)", eltc.getEndpointListenerScopes().get(sref).get(0));
-        assertEquals("(objectClass=mine)", eltc.getEndpointListenerScopes().get(sref2).get(0));
         assertEquals(1, eltc.getInterests().size());
 
         eltc.removeInterest(sref);
-
+        assertScopeIncludes(sref2, eltc);
         assertEquals(1, eltc.getEndpointListenerScopes().size());
-        assertEquals(1, eltc.getEndpointListenerScopes().get(sref2).size());
-        assertEquals("(objectClass=mine)", eltc.getEndpointListenerScopes().get(sref2).get(0));
         assertEquals(1, eltc.getInterests().size());
 
         eltc.removeInterest(sref);
-
+        assertScopeIncludes(sref2, eltc);
         assertEquals(1, eltc.getEndpointListenerScopes().size());
-        assertEquals(1, eltc.getEndpointListenerScopes().get(sref2).size());
-        assertEquals("(objectClass=mine)", eltc.getEndpointListenerScopes().get(sref2).get(0));
         assertEquals(1, eltc.getInterests().size());
 
         eltc.removeInterest(sref2);
-
         assertEquals(0, eltc.getEndpointListenerScopes().size());
         assertEquals(0, eltc.getInterests().size());
 
         c.verify();
-        for (IMocksControl control : controls) {
-            control.verify();
-        }
     }
+
+    @SuppressWarnings("unchecked")
+    private ServiceReference<EndpointListener> createService(IMocksControl c) {
+        final Map<String, ?> p = new HashMap<String, Object>();
+        ServiceReference<EndpointListener> sref = c.createMock(ServiceReference.class);
+        EasyMock.expect(sref.getPropertyKeys()).andAnswer(new IAnswer<String[]>() {
+            public String[] answer() throws Throwable {
+                return p.keySet().toArray(new String[p.size()]);
+            }
+        }).anyTimes();
+
+        EasyMock.expect(sref.getProperty((String)EasyMock.anyObject())).andAnswer(new IAnswer<Object>() {
+            public Object answer() throws Throwable {
+                String key = (String)(EasyMock.getCurrentArguments()[0]);
+                return p.get(key);
+            }
+        }).anyTimes();
+        return sref;
+    }
+
+    private void assertScopeIncludes(ServiceReference<EndpointListener> sref, InterfaceMonitorManager eltc) {
+        List<String> srefScope = eltc.getEndpointListenerScopes().get(sref);
+        assertEquals(1, srefScope.size());
+        assertEquals("(objectClass=mine)", srefScope.get(0));
+        
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/60e9ab9b/discovery/zookeeper/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/util/UtilsTest.java
----------------------------------------------------------------------
diff --git a/discovery/zookeeper/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/util/UtilsTest.java b/discovery/zookeeper/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/util/UtilsTest.java
index de4d9af..1f72b88 100644
--- a/discovery/zookeeper/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/util/UtilsTest.java
+++ b/discovery/zookeeper/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/util/UtilsTest.java
@@ -18,13 +18,6 @@
  */
 package org.apache.cxf.dosgi.discovery.zookeeper.util;
 
-import java.util.List;
-
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.remoteserviceadmin.EndpointListener;
-
 import junit.framework.TestCase;
 
 public class UtilsTest extends TestCase {
@@ -38,22 +31,5 @@ public class UtilsTest extends TestCase {
         assertEquals(Utils.PATH_PREFIX, Utils.getZooKeeperPath(""));
     }
 
-    public void testGetScopes() {
-        IMocksControl c = EasyMock.createNiceControl();
-
-        String[] scopes = new String[]{"myScope=test", ""};
-
-        @SuppressWarnings("unchecked")
-        ServiceReference<EndpointListener> sref = c.createMock(ServiceReference.class);
-        EasyMock.expect(sref.getProperty(EasyMock.eq(EndpointListener.ENDPOINT_LISTENER_SCOPE)))
-            .andReturn(scopes).anyTimes();
 
-        c.replay();
-
-        List<String> ret = Utils.getScopes(sref);
-
-        c.verify();
-        assertEquals(1, ret.size());
-        assertEquals(scopes[0], ret.get(0));
-    }
 }