cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1414645 [2/2] - in /cxf/dosgi/trunk/dsw/cxf-dsw/src: main/java/org/apache/cxf/dosgi/dsw/ main/java/org/apache/cxf/dosgi/dsw/handlers/ main/java/org/apache/cxf/dosgi/dsw/qos/ main/java/org/apache/cxf/dosgi/dsw/service/ main/resources/OSGI-I...
Date Wed, 28 Nov 2012 12:24:07 GMT
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactoryTest.java?rev=1414645&r1=1414644&r2=1414645&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactoryTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactoryTest.java
Wed Nov 28 12:24:01 2012
@@ -18,140 +18,75 @@
  */
 package org.apache.cxf.dosgi.dsw.handlers;
 
-import java.util.ArrayList;
+import static org.junit.Assert.assertTrue;
+
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
-import junit.framework.TestCase;
-
 import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.qos.DefaultIntentMapFactory;
 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.easymock.EasyMock;
+import org.junit.Test;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
 
-public class ConfigTypeHandlerFactoryTest extends TestCase {
+public class ConfigTypeHandlerFactoryTest {
 
+    @Test
+    public void testGetDefaultHandlerNoIntents() {
+        ConfigurationTypeHandler handler = getHandlerWith(null, null);
+        assertTrue(handler instanceof PojoConfigurationTypeHandler);
+    }
+    
+    @Test
     public void testGetJaxrsHandlerNoIntents() {
-        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.replay(bc);
-
-        List<String> configs = new ArrayList<String>();
-        Map<String, Object> serviceProps = new HashMap<String, Object>();
-
-        IntentMap intentMap = new IntentMap();
-        IntentManager intentManager = new IntentManagerImpl(intentMap);
-        ConfigTypeHandlerFactory f = new ConfigTypeHandlerFactory(intentManager );
-
-        configs.add(Constants.RS_CONFIG_TYPE);
-
-        ConfigurationTypeHandler handler = f.getHandler(bc, configs, serviceProps, null);
+        ConfigurationTypeHandler handler = getHandlerWith(Constants.RS_CONFIG_TYPE, null);
         assertTrue(handler instanceof JaxRSPojoConfigurationTypeHandler);
     }
 
+    @Test
     public void testGetJaxrsHandlerHttpIntents() {
-        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.replay(bc);
-
-        List<String> configs = new ArrayList<String>();
-        Map<String, Object> serviceProps = new HashMap<String, Object>();
-
-        IntentMap intentMap = new IntentMap();
-        IntentManager intentManager = new IntentManagerImpl(intentMap);
-        ConfigTypeHandlerFactory f = new ConfigTypeHandlerFactory(intentManager);
-        configs.add(Constants.RS_CONFIG_TYPE);
-        serviceProps.put(RemoteConstants.SERVICE_EXPORTED_INTENTS, "HTTP");
-
-        ConfigurationTypeHandler handler = f.getHandler(bc, configs, serviceProps, null);
+        ConfigurationTypeHandler handler = getHandlerWith(Constants.RS_CONFIG_TYPE, "HTTP");
         assertTrue(handler instanceof JaxRSPojoConfigurationTypeHandler);
     }
 
+    @Test
     public void testJaxrsPropertyIgnored() {
-        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.replay(bc);
-
-        List<String> configs = new ArrayList<String>();
-        Map<String, Object> serviceProps = new HashMap<String, Object>();
-
-        IntentMap intentMap = new IntentMap();
-        IntentManager intentManager = new IntentManagerImpl(intentMap);
-        ConfigTypeHandlerFactory f = new ConfigTypeHandlerFactory(intentManager);
-        configs.add(Constants.RS_CONFIG_TYPE);
-        serviceProps.put(RemoteConstants.SERVICE_EXPORTED_INTENTS, "SOAP HTTP");
-
-        ConfigurationTypeHandler handler = f.getHandler(bc, configs, serviceProps, null);
+        ConfigurationTypeHandler handler = getHandlerWith(Constants.RS_CONFIG_TYPE, "SOAP
HTTP");
         assertTrue(handler instanceof PojoConfigurationTypeHandler);
         assertTrue(!(handler instanceof JaxRSPojoConfigurationTypeHandler));
     }
 
+    @Test
     public void testGetPojoHandler() {
-        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.replay(bc);
-
-        List<String> configs = new ArrayList<String>();
-        Map<String, Object> serviceProps = new HashMap<String, Object>();
-
-        IntentMap intentMap = new IntentMap();
-        IntentManager intentManager = new IntentManagerImpl(intentMap);
-        ConfigTypeHandlerFactory f = new ConfigTypeHandlerFactory(intentManager);
-        configs.add(Constants.WS_CONFIG_TYPE);
-
-        ConfigurationTypeHandler handler = f.getHandler(bc, configs, serviceProps, null);
+        ConfigurationTypeHandler handler = getHandlerWith(Constants.WS_CONFIG_TYPE, null);
         assertTrue(handler instanceof PojoConfigurationTypeHandler);
     }
 
-    public void testGetHttpServiceHandler() {
-        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.replay(bc);
-
-        IntentMap intentMap = new IntentMap();
-        IntentManager intentManager = new IntentManagerImpl(intentMap);
-        ConfigTypeHandlerFactory f = new ConfigTypeHandlerFactory(intentManager);
-
-        List<String> configs = new ArrayList<String>();
-        Map<String, Object> serviceProps = new HashMap<String, Object>();
-
-        configs.add(Constants.WS_CONFIG_TYPE);
-        serviceProps.put(Constants.WS_HTTP_SERVICE_CONTEXT, "/abc");
-
-        ConfigurationTypeHandler handler = f.getHandler(bc, configs, serviceProps, null);
-        assertTrue(handler instanceof HttpServiceConfigurationTypeHandler);
-    }
-
+    @Test
     public void testGetWSDLHandler() {
-        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.replay(bc);
-
-        IntentMap intentMap = new IntentMap();
-        IntentManager intentManager = new IntentManagerImpl(intentMap);
-        ConfigTypeHandlerFactory f = new ConfigTypeHandlerFactory(intentManager);
-
-        List<String> configs = new ArrayList<String>();
-        Map<String, Object> serviceProps = new HashMap<String, Object>();
-        configs.add(Constants.WSDL_CONFIG_TYPE);
-
-        ConfigurationTypeHandler handler = f.getHandler(bc, configs, serviceProps, null);
-
+        ConfigurationTypeHandler handler = getHandlerWith(Constants.WSDL_CONFIG_TYPE, null);
         assertTrue(handler instanceof WsdlConfigurationTypeHandler);
     }
 
+    @Test(expected = RuntimeException.class)
     public void testUnsupportedConfiguration() {
+        getHandlerWith("notSupportedConfig", null);
+    }
+    
+    private ConfigurationTypeHandler getHandlerWith(String configType, String intents) {
         BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
         EasyMock.replay(bc);
-
-        IntentMap intentMap = new IntentMap();
-        IntentManager intentManager = new IntentManagerImpl(intentMap);
-        ConfigTypeHandlerFactory f = new ConfigTypeHandlerFactory(intentManager);
-
-        List<String> configs = new ArrayList<String>();
         Map<String, Object> serviceProps = new HashMap<String, Object>();
-        configs.add("notSupportedConfig");
-
-        assertNull("Should not get a handler as this an unsupported config type", f.getHandler(bc,
configs,
-                                                                                        
      serviceProps,
-                                                                                        
      null));
+        serviceProps.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, configType);
+        serviceProps.put(RemoteConstants.SERVICE_EXPORTED_INTENTS, intents);
+        IntentMap intentMap = new IntentMap(new DefaultIntentMapFactory().create());
+        IntentManager intentManager = new IntentManagerImpl(intentMap);
+        HttpServiceManager httpServiceManager = new HttpServiceManager(bc);
+        ConfigTypeHandlerFactory f = new ConfigTypeHandlerFactory(intentManager, httpServiceManager
);
+        return f.getHandler(bc, serviceProps, null);
     }
 }

Copied: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java
(from r1414579, cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java)
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java?p2=cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java&p1=cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java&r1=1414579&r2=1414645&rev=1414645&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceConfigurationTypeHandlerTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java
Wed Nov 28 12:24:01 2012
@@ -18,382 +18,94 @@
   */
 package org.apache.cxf.dosgi.dsw.handlers;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
 
+import java.util.Dictionary;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import junit.framework.Assert;
 import junit.framework.TestCase;
 
-import org.apache.cxf.binding.BindingConfiguration;
-import org.apache.cxf.dosgi.dsw.Constants;
-import org.apache.cxf.dosgi.dsw.qos.IntentManager;
-import org.apache.cxf.dosgi.dsw.qos.IntentUnsatifiedException;
-import org.apache.cxf.dosgi.dsw.service.RemoteServiceAdminCore;
-import org.apache.cxf.endpoint.AbstractEndpointFactory;
-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.service.factory.ReflectionServiceFactoryBean;
-import org.apache.cxf.transport.Destination;
-import org.apache.cxf.ws.addressing.AttributedURIType;
-import org.apache.cxf.ws.addressing.EndpointReferenceType;
-import org.easymock.IAnswer;
-import org.easymock.classextension.EasyMock;
-import org.easymock.classextension.IMocksControl;
+import org.apache.cxf.Bus;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
 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.remoteserviceadmin.EndpointDescription;
-import org.osgi.service.remoteserviceadmin.RemoteConstants;
+import org.osgi.service.http.NamespaceException;
 
-public class HttpServiceConfigurationTypeHandlerTest extends TestCase {
+public class HttpServiceManagerTest extends TestCase {
     
-    public void testServer() throws Exception {
-        IMocksControl c = EasyMock.createNiceControl();
+    public void testRegisterAndUnregisterServlet() throws Exception {
+        IMocksControl c = EasyMock.createControl();
         BundleContext dswContext = c.createMock(BundleContext.class);
-        EasyMock.expect(dswContext.getProperty("org.osgi.service.http.port")).
-            andReturn("1327").anyTimes();
-        HttpService httpService = c.createMock(HttpService.class);
-        // expect that the cxf servlet is registered
-        
-        ServiceReference httpSvcSR = c.createMock(ServiceReference.class);
-        EasyMock.expect(dswContext.getService(httpSvcSR)).andReturn(httpService).anyTimes();
-        
-        final ServerFactoryBean sfb = createMockServerFactoryBean();
-        
-        //        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
-        Map<String, Object> handlerProps = new HashMap<String, Object>();
-        IntentManager intentManager = new DummyIntentManager(new String [] {"a.b.c"});
-        c.replay();
-        
-        HttpServiceConfigurationTypeHandler h = 
-            new HttpServiceConfigurationTypeHandler(dswContext, intentManager , handlerProps)
{
-                @Override
-                ServerFactoryBean createServerFactoryBean(ServiceReference sRef, Class<?>
iClass) {
-                    return sfb;
-                }
-        };
-        h.httpServiceReferences.add(httpSvcSR);
-        
-        Runnable myService = new Runnable() {
-            public void run() {
-                System.out.println("blah");
-            }            
-        };
-                
-        ServiceReference sr = EasyMock.createNiceMock(ServiceReference.class);
-        BundleContext callingContext = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.replay(sr);
-        EasyMock.replay(callingContext);
-
-        Map<String, Object> props = new HashMap<String, Object>();
-        props.put(Constants.WS_HTTP_SERVICE_CONTEXT, "/myRunnable");
-        //ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Runnable.class.getName(),
props);
-        
-        //        assertEquals("Precondition failed", 0, dp.getExposedServices().size());
-        assertEquals("Precondition failed", "", sfb.getAddress());
-        ExportResult exportResult = h.createServer(sr, dswContext, callingContext, props,
Runnable.class, myService);
-        assertEquals("The address should be set to '/'. The Servlet context dictates the
actual location.", "/", sfb.getAddress());
-        //assertEquals(1, dp.getExposedServices().size());
-        //assertSame(sr, dp.getExposedServices().iterator().next());
-        
-        String hostName;
-        try {
-            hostName = LocalHostUtil.getLocalHost().getHostAddress();
-        } catch (Exception e) {
-            hostName = "localhost";
-        }
-        
-        Map edProps = exportResult.getEndpointProps();
-        
-        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://" + hostName + ":1327/myRunnable", edProps.get(RemoteConstants.ENDPOINT_ID));
-        assertNotNull(edProps.get(RemoteConstants.SERVICE_INTENTS));
-        assertTrue(((String[])edProps.get(RemoteConstants.SERVICE_INTENTS)).length>=1);
-        boolean intentIn = false;
-        for (String s : (String[])edProps.get(RemoteConstants.SERVICE_INTENTS)) {
-            if("a.b.c".equals(s)){
-                intentIn=true;
-                break;
-            }
-        }
-        assertTrue(intentIn);
-    } 
-    
-    public void testServerUsingDefaultAddress() throws Exception {
-        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
-        HttpService httpService = EasyMock.createNiceMock(HttpService.class);
-        // expect that the cxf servlet is registered
-        EasyMock.replay(httpService);
-        
-        ServiceReference httpSvcSR = EasyMock.createNiceMock(ServiceReference.class);
-        EasyMock.replay(httpSvcSR);
-        EasyMock.expect(dswContext.getService(httpSvcSR)).andReturn(httpService).anyTimes();
-        EasyMock.replay(dswContext);
-        
-        final ServerFactoryBean sfb = createMockServerFactoryBean();
-        
-        IntentManager intentManager = new DummyIntentManager(new String[]{});
-        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext, intentManager);
-        Map<String, Object> handlerProps = new HashMap<String, Object>();
-        
-        HttpServiceConfigurationTypeHandler h = 
-            new HttpServiceConfigurationTypeHandler(dswContext, intentManager, handlerProps)
{
-                @Override
-                ServerFactoryBean createServerFactoryBean(ServiceReference sRef, Class<?>
iClass) {
-                    return sfb;
-                }
-
-                            
-        };
-        h.httpServiceReferences.add(httpSvcSR);
-        
-        Runnable myService = new Runnable() {
-            public void run() {
-                System.out.println("blah");
-            }            
-        };
-                
-        ServiceReference sr = EasyMock.createNiceMock(ServiceReference.class);
-        BundleContext callingContext = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.replay(sr);
-        EasyMock.replay(callingContext);
-
-        Map<String, Object> props = new HashMap<String, Object>();
-        //ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Runnable.class.getName(),
props);
-        
-        //assertEquals("Precondition failed", 0, dp.getExposedServices().size());
-        ExportResult exportResult = h.createServer(sr, dswContext, callingContext, props,
Runnable.class, myService);
-        //assertEquals(1, dp.getExposedServices().size());
-        //assertSame(sr, dp.getExposedServices().iterator().next());
-        
-        String hostname;
-        try {
-            hostname = LocalHostUtil.getLocalHost().getHostAddress();
-        } catch (Exception e) {
-            hostname = "localhost";
-        }
-        
-        Map edProps = exportResult.getEndpointProps();
-        
-        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://" + hostname + ":8080/java/lang/Runnable", edProps.get(RemoteConstants.ENDPOINT_ID));
-        
-    }
-
-    public void testServerConfiguredUsingHttps() throws Exception {
-        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.expect(dswContext.getProperty("org.osgi.service.http.secure.enabled")).
-            andReturn("true").anyTimes();
-        EasyMock.expect(dswContext.getProperty("org.osgi.service.http.port.secure")).
-            andReturn("8432").anyTimes();
-        
-        HttpService httpService = EasyMock.createNiceMock(HttpService.class);
-        // expect that the cxf servlet is registered
-        EasyMock.replay(httpService);
-        
-        ServiceReference httpSvcSR = EasyMock.createNiceMock(ServiceReference.class);
-        EasyMock.replay(httpSvcSR);
-        EasyMock.expect(dswContext.getService(httpSvcSR)).andReturn(httpService).anyTimes();
-        EasyMock.replay(dswContext);
-        
-        final ServerFactoryBean sfb = createMockServerFactoryBean();
-        
-		IntentManager intentManager = new DummyIntentManager(new String [] {});
-        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext, intentManager);
-        Map<String, Object> handlerProps = new HashMap<String, Object>();
-        HttpServiceConfigurationTypeHandler h = 
-            new HttpServiceConfigurationTypeHandler(dswContext, intentManager, handlerProps)
{
-                @Override
-                ServerFactoryBean createServerFactoryBean(ServiceReference sRef, Class<?>
iClass) {
-                    return sfb;
-                }
-        };
-        h.httpServiceReferences.add(httpSvcSR);
-        
-        Runnable myService = new Runnable() {
-            public void run() {
-                System.out.println("blah");
-            }            
-        };
-                
-        ServiceReference sr = EasyMock.createNiceMock(ServiceReference.class);
-        BundleContext callingContext = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.replay(sr);
-        EasyMock.replay(callingContext);
-
-        Map<String, Object> props = new HashMap<String, Object>();
-        props.put("osgi.remote.configuration.type", Constants.WS_CONFIG_TYPE);
-        props.put(Constants.WS_HTTP_SERVICE_CONTEXT, "/myRunnable");
-        //ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Runnable.class.getName(),
props);
-        
-        //assertEquals("Precondition failed", 0, dp.getExposedServices().size());
-        ExportResult exportResult = h.createServer(sr, dswContext, callingContext, props,
Runnable.class, myService);
-        //assertEquals(1, dp.getExposedServices().size());
-        //assertSame(sr, dp.getExposedServices().iterator().next());
-        
-        String hostName;
-        try {
-            hostName = LocalHostUtil.getLocalHost().getHostAddress();
-        } catch (Exception e) {
-            hostName = "localhost";
-        }
-        Map edProps = exportResult.getEndpointProps();
-        
-        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("https://" + hostName + ":8432/myRunnable", edProps.get(RemoteConstants.ENDPOINT_ID));
-    } 
-
-    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;
-            }            
-        }).anyTimes();
-        EasyMock.expect(sfb.getAddress()).andAnswer(new IAnswer<String>() {
-            public String answer() throws Throwable {
-                return serverURI.toString();
-            }            
-        }).anyTimes();
-        EasyMock.replay(sfb);
-        return sfb;
-    }
-
-    private Server createMockServer(final ServerFactoryBean sfb) {
-        AttributedURIType addr = org.easymock.classextension.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 testCreateProxy() {
-        IMocksControl c = EasyMock.createNiceControl();
-        BundleContext bc1 = c.createMock(BundleContext.class);
-        BundleContext bc2 = c.createMock(BundleContext.class);
-
-        HttpService httpService = c.createMock(HttpService.class);
-
-        ServiceReference httpSvcSR = c.createMock(ServiceReference.class);
-        EasyMock.expect(bc1.getService(httpSvcSR)).andReturn(httpService).anyTimes();
-
-        final ClientProxyFactoryBean cpfb = c.createMock(ClientProxyFactoryBean.class);
-        ReflectionServiceFactoryBean sf = c.createMock(ReflectionServiceFactoryBean.class);
-        EasyMock.expect(cpfb.getServiceFactory()).andReturn(sf).anyTimes();
-
+        Filter filter = c.createMock(Filter.class);
+        expect(dswContext.createFilter(EasyMock.eq("(service.id=12345)"))).andReturn(filter).once();
+        Capture<ServiceListener> captured = new Capture<ServiceListener>();
+        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);
-
-        Map<String, Object> props = new HashMap<String, Object>();
-        props.put(RemoteConstants.ENDPOINT_ID, "000001");
-        props.put(Constants.WS_ADDRESS_PROPERTY, "http://google.de/");
-        props.put(org.osgi.framework.Constants.OBJECTCLASS, new String[] { "my.class" });
-        props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, new String[] { "my.config" });
-        EndpointDescription endpoint = new EndpointDescription(props);
-
-        cpfb.setAddress((String) EasyMock.eq(props.get(Constants.WS_ADDRESS_PROPERTY)));
-        EasyMock.expectLastCall().atLeastOnce();
-
-        cpfb.setServiceClass(EasyMock.eq(CharSequence.class));
-        EasyMock.expectLastCall().atLeastOnce();
-
+        expect(sr.getProperty(EasyMock.eq("service.id"))).andReturn(12345l).atLeastOnce();
         c.replay();
+        
+        HttpServiceManager h = new HttpServiceManager(dswContext, null) {
 
-        Map<String, Object> handlerProps = new HashMap<String, Object>();
-        IntentManager intentManager = new DummyIntentManager(new String[] { "a.b.c" });
-        HttpServiceConfigurationTypeHandler h = new HttpServiceConfigurationTypeHandler(bc1,
intentManager , handlerProps) {
             @Override
-            ClientProxyFactoryBean createClientProxyFactoryBean(ServiceReference sRef, Class<?>
iClass) {
-                return cpfb;
+            protected HttpService getHttpService() {
+                return httpService;
             }
-
+            
         };
-
-        h.httpServiceReferences.add(httpSvcSR);
-
-        Object proxy = h.createProxy(sr, bc1, bc2, CharSequence.class, endpoint);
-        assertNotNull(proxy);
-
-        if (proxy instanceof CharSequence) {
-            CharSequence cs = (CharSequence) proxy;
-        } else {
-            assertTrue("Proxy is not of the requested type! ", false);
-        }
-
+        Bus bus = h.registerServletAndGetBus("/myService", dswContext, sr);
+        Assert.assertNotNull(bus);
+        
+        ServiceEvent event = new ServiceEvent(ServiceEvent.UNREGISTERING, sr);
+        captured.getValue().serviceChanged(event);
         c.verify();
-    }
+    } 
 
-    // TODO these tests still need to be written...
-    /*
-    public void testNoHttpService() {
+    static class DummyHttpService implements HttpService {
         
-    }
-    
-    public void testHttpServiceDynamism() {
-        
-    }
-    
-    public void testServletUnregistration() {        
-    }
-    */
-    
-    class DummyIntentManager implements IntentManager {
-        private String[] applyResult;
+        private ServletConfig config;
 
-        public DummyIntentManager(String[] applyResult) {
-            this.applyResult = applyResult;
+        public DummyHttpService(ServletConfig config) {
+            this.config = config;
         }
-        
-        public BindingConfiguration getBindingConfiguration(String[] requestedIntents,
-                BindingConfiguration defaultConfig) {
-            return defaultConfig;
+
+        @SuppressWarnings("rawtypes")
+        public void registerServlet(String alias, Servlet servlet, Dictionary initparams,
HttpContext context)
+                throws ServletException, NamespaceException {
+            Assert.assertEquals("/myService", alias);
+            servlet.init(config);
         }
 
-        public String[] applyIntents(List<Feature> features, String[] requestedIntents)
-                throws IntentUnsatifiedException {
-            return applyResult;
+        public void registerResources(String alias, String name, HttpContext context) throws
NamespaceException {
+            throw new RuntimeException("This method should not be called");
         }
 
-        public String[] applyIntents(List<Feature> features, AbstractEndpointFactory
factory, Map<String, Object> props) {
-            return applyResult;
+        public void unregister(String alias) {
+
         }
 
-        public void assertAllIntentsSupported(Properties serviceProperties) {
+        public HttpContext createDefaultHttpContext() {
+            return EasyMock.createNiceMock(HttpContext.class);
         }
-    };
+        
+    }
 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java?rev=1414645&r1=1414644&r2=1414645&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
Wed Nov 28 12:24:01 2012
@@ -51,51 +51,57 @@ public class PojoConfigurationTypeHandle
     public void testGetPojoAddressEndpointURI() {
         Map<String, Object> hp = new HashMap<String, Object>();
         IntentManager intentManager = new IntentManagerImpl(new IntentMap());
-        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager
, hp);
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager,
dummyHttpServiceManager(), hp);
         Map<String, Object> sd = new HashMap<String, Object>();
         String url = "http://somewhere:1234/blah";
         sd.put(RemoteConstants.ENDPOINT_ID, url);
-        assertEquals(url, handler.getPojoAddress(sd, String.class));
+        assertEquals(url, handler.getServerAddress(sd, String.class));
     }
     
+    private HttpServiceManager dummyHttpServiceManager() {
+        HttpServiceManager httpServiceManager = EasyMock.createNiceMock(HttpServiceManager.class);
+        EasyMock.replay(httpServiceManager);
+        return httpServiceManager;
+    }
+
     public void testGetPojoAddressEndpointCxf() {
         Map<String, Object> hp = new HashMap<String, Object>();
         IntentManager intentManager = new IntentManagerImpl(new IntentMap());
-        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager
, hp);
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager,
dummyHttpServiceManager(), hp);
         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.getPojoAddress(sd, String.class));
+        assertEquals(url, handler.getServerAddress(sd, String.class));
     }
 
     public void testGetPojoAddressEndpointPojo() {
         Map<String, Object> hp = new HashMap<String, Object>();
         IntentManager intentManager = new IntentManagerImpl(new IntentMap());
-        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager
, hp);
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager,
dummyHttpServiceManager(), hp);
         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.getPojoAddress(sd, String.class));
+        assertEquals(url, handler.getServerAddress(sd, String.class));
     }
     
     public void testGetPojoAddressDefaultWithAlternatePort() {
         Map<String, Object> hp = new HashMap<String, Object>();
         IntentManager intentManager = new IntentManagerImpl(new IntentMap());
-        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager
, hp);
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager
, dummyHttpServiceManager(), hp);
         Map<String, Object> sd = new HashMap<String, Object>();
         String localIP = getLocalIp();
         String url = "http://"+localIP+":1234/java/lang/String";
         sd.put("org.apache.cxf.ws.port", "1234");
-        assertEquals(url, handler.getPojoAddress(sd, String.class));        
+        assertEquals(url, handler.getServerAddress(sd, String.class));        
     }
 
     public void testGetDefaultPojoAddress() {
         Map<String, Object> hp = new HashMap<String, Object>();
         IntentManager intentManager = new IntentManagerImpl(new IntentMap());
-        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager
, hp);
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager
, dummyHttpServiceManager(), hp);
         Map<String, Object> sd = new HashMap<String, Object>(); 
         String localIP = getLocalIp();
-        assertEquals("http://"+localIP+":9000/java/lang/String", handler.getPojoAddress(sd,
String.class));
+        assertEquals("http://"+localIP+":9000/java/lang/String", handler.getServerAddress(sd,
String.class));
     }
 
     private String getLocalIp() {
@@ -136,7 +142,7 @@ public class PojoConfigurationTypeHandle
                 return new String[0];
             }
         };
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(bc1, intentManager,
handlerProps) {
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(bc1, intentManager,
dummyHttpServiceManager(), handlerProps) {
             @Override
             ClientProxyFactoryBean createClientProxyFactoryBean(ServiceReference sRef, Class<?>
iClass) {
                 return cpfb;
@@ -273,7 +279,7 @@ public class PojoConfigurationTypeHandle
                 return new String []{};
             }
         };
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, intentManager,
handlerProps) {
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, intentManager,
dummyHttpServiceManager(), handlerProps) {
             @Override
             ServerFactoryBean createServerFactoryBean(ServiceReference sRef, Class<?>
iClass) {
                 return sfb;
@@ -359,7 +365,7 @@ public class PojoConfigurationTypeHandle
         EasyMock.replay(bc);
         
         IntentManager intentManager = new IntentManagerImpl(new IntentMap());
-        PojoConfigurationTypeHandler pch = new PojoConfigurationTypeHandler(bc, intentManager
, null);
+        PojoConfigurationTypeHandler pch = new PojoConfigurationTypeHandler(bc, intentManager,
dummyHttpServiceManager(), null);
         
         Map<String, Object> sd = new HashMap<String, Object>();
         sd.put(org.osgi.framework.Constants.SERVICE_ID, 42);

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java?rev=1414645&r1=1414644&r2=1414645&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java
Wed Nov 28 12:24:01 2012
@@ -21,10 +21,10 @@ package org.apache.cxf.dosgi.dsw.qos;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.junit.Test;
-
 import junit.framework.Assert;
 
+import org.junit.Test;
+
 public class IntentMapTest {
 
     @Test

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java?rev=1414645&r1=1414644&r2=1414645&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCoreTest.java
Wed Nov 28 12:24:01 2012
@@ -21,7 +21,6 @@ package org.apache.cxf.dosgi.dsw.service
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
 
 import java.util.Dictionary;
 import java.util.HashMap;
@@ -29,8 +28,13 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
+import org.apache.cxf.dosgi.dsw.handlers.ConfigTypeHandlerFactory;
 import org.apache.cxf.dosgi.dsw.handlers.ConfigurationTypeHandler;
+import org.apache.cxf.dosgi.dsw.handlers.HttpServiceManager;
+import org.apache.cxf.dosgi.dsw.qos.DefaultIntentMapFactory;
 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.easymock.IMocksControl;
 import org.easymock.classextension.EasyMock;
 import org.junit.Test;
@@ -39,6 +43,7 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.ExportRegistration;
 import org.osgi.service.remoteserviceadmin.ImportRegistration;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
 
@@ -53,19 +58,19 @@ public class RemoteServiceAdminCoreTest 
 
         EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
 
-        Dictionary d = new Properties();
+        Dictionary<?,?> d = new Properties();
         EasyMock.expect(b.getHeaders()).andReturn(d).anyTimes();
 
         ServiceReference sref = c.createMock(ServiceReference.class);
         EasyMock.expect(sref.getBundle()).andReturn(b).anyTimes();
 
-        IntentManager intentManager = c.createMock(IntentManager.class);
-		RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, intentManager);
+		ConfigTypeHandlerFactory configTypeHandlerFactory = c.createMock(ConfigTypeHandlerFactory.class);
+        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, configTypeHandlerFactory
);
 
         c.replay();
 
         // must return an empty List as sref if from the same bundle
-        List exRefs = rsaCore.exportService(sref, null);
+        List<ExportRegistration> exRefs = rsaCore.exportService(sref, null);
 
         assertNotNull(exRefs);
         assertEquals(0, exRefs.size());
@@ -77,7 +82,6 @@ public class RemoteServiceAdminCoreTest 
 
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void testImport() {
 
@@ -85,30 +89,31 @@ public class RemoteServiceAdminCoreTest 
         Bundle b = c.createMock(Bundle.class);
         BundleContext bc = c.createMock(BundleContext.class);
 
-        Dictionary d = new Properties();
+        Dictionary<?,?> d = new Properties();
         EasyMock.expect(b.getHeaders()).andReturn(d).anyTimes();
 
         EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
         EasyMock.expect(b.getSymbolicName()).andReturn("BundleName").anyTimes();
-
-        IntentManager intentManager = c.createMock(IntentManager.class);
-        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, intentManager) {
-            @Override
-            protected void proxifyMatchingInterface(String interfaceName, ImportRegistrationImpl
imReg,
-                                                    ConfigurationTypeHandler handler,
-                                                    BundleContext requestingContext) {
-
-            }
-        };
-
-        Map p = new HashMap();
+        
+        Map<String, Object> p = new HashMap<String, Object>();
         p.put(RemoteConstants.ENDPOINT_ID, "http://google.de");
         p.put(Constants.OBJECTCLASS, new String[] {
             "es.schaaf.my.class"
         });
         p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "unsupportetConfiguration");
         EndpointDescription endpoint = new EndpointDescription(p);
+        IntentMap intentMap = new IntentMap(new DefaultIntentMapFactory().create());
+        IntentManager intentManager = new IntentManagerImpl(intentMap, 10000);
+        HttpServiceManager httpServiceManager = c.createMock(HttpServiceManager.class);
+        ConfigTypeHandlerFactory configTypeHandlerFactory = new ConfigTypeHandlerFactory(intentManager,
httpServiceManager);
+        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, configTypeHandlerFactory
) {
+            @Override
+            protected void proxifyMatchingInterface(String interfaceName, ImportRegistrationImpl
imReg,
+                                                    ConfigurationTypeHandler handler,
+                                                    BundleContext requestingContext) {
 
+            }
+        };
         c.replay();
 
         // must be null as the endpoint doesn't contain any usable configurations
@@ -116,7 +121,7 @@ public class RemoteServiceAdminCoreTest 
         // must be empty ...
         assertEquals(0, rsaCore.getImportedEndpoints().size());
 
-        p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "org.apache.cxf.ws");
+        p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE);
         endpoint = new EndpointDescription(p);
 
         ImportRegistration ireg = rsaCore.importService(endpoint);
@@ -148,54 +153,4 @@ public class RemoteServiceAdminCoreTest 
 
     }
 
-    @Test
-    public void testDefaultConfigurationType() {
-
-        IMocksControl c = EasyMock.createNiceControl();
-        Bundle b = c.createMock(Bundle.class);
-        BundleContext bc = c.createMock(BundleContext.class);
-
-        IntentManager intentManager = c.createMock(IntentManager.class);
-        c.replay();
-        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, intentManager);
-
-        Properties serviceProperties = new Properties();
-
-        List<String> types = rsaCore.determineConfigurationTypes(serviceProperties);
-
-        c.verify();
-
-        assertNotNull(types);
-        assertEquals(1, types.size());
-
-        assertTrue(types.contains(org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE));
-    }
-
-    @Test
-    public void testSpecificConfigurationType() {
-
-        IMocksControl c = EasyMock.createNiceControl();
-        Bundle b = c.createMock(Bundle.class);
-        BundleContext bc = c.createMock(BundleContext.class);
-
-
-        IntentManager intentManager = c.createMock(IntentManager.class);
-        c.replay();
-        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, intentManager);
-
-        Properties serviceProperties = new Properties();
-
-        serviceProperties.setProperty(RemoteConstants.SERVICE_EXPORTED_CONFIGS,
-                                      org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE);
-
-        List<String> types = rsaCore.determineConfigurationTypes(serviceProperties);
-
-        c.verify();
-
-        assertNotNull(types);
-        assertEquals(1, types.size());
-
-        assertTrue(types.contains(org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE));
-    }
-
 }



Mime
View raw message