cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject cxf-dosgi git commit: Add test for DistributionProviderTracker
Date Fri, 11 Mar 2016 12:58:58 GMT
Repository: cxf-dosgi
Updated Branches:
  refs/heads/master 8c7fbc8c5 -> 9ed37bef0


Add test for DistributionProviderTracker


Project: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/commit/9ed37bef
Tree: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/tree/9ed37bef
Diff: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/diff/9ed37bef

Branch: refs/heads/master
Commit: 9ed37bef0eb4daf9f0e8dfbc098b14608c90c670
Parents: 8c7fbc8
Author: Christian Schneider <chris@die-schneider.net>
Authored: Fri Mar 11 13:58:50 2016 +0100
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Fri Mar 11 13:58:50 2016 +0100

----------------------------------------------------------------------
 .../service/DistributionProviderTracker.java    | 10 ++-
 .../DistributionProviderTrackerTest.java        | 82 ++++++++++++++++++++
 2 files changed, 90 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/9ed37bef/dsw/cxf-dosgi-rsa/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderTracker.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dosgi-rsa/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderTracker.java
b/dsw/cxf-dosgi-rsa/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderTracker.java
index 7dd31b7..675fcc6 100644
--- a/dsw/cxf-dosgi-rsa/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderTracker.java
+++ b/dsw/cxf-dosgi-rsa/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderTracker.java
@@ -44,9 +44,9 @@ public class DistributionProviderTracker extends ServiceTracker<DistributionProv
     public ServiceRegistration addingService(ServiceReference<DistributionProvider>
reference) {
         LOG.debug("RemoteServiceAdmin Implementation is starting up");
         DistributionProvider provider = context.getService(reference);
-        Bundle apiBundle = FrameworkUtil.getBundle(DistributionProvider.class);
+        BundleContext apiContext = getAPIContext();
         RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(context, 
-                                                                    apiBundle.getBundleContext(),

+                                                                    apiContext, 
                                                                     provider);
         RemoteServiceadminFactory rsaf = new RemoteServiceadminFactory(rsaCore);
         Dictionary<String, Object> props = new Hashtable<String, Object>();
@@ -55,6 +55,12 @@ public class DistributionProviderTracker extends ServiceTracker<DistributionProv
         LOG.info("Registering RemoteServiceAdmin for provider " + provider.getClass().getName());
         return context.registerService(RemoteServiceAdmin.class.getName(), rsaf, props);
     }
+
+    protected BundleContext getAPIContext() {
+        Bundle apiBundle = FrameworkUtil.getBundle(DistributionProvider.class);
+        BundleContext apiContext = apiBundle.getBundleContext();
+        return apiContext;
+    }
     
     @Override
     public void removedService(ServiceReference<DistributionProvider> reference,

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/9ed37bef/dsw/cxf-dosgi-rsa/src/test/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderTrackerTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dosgi-rsa/src/test/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderTrackerTest.java
b/dsw/cxf-dosgi-rsa/src/test/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderTrackerTest.java
new file mode 100644
index 0000000..6ae7004
--- /dev/null
+++ b/dsw/cxf-dosgi-rsa/src/test/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderTrackerTest.java
@@ -0,0 +1,82 @@
+/**
+ * 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.dsw.service;
+
+import java.util.Dictionary;
+
+import org.apache.cxf.dosgi.dsw.api.DistributionProvider;
+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.ServiceFactory;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+
+public class DistributionProviderTrackerTest {
+
+    @SuppressWarnings({
+     "unchecked", "rawtypes"
+    })
+    @Test
+    public void testAddingRemoved() throws InvalidSyntaxException {
+        IMocksControl c = EasyMock.createControl();
+        DistributionProvider provider = c.createMock(DistributionProvider.class);
+        
+        ServiceReference<DistributionProvider> providerRef = c.createMock(ServiceReference.class);
+        EasyMock.expect(providerRef.getProperty(RemoteConstants.REMOTE_INTENTS_SUPPORTED)).andReturn("");
+        EasyMock.expect(providerRef.getProperty(RemoteConstants.REMOTE_CONFIGS_SUPPORTED)).andReturn("");
+
+        BundleContext context = c.createMock(BundleContext.class);
+        Filter filter = FrameworkUtil.createFilter("(objectClass=org.apache.cxf.dosgi.dsw.api.DistributionProvider)");
+        EasyMock.expect(context.createFilter("(objectClass=org.apache.cxf.dosgi.dsw.api.DistributionProvider)"))
+            .andReturn(filter);
+        EasyMock.expect(context.getService(providerRef)).andReturn(provider);
+        ServiceRegistration rsaReg = c.createMock(ServiceRegistration.class);
+        EasyMock.expect(context.registerService(EasyMock.isA(String.class), EasyMock.isA(ServiceFactory.class),

+                                                EasyMock.isA(Dictionary.class)))
+            .andReturn(rsaReg).atLeastOnce();
+
+        context.addServiceListener(EasyMock.isA(ServiceListener.class), EasyMock.isA(String.class));
+        EasyMock.expectLastCall();
+        
+        final BundleContext apiContext = c.createMock(BundleContext.class);
+        c.replay();
+        DistributionProviderTracker tracker = new DistributionProviderTracker(context) {
+            protected BundleContext getAPIContext() {
+                return apiContext;
+            };
+        };
+        tracker.addingService(providerRef);
+        c.verify();
+        
+        c.reset();
+        rsaReg.unregister();
+        EasyMock.expectLastCall();
+        EasyMock.expect(context.ungetService(providerRef)).andReturn(true);
+        c.replay();
+        tracker.removedService(providerRef, rsaReg);
+        c.verify();
+    }
+}


Mime
View raw message