cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [1/2] cxf-dosgi git commit: Further refactoring TopologyManager
Date Thu, 10 Mar 2016 16:18:03 GMT
Repository: cxf-dosgi
Updated Branches:
  refs/heads/master ba591efab -> e5db6fdd7


http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/e5db6fdd/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 e01c068..01a9600 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
@@ -18,13 +18,10 @@
  */
 package org.apache.cxf.dosgi.topologymanager.importer;
 
-import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.cxf.dosgi.topologymanager.util.SimpleServiceTracker;
-import org.apache.cxf.dosgi.topologymanager.util.SimpleServiceTrackerListener;
 import org.easymock.EasyMock;
 import org.easymock.IAnswer;
 import org.easymock.IMocksControl;
@@ -52,7 +49,6 @@ public class TopologyManagerImportTest {
         final Semaphore sema = new Semaphore(0);
 
         BundleContext bc = c.createMock(BundleContext.class);
-        SimpleServiceTracker<RemoteServiceAdmin> rsaTracker = c.createMock(SimpleServiceTracker.class);
         ServiceRegistration sreg = c.createMock(ServiceRegistration.class);
         sreg.unregister();
         EasyMock.expectLastCall().once();
@@ -65,9 +61,8 @@ public class TopologyManagerImportTest {
         final ImportRegistration ireg = c.createMock(ImportRegistration.class);
         EasyMock.expect(ireg.getException()).andReturn(null).anyTimes();
         ImportReference iref = c.createMock(ImportReference.class);
-
-        rsaTracker.addListener(EasyMock.<SimpleServiceTrackerListener>anyObject());
-        EasyMock.expect(rsaTracker.getAllServices()).andReturn(Arrays.asList(rsa)).anyTimes();
+        EasyMock.expect(ireg.getImportReference()).andReturn(iref).anyTimes();
+        EasyMock.expect(iref.getImportedEndpoint()).andReturn(endpoint).anyTimes();
 
         EasyMock.expect(rsa.importService(EasyMock.eq(endpoint))).andAnswer(new IAnswer<ImportRegistration>()
{
             public ImportRegistration answer() throws Throwable {
@@ -75,17 +70,13 @@ public class TopologyManagerImportTest {
                 return ireg;
             }
         }).once();
-        EasyMock.expect(ireg.getImportReference()).andReturn(iref).anyTimes();
-        EasyMock.expect(iref.getImportedEndpoint()).andReturn(endpoint).anyTimes();
         c.replay();
 
-        TopologyManagerImport tm = new TopologyManagerImport(bc, rsaTracker);
-
+        TopologyManagerImport tm = new TopologyManagerImport(bc);
         tm.start();
-        // no RSA available yet so no import...
         tm.endpointAdded(endpoint, "myFilter");
-        tm.triggerImportsForRemoteServiceAdmin(rsa);
-        assertTrue("importService should have been called on RemoteServiceAdmin",
+        tm.add(rsa);
+        assertTrue("rsa.ImportService should have been called",
                    sema.tryAcquire(100, TimeUnit.SECONDS));
         tm.stop();
         c.verify();

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/e5db6fdd/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/util/SimpleServiceTrackerTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/util/SimpleServiceTrackerTest.java
b/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/util/SimpleServiceTrackerTest.java
deleted file mode 100644
index dd3aa0b..0000000
--- a/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/util/SimpleServiceTrackerTest.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/**
- * 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.util;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-
-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.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin;
-
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
-public class SimpleServiceTrackerTest {
-
-    private ServiceReference<RemoteServiceAdmin> createUserServiceBundle(IMocksControl
c, BundleContext context) {
-        @SuppressWarnings("unchecked")
-        final ServiceReference<RemoteServiceAdmin> sref = c.createMock(ServiceReference.class);
-        Bundle srefBundle = c.createMock(Bundle.class);
-        expect(srefBundle.getBundleContext()).andReturn(context).anyTimes();
-        expect(sref.getBundle()).andReturn(srefBundle).anyTimes();
-        expect(srefBundle.getSymbolicName()).andReturn("serviceBundleName").anyTimes();
-        return sref;
-    }
-
-    private static <T> void assertEqualsUnordered(Collection<T> c1, Collection<T>
c2) {
-        assertEquals(new HashSet<T>(c1), new HashSet<T>(c2));
-    }
-    
-    @Test
-    public void testTracker() throws InvalidSyntaxException {
-        IMocksControl c = EasyMock.createControl();
-        // create context mock
-        BundleContext context = c.createMock(BundleContext.class);
-        // capture service listener so we can invoke it
-        Capture<ServiceListener> capturedListener = EasyMock.newCapture();
-        context.addServiceListener(EasyMock.<ServiceListener>capture(capturedListener),
(String)anyObject());
-        expectLastCall().once();
-        context.removeServiceListener((ServiceListener)anyObject());
-        expectLastCall().once();
-        // support context.createFilter
-        Filter filter = c.createMock(Filter.class);
-        expect(context.createFilter("(objectClass=org.osgi.service.remoteserviceadmin.RemoteServiceAdmin)"))
-                .andReturn(filter).atLeastOnce();
-        // support context.getServiceReferences based on our list
-        final List<RemoteServiceAdmin> services = new ArrayList<RemoteServiceAdmin>();
-        final List<ServiceReference<RemoteServiceAdmin>> srefs = new ArrayList<ServiceReference<RemoteServiceAdmin>>();
-        expect(context.getServiceReferences((String)anyObject(), eq((String)null))).andAnswer(
-                new IAnswer<ServiceReference<?>[]>() {
-                @Override
-                public ServiceReference<?>[] answer() {
-                    return srefs.toArray(new ServiceReference[srefs.size()]);
-                }
-            });
-        // create services
-        ServiceReference<RemoteServiceAdmin> sref1 = createUserServiceBundle(c, context);
-        ServiceReference<RemoteServiceAdmin> sref2 = createUserServiceBundle(c, context);
-        RemoteServiceAdmin service1 = c.createMock(RemoteServiceAdmin.class);
-        RemoteServiceAdmin service2 = c.createMock(RemoteServiceAdmin.class);
-        expect(context.getService(sref1)).andReturn(service1).atLeastOnce();
-        expect(context.getService(sref2)).andReturn(service2).atLeastOnce();
-        expect(context.ungetService(sref1)).andReturn(false).atLeastOnce();
-        expect(context.ungetService(sref2)).andReturn(false).atLeastOnce();
-
-        replay(context);
-
-        // start tracking
-        final SimpleServiceTracker<RemoteServiceAdmin> tracker =
-                new SimpleServiceTracker<RemoteServiceAdmin>(context, RemoteServiceAdmin.class);
-        tracker.open();
-        ServiceListener sl = capturedListener.getValue();
-        // add our listener
-        SimpleServiceTrackerListener<RemoteServiceAdmin> listener =
-                new SimpleServiceTrackerListener<RemoteServiceAdmin>() {
-                @SuppressWarnings({ "unchecked", "rawtypes" })
-                @Override
-                public void added(ServiceReference<RemoteServiceAdmin> reference, RemoteServiceAdmin
service) {
-                    // prove that original ServiceTracker fails here
-                    Object[] trackerServices = (Object[])
-                        (tracker.getServices() != null ? tracker.getServices() : new Object[0]);
-                    assertFalse(new HashSet(services)
-                                .equals(new HashSet(Arrays.asList(trackerServices))));
-                    // but we succeed
-                    assertEqualsUnordered(services, tracker.getAllServices());
-                }
-
-                @Override
-                public void modified(ServiceReference<RemoteServiceAdmin> reference,
RemoteServiceAdmin service) {
-                }
-
-                @Override
-                public void removed(ServiceReference<RemoteServiceAdmin> reference,
RemoteServiceAdmin service) {
-                    assertEqualsUnordered(services, tracker.getAllServices());
-                }
-            };
-        tracker.addListener(listener);
-
-        // add and remove services and verify that getAllServices() is up to date
-        srefs.add(sref1);
-        services.add(service1);
-        sl.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, sref1));
-        assertEqualsUnordered(services, tracker.getAllServices());
-
-        srefs.add(sref2);
-        services.add(service2);
-        sl.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, sref2));
-        assertEqualsUnordered(services, tracker.getAllServices());
-
-        srefs.remove(sref1);
-        services.remove(service1);
-        sl.serviceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, sref1));
-        assertEqualsUnordered(services, tracker.getAllServices());
-
-        srefs.remove(sref2);
-        services.remove(service2);
-        sl.serviceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, sref2));
-        assertEqualsUnordered(services, tracker.getAllServices());
-
-        srefs.add(sref1);
-        services.add(service1);
-        sl.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, sref1));
-        services.remove(service1);
-        tracker.close();
-        assertEqualsUnordered(services, tracker.getAllServices());
-
-        verify(context);
-    }
-}


Mime
View raw message