Return-Path: X-Original-To: apmail-aries-commits-archive@www.apache.org Delivered-To: apmail-aries-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B36E910EFF for ; Fri, 11 Mar 2016 19:43:07 +0000 (UTC) Received: (qmail 80872 invoked by uid 500); 11 Mar 2016 19:43:02 -0000 Delivered-To: apmail-aries-commits-archive@aries.apache.org Received: (qmail 80344 invoked by uid 500); 11 Mar 2016 19:43:02 -0000 Mailing-List: contact commits-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aries.apache.org Delivered-To: mailing list commits@aries.apache.org Received: (qmail 79262 invoked by uid 99); 11 Mar 2016 19:43:01 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Mar 2016 19:43:01 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 34D45E07F3; Fri, 11 Mar 2016 19:43:01 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: cschneider@apache.org To: commits@aries.apache.org Date: Fri, 11 Mar 2016 19:43:19 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [20/50] [abbrv] aries-rsa git commit: Add test for DistributionProviderTracker Add test for DistributionProviderTracker Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/9ed37bef Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/9ed37bef Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/9ed37bef Branch: refs/heads/master Commit: 9ed37bef0eb4daf9f0e8dfbc098b14608c90c670 Parents: 8c7fbc8 Author: Christian Schneider Authored: Fri Mar 11 13:58:50 2016 +0100 Committer: Christian Schneider 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/aries-rsa/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 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 props = new Hashtable(); @@ -55,6 +55,12 @@ public class DistributionProviderTracker extends ServiceTracker reference, http://git-wip-us.apache.org/repos/asf/aries-rsa/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 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(); + } +}