aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject aries-rsa git commit: [ARIES-1763] Move old interface out of notifier
Date Fri, 02 Feb 2018 06:14:35 GMT
Repository: aries-rsa
Updated Branches:
  refs/heads/master ba7a6a047 -> 094996dc0


[ARIES-1763] Move old interface out of notifier


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

Branch: refs/heads/master
Commit: 094996dc0ce29bc8ab79357178253c6755906ed9
Parents: ba7a6a0
Author: Christian Schneider <cschneid@adobe.com>
Authored: Fri Feb 2 07:14:30 2018 +0100
Committer: Christian Schneider <cschneid@adobe.com>
Committed: Fri Feb 2 07:14:30 2018 +0100

----------------------------------------------------------------------
 .../aries/rsa/topologymanager/Activator.java    | 12 ++--
 .../exporter/EndpointListenerAdapter.java       |  2 +-
 .../exporter/EndpointListenerNotifier.java      | 12 +---
 .../exporter/EndpointListenerNotifierTest.java  | 75 +++++++++-----------
 4 files changed, 42 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/094996dc/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/Activator.java
----------------------------------------------------------------------
diff --git a/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/Activator.java
b/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/Activator.java
index e67b5a1..70d1111 100644
--- a/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/Activator.java
+++ b/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/Activator.java
@@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.aries.rsa.spi.ExportPolicy;
 import org.apache.aries.rsa.topologymanager.exporter.DefaultExportPolicy;
+import org.apache.aries.rsa.topologymanager.exporter.EndpointListenerAdapter;
 import org.apache.aries.rsa.topologymanager.exporter.EndpointListenerNotifier;
 import org.apache.aries.rsa.topologymanager.exporter.EndpointRepository;
 import org.apache.aries.rsa.topologymanager.exporter.TopologyManagerExport;
@@ -158,7 +159,8 @@ public class Activator implements BundleActivator {
         @Override
         public EndpointListener addingService(ServiceReference<EndpointListener> reference)
{
             EndpointListener listener = super.addingService(reference);
-            notifier.add(listener, EndpointListenerNotifier.filtersFromEL(reference));
+            EndpointListenerAdapter adapter = new EndpointListenerAdapter(listener);
+            notifier.add(adapter, EndpointListenerNotifier.filtersFromEL(reference));
             return listener;
         }
 
@@ -166,13 +168,15 @@ public class Activator implements BundleActivator {
         public void modifiedService(ServiceReference<EndpointListener> reference,
                                     EndpointListener listener) {
             super.modifiedService(reference, listener);
-            notifier.add(listener, EndpointListenerNotifier.filtersFromEL(reference));
+            EndpointListenerAdapter adapter = new EndpointListenerAdapter(listener);
+            notifier.add(adapter, EndpointListenerNotifier.filtersFromEL(reference));
         }
 
         @Override
         public void removedService(ServiceReference<EndpointListener> reference,
                                    EndpointListener listener) {
-            notifier.remove(listener);
+            EndpointListenerAdapter adapter = new EndpointListenerAdapter(listener);
+            notifier.remove(adapter);
             super.removedService(reference, listener);
         }
     }
@@ -192,8 +196,8 @@ public class Activator implements BundleActivator {
         @Override
         public void modifiedService(ServiceReference<EndpointEventListener> reference,
                 EndpointEventListener listener) {
-            super.modifiedService(reference, listener);
             notifier.add(listener, EndpointListenerNotifier.filtersFromEEL(reference));
+            super.modifiedService(reference, listener);
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/094996dc/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerAdapter.java
----------------------------------------------------------------------
diff --git a/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerAdapter.java
b/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerAdapter.java
index 0e0e1cc..7b15d0a 100644
--- a/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerAdapter.java
+++ b/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerAdapter.java
@@ -28,7 +28,7 @@ import org.osgi.service.remoteserviceadmin.EndpointListener;
  * EndpointEventListener interface
  */
 @SuppressWarnings("deprecation")
-class EndpointListenerAdapter implements EndpointEventListener {
+public class EndpointListenerAdapter implements EndpointEventListener {
     private EndpointListener epl;
 
     public EndpointListenerAdapter(EndpointListener epl) {

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/094996dc/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerNotifier.java
----------------------------------------------------------------------
diff --git a/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerNotifier.java
b/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerNotifier.java
index 7864bb4..827fe6a 100644
--- a/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerNotifier.java
+++ b/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerNotifier.java
@@ -74,17 +74,7 @@ public class EndpointListenerNotifier implements EndpointEventListener
{
         return filters;
     }
 
-    public void add(EndpointListener ep, Set<Filter> filters) {
-        LOG.debug("new EndpointListener detected");
-        EndpointListenerAdapter adapter = new EndpointListenerAdapter(ep);
-        listeners.put(adapter, filters);
-        for (EndpointDescription endpoint : endpointRepo.getAllEndpoints()) {
-            EndpointEvent event = new EndpointEvent(EndpointEvent.ADDED, endpoint);
-            notifyListener(event, adapter, filters);
-        }
-    }
-    
-    public void remove(EndpointListener ep) {
+    public void removre(EndpointListener ep) {
         LOG.debug("EndpointListener modified");
         EndpointListenerAdapter adapter = new EndpointListenerAdapter(ep);
         listeners.remove(adapter);

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/094996dc/topology-manager/src/test/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerNotifierTest.java
----------------------------------------------------------------------
diff --git a/topology-manager/src/test/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerNotifierTest.java
b/topology-manager/src/test/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerNotifierTest.java
index ccbeecf..3b88abd 100644
--- a/topology-manager/src/test/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerNotifierTest.java
+++ b/topology-manager/src/test/java/org/apache/aries/rsa/topologymanager/exporter/EndpointListenerNotifierTest.java
@@ -18,6 +18,11 @@
  */
 package org.apache.aries.rsa.topologymanager.exporter;
 
+import static java.util.Arrays.asList;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.newCapture;
+import static org.hamcrest.Matchers.samePropertyValuesAs;
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThat;
@@ -31,8 +36,12 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
+import org.easymock.Capture;
+import org.easymock.CaptureType;
 import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkUtil;
@@ -40,69 +49,48 @@ import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 import org.osgi.service.remoteserviceadmin.EndpointEvent;
-import org.osgi.service.remoteserviceadmin.EndpointListener;
+import org.osgi.service.remoteserviceadmin.EndpointEventListener;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
 
 @SuppressWarnings({
-    "rawtypes", "unchecked", "deprecation"
+    "rawtypes", "unchecked",
    })
 public class EndpointListenerNotifierTest {
+    
+    @Before
+    public void before() {
+    }
 
     @Test
     public void testNotifyListener() throws InvalidSyntaxException {
+        IMocksControl c = EasyMock.createControl();
+        EndpointEventListener epl = c.createMock(EndpointEventListener.class);
+        Capture<EndpointEvent> capturedEvents = newCapture(CaptureType.ALL);
+        Capture<String> capturedFilters = newCapture(CaptureType.ALL);
+        epl.endpointChanged(capture(capturedEvents), capture(capturedFilters));
+        expectLastCall().anyTimes();
+        
         EndpointDescription endpoint1 = createEndpoint("myClass");
         EndpointDescription endpoint2 = createEndpoint("notMyClass");
 
-        // Expect listener to be called for endpoint1 but not for endpoint2 
-        EndpointListener epl = listenerExpects(endpoint1, "(objectClass=myClass)");
-
         EndpointRepository exportRepository = new EndpointRepository();
         EndpointListenerNotifier notifier = new EndpointListenerNotifier(exportRepository);
 
-        EasyMock.replay(epl);
-        Set<Filter> filters = new HashSet<Filter>();
-        filters.add(FrameworkUtil.createFilter("(objectClass=myClass)"));
-        notifier.add(epl, filters);
+        c.replay();
+        Filter filter = FrameworkUtil.createFilter("(objectClass=myClass)");
+        notifier.add(epl, new HashSet(asList(filter)));
         notifier.endpointChanged(new EndpointEvent(EndpointEvent.ADDED, endpoint1), null);
         notifier.endpointChanged(new EndpointEvent(EndpointEvent.ADDED, endpoint2), null);
         notifier.endpointChanged(new EndpointEvent(EndpointEvent.REMOVED, endpoint1), null);
         notifier.endpointChanged(new EndpointEvent(EndpointEvent.REMOVED, endpoint2), null);
-        EasyMock.verify(epl);
-    }
+        c.verify();
 
-    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;
+        // Expect listener to be called for endpoint1 but not for endpoint2 
+        assertThat(capturedEvents.getValues().get(0), samePropertyValuesAs(new EndpointEvent(EndpointEvent.ADDED,
endpoint1)));
+        assertThat(capturedEvents.getValues().get(1), samePropertyValuesAs(new EndpointEvent(EndpointEvent.REMOVED,
endpoint1)));
     }
-    
-    @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.endpointChanged(new EndpointEvent(EndpointEvent.ADDED, endpoint1), null);
-        tm.endpointChanged(new EndpointEvent(EndpointEvent.REMOVED, endpoint1), null);
-        tm.remove(epl);
-        EasyMock.verify(epl);
-    }
-    
-    public EndpointDescription createEndpoint(String iface) {
+    private EndpointDescription createEndpoint(String iface) {
         Map<String, Object> props = new Hashtable<String, Object>(); 
         props.put("objectClass", new String[]{iface});
         props.put(RemoteConstants.ENDPOINT_ID, iface);
@@ -154,8 +142,9 @@ public class EndpointListenerNotifierTest {
 
     private ServiceReference createListenerServiceWithFilter(Object filters) {
         ServiceReference sr = EasyMock.createMock(ServiceReference.class);
-        EasyMock.expect(sr.getProperty(EndpointListener.ENDPOINT_LISTENER_SCOPE)).andReturn(filters);
+        EasyMock.expect(sr.getProperty(EndpointEventListener.ENDPOINT_LISTENER_SCOPE)).andReturn(filters);
         EasyMock.replay(sr);
         return sr;
     }
+    
 }


Mime
View raw message