You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2016/03/11 20:43:30 UTC
[31/50] [abbrv] aries-rsa git commit: Switch project setup to Aries
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
deleted file mode 100644
index 002f172..0000000
--- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
+++ /dev/null
@@ -1,422 +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.handlers;
-
-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.cxf.dosgi.dsw.Constants;
-import org.apache.cxf.dosgi.dsw.api.Endpoint;
-import org.apache.cxf.dosgi.dsw.api.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.qos.IntentManager;
-import org.apache.cxf.dosgi.dsw.qos.IntentManagerImpl;
-import org.apache.cxf.dosgi.dsw.qos.IntentMap;
-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/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContextTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContextTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContextTest.java
deleted file mode 100644
index 58b5f58..0000000
--- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContextTest.java
+++ /dev/null
@@ -1,267 +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.handlers;
-
-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/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java
deleted file mode 100644
index 64beeac..0000000
--- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandlerTest.java
+++ /dev/null
@@ -1,75 +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.handlers;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-public class ServiceInvocationHandlerTest extends TestCase {
-
- private static final Map<String, Method> OBJECT_METHODS = new HashMap<String, Method>(); {
- for (Method m : Object.class.getMethods()) {
- OBJECT_METHODS.put(m.getName(), m);
- }
- }
-
- public void testInvoke() throws Throwable {
- ServiceInvocationHandler sih = new ServiceInvocationHandler("hello", String.class);
- Method m = String.class.getMethod("length", new Class[] {});
- assertEquals(5, sih.invoke(null, m, new Object[] {}));
- }
-
- public void testInvokeObjectMethod() throws Throwable {
- final List<String> called = new ArrayList<String>();
- ServiceInvocationHandler sih = new ServiceInvocationHandler("hi", String.class) {
- public boolean equals(Object obj) {
- called.add("equals");
- return super.equals(obj);
- }
-
- public int hashCode() {
- called.add("hashCode");
- return super.hashCode();
- }
-
- public String toString() {
- called.add("toString");
- return "somestring";
- }
- };
-
- Object proxy = Proxy.newProxyInstance(
- getClass().getClassLoader(), new Class[] {Runnable.class}, sih);
-
- assertEquals(true,
- sih.invoke(null, OBJECT_METHODS.get("equals"), new Object[] {proxy}));
- assertEquals(System.identityHashCode(sih),
- sih.invoke(null, OBJECT_METHODS.get("hashCode"), new Object[] {}));
- assertEquals("somestring",
- sih.invoke(null, OBJECT_METHODS.get("toString"), new Object[] {}));
- assertEquals(Arrays.asList("equals", "hashCode", "toString"), called);
- }
-}
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandlerTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandlerTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandlerTest.java
deleted file mode 100644
index df90758..0000000
--- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandlerTest.java
+++ /dev/null
@@ -1,67 +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.handlers;
-
-import junit.framework.TestCase;
-
-public class WsdlConfigurationTypeHandlerTest extends TestCase {
-
- public void testDUMMY() {
- assertTrue(true);
- }
-
-// private Map<String, Object> handlerProps;
-//
-// @Override
-// protected void setUp() throws Exception {
-// super.setUp();
-//
-// handlerProps = new HashMap<String, Object>();
-// handlerProps.put(Constants.DEFAULT_HOST_CONFIG, "somehost");
-// handlerProps.put(Constants.DEFAULT_PORT_CONFIG, "54321");
-// }
-//
-// public void testCreateProxyPopulatesDistributionProvider() {
-// ServiceReference sr = EasyMock.createNiceMock(ServiceReference.class);
-// BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
-// BundleContext callingContext = EasyMock.createNiceMock(BundleContext.class);
-// ServiceEndpointDescription sd = TestUtils.mockServiceDescription("Foo");
-// EasyMock.replay(sr);
-// EasyMock.replay(dswContext);
-// EasyMock.replay(callingContext);
-// EasyMock.replay(sd);
-//
-// RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
-// WsdlConfigurationTypeHandler w = new WsdlConfigurationTypeHandler(dswContext, dp, handlerProps) {
-// @Override
-// Service createWebService(URL wsdlAddress, QName serviceQname) {
-// Service svc = EasyMock.createMock(Service.class);
-// EasyMock.expect(svc.getPort(CharSequence.class)).andReturn("Hi").anyTimes();
-// EasyMock.replay(svc);
-// return svc;
-// }
-// };
-//
-// assertEquals("Precondition failed", 0, dp.getRemoteServices().size());
-// w.createProxy(sr, dswContext, callingContext, CharSequence.class, sd);
-// assertEquals(1, dp.getRemoteServices().size());
-// assertSame(sr, dp.getRemoteServices().iterator().next());
-//
-// }
-}
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/jaxws/MyJaxWsEchoService.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/jaxws/MyJaxWsEchoService.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/jaxws/MyJaxWsEchoService.java
deleted file mode 100644
index 7814267..0000000
--- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/jaxws/MyJaxWsEchoService.java
+++ /dev/null
@@ -1,26 +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.handlers.jaxws;
-
-import javax.jws.WebService;
-
-@WebService
-public interface MyJaxWsEchoService {
- String echo(String message);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/jaxws/MyJaxWsEchoServiceImpl.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/jaxws/MyJaxWsEchoServiceImpl.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/jaxws/MyJaxWsEchoServiceImpl.java
deleted file mode 100644
index 699c9ae..0000000
--- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/jaxws/MyJaxWsEchoServiceImpl.java
+++ /dev/null
@@ -1,27 +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.handlers.jaxws;
-
-public class MyJaxWsEchoServiceImpl implements MyJaxWsEchoService {
-
- @Override
- public String echo(String message) {
- return message;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/simple/MySimpleEchoService.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/simple/MySimpleEchoService.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/simple/MySimpleEchoService.java
deleted file mode 100644
index 7d574ca..0000000
--- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/simple/MySimpleEchoService.java
+++ /dev/null
@@ -1,23 +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.handlers.simple;
-
-public interface MySimpleEchoService {
- String echo(String message);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/simple/MySimpleEchoServiceImpl.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/simple/MySimpleEchoServiceImpl.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/simple/MySimpleEchoServiceImpl.java
deleted file mode 100644
index 19dda4b..0000000
--- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/simple/MySimpleEchoServiceImpl.java
+++ /dev/null
@@ -1,27 +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.handlers.simple;
-
-public class MySimpleEchoServiceImpl implements MySimpleEchoService {
-
- @Override
- public String echo(String message) {
- return message;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfFindListenerHookTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfFindListenerHookTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfFindListenerHookTest.java
deleted file mode 100644
index fde48d2..0000000
--- a/dsw/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/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHookTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHookTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHookTest.java
deleted file mode 100644
index 40b40c5..0000000
--- a/dsw/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/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtilsTest.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtilsTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtilsTest.java
deleted file mode 100644
index c004702..0000000
--- a/dsw/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/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/TestService.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/TestService.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/TestService.java
deleted file mode 100644
index 07b5088..0000000
--- a/dsw/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 {
-}