You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by cs...@apache.org on 2013/08/10 12:06:20 UTC
svn commit: r1512597 - in /cxf/dosgi/trunk/dsw: cxf-dsw/
cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/
cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/
cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/
cxf-topology-manager/
Author: cschneider
Date: Sat Aug 10 10:06:20 2013
New Revision: 1512597
URL: http://svn.apache.org/r1512597
Log:
Refactor service decorator
Added:
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListener.java (with props)
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListenerTest.java (with props)
Modified:
cxf/dosgi/trunk/dsw/cxf-dsw/pom.xml
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImpl.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java
cxf/dosgi/trunk/dsw/cxf-topology-manager/pom.xml
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/pom.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/pom.xml?rev=1512597&r1=1512596&r2=1512597&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/pom.xml (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/pom.xml Sat Aug 10 10:06:20 2013
@@ -33,15 +33,6 @@
<properties>
<topDirectoryLocation>../..</topDirectoryLocation>
- <bundle.import.package>
- org.osgi.service.remoteserviceadmin;version="[${remote.service.admin.interfaces.version},2.0)",
- javax.servlet*;version="[0.0,4)",
- javax.xml.ws*;version="[2.1,3)",
- *
- </bundle.import.package>
- <bundle.export.package>
- org.apache.cxf.dosgi.*;version="${project.version}"
- </bundle.export.package>
</properties>
<dependencies>
@@ -119,8 +110,15 @@
<Bundle-Description>The CXF Remote Service Admin as described in the OSGi Remote Service Admin specification</Bundle-Description>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
- <Import-Package>${bundle.import.package}</Import-Package>
- <Export-Package>${bundle.export.package}</Export-Package>
+ <Import-Package>
+ org.osgi.service.remoteserviceadmin;version="[${remote.service.admin.interfaces.version},2.0)",
+ javax.servlet*;version="[0.0,4)",
+ javax.xml.ws*;version="[2.1,3)",
+ *
+ </Import-Package>
+ <Export-Package>
+ !*
+ </Export-Package>
<Bundle-Activator>org.apache.cxf.dosgi.dsw.Activator</Bundle-Activator>
<DynamicImport-Package>*</DynamicImport-Package>
</instructions>
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java?rev=1512597&r1=1512596&r2=1512597&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java Sat Aug 10 10:06:20 2013
@@ -27,6 +27,7 @@ import java.util.Map;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.dosgi.dsw.decorator.ServiceDecorator;
+import org.apache.cxf.dosgi.dsw.decorator.ServiceDecoratorBundleListener;
import org.apache.cxf.dosgi.dsw.decorator.ServiceDecoratorImpl;
import org.apache.cxf.dosgi.dsw.handlers.ConfigTypeHandlerFactory;
import org.apache.cxf.dosgi.dsw.handlers.HttpServiceManager;
@@ -40,6 +41,7 @@ import org.apache.cxf.dosgi.dsw.service.
import org.apache.cxf.dosgi.dsw.util.Utils;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleListener;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ConfigurationException;
@@ -59,6 +61,7 @@ public class Activator implements Manage
private IntentTracker intentTracker;
private HttpServiceManager httpServiceManager;
private BundleContext bc;
+ private BundleListener bundleListener;
public void start(BundleContext bundlecontext) throws Exception {
LOG.debug("RemoteServiceAdmin Implementation is starting up");
@@ -89,7 +92,10 @@ public class Activator implements Manage
obtainSupportedConfigTypes(configTypeHandlerFactory.getSupportedConfigurationTypes()));
LOG.info("Registering RemoteServiceAdminFactory...");
rsaFactoryReg = bc.registerService(RemoteServiceAdmin.class.getName(), rsaf, props);
- decoratorReg = bc.registerService(ServiceDecorator.class.getName(), new ServiceDecoratorImpl(bc), null);
+ ServiceDecoratorImpl serviceDecorator = new ServiceDecoratorImpl();
+ bundleListener = new ServiceDecoratorBundleListener(serviceDecorator);
+ bc.addBundleListener(bundleListener);
+ decoratorReg = bc.registerService(ServiceDecorator.class.getName(), serviceDecorator, null);
}
// The CT sometimes uses the first element returned to register a service, but
@@ -114,11 +120,7 @@ public class Activator implements Manage
public void stop(BundleContext context) throws Exception {
LOG.debug("RemoteServiceAdmin Implementation is shutting down now");
- uninit();
- shutdownCXFBus();
- }
-
- private synchronized void uninit() {
+ bc.removeBundleListener(bundleListener);
intentTracker.close();
// This also triggers the unimport and unexport of the remote services
rsaFactoryReg.unregister();
@@ -128,6 +130,7 @@ public class Activator implements Manage
intentTracker = null;
rsaFactoryReg = null;
decoratorReg = null;
+ shutdownCXFBus();
}
/**
@@ -146,7 +149,16 @@ public class Activator implements Manage
LOG.debug("RemoteServiceAdmin Implementation configuration is updated with {}", config);
if (config != null) {
try {
- uninit();
+ bc.removeBundleListener(bundleListener);
+ intentTracker.close();
+ // This also triggers the unimport and unexport of the remote services
+ rsaFactoryReg.unregister();
+ decoratorReg.unregister();
+ httpServiceManager.close();
+ httpServiceManager = null;
+ intentTracker = null;
+ rsaFactoryReg = null;
+ decoratorReg = null;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
Added: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListener.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListener.java?rev=1512597&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListener.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListener.java Sat Aug 10 10:06:20 2013
@@ -0,0 +1,48 @@
+/**
+ * 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.decorator;
+
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+
+public class ServiceDecoratorBundleListener implements BundleListener {
+ /**
+ *
+ */
+ private final ServiceDecoratorImpl serviceDecorator;
+
+ /**
+ * @param serviceDecorator
+ */
+ public ServiceDecoratorBundleListener(ServiceDecoratorImpl serviceDecorator) {
+ this.serviceDecorator = serviceDecorator;
+ }
+
+ public void bundleChanged(BundleEvent be) {
+ switch(be.getType()) {
+ case BundleEvent.STARTED:
+ this.serviceDecorator.addDecorations(be.getBundle());
+ break;
+ case BundleEvent.STOPPING:
+ this.serviceDecorator.removeDecorations(be.getBundle());
+ break;
+ default:
+ }
+ }
+}
\ No newline at end of file
Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImpl.java?rev=1512597&r1=1512596&r2=1512597&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImpl.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImpl.java Sat Aug 10 10:06:20 2013
@@ -31,9 +31,6 @@ import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.input.SAXBuilder;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleListener;
import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,18 +40,6 @@ public class ServiceDecoratorImpl implem
private static final Logger LOG = LoggerFactory.getLogger(ServiceDecoratorImpl.class);
final List<Rule> decorations = new CopyOnWriteArrayList<Rule>();
- private final BundleContext bundleContext;
- private final BundleListenerImpl bundleListener;
-
- public ServiceDecoratorImpl(BundleContext bc) {
- bundleContext = bc;
- bundleListener = new BundleListenerImpl();
- bc.addBundleListener(bundleListener);
- }
-
- public void shutdown() {
- bundleContext.removeBundleListener(bundleListener);
- }
public void decorate(ServiceReference sref, Map<String, Object> target) {
for (Rule matcher : decorations) {
@@ -81,16 +66,25 @@ public class ServiceDecoratorImpl implem
}
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @SuppressWarnings({ "rawtypes", "unchecked" })
static List<Element> getDecorationElements(Bundle bundle) {
Enumeration entries = bundle.findEntries("OSGI-INF/remote-service", "*.xml", false);
+ return getDecorationElementsForEntries(entries);
+ }
+
+ /**
+ * Only for tests
+ * @param entries
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ static List<Element> getDecorationElementsForEntries(Enumeration<URL> entries) {
if (entries == null) {
return Collections.emptyList();
}
-
List<Element> elements = new ArrayList<Element>();
while (entries.hasMoreElements()) {
- URL resourceURL = (URL) entries.nextElement();
+ URL resourceURL = entries.nextElement();
try {
Document d = new SAXBuilder().build(resourceURL.openStream());
Namespace ns = Namespace.getNamespace("http://cxf.apache.org/xmlns/service-decoration/1.0.0");
@@ -109,18 +103,4 @@ public class ServiceDecoratorImpl implem
}
}
}
-
- private class BundleListenerImpl implements BundleListener {
- public void bundleChanged(BundleEvent be) {
- switch(be.getType()) {
- case BundleEvent.STARTED:
- addDecorations(be.getBundle());
- break;
- case BundleEvent.STOPPING:
- removeDecorations(be.getBundle());
- break;
- default:
- }
- }
- }
}
Added: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListenerTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListenerTest.java?rev=1512597&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListenerTest.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListenerTest.java Sat Aug 10 10:06:20 2013
@@ -0,0 +1,69 @@
+/**
+ * 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.decorator;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.easymock.EasyMock;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+
+import static org.junit.Assert.assertEquals;
+
+public class ServiceDecoratorBundleListenerTest {
+
+ @Test
+ public void testBundleListener() {
+ BundleContext bc = EasyMock.createMock(BundleContext.class);
+ EasyMock.replay(bc);
+
+ final List<String> called = new ArrayList<String>();
+ ServiceDecoratorImpl serviceDecorator = new ServiceDecoratorImpl() {
+ @Override
+ void addDecorations(Bundle bundle) {
+ called.add("addDecorations");
+ }
+
+ @Override
+ void removeDecorations(Bundle bundle) {
+ called.add("removeDecorations");
+ }
+ };
+
+ Bundle b = EasyMock.createMock(Bundle.class);
+ EasyMock.replay(b);
+
+ ServiceDecoratorBundleListener listener = new ServiceDecoratorBundleListener(serviceDecorator);
+
+ assertEquals("Precondition failed", 0, called.size());
+ listener.bundleChanged(new BundleEvent(BundleEvent.INSTALLED, b));
+ assertEquals(0, called.size());
+
+ listener.bundleChanged(new BundleEvent(BundleEvent.STARTED, b));
+ assertEquals(Arrays.asList("addDecorations"), called);
+
+ listener.bundleChanged(new BundleEvent(BundleEvent.STOPPING, b));
+ assertEquals(Arrays.asList("addDecorations", "removeDecorations"), called);
+
+ }
+}
Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorBundleListenerTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java?rev=1512597&r1=1512596&r2=1512597&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/decorator/ServiceDecoratorImplTest.java Sat Aug 10 10:06:20 2013
@@ -19,76 +19,42 @@
package org.apache.cxf.dosgi.dsw.decorator;
import java.net.URL;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import junit.framework.Assert;
import junit.framework.TestCase;
import org.easymock.EasyMock;
import org.easymock.IAnswer;
import org.jdom.Element;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleListener;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
public class ServiceDecoratorImplTest extends TestCase {
- public void testServiceDecorator() {
- final BundleListener[] bundleListener = new BundleListener[1];
-
- BundleContext bc = EasyMock.createMock(BundleContext.class);
- bc.addBundleListener((BundleListener) EasyMock.anyObject());
- EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
- public Object answer() throws Throwable {
- bundleListener[0] = (BundleListener) EasyMock.getCurrentArguments()[0];
- return null;
- }
- });
- EasyMock.replay(bc);
-
- ServiceDecoratorImpl sd = new ServiceDecoratorImpl(bc);
- EasyMock.verify(bc);
- assertNotNull(bundleListener[0]);
-
- EasyMock.reset(bc);
- bc.removeBundleListener(bundleListener[0]);
- EasyMock.replay(bc);
- sd.shutdown();
-
- EasyMock.verify(bc);
- }
-
public void testGetDecoratorElements() {
- URL sdURL = getClass().getResource("/test-resources/sd.xml");
- Bundle b = EasyMock.createMock(Bundle.class);
- EasyMock.expect(b.findEntries("OSGI-INF/remote-service", "*.xml", false)).andReturn(
- Collections.enumeration(Arrays.asList(sdURL))).anyTimes();
- EasyMock.replay(b);
+ URL sdURL = getValidResource("/test-resources/sd.xml");
+ Enumeration<URL> urls = Collections.enumeration(Collections.singletonList(sdURL));
- List<Element> elements = ServiceDecoratorImpl.getDecorationElements(b);
+ List<Element> elements = ServiceDecoratorImpl.getDecorationElementsForEntries(urls);
assertEquals(1, elements.size());
assertEquals("service-decoration", elements.get(0).getName());
assertEquals("http://cxf.apache.org/xmlns/service-decoration/1.0.0", elements.get(0).getNamespaceURI());
}
public void testGetDecoratorElements2() {
- Bundle b = EasyMock.createMock(Bundle.class);
- EasyMock.expect(b.findEntries("OSGI-INF/remote-service", "*.xml", false)).andReturn(null).anyTimes();
- EasyMock.replay(b);
-
- List<Element> elements = ServiceDecoratorImpl.getDecorationElements(b);
+ List<Element> elements = ServiceDecoratorImpl.getDecorationElementsForEntries(null);
assertEquals(0, elements.size());
}
public void testAddRemoveDecorations() {
- URL res = getClass().getResource("/test-resources/sd.xml");
+ URL res = getValidResource("/test-resources/sd.xml");
final Map<String, Object> serviceProps = new HashMap<String, Object>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.acme.foo.Bar"});
serviceProps.put("test.prop", "xyz");
@@ -98,9 +64,7 @@ public class ServiceDecoratorImplTest ex
.andReturn(Collections.enumeration(Arrays.asList(res))).anyTimes();
EasyMock.replay(b);
- BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
- EasyMock.replay(bc);
- ServiceDecoratorImpl sd = new ServiceDecoratorImpl(bc);
+ ServiceDecoratorImpl sd = new ServiceDecoratorImpl();
assertEquals("Precondition failed", 0, sd.decorations.size());
sd.addDecorations(b);
assertEquals(1, sd.decorations.size());
@@ -129,7 +93,7 @@ public class ServiceDecoratorImplTest ex
}
public void testAddDecorations() {
- URL res = getClass().getResource("/test-resources/sd.xml");
+ URL res = getValidResource("/test-resources/sd.xml");
final Map<String, Object> serviceProps = new HashMap<String, Object>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.acme.foo.Bar"});
serviceProps.put("test.prop", "xyz");
@@ -141,8 +105,8 @@ public class ServiceDecoratorImplTest ex
}
public void testAddDecorations1() {
- URL r1 = getClass().getResource("/test-resources/sd1.xml");
- URL r2 = getClass().getResource("/test-resources/sd2.xml");
+ URL r1 = getValidResource("/test-resources/sd1.xml");
+ URL r2 = getValidResource("/test-resources/sd2.xml");
Map<String, Object> serviceProps = new HashMap<String, Object>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.A"});
@@ -155,8 +119,8 @@ public class ServiceDecoratorImplTest ex
}
public void testAddDecorations2() {
- URL r1 = getClass().getResource("/test-resources/sd1.xml");
- URL r2 = getClass().getResource("/test-resources/sd2.xml");
+ URL r1 = getValidResource("/test-resources/sd1.xml");
+ URL r2 = getValidResource("/test-resources/sd2.xml");
Map<String, Object> serviceProps = new HashMap<String, Object>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.D"});
@@ -167,8 +131,8 @@ public class ServiceDecoratorImplTest ex
}
public void testAddDecorations3() {
- URL r1 = getClass().getResource("/test-resources/sd1.xml");
- URL r2 = getClass().getResource("/test-resources/sd2.xml");
+ URL r1 = getValidResource("/test-resources/sd1.xml");
+ URL r2 = getValidResource("/test-resources/sd2.xml");
Map<String, Object> serviceProps = new HashMap<String, Object>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.B"});
@@ -181,8 +145,8 @@ public class ServiceDecoratorImplTest ex
}
public void testAddDecorations4() {
- URL r1 = getClass().getResource("/test-resources/sd1.xml");
- URL r2 = getClass().getResource("/test-resources/sd2.xml");
+ URL r1 = getValidResource("/test-resources/sd1.xml");
+ URL r2 = getValidResource("/test-resources/sd2.xml");
Map<String, Object> serviceProps = new HashMap<String, Object>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.C"});
@@ -195,8 +159,8 @@ public class ServiceDecoratorImplTest ex
}
public void testAddDecorations5() {
- URL r1 = getClass().getResource("/test-resources/sd1.xml");
- URL r2 = getClass().getResource("/test-resources/sd2.xml");
+ URL r1 = getValidResource("/test-resources/sd1.xml");
+ URL r2 = getValidResource("/test-resources/sd2.xml");
Map<String, Object> serviceProps = new HashMap<String, Object>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.C"});
@@ -208,7 +172,7 @@ public class ServiceDecoratorImplTest ex
}
public void testAddDecorations6() {
- URL r1 = getClass().getResource("/test-resources/sd0.xml");
+ URL r1 = getValidResource("/test-resources/sd0.xml");
Map<String, Object> serviceProps = new HashMap<String, Object>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.D"});
@@ -219,7 +183,7 @@ public class ServiceDecoratorImplTest ex
}
public void testAddDecorations7() {
- URL r1 = getClass().getResource("/test-resources/sd-1.xml");
+ URL r1 = getValidResource("/test-resources/sd-1.xml");
Map<String, Object> serviceProps = new HashMap<String, Object>();
serviceProps.put(Constants.OBJECTCLASS, new String[] {"org.test.D"});
@@ -235,9 +199,7 @@ public class ServiceDecoratorImplTest ex
Collections.enumeration(Arrays.asList(resources))).anyTimes();
EasyMock.replay(b);
- BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
- EasyMock.replay(bc);
- ServiceDecoratorImpl sd = new ServiceDecoratorImpl(bc);
+ ServiceDecoratorImpl sd = new ServiceDecoratorImpl();
sd.addDecorations(b);
Map<String, Object> target = new HashMap<String, Object>();
@@ -252,43 +214,12 @@ public class ServiceDecoratorImplTest ex
return target;
}
- public void testBundleListener() {
- final BundleListener[] bundleListener = new BundleListener[1];
- BundleContext bc = EasyMock.createMock(BundleContext.class);
- bc.addBundleListener((BundleListener) EasyMock.anyObject());
- EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
- public Object answer() throws Throwable {
- bundleListener[0] = (BundleListener) EasyMock.getCurrentArguments()[0];
- return null;
- }
- });
- EasyMock.replay(bc);
-
- final List<String> called = new ArrayList<String>();
- new ServiceDecoratorImpl(bc) {
- @Override
- void addDecorations(Bundle bundle) {
- called.add("addDecorations");
- }
-
- @Override
- void removeDecorations(Bundle bundle) {
- called.add("removeDecorations");
- }
- };
-
- Bundle b = EasyMock.createMock(Bundle.class);
- EasyMock.replay(b);
-
- assertEquals("Precondition failed", 0, called.size());
- bundleListener[0].bundleChanged(new BundleEvent(BundleEvent.INSTALLED, b));
- assertEquals(0, called.size());
-
- bundleListener[0].bundleChanged(new BundleEvent(BundleEvent.STARTED, b));
- assertEquals(Arrays.asList("addDecorations"), called);
-
- bundleListener[0].bundleChanged(new BundleEvent(BundleEvent.STOPPING, b));
- assertEquals(Arrays.asList("addDecorations", "removeDecorations"), called);
+
+ private URL getValidResource(String path) {
+ URL resource = ServiceDecoratorImplTest.class.getResource(path);
+ Assert.assertNotNull("Resource " + path + " not found!", resource);
+ return resource;
}
+
}
Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/pom.xml
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/pom.xml?rev=1512597&r1=1512596&r2=1512597&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/pom.xml (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/pom.xml Sat Aug 10 10:06:20 2013
@@ -33,13 +33,6 @@
<properties>
<topDirectoryLocation>../..</topDirectoryLocation>
- <bundle.import.package>
- org.osgi.service.remoteserviceadmin;version="[${remote.service.admin.interfaces.version},2)",
- *
- </bundle.import.package>
- <bundle.export.package>
- !*
- </bundle.export.package>
</properties>
<dependencies>
@@ -86,8 +79,13 @@
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
<Bundle-Activator>org.apache.cxf.dosgi.topologymanager.Activator</Bundle-Activator>
- <Import-Package>${bundle.import.package}</Import-Package>
- <Export-Package>${bundle.export.package}</Export-Package>
+ <Import-Package>
+ org.osgi.service.remoteserviceadmin;version="[${remote.service.admin.interfaces.version},2)",
+ *
+ </Import-Package>
+ <Export-Package>
+ !*
+ </Export-Package>
</instructions>
</configuration>
</plugin>