cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r917537 [2/3] - in /cxf/dosgi/trunk: discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/ dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers...
Date Mon, 01 Mar 2010 14:06:35 GMT
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventProducer.java Mon Mar  1 14:06:34 2010
@@ -24,6 +24,7 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
+import org.osgi.service.remoteserviceadmin.ExportReference;
 import org.osgi.service.remoteserviceadmin.ExportRegistration;
 import org.osgi.service.remoteserviceadmin.ImportRegistration;
 import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
@@ -50,7 +51,7 @@
     protected void publishNotifcation(ExportRegistration er) {
         RemoteServiceAdminEvent rsae = null;
         if (er.getException() != null) {
-            rsae = new RemoteServiceAdminEvent(RemoteServiceAdminEvent.EXPORT_ERROR, bctx.getBundle(), er.getExportReference(), er
+            rsae = new RemoteServiceAdminEvent(RemoteServiceAdminEvent.EXPORT_ERROR, bctx.getBundle(),(ExportReference)null, er
                 .getException());
         } else {
             rsae = new RemoteServiceAdminEvent(RemoteServiceAdminEvent.EXPORT_REGISTRATION, bctx.getBundle(),
@@ -68,7 +69,7 @@
             if (listenerRefs != null) {
                 for (ServiceReference sref : listenerRefs) {
                     RemoteServiceAdminListener rsal = (RemoteServiceAdminListener)bctx.getService(sref);
-                    LOG.info("::::::::::::::::::::: notify RemoteServiceAdminListener " + rsal
+                    LOG.fine("notify RemoteServiceAdminListener " + rsal
                              + " of bundle " + sref.getBundle().getSymbolicName());
                     rsal.remoteAdminEvent(rsae);
                 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java Mon Mar  1 14:06:34 2010
@@ -161,10 +161,10 @@
                 r += entry.getKey() + "  => " + entry.getValue() + "\n";
             }
         }
-        r += "\n\n";
+        r += "\n";
         r += "*** Exception: " + exception + " **** \n";
         r += "*** isClosed : " + closed + " ****\n";
-        r += "\n\n";
+        r += "\n";
 
         return r;
     }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java Mon Mar  1 14:06:34 2010
@@ -31,12 +31,13 @@
 import java.util.Set;
 import java.util.logging.Logger;
 
-import org.apache.commons.lang.ArrayUtils;
 import org.apache.cxf.dosgi.dsw.ClassUtils;
 import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.OsgiUtils;
 import org.apache.cxf.dosgi.dsw.handlers.ClientServiceFactory;
 import org.apache.cxf.dosgi.dsw.handlers.ConfigTypeHandlerFactory;
 import org.apache.cxf.dosgi.dsw.handlers.ConfigurationTypeHandler;
+import org.apache.cxf.dosgi.dsw.qos.IntentMap;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
@@ -51,8 +52,7 @@
 
     private LinkedHashMap<ServiceReference, Collection<ExportRegistrationImpl>> exportedServices = new LinkedHashMap<ServiceReference, Collection<ExportRegistrationImpl>>();
     private LinkedHashMap<EndpointDescription, Collection<ImportRegistrationImpl>> importedServices = new LinkedHashMap<EndpointDescription, Collection<ImportRegistrationImpl>>();
-    
-    
+
     private BundleContext bctx;
 
     private EventProducer eventProducer;
@@ -60,7 +60,7 @@
     private volatile boolean useMasterMap = true;
     private volatile String defaultPort;
     private volatile String defaultHost;
-    
+
     // protected because of tests
     protected static List<String> supportedConfigurationTypes = new ArrayList<String>();
     static {
@@ -69,6 +69,8 @@
         supportedConfigurationTypes.add(Constants.WS_CONFIG_TYPE);
         supportedConfigurationTypes.add(Constants.WS_CONFIG_TYPE_OLD);
     }
+    
+    protected final static String DEFAULT_CONFIGURATION = Constants.WS_CONFIG_TYPE;
 
     public RemoteServiceAdminCore(BundleContext bc) {
         bctx = bc;
@@ -87,37 +89,41 @@
                 Collection<ExportRegistrationImpl> regs = exportedServices.get(serviceReference);
 
                 List<EndpointDescription> copiedEndpoints = new ArrayList<EndpointDescription>();
-                
+
                 // / create a new list with copies of the exportRegistrations
                 List<ExportRegistrationImpl> copy = new ArrayList<ExportRegistrationImpl>(regs.size());
                 for (ExportRegistrationImpl exportRegistration : regs) {
-                    // create one copy for each distinct endpoint description 
-                    if(!copiedEndpoints.contains(exportRegistration.getEndpointDescription())){
+                    // create one copy for each distinct endpoint description
+                    if (!copiedEndpoints.contains(exportRegistration.getEndpointDescription())) {
                         copiedEndpoints.add(exportRegistration.getEndpointDescription());
                         copy.add(new ExportRegistrationImpl(exportRegistration));
                     }
                 }
-                
+
                 regs.addAll(copy);
-                
+
                 eventProducer.publishNotifcation(copy);
                 return copy;
             }
 
             if (isCreatedByThisRSA(serviceReference)) {
                 LOG.fine("proxy provided by this bundle ...  " + serviceReference.getClass().getName());
-                return null;
+                // TODO: publish error event ? Not sure
+                return Collections.EMPTY_LIST;
             }
 
+            
+            
             Properties serviceProperties = new Properties();
 
-            {// gather EventProducerproperties from sRef
+            {// gather properties from sRef
                 String[] keys = serviceReference.getPropertyKeys();
                 for (String k : keys) {
                     serviceProperties.put(k, serviceReference.getProperty(k));
                 }
             }
 
+
             if (additionalProperties != null) {// overlay properties with the additionalProperies
                 Set<Map.Entry> adProps = additionalProperties.entrySet();
                 for (Map.Entry e : adProps) {
@@ -134,26 +140,34 @@
                         }
                     }
                     serviceProperties.put(e.getKey(), e.getValue());
-                    LOG.fine("Overwriting property ["+e.getKey()+"]  with value ["+e.getValue()+"]");
+                    LOG.fine("Overwriting property [" + e.getKey() + "]  with value [" + e.getValue() + "]");
                 }
             }
-            
-            
-          
-            
-            
+
             // Get the intents that need to be supported by the RSA
             String[] requiredIntents = Utils.getAllRequiredIntents(serviceProperties);
-            
-            { // TODO: Determine if the required intents can be provided by the RSA ....
-                
-                // if not return null
-                if(requiredIntents!=null && requiredIntents.length>0) 
-                    return null; 
+
+            {
+                IntentMap im = OsgiUtils.getIntentMap(bctx);
+
+                List<String> unsupportedIntents = new ArrayList<String>();
+
+                for (String ri : requiredIntents) {
+                    if (!im.getIntents().containsKey(ri)) {
+                        unsupportedIntents.add(ri);
+                    }
+                }
+
+                if (unsupportedIntents.size() > 0) {
+                    LOG
+                        .severe("service cannot be exported because the following intents are not supported by this RSA: "
+                                + unsupportedIntents);
+                    // TODO: publish error event
+                    return Collections.EMPTY_LIST;
+                }
+
             }
-            
-            
-            
+
             List<String> interfaces = new ArrayList<String>(1);
 
             {// determine which interfaces should be exported ? based on props and sRef
@@ -164,7 +178,8 @@
                 if (providedInterfaces == null || allowedInterfaces == null) {
                     LOG
                         .severe("export failed: no provided service interfaces found or service_exported_interfaces is null !!");
-                    return null;
+                    // TODO: publish error event ? not sure
+                    return Collections.EMPTY_LIST;
                 }
 
                 if (allowedInterfaces.length == 1 && "*".equals(allowedInterfaces[0])) {
@@ -187,7 +202,8 @@
             // if no interface is to be exported return null
             if (interfaces.size() == 0) {
                 LOG.info("no interfaces to be exported");
-                return null;
+                // TODO: publish error event ? not sure
+                return Collections.EMPTY_LIST;
             }
 
             List<String> configurationTypes = determineConfigurationTypes(serviceProperties);
@@ -197,12 +213,13 @@
             // if no configuration type is supported ? return null
             if (configurationTypes.size() == 0) {
                 LOG.info("the requested configuration types are not supported");
-                return null;
+                // TODO: publish error event ? not sure
+                return Collections.EMPTY_LIST;
             }
 
             LinkedHashMap<String, ExportRegistrationImpl> exportRegs = new LinkedHashMap<String, ExportRegistrationImpl>(
                                                                                                                          1);
-            
+
             for (String iface : interfaces) {
                 LOG.info("creating initial ExportDescription for interface " + iface
                          + "  with configuration types " + configurationTypes);
@@ -215,7 +232,8 @@
             }
 
             // enlist initial export Registrations in global list of exprtRegistrations
-            exportedServices.put(serviceReference, new ArrayList<ExportRegistrationImpl>(exportRegs.values()));
+            exportedServices
+                .put(serviceReference, new ArrayList<ExportRegistrationImpl>(exportRegs.values()));
 
             // FIXME: move out of synchronized ... -> blocks until publication is finished
             for (String iface : interfaces) {
@@ -228,7 +246,8 @@
                 BundleContext callingContext = serviceReference.getBundle().getBundleContext();
 
                 if (handler == null) {
-                    return null;
+                    // TODO: publish error event ? not sure
+                    return Collections.EMPTY_LIST;
                 }
 
                 LOG.info("found handler for " + iface + "  -> " + handler);
@@ -241,10 +260,17 @@
 
                     handler.createServer(exportRegistration, bctx, callingContext, serviceProperties,
                                          interfaceClass, serviceObject);
-                    LOG.info("created server for interface " + iface);
+                    
+                    if(exportRegistration.getException()==null){
+                        LOG.info("created server for interface " + iface);
 
-                    exportRegistration.startServiceTracker(bctx);
+                        exportRegistration.startServiceTracker(bctx);
+                    }else{
+                        LOG.warning("server creation for interface " + iface + "  failed!");
+                        // Fire event happens at the end
+                    }
                     
+
                 }
             }
 
@@ -257,15 +283,15 @@
     }
 
     protected List<String> determineConfigurationTypes(Properties serviceProperties) {
-        
+
         List<String> configurationTypes = new ArrayList<String>();
-        
+
         {// determine which configuration types should be used / if the requested are supported
             String[] requestedConfigurationTypes = Utils.normalizeStringPlus(serviceProperties
                 .get(RemoteConstants.SERVICE_EXPORTED_CONFIGS));
             if (requestedConfigurationTypes == null || requestedConfigurationTypes.length == 0) {
-                // add all supported
-                configurationTypes.addAll(supportedConfigurationTypes);
+                // add default configuration
+                configurationTypes.add(DEFAULT_CONFIGURATION);
             } else {
                 for (String rct : requestedConfigurationTypes) {
                     if (supportedConfigurationTypes.contains(rct)) {
@@ -276,7 +302,7 @@
             }
 
         }
-        
+
         return configurationTypes;
     }
 
@@ -304,8 +330,6 @@
         }
     }
 
-
-
     private ConfigurationTypeHandler getHandler(List<String> configurationTypes, Map serviceProperties,
                                                 Map<String, Object> props) {
         return ConfigTypeHandlerFactory.getInstance().getHandler(bctx, configurationTypes, serviceProperties,
@@ -325,28 +349,22 @@
     /**
      * Importing form here ....
      */
-
-    /**
-     * For me it looks like the RSA is only able to import one interface by creating one proxy service which
-     * can than be placed in the ImportRegistration object. However the decision which service should be
-     * imported lies in the hands f the TopologyManager as the RSA has no idea about service interests ...
-     * Therefore the TM needs to modify the EndpointDescription in such a way that only one interface is
-     * listed in it anymore...
-     */
     public ImportRegistration importService(EndpointDescription endpoint) {
 
         LOG.info("importService() Endpoint: " + endpoint.getProperties());
 
         synchronized (importedServices) {
-            if (importedServices.containsKey(endpoint) && importedServices.get(endpoint).size()>0) {
+            if (importedServices.containsKey(endpoint) && importedServices.get(endpoint).size() > 0) {
+                LOG.fine("creating copy of existing import registrations");
                 Collection<ImportRegistrationImpl> imRegs = importedServices.get(endpoint);
                 ImportRegistrationImpl irParent = imRegs.iterator().next();
                 ImportRegistrationImpl ir = new ImportRegistrationImpl(irParent);
+                imRegs.add(ir);
                 eventProducer.publishNotifcation(ir);
                 return ir;
             }
 
-            List remoteConfigurationTypes = endpoint.getConfigurationTypes(); 
+            List remoteConfigurationTypes = endpoint.getConfigurationTypes();
 
             if (remoteConfigurationTypes == null) {
                 LOG.severe("the supplied endpoint has no configuration type");
@@ -363,7 +381,9 @@
             if (usableConfigurationTypes.size() == 0) {
                 LOG
                     .severe("the supplied endpoint has no compatible configuration type. Supported types are: "
-                            + supportedConfigurationTypes  +  "    Types needed by the endpoint: " +remoteConfigurationTypes);
+                            + supportedConfigurationTypes
+                            + "    Types needed by the endpoint: "
+                            + remoteConfigurationTypes);
                 return null;
             }
 
@@ -376,7 +396,7 @@
                 return null;
             }
 
-            LOG.fine("Handler: "+handler);
+            LOG.fine("Handler: " + handler);
 
             // // TODO: somehow select the interfaces that should be imported ----> job of the TopologyManager
             // ?
@@ -387,13 +407,13 @@
             if (matchingInterfaces.size() == 1) {
                 LOG.info("Proxifying interface : " + matchingInterfaces.get(0));
 
-                ImportRegistrationImpl imReg = new ImportRegistrationImpl(endpoint,this);
+                ImportRegistrationImpl imReg = new ImportRegistrationImpl(endpoint, this);
 
                 proxifyMatchingInterface(matchingInterfaces.get(0), imReg, handler, bctx);
                 Collection<ImportRegistrationImpl> imRegs = importedServices.get(endpoint);
-                if(imRegs==null){
+                if (imRegs == null) {
                     imRegs = new ArrayList<ImportRegistrationImpl>();
-                    importedServices.put(endpoint,imRegs);
+                    importedServices.put(endpoint, imRegs);
                 }
                 imRegs.add(imReg);
                 eventProducer.publishNotifcation(imReg);
@@ -406,7 +426,7 @@
     }
 
     protected void proxifyMatchingInterface(String interfaceName, ImportRegistrationImpl imReg,
-                                          ConfigurationTypeHandler handler, BundleContext requestingContext) {
+                                            ConfigurationTypeHandler handler, BundleContext requestingContext) {
 
         try {
             // MARC: relies on dynamic imports ?
@@ -430,7 +450,7 @@
 
                 // synchronized (discoveredServices) {
                 ClientServiceFactory csf = new ClientServiceFactory(actualContext, iClass, imReg
-                    .getImportedEndpointDescription(), handler,imReg);
+                    .getImportedEndpointDescription(), handler, imReg);
 
                 imReg.setClientServiceFactory(csf);
                 ServiceRegistration proxyRegistration = actualContext.registerService(interfaceName, csf,
@@ -458,12 +478,13 @@
 
         synchronized (exportedServices) {
             Collection<ExportRegistrationImpl> exRegs = exportedServices.get(eri.getServiceReference());
-            if (exRegs.contains(eri)) {
+            if (exRegs != null && exRegs.contains(eri)) {
                 exRegs.remove(eri);
             } else {
-                LOG.severe("An exportRegistartion was intended to be removed form internal management structure but couldn't be found in it !! ");
+                LOG
+                    .severe("An exportRegistartion was intended to be removed form internal management structure but couldn't be found in it !! ");
             }
-            if (exRegs.size() == 0) {
+            if (exRegs == null || exRegs.size() == 0) {
                 exportedServices.remove(eri.getServiceReference());
             }
 
@@ -471,25 +492,22 @@
         }
 
     }
-    
-    protected void removeImportRegistration(ImportRegistrationImpl iri){
+
+    protected void removeImportRegistration(ImportRegistrationImpl iri) {
         synchronized (importedServices) {
-            LOG.finest("Removing importRegistration "+iri);
-            
+            LOG.finest("Removing importRegistration " + iri);
+
             Collection<ImportRegistrationImpl> imRegs = importedServices.get(iri.getImportedEndpointAlways());
-            if (imRegs.contains(iri)) {
+            if (imRegs!=null && imRegs.contains(iri)) {
                 imRegs.remove(iri);
             } else {
-                LOG.severe("An importRegistartion was intended to be removed form internal management structure but couldn't be found in it !! ");
+                LOG
+                    .severe("An importRegistartion was intended to be removed form internal management structure but couldn't be found in it !! ");
             }
-            if (imRegs.size() == 0) {
+            if (imRegs == null || imRegs.size() == 0) {
                 importedServices.remove(iri.getImportedEndpointAlways());
             }
-            
-//            if(importedServices.remove(iri.getImportedEndpointDescription())==null){
-//                LOG.severe("An importRegistartion couldn't be removed from the internal management structure -> structure is inconsistent !!");
-//            }
-            
+
             eventProducer.notifyRemoval(iri);
         }
     }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminInstance.java Mon Mar  1 14:06:34 2010
@@ -20,6 +20,7 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.logging.Logger;
@@ -51,7 +52,7 @@
     public List /* ExportRegistration */exportService(ServiceReference ref, Map properties)
         throws IllegalArgumentException, UnsupportedOperationException {
         if (closed)
-            return null;
+            return Collections.EMPTY_LIST;
 
         synchronized (exportedServices) {
             List er = rsaCore.exportService(ref, properties);

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/Utils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/Utils.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/Utils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/Utils.java Mon Mar  1 14:06:34 2010
@@ -105,17 +105,11 @@
         return requiredIntents;
     }
 
-    public static String[] getAllIntentsCombined(Map serviceProperties){
-        String[] requiredIntents = getAllRequiredIntents(serviceProperties);
-        
+    public static String[] getInetntsImplementedByTheService(Map serviceProperties){
         // Get the Intents that are implemented by the service 
         String[] serviceIntents = Utils.normalizeStringPlus(serviceProperties.get(RemoteConstants.SERVICE_INTENTS));
         
-        if(serviceIntents!= null && serviceIntents.length>0){
-            requiredIntents = mergeArrays(requiredIntents, serviceIntents);
-        }
-        
-        return requiredIntents;
+        return serviceIntents;
     }
  
     

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java Mon Mar  1 14:06:34 2010
@@ -19,20 +19,15 @@
 package org.apache.cxf.dosgi.dsw;
 
 import java.util.Dictionary;
-import java.util.HashMap;
 import java.util.Hashtable;
-import java.util.Map;
 
 import junit.framework.TestCase;
 
-import org.apache.cxf.dosgi.dsw.hooks.TestService;
 import org.easymock.EasyMock;
-import org.easymock.IAnswer;
 import org.easymock.IMocksControl;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.remoteserviceadmin.RemoteConstants;
 import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin;
 
 public class ActivatorTest extends TestCase{
@@ -45,23 +40,31 @@
 
         EasyMock.expect(b.getBundleContext()).andReturn(bc).anyTimes();
         EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
-//        EasyMock.expect(bc.registerService(
-//            (String) EasyMock.anyObject(), EasyMock.anyObject(), 
-//            (Dictionary) EasyMock.anyObject())).andAnswer(new IAnswer<ServiceRegistration>() {
-//                public ServiceRegistration answer() throws Throwable {
-//                    ServiceRegistration sr = EasyMock.createNiceMock(ServiceRegistration.class);
-//                    EasyMock.replay(sr);
-//                    return sr;
-//                }                
-//            }).anyTimes();
+        //        EasyMock.expect(bc.registerService(
+        //            (String) EasyMock.anyObject(), EasyMock.anyObject(), 
+        //            (Dictionary) EasyMock.anyObject())).andAnswer(new IAnswer<ServiceRegistration>() {
+        //                public ServiceRegistration answer() throws Throwable {
+        //                    ServiceRegistration sr = EasyMock.createNiceMock(ServiceRegistration.class);
+        //                    EasyMock.replay(sr);
+        //                    return sr;
+        //                }                
+        //            }).anyTimes();
         return bc;
     }
     
+    
+    
+    
     public void testCreateAndShutdownRemoteServiceAdminService() throws Exception {
+        
+       //IntentMap im = new IntentMap();
+       //im.setIntents(new HashMap<String, Object>());
+
+       // IntentMapLoader.initializeWithExistingMap(im);
+        
         IMocksControl control = EasyMock.createNiceControl();
         BundleContext bc = getMockBundleContext(control);
         
-        
         ServiceRegistration sr = control.createMock(ServiceRegistration.class);
         EasyMock.expect(bc.registerService(EasyMock.eq(RemoteServiceAdmin.class.getName()),EasyMock.anyObject(), (Dictionary)EasyMock.anyObject())).andReturn(sr).atLeastOnce();
         
@@ -69,30 +72,11 @@
         control.replay();
         
         
-        Activator a = new Activator() {
-//            @Override
-//            IntentMap getIntentMap() {
-//                IntentMap intentMap = new IntentMap();
-//                intentMap.setIntents(new HashMap<String, Object>());
-//                return intentMap;                
-//            }            
-        };   
-        
-        
-        
-        
+        Activator a = new Activator();   
         a.start(bc);
         
         control.verify();
         
-        
-//        CxfRemoteServiceAdmin mockRSA = EasyMock.createMock(CxfRemoteServiceAdmin.class);
-//        mockRSA.shutdown();
-//        EasyMock.replay(mockRSA);
-//        a.rsa = mockRSA;
-//        a.stop(bc);
-//        EasyMock.verify(mockRSA);
-        
     }
     
 //    @SuppressWarnings("unchecked")

Modified: 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/HttpServiceConfigurationTypeHandlerTest.java?rev=917537&r1=917536&r2=917537&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/HttpServiceConfigurationTypeHandlerTest.java Mon Mar  1 14:06:34 2010
@@ -18,260 +18,306 @@
   */
 package org.apache.cxf.dosgi.dsw.handlers;
 
+import java.net.InetAddress;
+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.service.ExportRegistrationImpl;
+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.AbstractFeature;
+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.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+
 public class HttpServiceConfigurationTypeHandlerTest extends TestCase {
     
     public void testDUMMY(){
         assertTrue(true);
     }
     
-//    public void testServer() throws Exception {
-//        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
-//        EasyMock.expect(dswContext.getProperty("org.osgi.service.http.port")).
-//            andReturn("1327").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();
-//        
-//        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
-//        Map<String, Object> handlerProps = new HashMap<String, Object>();
-//        HttpServiceConfigurationTypeHandler h = 
-//            new HttpServiceConfigurationTypeHandler(dswContext, dp, handlerProps) {
-//                @Override
-//                ServerFactoryBean createServerFactoryBean(String frontend) {
-//                    return sfb;
-//                }
-//
-//                @Override
-//                String[] applyIntents(BundleContext dswContext, BundleContext callingContext,
-//                        List<AbstractFeature> features, AbstractEndpointFactory factory, 
-//                        ServiceEndpointDescription sd) {
-//                    return new String [] {"a.b.c"};
-//                }            
-//        };
-//        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());
-//        h.createServer(sr, dswContext, callingContext, sd, 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 = InetAddress.getLocalHost().getHostName();
-//        Map<String, String> expected = new HashMap<String, String>();
-//        expected.put("service.exported.configs", "org.apache.cxf.ws");
-//        expected.put("org.apache.cxf.ws.address", "http://" + hostName + ":1327/myRunnable");
-//        expected.put("service.intents", "a.b.c");
-//        assertEquals(expected, dp.getExposedProperties(sr));
-//    } 
-//    
-//    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();
-//        
-//        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
-//        Map<String, Object> handlerProps = new HashMap<String, Object>();
-//        HttpServiceConfigurationTypeHandler h = 
-//            new HttpServiceConfigurationTypeHandler(dswContext, dp, handlerProps) {
-//                @Override
-//                ServerFactoryBean createServerFactoryBean(String frontend) {
-//                    return sfb;
-//                }
-//
-//                @Override
-//                String[] applyIntents(BundleContext dswContext, BundleContext callingContext,
-//                        List<AbstractFeature> features, AbstractEndpointFactory factory, 
-//                        ServiceEndpointDescription sd) {
-//                    return new String [] {};
-//                }            
-//        };
-//        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());
-//        h.createServer(sr, dswContext, callingContext, sd, Runnable.class, myService);
-//        assertEquals(1, dp.getExposedServices().size());
-//        assertSame(sr, dp.getExposedServices().iterator().next());
-//        
-//        String hostname = InetAddress.getLocalHost().getHostName();
-//        Map<String, String> expected = new HashMap<String, String>();
-//        expected.put("service.exported.configs", "org.apache.cxf.ws");
-//        expected.put("org.apache.cxf.ws.address", "http://" + hostname + ":8080/java/lang/Runnable");
-//        assertEquals(expected, dp.getExposedProperties(sr));
-//    }
-//
-//    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();
-//        
-//        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
-//        Map<String, Object> handlerProps = new HashMap<String, Object>();
-//        HttpServiceConfigurationTypeHandler h = 
-//            new HttpServiceConfigurationTypeHandler(dswContext, dp, handlerProps) {
-//                @Override
-//                ServerFactoryBean createServerFactoryBean(String frontend) {
-//                    return sfb;
-//                }
-//
-//                @Override
-//                String[] applyIntents(BundleContext dswContext, BundleContext callingContext,
-//                        List<AbstractFeature> features, AbstractEndpointFactory factory, 
-//                        ServiceEndpointDescription sd) {
-//                    return new String [] {};
-//                }            
-//        };
-//        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());
-//        h.createServer(sr, dswContext, callingContext, sd, Runnable.class, myService);
-//        assertEquals(1, dp.getExposedServices().size());
-//        assertSame(sr, dp.getExposedServices().iterator().next());
-//        
-//        String hostName = InetAddress.getLocalHost().getHostName();
-//        Map<String, String> expected = new HashMap<String, String>();
-//        expected.put("service.exported.configs", "org.apache.cxf.ws");
-//        expected.put("org.apache.cxf.ws.address", "https://" + hostName + ":8432/myRunnable");
-//        assertEquals(expected, dp.getExposedProperties(sr));
-//    } 
-//
-//    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 = 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;
-//    }
-//
-//    // TODO these tests still need to be written...
-//    /*
-//    public void testNoHttpService() {
-//        
-//    }
-//    
-//    public void testHttpServiceDynamism() {
-//        
-//    }
-//    
-//    public void testServletUnregistration() {        
-//    }
-//    */
+    public void testServer() throws Exception {
+        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.expect(dswContext.getProperty("org.osgi.service.http.port")).
+            andReturn("1327").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();
+        
+        //        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
+        Map<String, Object> handlerProps = new HashMap<String, Object>();
+        HttpServiceConfigurationTypeHandler h = 
+            new HttpServiceConfigurationTypeHandler(dswContext,  handlerProps) {
+                @Override
+                ServerFactoryBean createServerFactoryBean(String frontend) {
+                    return sfb;
+                }
+
+                @Override
+                String[] applyIntents(BundleContext dswContext, BundleContext callingContext,
+                        List<AbstractFeature> features, AbstractEndpointFactory factory, 
+                        Map sd) {
+                    return new String [] {"a.b.c"};
+                }            
+        };
+        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);
+        
+        ExportRegistrationImpl exReg = new ExportRegistrationImpl(sr,null,null);
+        
+        //        assertEquals("Precondition failed", 0, dp.getExposedServices().size());
+        assertEquals("Precondition failed", "", sfb.getAddress());
+        h.createServer(exReg, 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 = InetAddress.getLocalHost().getHostName();
+        
+        Map edProps = exReg.getEndpointDescription().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://" + 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();
+        
+        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
+        Map<String, Object> handlerProps = new HashMap<String, Object>();
+        HttpServiceConfigurationTypeHandler h = 
+            new HttpServiceConfigurationTypeHandler(dswContext,  handlerProps) {
+                @Override
+                ServerFactoryBean createServerFactoryBean(String frontend) {
+                    return sfb;
+                }
+
+                @Override
+                String[] applyIntents(BundleContext dswContext, BundleContext callingContext,
+                        List<AbstractFeature> features, AbstractEndpointFactory factory, 
+                        Map sd) {
+                    return new String [] {};
+                }            
+        };
+        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);
+        
+        ExportRegistrationImpl exReg = new ExportRegistrationImpl(sr,null,null);
+        
+        //assertEquals("Precondition failed", 0, dp.getExposedServices().size());
+        h.createServer(exReg, dswContext, callingContext, props, Runnable.class, myService);
+        //assertEquals(1, dp.getExposedServices().size());
+        //assertSame(sr, dp.getExposedServices().iterator().next());
+        
+        String hostname = InetAddress.getLocalHost().getHostName();
+        Map edProps = exReg.getEndpointDescription().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://" + 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();
+        
+        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
+        Map<String, Object> handlerProps = new HashMap<String, Object>();
+        HttpServiceConfigurationTypeHandler h = 
+            new HttpServiceConfigurationTypeHandler(dswContext,  handlerProps) {
+                @Override
+                ServerFactoryBean createServerFactoryBean(String frontend) {
+                    return sfb;
+                }
+
+                @Override
+                String[] applyIntents(BundleContext dswContext, BundleContext callingContext,
+                        List<AbstractFeature> features, AbstractEndpointFactory factory, 
+                        Map sd) {
+                    return new String [] {};
+                }            
+        };
+        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);
+        
+        ExportRegistrationImpl exReg = new ExportRegistrationImpl(sr,null,null);
+        
+        //assertEquals("Precondition failed", 0, dp.getExposedServices().size());
+        h.createServer(exReg, dswContext, callingContext, props, Runnable.class, myService);
+        //assertEquals(1, dp.getExposedServices().size());
+        //assertSame(sr, dp.getExposedServices().iterator().next());
+        
+        String hostName = InetAddress.getLocalHost().getHostName();
+        Map edProps = exReg.getEndpointDescription().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("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;
+    }
+
+    // TODO these tests still need to be written...
+    /*
+    public void testNoHttpService() {
+        
+    }
+    
+    public void testHttpServiceDynamism() {
+        
+    }
+    
+    public void testServletUnregistration() {        
+    }
+    */
 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/JaxRSUtilsTest.java Mon Mar  1 14:06:34 2010
@@ -51,9 +51,7 @@
 
         props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false");
 
-        EndpointDescription sd = new EndpointDescription(props);
-
-        assertEquals(0, JaxRSUtils.getProviders(null, null, sd).size());
+        assertEquals(0, JaxRSUtils.getProviders(null, null, props).size());
     }
 
     public void testAegisProvider() {
@@ -62,9 +60,8 @@
         props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false");
 
         addRequiredProps(props);
-        EndpointDescription sd = new EndpointDescription(props);
 
-        List<Object> providers = JaxRSUtils.getProviders(null, null, sd);
+        List<Object> providers = JaxRSUtils.getProviders(null, null, props);
         assertEquals(1, providers.size());
         assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName());
     }
@@ -76,9 +73,8 @@
         });
         props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false");
         addRequiredProps(props);
-        EndpointDescription sd = new EndpointDescription(props);
 
-        List<Object> providers = JaxRSUtils.getProviders(null, null, sd);
+        List<Object> providers = JaxRSUtils.getProviders(null, null, props);
         assertEquals(1, providers.size());
         assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName());
     }
@@ -102,9 +98,8 @@
 
         props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false");
         addRequiredProps(props);
-        EndpointDescription sd = new EndpointDescription(props);
 
-        List<Object> providers = JaxRSUtils.getProviders(bc, null, sd);
+        List<Object> providers = JaxRSUtils.getProviders(bc, null, props);
         assertEquals(2, providers.size());
         assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName());
         assertEquals(JAXBElementProvider.class.getName(), providers.get(1).getClass().getName());
@@ -130,9 +125,8 @@
 
         props.put(Constants.RS_PROVIDER_GLOBAL_PROP_KEY, "false");
         addRequiredProps(props);
-        EndpointDescription sd = new EndpointDescription(props);
 
-        List<Object> providers = JaxRSUtils.getProviders(bc, null, sd);
+        List<Object> providers = JaxRSUtils.getProviders(bc, null, props);
         assertEquals(2, providers.size());
         assertEquals(AegisElementProvider.class.getName(), providers.get(0).getClass().getName());
         assertEquals(JAXBElementProvider.class.getName(), providers.get(1).getClass().getName());
@@ -153,9 +147,8 @@
         EasyMock.replay(bc, sref);
         Map<String, Object> props = new HashMap<String, Object>();
         addRequiredProps(props);
-        EndpointDescription sd = new EndpointDescription(props);
 
-        List<Object> providers = JaxRSUtils.getProviders(bc, null, sd);
+        List<Object> providers = JaxRSUtils.getProviders(bc, null, props);
         assertEquals(1, providers.size());
         assertSame(p, providers.get(0));
     }
@@ -176,9 +169,8 @@
         Map<String, Object> props = new HashMap<String, Object>();
         props.put(Constants.RS_PROVIDER_EXPECTED_PROP_KEY, "true");
         addRequiredProps(props);
-        EndpointDescription sd = new EndpointDescription(props);
 
-        List<Object> providers = JaxRSUtils.getProviders(bc, null, sd);
+        List<Object> providers = JaxRSUtils.getProviders(bc, null, props);
         assertEquals(0, providers.size());
     }
 
@@ -198,9 +190,8 @@
         Map<String, Object> props = new HashMap<String, Object>();
         props.put(Constants.RS_PROVIDER_EXPECTED_PROP_KEY, "true");
         addRequiredProps(props);
-        EndpointDescription sd = new EndpointDescription(props);
 
-        List<Object> providers = JaxRSUtils.getProviders(bc, null, sd);
+        List<Object> providers = JaxRSUtils.getProviders(bc, null, props);
         assertEquals(1, providers.size());
         assertSame(p, providers.get(0));
     }



Mime
View raw message