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 2016/07/01 12:09:08 UTC

[2/5] cxf-dosgi git commit: [DOSGI-242] Refactor provider, Cleanup

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/pojo/PojoConfigurationTypeHandlerTest.java
----------------------------------------------------------------------
diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/pojo/PojoConfigurationTypeHandlerTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/pojo/PojoConfigurationTypeHandlerTest.java
new file mode 100644
index 0000000..678a495
--- /dev/null
+++ b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/pojo/PojoConfigurationTypeHandlerTest.java
@@ -0,0 +1,424 @@
+/**
+ * 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.handlers.pojo;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.aries.rsa.spi.Endpoint;
+import org.apache.aries.rsa.util.EndpointHelper;
+import org.apache.cxf.dosgi.dsw.handlers.jaxws.MyJaxWsEchoService;
+import org.apache.cxf.dosgi.dsw.handlers.simple.MySimpleEchoService;
+import org.apache.cxf.dosgi.dsw.httpservice.HttpServiceManager;
+import org.apache.cxf.dosgi.dsw.osgi.Constants;
+import org.apache.cxf.dosgi.dsw.qos.IntentManager;
+import org.apache.cxf.dosgi.dsw.qos.IntentManagerImpl;
+import org.apache.cxf.dosgi.dsw.qos.IntentMap;
+import org.apache.cxf.dosgi.dsw.util.ServerWrapper;
+import org.apache.cxf.endpoint.AbstractEndpointFactory;
+import org.apache.cxf.endpoint.EndpointImpl;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.feature.Feature;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.jaxws.support.JaxWsEndpointImpl;
+import org.apache.cxf.transport.Destination;
+import org.apache.cxf.ws.addressing.AttributedURIType;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+import org.easymock.IMocksControl;
+import org.junit.Assert;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Version;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+
+public class PojoConfigurationTypeHandlerTest extends TestCase {
+
+    public void testGetPojoAddressEndpointURI() {
+        IntentManager intentManager = new IntentManagerImpl(new IntentMap());
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null,
+                                                                                intentManager,
+                                                                                dummyHttpServiceManager());
+        Map<String, Object> sd = new HashMap<String, Object>();
+        String url = "http://somewhere:1234/blah";
+        sd.put(RemoteConstants.ENDPOINT_ID, url);
+        assertEquals(url, handler.getServerAddress(sd, String.class));
+    }
+
+    private HttpServiceManager dummyHttpServiceManager() {
+        return new HttpServiceManager(null, null, null, null);
+    }
+
+    public void testGetPojoAddressEndpointCxf() {
+        IntentManager intentManager = new IntentManagerImpl(new IntentMap());
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null,
+                                                                                intentManager,
+                                                                                dummyHttpServiceManager());
+        Map<String, Object> sd = new HashMap<String, Object>();
+        String url = "http://somewhere:29/boo";
+        sd.put("org.apache.cxf.ws.address", url);
+        assertEquals(url, handler.getServerAddress(sd, String.class));
+    }
+
+    public void testGetPojoAddressEndpointPojo() {
+        IntentManager intentManager = new IntentManagerImpl(new IntentMap());
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null,
+                                                                                intentManager,
+                                                                                dummyHttpServiceManager());
+        Map<String, Object> sd = new HashMap<String, Object>();
+        String url = "http://somewhere:32768/foo";
+        sd.put("osgi.remote.configuration.pojo.address", url);
+        assertEquals(url, handler.getServerAddress(sd, String.class));
+    }
+
+    public void testGetDefaultPojoAddress() {
+        IntentManager intentManager = new IntentManagerImpl(new IntentMap());
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null,
+                                                                                intentManager,
+                                                                                dummyHttpServiceManager());
+        Map<String, Object> sd = new HashMap<String, Object>();
+        assertEquals("/java/lang/String", handler.getServerAddress(sd, String.class));
+    }
+
+    // todo: add test for data bindings
+    public void testCreateProxy() {
+        IMocksControl c = EasyMock.createNiceControl();
+        BundleContext bc1 = c.createMock(BundleContext.class);
+        
+        BundleContext requestingContext = c.createMock(BundleContext.class);
+
+        final ClientProxyFactoryBean cpfb = c.createMock(ClientProxyFactoryBean.class);
+        ReflectionServiceFactoryBean sf = c.createMock(ReflectionServiceFactoryBean.class);
+        EasyMock.expect(cpfb.getServiceFactory()).andReturn(sf).anyTimes();
+        IntentManager intentManager = new IntentManagerImpl(new IntentMap()) {
+            @Override
+            public String[] applyIntents(List<Feature> features,
+                                         AbstractEndpointFactory factory,
+                                         Map<String, Object> sd) {
+                return new String[0];
+            }
+        };
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(bc1,
+                                                                          intentManager,
+                                                                          dummyHttpServiceManager()) {
+            @Override
+            protected ClientProxyFactoryBean createClientProxyFactoryBean(Map<String, Object> sd, Class<?> iClass) {
+                return cpfb;
+            }
+        };
+
+        Class<?>[] exportedInterfaces = new Class[]{Runnable.class};
+        
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(RemoteConstants.ENDPOINT_ID, "http://google.de/");
+        EndpointHelper.addObjectClass(props, exportedInterfaces);
+        props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, new String[]{"my.config"});
+        EndpointDescription endpoint = new EndpointDescription(props);
+
+        cpfb.setAddress((String)EasyMock.eq(props.get(RemoteConstants.ENDPOINT_ID)));
+        EasyMock.expectLastCall().atLeastOnce();
+
+        cpfb.setServiceClass(EasyMock.eq(Runnable.class));
+        EasyMock.expectLastCall().atLeastOnce();
+
+        c.replay();
+        ClassLoader cl = null;
+        Object proxy = p.importEndpoint(cl, requestingContext, exportedInterfaces, endpoint);
+        assertNotNull(proxy);
+        assertTrue("Proxy is not of the requested type! ", proxy instanceof Runnable);
+        c.verify();
+    }
+
+    public void testCreateServerWithAddressProperty() throws Exception {
+        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(dswContext);
+
+        String myService = "Hi";
+        final ServerFactoryBean sfb = createMockServerFactoryBean();
+
+        IntentMap intentMap = new IntentMap();
+        IntentManager intentManager = new IntentManagerImpl(intentMap) {
+            @Override
+            public String[] applyIntents(List<Feature> features, AbstractEndpointFactory factory,
+                                         Map<String, Object> sd) {
+                return new String[]{};
+            }
+        };
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, intentManager,
+                                                                          dummyHttpServiceManager()) {
+            @Override
+            protected ServerFactoryBean createServerFactoryBean(Map<String, Object> sd, Class<?> iClass) {
+                return sfb;
+            }
+        };
+        BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(bundleContext);
+        
+        Class<?>[] exportedInterface = new Class[]{String.class};
+        Map<String, Object> props = new HashMap<String, Object>();
+        EndpointHelper.addObjectClass(props, exportedInterface);
+        props.put(Constants.WS_ADDRESS_PROPERTY, "http://alternate_host:80/myString");
+
+        Endpoint exportResult = p.exportService(myService, bundleContext, props, exportedInterface);
+        Map<String, Object> edProps = exportResult.description().getProperties();
+
+        assertNotNull(edProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS));
+        assertEquals(1, ((String[])edProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS)).length);
+        assertEquals(Constants.WS_CONFIG_TYPE, ((String[])edProps.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS))[0]);
+        assertEquals("http://alternate_host:80/myString", edProps.get(RemoteConstants.ENDPOINT_ID));
+    }
+
+    public void testAddressing() throws Exception {
+        runAddressingTest(new HashMap<String, Object>(), "http://localhost:9000/java/lang/Runnable");
+
+        Map<String, Object> p1 = new HashMap<String, Object>();
+        p1.put("org.apache.cxf.ws.address", "http://somewhere");
+        runAddressingTest(p1, "http://somewhere");
+
+        Map<String, Object> p2 = new HashMap<String, Object>();
+        p2.put("org.apache.cxf.rs.address", "https://somewhereelse");
+        runAddressingTest(p2, "https://somewhereelse");
+
+        Map<String, Object> p3 = new HashMap<String, Object>();
+        p3.put("org.apache.cxf.ws.port", 65535);
+        runAddressingTest(p3, "http://localhost:65535/java/lang/Runnable");
+
+        Map<String, Object> p4 = new HashMap<String, Object>();
+        p4.put("org.apache.cxf.ws.port", "8181");
+        runAddressingTest(p4, "http://localhost:8181/java/lang/Runnable");
+    }
+
+    private void runAddressingTest(Map<String, Object> properties, String expectedAddress) throws Exception {
+        Class<?>[] exportedInterface = new Class[]{Runnable.class};
+        EndpointHelper.addObjectClass(properties, exportedInterface);
+        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
+        String expectedUUID = UUID.randomUUID().toString();
+        EasyMock.expect(dswContext.getProperty(org.osgi.framework.Constants.FRAMEWORK_UUID)).andReturn(expectedUUID);
+        EasyMock.replay(dswContext);
+
+        IntentManager intentManager = EasyMock.createNiceMock(IntentManager.class);
+        EasyMock.replay(intentManager);
+
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(dswContext,
+                                                                                intentManager,
+                                                                                dummyHttpServiceManager()) {
+            @Override
+            protected Endpoint createServerFromFactory(ServerFactoryBean factory,
+                                                       EndpointDescription epd) {
+                return new ServerWrapper(epd, null);
+            }
+        };
+        Runnable myService = EasyMock.createMock(Runnable.class);
+        EasyMock.replay(myService);
+        
+        BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(bundleContext);
+
+        Endpoint result = handler.exportService(myService, bundleContext, properties, exportedInterface);
+        Map<String, Object> props = result.description().getProperties();
+        assertEquals(expectedAddress, props.get("org.apache.cxf.ws.address"));
+        Assert.assertArrayEquals(new String[] {"org.apache.cxf.ws"}, 
+                     (String[]) props.get(RemoteConstants.SERVICE_IMPORTED_CONFIGS));
+        Assert.assertArrayEquals(new String[] {"java.lang.Runnable"}, 
+                     (String[]) props.get(org.osgi.framework.Constants.OBJECTCLASS));
+    }
+
+    public void t2estCreateServerException() {
+        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(dswContext);
+
+        IntentManager intentManager = EasyMock.createNiceMock(IntentManager.class);
+        EasyMock.replay(intentManager);
+
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(dswContext,
+                                                                                intentManager,
+                                                                                dummyHttpServiceManager()) {
+            @Override
+            protected Endpoint createServerFromFactory(ServerFactoryBean factory,
+                                                       EndpointDescription epd) {
+                throw new TestException();
+            }
+        };
+
+        Map<String, Object> props = new HashMap<String, Object>();
+
+        Runnable myService = EasyMock.createMock(Runnable.class);
+        EasyMock.replay(myService);
+        try {
+            handler.exportService(myService, null, props, new Class[]{Runnable.class});
+            fail("Expected TestException");
+        } catch (TestException e) {
+            // Expected
+        }
+    }
+
+    private ServerFactoryBean createMockServerFactoryBean() {
+        ReflectionServiceFactoryBean sf = EasyMock.createNiceMock(ReflectionServiceFactoryBean.class);
+        EasyMock.replay(sf);
+
+        final StringBuilder serverURI = new StringBuilder();
+
+        ServerFactoryBean sfb = EasyMock.createNiceMock(ServerFactoryBean.class);
+        Server server = createMockServer(sfb);
+
+        EasyMock.expect(sfb.getServiceFactory()).andReturn(sf).anyTimes();
+        EasyMock.expect(sfb.create()).andReturn(server);
+        sfb.setAddress((String) EasyMock.anyObject());
+        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+            public Object answer() throws Throwable {
+                serverURI.setLength(0);
+                serverURI.append(EasyMock.getCurrentArguments()[0]);
+                return null;
+            }
+        });
+        EasyMock.expect(sfb.getAddress()).andAnswer(new IAnswer<String>() {
+            public String answer() throws Throwable {
+                return serverURI.toString();
+            }
+        });
+        EasyMock.replay(sfb);
+        return sfb;
+    }
+
+    private Server createMockServer(final ServerFactoryBean sfb) {
+        AttributedURIType addr = EasyMock.createMock(AttributedURIType.class);
+        EasyMock.expect(addr.getValue()).andAnswer(new IAnswer<String>() {
+            public String answer() throws Throwable {
+                return sfb.getAddress();
+            }
+        });
+        EasyMock.replay(addr);
+
+        EndpointReferenceType er = EasyMock.createMock(EndpointReferenceType.class);
+        EasyMock.expect(er.getAddress()).andReturn(addr);
+        EasyMock.replay(er);
+
+        Destination destination = EasyMock.createMock(Destination.class);
+        EasyMock.expect(destination.getAddress()).andReturn(er);
+        EasyMock.replay(destination);
+
+        Server server = EasyMock.createNiceMock(Server.class);
+        EasyMock.expect(server.getDestination()).andReturn(destination);
+        EasyMock.replay(server);
+        return server;
+    }
+
+    public void testCreateEndpointProps() {
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.expect(bc.getProperty("org.osgi.framework.uuid")).andReturn("some_uuid1");
+        EasyMock.replay(bc);
+
+        IntentManager intentManager = new IntentManagerImpl(new IntentMap());
+        PojoConfigurationTypeHandler pch = new PojoConfigurationTypeHandler(bc,
+                                                                            intentManager,
+                                                                            dummyHttpServiceManager());
+        Class<?>[] exportedInterfaces = new Class[] {String.class};
+        Map<String, Object> sd = new HashMap<String, Object>();
+        sd.put(org.osgi.framework.Constants.SERVICE_ID, 42);
+        EndpointHelper.addObjectClass(sd, exportedInterfaces);
+        EndpointDescription epd = pch.createEndpointDesc(sd, new String[] {"org.apache.cxf.ws"},
+                "http://localhost:12345", new String[] {"my_intent", "your_intent"});
+
+        assertEquals("http://localhost:12345", epd.getId());
+        assertEquals(Arrays.asList("java.lang.String"), epd.getInterfaces());
+        assertEquals(Arrays.asList("org.apache.cxf.ws"), epd.getConfigurationTypes());
+        assertEquals(Arrays.asList("my_intent", "your_intent"), epd.getIntents());
+        assertEquals(new Version("0.0.0"), epd.getPackageVersion("java.lang"));
+    }
+
+    public void t2estCreateJaxWsEndpointWithoutIntents() {
+        IMocksControl c = EasyMock.createNiceControl();
+        BundleContext dswBC = c.createMock(BundleContext.class);
+        
+        IntentManager intentManager = new DummyIntentManager();
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(dswBC,
+                                                                                intentManager,
+                                                                                dummyHttpServiceManager());
+
+        Map<String, Object> sd = new HashMap<String, Object>();
+        sd.put(Constants.WS_ADDRESS_PROPERTY, "/somewhere");
+        BundleContext serviceBC = c.createMock(BundleContext.class);
+        Object myService = null;
+        c.replay();
+
+        ServerWrapper serverWrapper = (ServerWrapper)handler.exportService(myService,
+                                                                           serviceBC, 
+                                                                           sd, 
+                                                                           new Class[]{MyJaxWsEchoService.class});
+        c.verify();
+
+        org.apache.cxf.endpoint.Endpoint ep = serverWrapper.getServer().getEndpoint();
+        QName bindingName = ep.getEndpointInfo().getBinding().getName();
+        Assert.assertEquals(JaxWsEndpointImpl.class, ep.getClass());
+        Assert.assertEquals(new QName("http://jaxws.handlers.dsw.dosgi.cxf.apache.org/",
+                                      "MyJaxWsEchoServiceServiceSoapBinding"),
+                            bindingName);
+    }
+
+    public void t2estCreateSimpleEndpointWithoutIntents() {
+        IMocksControl c = EasyMock.createNiceControl();
+        BundleContext dswBC = c.createMock(BundleContext.class);
+
+        IntentManager intentManager = new DummyIntentManager();
+        PojoConfigurationTypeHandler handler
+            = new PojoConfigurationTypeHandler(dswBC, intentManager, dummyHttpServiceManager());
+        Map<String, Object> sd = new HashMap<String, Object>();
+        sd.put(Constants.WS_ADDRESS_PROPERTY, "/somewhere_else");
+        BundleContext serviceBC = c.createMock(BundleContext.class);
+        c.replay();
+        ServerWrapper serverWrapper = (ServerWrapper)handler.exportService(null, serviceBC, sd, 
+                                                                          new Class[]{MySimpleEchoService.class});
+        c.verify();
+
+        org.apache.cxf.endpoint.Endpoint ep = serverWrapper.getServer().getEndpoint();
+        QName bindingName = ep.getEndpointInfo().getBinding().getName();
+        Assert.assertEquals(EndpointImpl.class, ep.getClass());
+        Assert.assertEquals(new QName("http://simple.handlers.dsw.dosgi.cxf.apache.org/",
+                                      "MySimpleEchoServiceSoapBinding"),
+                            bindingName);
+    }
+
+    public static class DummyIntentManager implements IntentManager {
+
+        @Override
+        public String[] applyIntents(List<Feature> features,
+                                     AbstractEndpointFactory factory,
+                                     Map<String, Object> props) {
+            return new String[]{};
+        }
+
+        @Override
+        public void assertAllIntentsSupported(Map<String, Object> serviceProperties) {
+        }
+    }
+
+    @SuppressWarnings("serial")
+    public static class TestException extends RuntimeException {
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/rest/JaxRSUtilsTest.java
----------------------------------------------------------------------
diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/rest/JaxRSUtilsTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/rest/JaxRSUtilsTest.java
new file mode 100644
index 0000000..72e578b
--- /dev/null
+++ b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/rest/JaxRSUtilsTest.java
@@ -0,0 +1,195 @@
+/**
+ * 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.handlers.rest;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.dosgi.dsw.osgi.Constants;
+import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
+import org.apache.cxf.jaxrs.provider.aegis.AegisElementProvider;
+import org.easymock.EasyMock;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+
+public class JaxRSUtilsTest extends TestCase {
+
+    private void addRequiredProps(Map<String, Object> props) {
+        props.put(RemoteConstants.ENDPOINT_ID, "http://google.de");
+        props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "myGreatConfiguration");
+        props.put(org.osgi.framework.Constants.OBJECTCLASS, new String[] {"my.class"});
+    }
+
+    public void testNoGlobalProviders() {
+        Map<String, Object> props = new HashMap<String, Object>();
+        addRequiredProps(props);
+        props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false");
+
+        assertEquals(0, JaxRSUtils.getProviders(null, props).size());
+    }
+
+    public void testAegisProvider() {
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(Constants.RS_DATABINDING_PROP_KEY, "aegis");
+        props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false");
+
+        addRequiredProps(props);
+
+        List<Object> providers = JaxRSUtils.getProviders(null, props);
+        assertEquals(1, providers.size());
+        assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName());
+    }
+
+    @SuppressWarnings("rawtypes")
+    public void testServiceProviders() {
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(Constants.RS_PROVIDER_PROP_KEY, new Object[] {
+            new AegisElementProvider()
+        });
+        props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false");
+        addRequiredProps(props);
+
+        List<Object> providers = JaxRSUtils.getProviders(null, props);
+        assertEquals(1, providers.size());
+        assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName());
+    }
+
+    public void testServiceProviderProperty() throws Exception {
+        BundleContext bc = EasyMock.createMock(BundleContext.class);
+        Bundle bundle = EasyMock.createMock(Bundle.class);
+        bc.getBundle();
+        EasyMock.expectLastCall().andReturn(bundle).times(2);
+        bundle.loadClass(AegisElementProvider.class.getName());
+        EasyMock.expectLastCall().andReturn(AegisElementProvider.class);
+        bundle.loadClass(JAXBElementProvider.class.getName());
+        EasyMock.expectLastCall().andReturn(JAXBElementProvider.class);
+        EasyMock.replay(bc, bundle);
+
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(Constants.RS_PROVIDER_PROP_KEY,
+                "\r\n " + AegisElementProvider.class.getName() + " , \r\n"
+                        + JAXBElementProvider.class.getName() + "\r\n");
+
+        props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false");
+        addRequiredProps(props);
+
+        List<Object> providers = JaxRSUtils.getProviders(bc, props);
+        assertEquals(2, providers.size());
+        assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName());
+        assertEquals(JAXBElementProvider.class.getName(), providers.get(1).getClass().getName());
+    }
+
+    public void testServiceProviderStrings() throws Exception {
+        BundleContext bc = EasyMock.createMock(BundleContext.class);
+        Bundle bundle = EasyMock.createMock(Bundle.class);
+        bc.getBundle();
+        EasyMock.expectLastCall().andReturn(bundle).times(2);
+        bundle.loadClass(AegisElementProvider.class.getName());
+        EasyMock.expectLastCall().andReturn(AegisElementProvider.class);
+        bundle.loadClass(JAXBElementProvider.class.getName());
+        EasyMock.expectLastCall().andReturn(JAXBElementProvider.class);
+        EasyMock.replay(bc, bundle);
+
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(Constants.RS_PROVIDER_PROP_KEY, new String[] {
+            "\r\n " + AegisElementProvider.class.getName(),
+            JAXBElementProvider.class.getName() + "\r\n"
+        });
+
+        props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false");
+        addRequiredProps(props);
+
+        List<Object> providers = JaxRSUtils.getProviders(bc, props);
+        assertEquals(2, providers.size());
+        assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName());
+        assertEquals(JAXBElementProvider.class.getName(), providers.get(1).getClass().getName());
+    }
+
+    @SuppressWarnings({
+     "rawtypes", "unchecked"
+    })
+    public void testCustomGlobalProvider() throws Exception {
+        ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class);
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        bc.getServiceReferences((String)null, JaxRSUtils.PROVIDERS_FILTER);
+        EasyMock.expectLastCall().andReturn(new ServiceReference[] {sref});
+        sref.getProperty(Constants.RS_PROVIDER_EXPECTED_PROP_KEY);
+        EasyMock.expectLastCall().andReturn(false);
+        bc.getService(sref);
+        AegisElementProvider<?> p = new AegisElementProvider();
+        EasyMock.expectLastCall().andReturn(p);
+        EasyMock.replay(bc, sref);
+        Map<String, Object> props = new HashMap<String, Object>();
+        addRequiredProps(props);
+
+        List<Object> providers = JaxRSUtils.getProviders(bc, props);
+        assertEquals(1, providers.size());
+        assertSame(p, providers.get(0));
+    }
+
+    @SuppressWarnings({
+     "rawtypes", "unchecked"
+    })
+    public void testNoCustomGlobalProvider() throws Exception {
+        ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class);
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        bc.getServiceReferences((String)null, JaxRSUtils.PROVIDERS_FILTER);
+        EasyMock.expectLastCall().andReturn(new ServiceReference[] {sref});
+        sref.getProperty(Constants.RS_PROVIDER_PROP_KEY);
+        EasyMock.expectLastCall().andReturn(false);
+        bc.getService(sref);
+        AegisElementProvider<?> p = new AegisElementProvider();
+        EasyMock.expectLastCall().andReturn(p);
+        EasyMock.replay(bc);
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(Constants.RS_PROVIDER_EXPECTED_PROP_KEY, "true");
+        addRequiredProps(props);
+
+        List<Object> providers = JaxRSUtils.getProviders(bc, props);
+        assertEquals(0, providers.size());
+    }
+
+    @SuppressWarnings({
+     "rawtypes", "unchecked"
+    })
+    public void testCustomGlobalProviderExpected() throws Exception {
+        ServiceReference sref = EasyMock.createNiceMock(ServiceReference.class);
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        bc.getServiceReferences((String)null, JaxRSUtils.PROVIDERS_FILTER);
+        EasyMock.expectLastCall().andReturn(new ServiceReference[] {sref});
+        sref.getProperty(Constants.RS_PROVIDER_PROP_KEY);
+        EasyMock.expectLastCall().andReturn(true);
+        bc.getService(sref);
+        AegisElementProvider<?> p = new AegisElementProvider();
+        EasyMock.expectLastCall().andReturn(p);
+        EasyMock.replay(bc, sref);
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(Constants.RS_PROVIDER_EXPECTED_PROP_KEY, "true");
+        addRequiredProps(props);
+
+        List<Object> providers = JaxRSUtils.getProviders(bc, props);
+        assertEquals(1, providers.size());
+        assertSame(p, providers.get(0));
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfFindListenerHookTest.java
----------------------------------------------------------------------
diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfFindListenerHookTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfFindListenerHookTest.java
deleted file mode 100644
index fde48d2..0000000
--- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfFindListenerHookTest.java
+++ /dev/null
@@ -1,341 +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.dsw.hooks;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class CxfFindListenerHookTest extends Assert {
-
-    @Test
-    public void testDUMMY() throws Exception {
-    }
-
-//    private IMocksControl control;
-//
-//    @Before
-//    public void setUp() {
-//        control = EasyMock.createNiceControl();
-//    }
-
-    /* Todo this test doesn't apply at the moment since the ListenerHook doesn't
-     * have a serviceReferencesRequested() API (yet).
-    @Test
-    public void testSyncListenerHook() throws Exception {
-        Bundle bundle = control.createMock(Bundle.class);
-        bundle.findEntries(EasyMock.eq("OSGI-INF/remote-service"),
-            EasyMock.eq("*.xml"), EasyMock.anyBoolean());
-        EasyMock.expectLastCall().andReturn(Collections.enumeration(
-            Arrays.asList(getClass().getResource("/OSGI-INF/remote-service/remote-services.xml"))));
-        Dictionary<String, String> bundleHeaders = new Hashtable<String, String>();
-        bundleHeaders.put(org.osgi.framework.Constants.BUNDLE_NAME,
-                          "Test Bundle");
-        bundleHeaders.put(org.osgi.framework.Constants.BUNDLE_VERSION,
-                          "1.0.0");
-        bundle.getHeaders();
-        EasyMock.expectLastCall().andReturn(bundleHeaders).anyTimes();
-        bundle.loadClass(TestService.class.getName());
-        EasyMock.expectLastCall().andReturn(TestService.class).anyTimes();
-        final BundleContext requestingContext = control.createMock(BundleContext.class);
-        requestingContext.getBundle();
-        EasyMock.expectLastCall().andReturn(bundle).anyTimes();
-
-        BundleTestContext dswContext = new BundleTestContext(bundle);
-        dswContext.addServiceReference(TestService.class.getName(),
-                                       control.createMock(ServiceReference.class));
-        control.replay();
-
-        CxfListenerHook hook = new CxfListenerHook(dswContext, null);
-
-        // TODO : if the next call ends up being executed in a thread of its own then
-        // update the test accordingly, use Futures for ex
-
-        hook.serviceReferencesRequested(requestingContext,
-                                       TestService.class.getName(), null, true);
-
-        List<ServiceReference> registeredRefs = dswContext.getRegisteredReferences();
-        assertNotNull(registeredRefs);
-        assertEquals(1, registeredRefs.size());
-    } */
-
-//    @Test
-//    public void testTrackerPropertiesOnlyClassInFilterWithMatchingInterface() throws Exception {
-//        String filter = "(objectClass=" + TestService.class.getName() + ")";
-//        doTestTrackerPropertiesSet(filter,
-//                                   "osgi.remote.discovery.interest.interfaces",
-//                                   TestService.class.getName(),
-//                                   asList(TestService.class.getName()),
-//                                   Collections.EMPTY_SET);
-//    }
-//
-//    @Test
-//    public void testTrackerPropertiesGenericFilterWithMatchingInterface() throws Exception {
-//        String filter = "(&(objectClass=" + TestService.class.getName()
-//                        + ")(colour=blue))";
-//        doTestTrackerPropertiesSet(filter,
-//                                   "osgi.remote.discovery.interest.filters",
-//                                   replacePredicate(filter),
-//                                   asList(TestService.class.getName()),
-//                                   Collections.EMPTY_SET);
-//    }
-//
-//    @Test
-//    public void testTrackerPropertiesOnlyClassInFilterWithMatchingFilter() throws Exception {
-//        String filter = "(objectClass=" + TestService.class.getName() + ")";
-//        doTestTrackerPropertiesSet(filter,
-//                                   "osgi.remote.discovery.interest.interfaces",
-//                                   TestService.class.getName(),
-//                                   Collections.EMPTY_SET,
-//                                   asList(replacePredicate(filter)));
-//    }
-//
-//    @Test
-//    public void testTrackerPropertiesGenericFilterWithMatchingFilter() throws Exception {
-//        String filter = "(&(objectClass=" + TestService.class.getName()
-//                        + ")(colour=blue))";
-//        doTestTrackerPropertiesSet(filter,
-//                                   "osgi.remote.discovery.interest.filters",
-//                                   replacePredicate(filter),
-//                                   Collections.EMPTY_SET,
-//                                   asList(replacePredicate(filter)));
-//    }
-//
-//    @Test
-//    public void testTrackerPropertiesOnlyClassInFilterWithMatchingBoth() throws Exception {
-//        String filter = "(objectClass=" + TestService.class.getName() + ")";
-//        doTestTrackerPropertiesSet(filter,
-//                                   "osgi.remote.discovery.interest.interfaces",
-//                                   TestService.class.getName(),
-//                                   asList(TestService.class.getName()),
-//                                   asList(replacePredicate(filter)));
-//    }
-//
-//    @Test
-//    public void testTrackerPropertiesGenericFilterWithMatchingBoth() throws Exception {
-//        String filter = "(&(objectClass=" + TestService.class.getName()
-//                        + ")(colour=blue))";
-//        doTestTrackerPropertiesSet(filter,
-//                                   "osgi.remote.discovery.interest.filters",
-//                                   replacePredicate(filter),
-//                                   Collections.EMPTY_SET,
-//                                   asList(replacePredicate(filter)));
-//    }
-//
-//    private void doTestTrackerPropertiesSet(final String filter,
-//                                            String propKey,
-//                                            String propValue,
-//                                            Collection matchingInterfaces,
-//                                            Collection matchingFilters) throws Exception {
-//        Bundle bundle = control.createMock(Bundle.class);
-//        Dictionary<String, String> bundleHeaders = new Hashtable<String, String>();
-//        bundleHeaders.put(org.osgi.framework.Constants.BUNDLE_NAME,
-//                          "Test Bundle");
-//        bundleHeaders.put(org.osgi.framework.Constants.BUNDLE_VERSION,
-//                          "1.0.0");
-//        bundle.getHeaders();
-//        EasyMock.expectLastCall().andReturn(bundleHeaders).times(2);
-//        final String serviceClass = TestService.class.getName();
-//        bundle.loadClass(serviceClass);
-//        EasyMock.expectLastCall().andReturn(TestService.class).times(2);
-//        final BundleContext requestingContext = control.createMock(BundleContext.class);
-//
-//        BundleTestContext dswContext = new BundleTestContext(bundle);
-//        ServiceRegistration serviceRegistration = control.createMock(ServiceRegistration.class);
-//        dswContext.addServiceRegistration(serviceClass, serviceRegistration);
-//        serviceRegistration.unregister();
-//        EasyMock.expectLastCall().times(1);
-//        ServiceReference serviceReference = control.createMock(ServiceReference.class);
-//        dswContext.addServiceReference(serviceClass, serviceReference);
-//
-//        final String trackerClass = DiscoveredServiceTracker.class.getName();
-//        ServiceRegistration trackerRegistration = control.createMock(ServiceRegistration.class);
-//        dswContext.addServiceRegistration(trackerClass, trackerRegistration);
-//        ServiceReference trackerReference = control.createMock(ServiceReference.class);
-//        dswContext.addServiceReference(trackerClass, trackerReference);
-//
-//        List property = asList(propValue);
-//        Dictionary properties = new Hashtable();
-//        properties.put(propKey, property);
-//        trackerRegistration.setProperties(properties);
-//        EasyMock.expectLastCall();
-//
-//        if (matchingInterfaces.size() == 0 && matchingFilters.size() > 0) {
-//            Iterator filters = matchingFilters.iterator();
-//            while (filters.hasNext()) {
-//                Filter f = control.createMock(Filter.class);
-//                dswContext.addFilter((String)filters.next(), f);
-//                f.match(EasyMock.isA(Dictionary.class));
-//                EasyMock.expectLastCall().andReturn(true);
-//            }
-//        }
-//
-//        control.replay();
-//
-//        CxfFindListenerHook hook = new CxfFindListenerHook(dswContext, null);
-//
-//        ListenerHook.ListenerInfo info = new ListenerHook.ListenerInfo() {
-//            public BundleContext getBundleContext() {
-//                return requestingContext;
-//            }
-//
-//            public String getFilter() {
-//                return filter;
-//            }
-//
-//            public boolean isRemoved() {
-//                return false;
-//            }
-//        };
-//        hook.added(Collections.singleton(info));
-//
-//        DiscoveredServiceTracker tracker = (DiscoveredServiceTracker)
-//            dswContext.getService(trackerReference);
-//        assertNotNull(tracker);
-//
-//        Collection interfaces = asList(serviceClass);
-//
-//        notifyAvailable(tracker, matchingInterfaces, matchingFilters, "1234");
-//        notifyAvailable(tracker, matchingInterfaces, matchingFilters, "5678");
-//        notifyAvailable(tracker, matchingInterfaces, matchingFilters, "1234");
-//
-//        notifyUnAvailable(tracker, "1234");
-//        notifyUnAvailable(tracker, "5678");
-//
-//        notifyAvailable(tracker, matchingInterfaces, matchingFilters , "1234");
-//
-//        control.verify();
-//
-//        Map<String, ServiceReference> registeredRefs = dswContext.getRegisteredReferences();
-//        assertNotNull(registeredRefs);
-//        assertEquals(2, registeredRefs.size());
-//        assertNotNull(registeredRefs.get(serviceClass));
-//        assertSame(serviceReference, registeredRefs.get(serviceClass));
-//
-//        Map<String, ServiceRegistration> registeredRegs = dswContext.getRegisteredRegistrations();
-//        assertNotNull(registeredRegs);
-//        assertEquals(2, registeredRegs.size());
-//        assertNotNull(registeredRegs.get(trackerClass));
-//        assertSame(trackerRegistration, registeredRegs.get(trackerClass));
-//
-//        List<Object> registeredServices = dswContext.getRegisteredServices();
-//        assertNotNull(registeredServices);
-//        assertEquals(2, registeredServices.size());
-//    }
-//
-//    @Test
-//    public void testConstructorAndGetters() {
-//        BundleContext bc = control.createMock(BundleContext.class);
-//        CxfRemoteServiceAdmin dp = control.createMock(CxfRemoteServiceAdmin.class);
-//        control.replay();
-//
-//        CxfFindListenerHook clh = new CxfFindListenerHook(bc, dp);
-//        assertSame(bc, clh.getContext());
-//        assertSame(dp, clh.getDistributionProvider());
-//    }
-//
-//    @Test
-//    public void testFindHook() {
-//        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
-//
-//        final List<String> lookupCalls = new ArrayList<String>();
-//        CxfFindListenerHook fh = new CxfFindListenerHook(bc, null) {
-//            @Override
-//            protected synchronized void lookupDiscoveryService(
-//                    String interfaceName, String filterValue) {
-//                lookupCalls.add(interfaceName);
-//                lookupCalls.add(filterValue);
-//            }
-//        };
-//
-//        String clazz = "my.app.Class";
-//        String filter = "&(A=B)(C=D)";
-//        fh.find(null, clazz, filter, true, null);
-//
-//        assertEquals(Arrays.asList(clazz, filter), lookupCalls);
-//    }
-//
-//    private void notifyAvailable(DiscoveredServiceTracker tracker,
-//                                 Collection interfaces,
-//                                 Collection filters,
-//                                 String endpointId) {
-//        Map<String, Object> props = new Hashtable<String, Object>();
-//        props.put("osgi.remote.interfaces", "*");
-//        props.put("osgi.remote.endpoint.id", endpointId);
-//        tracker.serviceChanged(new Notification(AVAILABLE,
-//                                                TestService.class.getName(),
-//                                                interfaces,
-//                                                filters,
-//                                                props));
-//    }
-//
-//    private void notifyUnAvailable(DiscoveredServiceTracker tracker,
-//                                   String endpointId) {
-//        Map<String, Object> props = new Hashtable<String, Object>();
-//        props.put("osgi.remote.endpoint.id", endpointId);
-//        tracker.serviceChanged(new Notification(UNAVAILABLE,
-//                                                TestService.class.getName(),
-//                                                Collections.EMPTY_SET,
-//                                                Collections.EMPTY_SET,
-//                                                props));
-//    }
-//
-//    private List<String> asList(String s) {
-//        List l = new ArrayList<String>();
-//        l.add(s);
-//        return l;
-//    }
-//
-//    private String replacePredicate(String filter) {
-//        return filter.replace("objectClass", ServicePublication.SERVICE_INTERFACE_NAME);
-//    }
-//
-//    private class Notification implements DiscoveredServiceNotification {
-//        private int type;
-//        private ServiceEndpointDescription sed;
-//        private Collection interfaces;
-//        private Collection filters;
-//
-//        Notification(int type,
-//                     String interfaceName,
-//                     Collection interfaces,
-//                     Collection filters,
-//                     Map<String, Object> props) {
-//            this.type = type;
-//            this.sed = new ServiceEndpointDescriptionImpl(interfaceName, props);
-//            this.interfaces = interfaces;
-//            this.filters = filters;
-//        }
-//
-//        public int getType() {
-//            return type;
-//        }
-//
-//        public ServiceEndpointDescription getServiceEndpointDescription() {
-//            return sed;
-//        }
-//
-//        public Collection getInterfaces() {
-//            return interfaces;
-//        }
-//
-//        public Collection getFilters() {
-//            return filters;
-//        }
-//    }
-}

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHookTest.java
----------------------------------------------------------------------
diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHookTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHookTest.java
deleted file mode 100644
index 40b40c5..0000000
--- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHookTest.java
+++ /dev/null
@@ -1,299 +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.dsw.hooks;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class CxfPublishHookTest extends Assert {
-
-    @Test
-    public void testDUMMY() throws Exception {
-    }
-
-    //
-    // private IMocksControl control;
-    //
-    // @Before
-    // public void setUp() {
-    // control = EasyMock.createNiceControl();
-    // }
-    //
-    // @Test
-    // public void testPublishSingleInterface() throws Exception {
-    // String[] serviceNames = new String[]{TestService.class.getName()};
-    // String[] addresses = new String[]{"http://localhost:9000/hello"};
-    // doTestPublishHook("remote-services.xml", serviceNames, addresses);
-    // }
-    //
-    // @Test
-    // public void testPublishSingleInterfaceAltFormat() throws Exception {
-    // String[] serviceNames = new String[]{TestService.class.getName()};
-    // String[] addresses = new String[]{"http://localhost:9000/hello"};
-    // doTestPublishHook("alt-remote-services.xml", serviceNames, addresses);
-    // }
-    //
-    // @Test
-    // public void testPublishMultiInterface() throws Exception {
-    // String[] serviceNames = new String[]{TestService.class.getName(),
-    // AdditionalInterface.class.getName()};
-    // String[] addresses = new String[]{"http://localhost:9001/hello",
-    // "http://localhost:9002/hello"};
-    // doTestPublishHook("multi-services.xml", serviceNames, addresses);
-    // }
-    //
-    // @SuppressWarnings("unchecked")
-    // private void doTestPublishHook(String remoteServices,
-    // String[] serviceNames,
-    // String[] addresses) throws Exception {
-    //
-    // Bundle bundle = control.createMock(Bundle.class);
-    // bundle.findEntries(EasyMock.eq("OSGI-INF/remote-service"),
-    // EasyMock.eq("*.xml"), EasyMock.anyBoolean());
-    // EasyMock.expectLastCall().andReturn(Collections.enumeration(
-    // Arrays.asList(getClass().getResource("/OSGI-INF/remote-service/" + remoteServices))));
-    // Dictionary<String, String> bundleHeaders = new Hashtable<String, String>();
-    // bundleHeaders.put(org.osgi.framework.Constants.BUNDLE_NAME,
-    // "Test Bundle");
-    // bundleHeaders.put(org.osgi.framework.Constants.BUNDLE_VERSION,
-    // "1.0.0");
-    // bundle.getHeaders();
-    // EasyMock.expectLastCall().andReturn(bundleHeaders).anyTimes();
-    // BundleContext requestingContext = control.createMock(BundleContext.class);
-    // bundle.getBundleContext();
-    // EasyMock.expectLastCall().andReturn(requestingContext).anyTimes();
-    //
-    // TestService serviceObject = new TestServiceImpl();
-    // Dictionary serviceProps = new Hashtable();
-    //
-    // ServiceReference sref = control.createMock(ServiceReference.class);
-    // sref.getBundle();
-    // EasyMock.expectLastCall().andReturn(bundle).anyTimes();
-    // sref.getProperty(Constants.OBJECTCLASS);
-    // EasyMock.expectLastCall().andReturn(serviceNames).anyTimes();
-    // sref.getPropertyKeys();
-    // EasyMock.expectLastCall().andReturn(new String[]{}).anyTimes();
-    //
-    // BundleTestContext dswContext = new BundleTestContext(bundle);
-    //
-    // ServiceRegistration[] serviceRegistrations =
-    // new ServiceRegistration[serviceNames.length];
-    //
-    // for (int i = 0; i < serviceNames.length ; i++) {
-    // serviceRegistrations[i] =
-    // control.createMock(ServiceRegistration.class);
-    // dswContext.addServiceRegistration(serviceNames[i],
-    // serviceRegistrations[i]);
-    // dswContext.addServiceReference(serviceNames[i], sref);
-    // }
-    // dswContext.registerService(serviceNames, serviceObject, serviceProps);
-    //
-    // Server server = control.createMock(Server.class);
-    //
-    // String publicationClass = ServicePublication.class.getName();
-    // ServiceRegistration publicationRegistration =
-    // control.createMock(ServiceRegistration.class);
-    // publicationRegistration.unregister();
-    // EasyMock.expectLastCall().times(serviceNames.length);
-    // dswContext.addServiceRegistration(publicationClass, publicationRegistration);
-    // ServiceReference publicationReference =
-    // control.createMock(ServiceReference.class);
-    // dswContext.addServiceReference(publicationClass, publicationReference);
-    // control.replay();
-    //
-    // TestPublishHook hook = new TestPublishHook(dswContext,
-    // serviceObject,
-    // server);
-    // hook.publishEndpoint(sref);
-    // hook.verify();
-    //
-    // assertEquals(1, hook.getEndpoints().size());
-    // List<EndpointInfo> list = hook.getEndpoints().get(sref);
-    // assertNotNull(list);
-    // assertEquals(serviceNames.length, list.size());
-    // for (int i = 0; i < serviceNames.length; i++) {
-    // assertNotNull(list.get(i));
-    // ServiceEndpointDescription sd = list.get(i).getServiceDescription();
-    // assertNotNull(sd);
-    // assertNotNull(sd.getProvidedInterfaces());
-    // assertEquals(1, sd.getProvidedInterfaces().size());
-    // Collection names = sd.getProvidedInterfaces();
-    // assertEquals(1, names.size());
-    // assertEquals(serviceNames[i], names.toArray()[0]);
-    // String excludeProp = "osgi.remote.interfaces";
-    // assertNull(sd.getProperties().get(excludeProp));
-    // String addrProp =
-    // org.apache.cxf.dosgi.dsw.Constants.WS_ADDRESS_PROPERTY_OLD;
-    // assertEquals(addresses[i], sd.getProperties().get(addrProp));
-    // }
-    //
-    // Map<String, ServiceRegistration> registeredRegs =
-    // dswContext.getRegisteredRegistrations();
-    // assertNotNull(registeredRegs);
-    // assertEquals(serviceNames.length + 1, registeredRegs.size());
-    // assertNotNull(registeredRegs.get(publicationClass));
-    // assertSame(publicationRegistration, registeredRegs.get(publicationClass));
-    //
-    // Map<String, List<Dictionary>> registeredProps =
-    // dswContext.getRegisteredProperties();
-    // assertNotNull(registeredProps);
-    // assertEquals(serviceNames.length + 1, registeredProps.size());
-    // assertNotNull(registeredProps.get(publicationClass));
-    // List<Dictionary> propsList = registeredProps.get(publicationClass);
-    // assertEquals(serviceNames.length, propsList.size());
-    // for (Dictionary props : propsList) {
-    // Collection interfaces =
-    // (Collection)props.get(SERVICE_INTERFACE_NAME);
-    // assertNotNull(interfaces);
-    // assertTrue(interfaces.contains(TestService.class.getName())
-    // || interfaces.contains(AdditionalInterface.class.getName()));
-    // }
-    //
-    // hook.removeEndpoints();
-    //
-    // control.verify();
-    // }
-    //
-    // @SuppressWarnings("unchecked")
-    // @Test
-    // public void testPublishMultipleTimes() {
-    // Bundle bundle = control.createMock(Bundle.class);
-    // bundle.findEntries(EasyMock.eq("OSGI-INF/remote-service"),
-    // EasyMock.eq("*.xml"), EasyMock.anyBoolean());
-    // EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
-    // public Object answer() throws Throwable {
-    // return Collections.enumeration(Arrays.asList(
-    // getClass().getResource("/OSGI-INF/remote-service/remote-services.xml")));
-    // }
-    // }).anyTimes();
-    // Dictionary<String, String> bundleHeaders = new Hashtable<String, String>();
-    // bundleHeaders.put(org.osgi.framework.Constants.BUNDLE_NAME,
-    // "org.apache.cxf.example.bundle");
-    // bundleHeaders.put(org.osgi.framework.Constants.BUNDLE_VERSION,
-    // "1.0.0");
-    // bundle.getHeaders();
-    // EasyMock.expectLastCall().andReturn(bundleHeaders).anyTimes();
-    // BundleContext requestingContext = control.createMock(BundleContext.class);
-    // bundle.getBundleContext();
-    // EasyMock.expectLastCall().andReturn(requestingContext).anyTimes();
-    //
-    // TestService serviceObject = new TestServiceImpl();
-    // Dictionary serviceProps = new Hashtable();
-    //
-    // ServiceReference sref = control.createMock(ServiceReference.class);
-    // sref.getBundle();
-    // EasyMock.expectLastCall().andReturn(bundle).anyTimes();
-    // sref.getProperty(Constants.OBJECTCLASS);
-    // String[] serviceNames = {TestService.class.getName()};
-    // EasyMock.expectLastCall().andReturn(serviceNames).anyTimes();
-    // sref.getPropertyKeys();
-    // EasyMock.expectLastCall().andReturn(new String[]{}).anyTimes();
-    //
-    // BundleTestContext dswContext = new BundleTestContext(bundle);
-    // ServiceRegistration[] serviceRegistrations =
-    // new ServiceRegistration[serviceNames.length];
-    // for (int i = 0; i < serviceNames.length ; i++) {
-    // serviceRegistrations[i] =
-    // control.createMock(ServiceRegistration.class);
-    // dswContext.addServiceRegistration(serviceNames[i],
-    // serviceRegistrations[i]);
-    // dswContext.addServiceReference(serviceNames[i], sref);
-    // }
-    // dswContext.registerService(serviceNames, serviceObject, serviceProps);
-    //
-    // final Server server = control.createMock(Server.class);
-    // control.replay();
-    //
-    // CxfPublishHook hook = new CxfPublishHook(dswContext, null) {
-    // @Override
-    // Server createServer(ServiceReference sref, ServiceEndpointDescription sd) {
-    // return server;
-    // }
-    // };
-    // assertNull("Precondition not met", hook.getEndpoints().get(sref));
-    // hook.publishEndpoint(sref);
-    // assertEquals(1, hook.getEndpoints().get(sref).size());
-    //
-    // hook.endpoints.put(sref, new ArrayList<EndpointInfo>());
-    // assertEquals("Precondition failed", 0, hook.getEndpoints().get(sref).size());
-    // hook.publishEndpoint(sref);
-    // assertEquals(0, hook.getEndpoints().get(sref).size());
-    //
-    // control.verify();
-    // }
-    //
-    // private static class TestPublishHook extends CxfPublishHook {
-    //
-    // private boolean called;
-    // private TestService serviceObject;
-    // private Server server;
-    //
-    // public TestPublishHook(BundleContext bc, TestService serviceObject,
-    // Server s) {
-    // super(bc, null);
-    // this.serviceObject = serviceObject;
-    // this.server = s;
-    // }
-    //
-    // @Override
-    // protected ConfigurationTypeHandler getHandler(ServiceEndpointDescription sd,
-    // Map<String, Object> props) {
-    // return new ConfigurationTypeHandler() {
-    // public String getType() {
-    // return "test";
-    // }
-    //
-    // public Object createProxy(ServiceReference sr,
-    // BundleContext dswContext, BundleContext callingContext,
-    // Class<?> iClass, ServiceEndpointDescription sd) {
-    // throw new UnsupportedOperationException();
-    // }
-    //
-    // public Server createServer(ServiceReference sr,
-    // BundleContext dswContext, BundleContext callingContext,
-    // ServiceEndpointDescription sd, Class<?> iClass, Object serviceBean) {
-    // Assert.assertSame(serviceBean, serviceObject);
-    // TestPublishHook.this.setCalled();
-    // Map props = sd.getProperties();
-    // String address = (String)props.get(WS_ADDRESS_PROPERTY);
-    // if (address != null) {
-    // props.put(ENDPOINT_LOCATION, address);
-    // }
-    // return server;
-    // }
-    //
-    // };
-    // }
-    //
-    // public void setCalled() {
-    // called = true;
-    // }
-    //
-    // public void verify() {
-    // Assert.assertTrue(called);
-    // }
-    // }
-    //
-    // public interface AdditionalInterface {
-    // }
-    //
-    // private static class TestServiceImpl implements TestService, AdditionalInterface {
-    //
-    // }
-}

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtilsTest.java
----------------------------------------------------------------------
diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtilsTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtilsTest.java
deleted file mode 100644
index c004702..0000000
--- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtilsTest.java
+++ /dev/null
@@ -1,116 +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.dsw.hooks;
-
-import junit.framework.TestCase;
-
-public class ServiceHookUtilsTest extends TestCase {
-
-    public void testDUMMY() {
-        assertTrue(true);
-    }
-
-/*
-    public void testCreateServer() {
-        IMocksControl control = EasyMock.createNiceControl();
-
-        Server srvr = control.createMock(Server.class);
-        ServiceReference serviceReference = control.createMock(ServiceReference.class);
-        BundleContext dswContext = control.createMock(BundleContext.class);
-        BundleContext callingContext = control.createMock(BundleContext.class);
-        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl("java.lang.String");
-        Object service = "hi";
-
-        ConfigurationTypeHandler handler = control.createMock(ConfigurationTypeHandler.class);
-        handler.createServer(serviceReference, dswContext, callingContext, sd, String.class, service);
-        EasyMock.expectLastCall().andReturn(srvr);
-        control.replay();
-
-        assertSame(srvr,
-            ServiceHookUtils.createServer(handler, serviceReference, dswContext, callingContext, sd, service));
-    }
-
-    public void testNoServerWhenNoInterfaceSpecified() {
-        IMocksControl control = EasyMock.createNiceControl();
-
-        Server srvr = control.createMock(Server.class);
-        ServiceReference serviceReference = control.createMock(ServiceReference.class);
-        BundleContext dswContext = control.createMock(BundleContext.class);
-        BundleContext callingContext = control.createMock(BundleContext.class);
-        ServiceEndpointDescription sd = mockServiceDescription(control, "Foo");
-        Object service = "hi";
-
-        ConfigurationTypeHandler handler = control.createMock(ConfigurationTypeHandler.class);
-        handler.createServer(serviceReference, dswContext, callingContext, sd, String.class, service);
-        EasyMock.expectLastCall().andReturn(srvr);
-        control.replay();
-
-        assertNull(ServiceHookUtils.createServer(handler, serviceReference, dswContext,
-                                                 callingContext, sd, service));
-    }
-
-    public void testPublish() throws Exception {
-        Map<String, Object> props = new HashMap<String, Object>();
-        props.put("foo", "bar");
-        props.put(ServicePublication.ENDPOINT_LOCATION, "http:localhost/xyz");
-        ServiceEndpointDescriptionImpl sed = new ServiceEndpointDescriptionImpl(String.class.getName(), props);
-        assertEquals(new URI("http:localhost/xyz"), sed.getLocation());
-
-        final Dictionary<String, Object> expectedProps = new Hashtable<String, Object>();
-        expectedProps.put(ServicePublication.SERVICE_PROPERTIES, props);
-        expectedProps.put(ServicePublication.SERVICE_INTERFACE_NAME, Collections.singleton(String.class.getName()));
-        expectedProps.put(ServicePublication.ENDPOINT_LOCATION, new URI("http:localhost/xyz"));
-
-        BundleContext bc = EasyMock.createMock(BundleContext.class);
-        EasyMock.expect(bc.registerService(
-            EasyMock.eq(ServicePublication.class.getName()),
-            EasyMock.anyObject(),
-            (Dictionary<?, ?>) EasyMock.anyObject()))
-                .andAnswer(new IAnswer<ServiceRegistration>() {
-                    public ServiceRegistration answer() throws Throwable {
-                        assertTrue(EasyMock.getCurrentArguments()[1] instanceof ServicePublication);
-                        Dictionary<?, ?> actualProps =
-                            (Dictionary<?, ?>) EasyMock.getCurrentArguments()[2];
-                        UUID uuid = UUID.fromString(actualProps.get(ServicePublication.ENDPOINT_SERVICE_ID)
-                                                        .toString());
-                        expectedProps.put(ServicePublication.ENDPOINT_SERVICE_ID, uuid.toString());
-                        assertEquals(expectedProps, actualProps);
-                        return EasyMock.createMock(ServiceRegistration.class);
-                    }
-                });
-        EasyMock.replay(bc);
-
-        ServiceHookUtils.publish(bc, null, sed);
-        EasyMock.verify(bc);
-    }
-
-    private ServiceEndpointDescription mockServiceDescription(IMocksControl control,
-                                                              String... interfaceNames) {
-        List<String> iList = new ArrayList<String>();
-        for (String iName : interfaceNames) {
-            iList.add(iName);
-        }
-        ServiceEndpointDescription sd = control.createMock(ServiceEndpointDescription.class);
-        sd.getProvidedInterfaces();
-        EasyMock.expectLastCall().andReturn(iList);
-        return sd;
-    }
-*/
-}
-

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/TestService.java
----------------------------------------------------------------------
diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/TestService.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/TestService.java
deleted file mode 100644
index 07b5088..0000000
--- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/TestService.java
+++ /dev/null
@@ -1,22 +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.dsw.hooks;
-
-public interface TestService {
-}

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/HttpServiceManagerTest.java
----------------------------------------------------------------------
diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/HttpServiceManagerTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/HttpServiceManagerTest.java
new file mode 100644
index 0000000..593a06d
--- /dev/null
+++ b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/HttpServiceManagerTest.java
@@ -0,0 +1,125 @@
+/**
+ * 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.httpservice;
+
+import java.util.Dictionary;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+import org.junit.Assert;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.NamespaceException;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+
+public class HttpServiceManagerTest extends TestCase {
+
+    public void testGetAbsoluteAddress() {
+        IMocksControl c = EasyMock.createControl();
+        BundleContext bundleContext = c.createMock(BundleContext.class);
+        c.replay();
+        HttpServiceManager manager = new HttpServiceManager(bundleContext, null, null, null);
+        String localIp = LocalHostUtil.getLocalIp();
+
+        String address1 = manager.getAbsoluteAddress(null, "/myservice");
+        assertEquals("http://" + localIp + ":8181/cxf/myservice", address1);
+
+        String address2 = manager.getAbsoluteAddress("/mycontext", "/myservice");
+        assertEquals("http://" + localIp + ":8181/mycontext/myservice", address2);
+
+        c.verify();
+    }
+
+    public void testRegisterAndUnregisterServlet() throws Exception {
+        IMocksControl c = EasyMock.createControl();
+        BundleContext dswContext = c.createMock(BundleContext.class);
+        Filter filter = c.createMock(Filter.class);
+        expect(dswContext.createFilter(EasyMock.eq("(service.id=12345)"))).andReturn(filter).once();
+        Capture<ServiceListener> captured = EasyMock.newCapture();
+        dswContext.addServiceListener(EasyMock.capture(captured), EasyMock.<String>anyObject());
+        expectLastCall().atLeastOnce();
+        expect(dswContext.getProperty("org.apache.cxf.httpservice.requirefilter")).andReturn(null).atLeastOnce();
+        ServletConfig config = c.createMock(ServletConfig.class);
+        expect(config.getInitParameter(EasyMock.<String>anyObject())).andReturn(null).atLeastOnce();
+        ServletContext servletContext = c.createMock(ServletContext.class);
+        expect(config.getServletContext()).andReturn(servletContext);
+        final HttpService httpService = new DummyHttpService(config);
+        ServiceReference<?> sr = c.createMock(ServiceReference.class);
+        expect(sr.getProperty(EasyMock.eq("service.id"))).andReturn(12345L).atLeastOnce();
+        expect(servletContext.getResourceAsStream((String)EasyMock.anyObject())).andReturn(null).anyTimes();
+        c.replay();
+
+        HttpServiceManager h = new HttpServiceManager(dswContext, null, null, null) {
+            @Override
+            protected HttpService getHttpService() {
+                return httpService;
+            }
+        };
+        Bus bus = BusFactory.newInstance().createBus();
+        h.registerServlet(bus, "/myService", dswContext, 12345L);
+
+        ServiceEvent event = new ServiceEvent(ServiceEvent.UNREGISTERING, sr);
+        captured.getValue().serviceChanged(event);
+        c.verify();
+    }
+
+    static class DummyHttpService implements HttpService {
+
+        private ServletConfig config;
+
+        DummyHttpService(ServletConfig config) {
+            this.config = config;
+        }
+
+        @SuppressWarnings("rawtypes")
+        public void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext context)
+            throws ServletException, NamespaceException {
+            Assert.assertEquals("/myService", alias);
+            servlet.init(config);
+        }
+
+        public void registerResources(String alias, String name, HttpContext context) throws NamespaceException {
+            throw new RuntimeException("This method should not be called");
+        }
+
+        public void unregister(String alias) {
+        }
+
+        public HttpContext createDefaultHttpContext() {
+            return EasyMock.createNiceMock(HttpContext.class);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/SecurityDelegatingHttpContextTest.java
----------------------------------------------------------------------
diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/SecurityDelegatingHttpContextTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/SecurityDelegatingHttpContextTest.java
new file mode 100644
index 0000000..84718ad
--- /dev/null
+++ b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/httpservice/SecurityDelegatingHttpContextTest.java
@@ -0,0 +1,267 @@
+/**
+ * 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.httpservice;
+
+import java.io.PrintWriter;
+import java.net.URL;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpContext;
+
+@SuppressWarnings({
+    "unchecked", "rawtypes"
+   })
+public class SecurityDelegatingHttpContextTest extends TestCase {
+
+    protected HttpContext defaultHttpContext;
+    protected SecurityDelegatingHttpContext httpContext;
+    protected CommitResponseFilter commitFilter;
+    protected DoNothingFilter doNothingFilter;
+    protected AccessDeniedFilter accessDeniedFilter;
+    protected String mimeType;
+    protected URL url; // does not need to exist
+
+    public void setUp() throws Exception {
+        mimeType = "text/xml";
+        url = new URL("file:test.xml"); // does not need to exist
+
+        // Sample filters
+        commitFilter = new CommitResponseFilter();
+        doNothingFilter = new DoNothingFilter();
+        accessDeniedFilter = new AccessDeniedFilter();
+
+        // Mock up the default http context
+        defaultHttpContext = EasyMock.createNiceMock(HttpContext.class);
+        EasyMock.expect(defaultHttpContext.getMimeType((String)EasyMock.anyObject())).andReturn(mimeType);
+        EasyMock.expect(defaultHttpContext.getResource((String)EasyMock.anyObject())).andReturn(url);
+        EasyMock.replay(defaultHttpContext);
+    }
+
+    public void testFilterRequired() throws Exception {
+        // Mock up the service references
+        ServiceReference[] serviceReferences = new ServiceReference[] {};
+
+        // Mock up the bundle context
+        BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.expect(bundleContext.getServiceReferences(Filter.class.getName(),
+                                                           "(org.apache.cxf.httpservice.filter=true)"))
+            .andReturn(serviceReferences);
+        EasyMock.replay(bundleContext);
+
+        // Set up the secure http context
+        httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
+        httpContext.requireFilter = true;
+
+        // Ensure that the httpContext doesn't allow the request to be processed, since there are no registered servlet
+        // filters
+        HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
+        EasyMock.replay(request);
+        HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
+        EasyMock.replay(response);
+        boolean requestAllowed = httpContext.handleSecurity(request, response);
+        Assert.assertFalse(requestAllowed);
+
+        // Ensure that the httpContext returns true if there is no requirement for registered servlet filters
+        httpContext.requireFilter = false;
+        requestAllowed = httpContext.handleSecurity(request, response);
+        Assert.assertTrue(requestAllowed);
+    }
+
+    public void testSingleCommitFilter() throws Exception {
+        // Mock up the service references
+        ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class);
+        EasyMock.replay(filterReference);
+        ServiceReference[] serviceReferences = new ServiceReference[] {
+            filterReference
+        };
+
+        // Mock up the bundle context
+        BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject()))
+            .andReturn(serviceReferences);
+        EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(commitFilter);
+        EasyMock.replay(bundleContext);
+
+        // Set up the secure http context
+        httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
+
+        // Ensure that the httpContext returns false, since the filter has committed the response
+        HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
+        EasyMock.replay(request);
+        HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
+        EasyMock.expect(response.isCommitted()).andReturn(false); // the first call checks to see whether to invoke the
+                                                                  // filter
+        EasyMock.expect(response.isCommitted()).andReturn(true); // the second is called to determine the handleSecurity
+                                                                 // return value
+        EasyMock.expect(response.getWriter()).andReturn(new PrintWriter(System.out));
+        EasyMock.replay(response);
+        Assert.assertFalse(httpContext.handleSecurity(request, response));
+
+        // Ensure that the appropriate filters were called
+        Assert.assertTrue(commitFilter.called);
+        Assert.assertFalse(doNothingFilter.called);
+        Assert.assertFalse(accessDeniedFilter.called);
+    }
+
+    public void testFilterChain() throws Exception {
+        // Mock up the service references
+        ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class);
+        EasyMock.replay(filterReference);
+        ServiceReference[] serviceReferences = new ServiceReference[] {
+            filterReference, filterReference
+        };
+
+        // Mock up the bundle context
+        BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject()))
+            .andReturn(serviceReferences);
+        EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(doNothingFilter);
+        EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(commitFilter);
+        EasyMock.replay(bundleContext);
+
+        // Set up the secure http context
+        httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
+
+        // Ensure that the httpContext returns false, since the filter has committed the response
+        HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
+        EasyMock.replay(request);
+        HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
+        EasyMock.expect(response.isCommitted()).andReturn(false); // doNothingFilter should not commit the response
+        EasyMock.expect(response.getWriter()).andReturn(new PrintWriter(System.out));
+        EasyMock.expect(response.isCommitted()).andReturn(false);
+        EasyMock.expect(response.isCommitted()).andReturn(true); // the commit filter indicating that it committed the
+                                                                 // response
+        EasyMock.replay(response);
+        Assert.assertFalse(httpContext.handleSecurity(request, response));
+
+        // Ensure that the appropriate filters were called
+        Assert.assertTrue(doNothingFilter.called);
+        Assert.assertTrue(commitFilter.called);
+        Assert.assertFalse(accessDeniedFilter.called);
+    }
+
+    public void testAllowRequest() throws Exception {
+        // Mock up the service references
+        ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class);
+        EasyMock.replay(filterReference);
+        ServiceReference[] serviceReferences = new ServiceReference[] {
+            filterReference
+        };
+
+        // Mock up the bundle context
+        BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject()))
+            .andReturn(serviceReferences);
+        EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(doNothingFilter);
+        EasyMock.replay(bundleContext);
+
+        // Set up the secure http context
+        httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
+
+        // Ensure that the httpContext returns true, since the filter has not committed the response
+        HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
+        EasyMock.replay(request);
+        HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
+        EasyMock.expect(response.isCommitted()).andReturn(false);
+        EasyMock.replay(response);
+        Assert.assertTrue(httpContext.handleSecurity(request, response));
+
+        // Ensure that the appropriate filters were called
+        Assert.assertTrue(doNothingFilter.called);
+        Assert.assertFalse(commitFilter.called);
+        Assert.assertFalse(accessDeniedFilter.called);
+    }
+
+    public void testDelegation() throws Exception {
+        BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(bundleContext);
+
+        // Set up the secure http context
+        httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
+
+        // Ensure that it delegates non-security calls to the wrapped implementation (in this case, the mock)
+        Assert.assertEquals(mimeType, httpContext.getMimeType(""));
+        Assert.assertEquals(url, httpContext.getResource(""));
+    }
+}
+
+class CommitResponseFilter implements Filter {
+
+    boolean called;
+
+    public void init(FilterConfig filterConfig) throws ServletException {
+    }
+
+    public void destroy() {
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+        throws java.io.IOException, javax.servlet.ServletException {
+        called = true;
+        response.getWriter().write("committing the response");
+    }
+}
+
+class DoNothingFilter implements Filter {
+
+    boolean called;
+
+    public void init(FilterConfig filterConfig) throws ServletException {
+    }
+
+    public void destroy() {
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+        throws java.io.IOException, javax.servlet.ServletException {
+        called = true;
+        chain.doFilter(request, response);
+    }
+}
+
+class AccessDeniedFilter implements Filter {
+
+    boolean called;
+
+    public void init(FilterConfig filterConfig) throws ServletException {
+    }
+
+    public void destroy() {
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+        throws java.io.IOException, javax.servlet.ServletException {
+        called = true;
+        ((HttpServletResponse)response).sendError(HttpServletResponse.SC_FORBIDDEN);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentTrackerTest.java
----------------------------------------------------------------------
diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentTrackerTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentTrackerTest.java
index b68cf61..380478c 100644
--- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentTrackerTest.java
+++ b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentTrackerTest.java
@@ -18,7 +18,7 @@
  */
 package org.apache.cxf.dosgi.dsw.qos;
 
-import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.osgi.Constants;
 import org.apache.cxf.feature.AbstractFeature;
 import org.easymock.Capture;
 import org.easymock.EasyMock;

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/79bb9a43/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java
----------------------------------------------------------------------
diff --git a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java
index f7fe844..ad04be0 100644
--- a/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java
+++ b/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java
@@ -25,7 +25,7 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.osgi.Constants;
 import org.junit.Assert;
 import org.junit.Test;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;