cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1412157 [2/2] - in /cxf/dosgi/trunk: distribution/single-bundle/src/main/java/org/apache/cxf/dosgi/singlebundle/ dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/ dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ dsw/cxf-dsw/s...
Date Wed, 21 Nov 2012 15:51:38 GMT
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=1412157&r1=1412156&r2=1412157&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 21 15:51:35 2012
@@ -18,23 +18,19 @@
   */
 package org.apache.cxf.dosgi.dsw.handlers;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 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.IntentManagerImpl;
 import org.apache.cxf.dosgi.dsw.qos.IntentMap;
-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.feature.Feature;
 import org.apache.cxf.frontend.ClientProxyFactoryBean;
 import org.apache.cxf.frontend.ServerFactoryBean;
@@ -54,7 +50,8 @@ import org.osgi.service.remoteserviceadm
 public class PojoConfigurationTypeHandlerTest extends TestCase {
     public void testGetPojoAddressEndpointURI() {
         Map<String, Object> hp = new HashMap<String, Object>();
-        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, hp);
+        IntentManager intentManager = new IntentManagerImpl(new IntentMap());
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager
, hp);
         Map<String, Object> sd = new HashMap<String, Object>();
         String url = "http://somewhere:1234/blah";
         sd.put(RemoteConstants.ENDPOINT_ID, url);
@@ -63,7 +60,8 @@ public class PojoConfigurationTypeHandle
     
     public void testGetPojoAddressEndpointCxf() {
         Map<String, Object> hp = new HashMap<String, Object>();
-        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, hp);
+        IntentManager intentManager = new IntentManagerImpl(new IntentMap());
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager
, hp);
         Map<String, Object> sd = new HashMap<String, Object>();
         String url = "http://somewhere:29/boo";
         sd.put("org.apache.cxf.ws.address", url);
@@ -72,7 +70,8 @@ public class PojoConfigurationTypeHandle
 
     public void testGetPojoAddressEndpointPojo() {
         Map<String, Object> hp = new HashMap<String, Object>();
-        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, hp);
+        IntentManager intentManager = new IntentManagerImpl(new IntentMap());
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager
, hp);
         Map<String, Object> sd = new HashMap<String, Object>();
         String url = "http://somewhere:32768/foo";
         sd.put("osgi.remote.configuration.pojo.address", url);
@@ -81,14 +80,10 @@ public class PojoConfigurationTypeHandle
     
     public void testGetPojoAddressDefaultWithAlternatePort() {
         Map<String, Object> hp = new HashMap<String, Object>();
-        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, hp);
+        IntentManager intentManager = new IntentManagerImpl(new IntentMap());
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager
, hp);
         Map<String, Object> sd = new HashMap<String, Object>();
-        String localIP;
-        try {
-            localIP = AbstractConfigurationHandler.getLocalHost().getHostAddress();
-        } catch (Exception e) {
-            localIP = "localhost";
-        }
+        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));        
@@ -96,15 +91,21 @@ public class PojoConfigurationTypeHandle
 
     public void testGetDefaultPojoAddress() {
         Map<String, Object> hp = new HashMap<String, Object>();
-        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, hp);
+        IntentManager intentManager = new IntentManagerImpl(new IntentMap());
+        PojoConfigurationTypeHandler handler = new PojoConfigurationTypeHandler(null, intentManager
, hp);
         Map<String, Object> sd = new HashMap<String, Object>(); 
+        String localIP = getLocalIp();
+        assertEquals("http://"+localIP+":9000/java/lang/String", handler.getPojoAddress(sd,
String.class));
+    }
+
+    private String getLocalIp() {
         String localIP;
         try {
-            localIP = AbstractConfigurationHandler.getLocalHost().getHostAddress();
+            localIP = LocalHostUtil.getLocalHost().getHostAddress();
         } catch (Exception e) {
             localIP = "localhost";
         }
-        assertEquals("http://"+localIP+":9000/java/lang/String", handler.getPojoAddress(sd,
String.class));
+        return localIP;
     }
 
     private Map<String, Object> handlerProps;
@@ -129,17 +130,16 @@ public class PojoConfigurationTypeHandle
         final ClientProxyFactoryBean cpfb = c.createMock(ClientProxyFactoryBean.class);
         ReflectionServiceFactoryBean sf = c.createMock(ReflectionServiceFactoryBean.class);
         EasyMock.expect(cpfb.getServiceFactory()).andReturn(sf).anyTimes();
-        
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(bc1, handlerProps)
{
+        IntentManager intentManager = new IntentManagerImpl(new IntentMap()) {
             @Override
-            ClientProxyFactoryBean createClientProxyFactoryBean(String frontend) {
-                return cpfb;
+            public String[] applyIntents(List<Feature> features, AbstractEndpointFactory
factory, Map<String, Object> sd) {
+                return new String[0];
             }
-            
+        };
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(bc1, intentManager,
handlerProps) {
             @Override
-            String[] applyIntents(BundleContext dswContext, BundleContext callingContext,
-                List<Feature> features, AbstractEndpointFactory factory, Map sd) {
-                return new String[0];
+            ClientProxyFactoryBean createClientProxyFactoryBean(String frontend) {
+                return cpfb;
             }
         };
         
@@ -266,16 +266,17 @@ public class PojoConfigurationTypeHandle
         String myService = "Hi";                
         final ServerFactoryBean sfb = createMockServerFactoryBean();
         
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, handlerProps)
{
+        IntentMap intentMap = new IntentMap();
+        IntentManager intentManager = new IntentManagerImpl(intentMap ) {
             @Override
-            ServerFactoryBean createServerFactoryBean(String frontend) {
-                return sfb;
+            public String[] applyIntents(List<Feature> features, AbstractEndpointFactory
factory, Map<String, Object> sd) {
+                return new String []{};
             }
-
+        };
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, intentManager,
handlerProps) {
             @Override
-            String[] applyIntents(BundleContext dswContext, BundleContext callingContext,
-                List<Feature> features, AbstractEndpointFactory factory, Map sd) {
-                return new String []{};
+            ServerFactoryBean createServerFactoryBean(String frontend) {
+                return sfb;
             }
         };
         
@@ -350,372 +351,15 @@ public class PojoConfigurationTypeHandle
         return server;
     }
     
-    public void testIntents() throws Exception {
-        Map<String, Object> intents = new HashMap<String, Object>();
-        intents.put("A", new AbstractFeature() {});
-        intents.put("SOAP", new AbstractFeature() {});
-        final IntentMap intentMap = new IntentMap();
-        intentMap.setIntents(intents);
-        
-        IMocksControl control = EasyMock.createNiceControl();
-        BundleContext dswContext = control.createMock(BundleContext.class);
-        BundleContext callingContext = control.createMock(BundleContext.class);        
-        List<Feature> features = new ArrayList<Feature>();
-        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-        control.replay();
-
-        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext, intentMap);
-        AbstractPojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext,
 handlerProps) {
-            @Override
-            IntentMap getIntentMap(BundleContext callingContext) {
-                return intentMap;
-            }
-
-            @Override
-            String getDefaultBindingIntent() {
-                return null;
-            }        
-        };
-        
-        Map<String, Object> props = new HashMap<String, Object>();
-        props.put("osgi.remote.requires.intents", "A");
-        //ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
-
-        List<String> effectiveIntents = 
-            Arrays.asList(p.applyIntents(dswContext, callingContext, features, factory, props));
-        assertEquals(Arrays.asList("A"), effectiveIntents);
-    }    
-    
-    public void testMultiIntents() {
-        Map<String, Object> intents = new HashMap<String, Object>();
-        intents.put("confidentiality.message", new AbstractFeature() {});
-        intents.put("transactionality", new AbstractFeature() {});
-        final IntentMap intentMap = new IntentMap();
-        intentMap.setIntents(intents);
-        
-        IMocksControl control = EasyMock.createNiceControl();
-        BundleContext dswContext = control.createMock(BundleContext.class);
-        BundleContext callingContext = control.createMock(BundleContext.class);        
-        List<Feature> features = new ArrayList<Feature>();
-        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-        control.replay();
-
-        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext, intentMap);
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext,  handlerProps)
{
-            @Override
-            IntentMap getIntentMap(BundleContext callingContext) {
-                return intentMap;
-            }            
-
-            @Override
-            String getDefaultBindingIntent() {
-                return null;
-            }        
-        };
-        
-        Map<String, Object> props = new HashMap<String, Object>();
-        props.put("osgi.remote.requires.intents", "transactionality confidentiality.message");
-        //ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
-
-        List<String> effectiveIntents = 
-            Arrays.asList(p.applyIntents(dswContext, callingContext, features, factory, props));
-        assertTrue(effectiveIntents.contains("transactionality"));        
-        assertTrue(effectiveIntents.contains("confidentiality.message"));        
-    }
-    
-    public void testFailedIntent() {
-        Map<String, Object> intents = new HashMap<String, Object>();
-        intents.put("A", new AbstractFeature() {});
-        final IntentMap intentMap = new IntentMap();
-        intentMap.setIntents(intents);
-                
-        IMocksControl control = EasyMock.createNiceControl();
-        BundleContext dswContext = control.createMock(BundleContext.class);
-        BundleContext callingContext = control.createMock(BundleContext.class);        
-        List<Feature> features = new ArrayList<Feature>();
-        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-        control.replay();
-
-        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext, intentMap);
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext,  handlerProps)
{
-            @Override
-            IntentMap getIntentMap(BundleContext callingContext) {
-                return intentMap;
-            }            
-        };
-
-        Map<String, Object> props = new HashMap<String, Object>();
-        props.put("osgi.remote.requires.intents", "A B");
-        //        ServiceEndpointDescription sd = 
-        //            new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
-
-        try {
-            p.applyIntents(dswContext, callingContext, features, factory, props);
-            fail("applyIntents() should have thrown an exception as there was an unsatisfiable
intent");
-        } catch (IntentUnsatifiedException iue) {
-            assertEquals("B", iue.getIntent());
-        }
-    }
- 
-    public void testInferIntents() {
-        Map<String, Object> intents = new HashMap<String, Object>();
-        intents.put("Prov", "PROVIDED");
-        AbstractFeature feat1 = new AbstractFeature() {};
-        intents.put("A", feat1);
-        intents.put("A_alt", feat1);
-        intents.put("B", new AbstractFeature() {});
-        final IntentMap intentMap = new IntentMap();
-        intentMap.setIntents(intents);
-        
-        IMocksControl control = EasyMock.createNiceControl();
-        BundleContext dswContext = control.createMock(BundleContext.class);
-        BundleContext callingContext = control.createMock(BundleContext.class);
-        List<Feature> features = new ArrayList<Feature>();
-        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-        control.replay();
-        
-        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext, intentMap);
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext,  handlerProps)
{
-            @Override
-            IntentMap getIntentMap(BundleContext callingContext) {
-                return intentMap;
-            }            
-
-            @Override
-            String getDefaultBindingIntent() {
-                return null;
-            }        
-        };
-        
-        Map<String, Object> props = new HashMap<String, Object>();
-        props.put("osgi.remote.requires.intents", "A");
-        //        ServiceEndpointDescription sd = 
-        //            new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
-        
-        List<String> effectiveIntents = 
-            Arrays.asList(p.applyIntents(dswContext, callingContext, features, factory, props));
-        assertEquals(3, effectiveIntents.size());
-        assertTrue(effectiveIntents.contains("Prov"));
-        assertTrue(effectiveIntents.contains("A"));
-        assertTrue(effectiveIntents.contains("A_alt"));
-    }
-    
-    public void testDefaultBindingIntent() {        
-        IMocksControl control = EasyMock.createNiceControl();
-
-        Map<String, Object> intents = new HashMap<String, Object>();
-        BindingConfiguration feat1 = control.createMock(BindingConfiguration.class);
-        intents.put("A", new AbstractFeature() {});
-        intents.put("SOAP", feat1);
-        intents.put("SOAP.1_1", feat1);
-        intents.put("SOAP.1_2", control.createMock(BindingConfiguration.class));
-        final IntentMap intentMap = new IntentMap();
-        intentMap.setIntents(intents);
-
-        BundleContext dswContext = control.createMock(BundleContext.class);
-        BundleContext callingContext = control.createMock(BundleContext.class);
-        List<Feature> features = new ArrayList<Feature>();
-        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-        control.replay();
-        
-        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext, intentMap);
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext,  handlerProps)
{
-            @Override
-            IntentMap getIntentMap(BundleContext callingContext) {
-                return intentMap;
-            }            
-        };
-
-        Map<String, Object> props = new HashMap<String, Object>();
-        props.put("osgi.remote.requires.intents", "A");
-        //        ServiceEndpointDescription sd = 
-        //            new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
-        
-        List<String> effectiveIntents = 
-            Arrays.asList(p.applyIntents(dswContext, callingContext, features, factory, props));
-        assertEquals(3, effectiveIntents.size());
-        assertTrue(effectiveIntents.contains("A"));
-        assertTrue(effectiveIntents.contains("SOAP"));
-        assertTrue(effectiveIntents.contains("SOAP.1_1"));
-    }
-    
-    public void testExplicitBindingIntent() {
-        IMocksControl control = EasyMock.createNiceControl();
-
-        Map<String, Object> intents = new HashMap<String, Object>();
-        BindingConfiguration feat1 = control.createMock(BindingConfiguration.class);
-        intents.put("A", new AbstractFeature() {});
-        intents.put("SOAP", feat1);
-        intents.put("SOAP.1_1", feat1);
-        intents.put("SOAP.1_2", control.createMock(BindingConfiguration.class));
-        final IntentMap intentMap = new IntentMap();
-        intentMap.setIntents(intents);
-
-        BundleContext dswContext = control.createMock(BundleContext.class);
-        BundleContext callingContext = control.createMock(BundleContext.class);
-        List<Feature> features = new ArrayList<Feature>();
-        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-        control.replay();
-        
-        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext, intentMap);
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext,  handlerProps)
{
-            @Override
-            IntentMap getIntentMap(BundleContext callingContext) {
-                return intentMap;
-            }            
-        };
-
-        Map<String, Object> props = new HashMap<String, Object>();
-        props.put("osgi.remote.requires.intents", "A SOAP.1_2");
-        //        ServiceEndpointDescription sd = 
-        //            new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
-        
-        List<String> effectiveIntents = 
-            Arrays.asList(p.applyIntents(dswContext, callingContext, features, factory, props));
-        assertEquals(2, effectiveIntents.size());
-        assertTrue(effectiveIntents.contains("A"));
-        assertTrue(effectiveIntents.contains("SOAP.1_2"));        
-    }
-    
-    public void testInheritMasterIntentMapDefault() {
-        List<String> features = runTestInheritMasterIntentMap("A B");
-        
-        assertEquals(2, features.size());
-        assertTrue(features.contains("appFeatureA"));
-        assertTrue(features.contains("masterFeatureB"));
-    }
-    
-    public void testInheritMasterIntentMap() {
-        handlerProps.put(Constants.USE_MASTER_MAP, "true");
-        List<String> features = runTestInheritMasterIntentMap("A B");
-        
-        assertEquals(2, features.size());
-        assertTrue(features.contains("appFeatureA"));
-        assertTrue(features.contains("masterFeatureB"));
-    }
-
-    public void testDontInheritMasterIntentMapFails() {
-        handlerProps.put(Constants.USE_MASTER_MAP, "false");
-        try {
-            runTestInheritMasterIntentMap("A B");
-            fail("Should have failed as intent B was not satisfied");
-        } catch (IntentUnsatifiedException iue) {
-            assertEquals("B", iue.getIntent());
-        }    
-    }
-
-    public void testDontInheritMasterIntentMapSucceeds() {
-        handlerProps.put(Constants.USE_MASTER_MAP, "false");
-        List<String> features = runTestInheritMasterIntentMap("A");
-        
-        assertEquals(1, features.size());
-        assertTrue(features.contains("appFeatureA"));
-    }
-
-    private List<String> runTestInheritMasterIntentMap(String requestedIntents) {
-        Map<String, Object> masterIntents = new HashMap<String, Object>();
-        masterIntents.put("A", new TestFeature("masterFeatureA"));
-        masterIntents.put("B", new TestFeature("masterFeatureB"));
-        final IntentMap masterIntentMap = new IntentMap();
-        masterIntentMap.setIntents(masterIntents);
-        
-        Map<String, Object> appIntents = new HashMap<String, Object>();
-        appIntents.put("A", new TestFeature("appFeatureA"));
-        final IntentMap appIntentMap = new IntentMap();
-        appIntentMap.setIntents(appIntents);
-
-        IMocksControl control = EasyMock.createNiceControl();
-        final BundleContext dswContext = control.createMock(BundleContext.class);
-        final BundleContext callingContext = control.createMock(BundleContext.class);   
    
-        List<Feature> features = new ArrayList<Feature>();
-        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-        control.replay();
-
-        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext, masterIntentMap);
-
-        Map<String, Object> props = new HashMap<String, Object>();
-        props.put("osgi.remote.requires.intents", requestedIntents);
-        //ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
-        
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext,  handlerProps)
{
-            @Override
-            IntentMap getIntentMap(BundleContext ctx) {
-                if (ctx == callingContext) {
-                    return appIntentMap;
-                } else if (ctx == dswContext) {
-                    return masterIntentMap;
-                } else {
-                    return null;
-                }
-            }            
-
-            @Override
-            String getDefaultBindingIntent() {
-                return null;
-            }        
-        };
-        
-        p.applyIntents(dswContext, callingContext, features, factory, props);
-
-        List<String> featureNames = new ArrayList<String>();
-        for (Feature f : features) {
-            featureNames.add(f.toString());
-        }
-        return featureNames;
-    }
-    
-    public void testProvidedIntents() {
-        Map<String, Object> masterIntents = new HashMap<String, Object>();
-        masterIntents.put("A", "Provided");
-        masterIntents.put("B", "PROVIDED");
-        final IntentMap masterIntentMap = new IntentMap();
-        masterIntentMap.setIntents(masterIntents);        
-        final IntentMap appIntentMap = new IntentMap();
-        appIntentMap.setIntents(new HashMap<String, Object>());
-
-        IMocksControl control = EasyMock.createNiceControl();
-        final BundleContext dswContext = control.createMock(BundleContext.class);
-        final BundleContext callingContext = control.createMock(BundleContext.class);   
    
-        List<Feature> features = new ArrayList<Feature>();
-        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-        control.replay();
-        
-        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext, masterIntentMap);
-
-        Map<String, Object> props = new HashMap<String, Object>();
-        props.put("osgi.remote.requires.intents", "B A");
-        //ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
-        
-        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext,  handlerProps)
{
-            @Override
-            IntentMap getIntentMap(BundleContext ctx) {
-                if (ctx == callingContext) {
-                    return appIntentMap;
-                } else if (ctx == dswContext) {
-                    return masterIntentMap;
-                } else {
-                    return null;
-                }
-            }                      
 
-            @Override
-            String getDefaultBindingIntent() {
-                return null;
-            }        
-        };
-        
-        Set<String> effectiveIntents = new HashSet<String>(Arrays.asList( 
-            p.applyIntents(dswContext, callingContext, features, factory, props)));
-        Set<String> expectedIntents = new HashSet<String>(Arrays.asList(new String
[] {"A", "B"}));
-        assertEquals(expectedIntents, effectiveIntents);
-    }
     
     public void testCreateEndpointProps() {
         BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
         EasyMock.expect(bc.getProperty("org.osgi.framework.uuid")).andReturn("some_uuid1");
         EasyMock.replay(bc);
         
-        PojoConfigurationTypeHandler pch = new PojoConfigurationTypeHandler(bc, null);
+        IntentManager intentManager = new IntentManagerImpl(new IntentMap());
+        PojoConfigurationTypeHandler pch = new PojoConfigurationTypeHandler(bc, intentManager
, null);
         
         Map<String, Object> sd = new HashMap<String, Object>();
         sd.put(org.osgi.framework.Constants.SERVICE_ID, 42);
@@ -849,18 +493,5 @@ public class PojoConfigurationTypeHandle
 //        }
 //        EasyMock.verify(ea);
 //    }
-
-    private static class TestFeature extends AbstractFeature {
-        private final String name;
-        
-        private TestFeature(String n) {
-            name = n;
-        }
-
-        @Override
-        public String toString() {
-            return name;
-        }
-    }
     
 }

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java?rev=1412157&r1=1412156&r2=1412157&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java
Wed Nov 21 15:51:35 2012
@@ -4,23 +4,8 @@ import java.util.Arrays;
 
 import junit.framework.Assert;
 
-import org.easymock.EasyMock;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-
 public class IntentUtilsTest {
     
-    public void testNoIntentMap() {
-        Bundle b = EasyMock.createNiceMock(Bundle.class);
-        EasyMock.replay(b);
-        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
-        EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
-        EasyMock.replay(bc);
-        
-        Assert.assertNull(IntentUtils.readIntentMap(bc));
-        Assert.assertNotNull(IntentUtils.getIntentMap(bc));
-    }    
-    
     public void testIntentsParsingAndFormatting() {
         String initial = "A SOAP_1.1 integrity";
 

Added: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/IntentManagerTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/IntentManagerTest.java?rev=1412157&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/IntentManagerTest.java
(added)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/IntentManagerTest.java
Wed Nov 21 15:51:35 2012
@@ -0,0 +1,300 @@
+/** 
+  * Licensed to the Apache Software Foundation (ASF) under one 
+  * or more contributor license agreements. See the NOTICE file 
+  * distributed with this work for additional information 
+  * regarding copyright ownership. The ASF licenses this file 
+  * to you under the Apache License, Version 2.0 (the 
+  * "License"); you may not use this file except in compliance 
+  * with the License. You may obtain a copy of the License at 
+  * 
+  * http://www.apache.org/licenses/LICENSE-2.0 
+  * 
+  * Unless required by applicable law or agreed to in writing, 
+  * software distributed under the License is distributed on an 
+  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
+  * KIND, either express or implied. See the License for the 
+  * specific language governing permissions and limitations 
+  * under the License. 
+  */
+package org.apache.cxf.dosgi.dsw.service;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.apache.cxf.binding.BindingConfiguration;
+import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.handlers.IntentUnsatifiedException;
+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.apache.cxf.endpoint.AbstractEndpointFactory;
+import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.feature.Feature;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+
+public class IntentManagerTest {
+    private Map<String, Object> handlerProps;
+    
+    @Before
+    public void setUp() throws Exception {
+        handlerProps = new HashMap<String, Object>();
+        handlerProps.put(Constants.DEFAULT_HOST_CONFIG, "somehost");
+        handlerProps.put(Constants.DEFAULT_PORT_CONFIG, "54321");
+    }
+    
+    @Test
+    public void testIntents() throws Exception {
+        Map<String, Object> intents = new HashMap<String, Object>();
+        intents.put("A", new TestFeature("A"));
+        intents.put("SOAP", new TestFeature("SOAP"));
+        final IntentMap intentMap = new IntentMap(intents);
+        
+        IMocksControl control = EasyMock.createNiceControl();
+        List<Feature> features = new ArrayList<Feature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+
+        IntentManager intentManager = new IntentManagerImpl(intentMap);
+        
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put("osgi.remote.requires.intents", "A");
+        //ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
+
+        List<String> effectiveIntents = Arrays.asList(intentManager.applyIntents(features,
factory, props));
+        assertEquals(Arrays.asList("A", "SOAP"), effectiveIntents);
+    }    
+    
+    @Test
+    public void testMultiIntents() {
+        final IntentMap intentMap = new IntentMap(new DefaultIntentMapFactory().create());
+        intentMap.put("confidentiality.message", new TestFeature("confidentiality.message"));
+        intentMap.put("transactionality", new TestFeature("transactionality"));
+        
+        IMocksControl control = EasyMock.createNiceControl();
+        List<Feature> features = new ArrayList<Feature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+
+        IntentManager intentManager = new IntentManagerImpl(intentMap);
+        
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put("osgi.remote.requires.intents", "transactionality confidentiality.message");
+        //ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
+
+        List<String> effectiveIntents = Arrays.asList(intentManager.applyIntents(features,
factory, props));
+        assertTrue(effectiveIntents.contains("transactionality"));        
+        assertTrue(effectiveIntents.contains("confidentiality.message"));        
+    }
+    
+    @Test
+    public void testFailedIntent() {
+        Map<String, Object> intents = new HashMap<String, Object>();
+        intents.put("A", new TestFeature("A"));
+        final IntentMap intentMap = new IntentMap(intents);
+                
+        IMocksControl control = EasyMock.createNiceControl();
+        List<Feature> features = new ArrayList<Feature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+        
+        IntentManager intentManager = new IntentManagerImpl(intentMap);
+
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put("osgi.remote.requires.intents", "A B");
+        //        ServiceEndpointDescription sd = 
+        //            new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
+
+        try {
+            intentManager.applyIntents(features, factory, props);
+            Assert.fail("applyIntents() should have thrown an exception as there was an unsatisfiable
intent");
+        } catch (IntentUnsatifiedException iue) {
+            assertEquals("B", iue.getIntent());
+        }
+    }
+ 
+    @Test
+    public void testInferIntents() {
+        Map<String, Object> intents = new HashMap<String, Object>();
+        intents.put("SOAP", new TestFeature("SOAP"));
+        intents.put("Prov", "PROVIDED");
+        AbstractFeature feat1 = new TestFeature("feat1");
+        intents.put("A", feat1);
+        intents.put("A_alt", feat1);
+        intents.put("B", new TestFeature("B"));
+        final IntentMap intentMap = new IntentMap(intents);
+        
+        IMocksControl control = EasyMock.createNiceControl();
+        List<Feature> features = new ArrayList<Feature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+
+        IntentManager intentManager = new IntentManagerImpl(intentMap);
+        
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put("osgi.remote.requires.intents", "A");
+        //        ServiceEndpointDescription sd = 
+        //            new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
+        
+        List<String> effectiveIntents = Arrays.asList(intentManager.applyIntents(features,
factory, props));
+        assertEquals(4, effectiveIntents.size());
+        assertTrue(effectiveIntents.contains("Prov"));
+        assertTrue(effectiveIntents.contains("A"));
+        assertTrue(effectiveIntents.contains("A_alt"));
+    }
+    
+    @Test
+    public void testDefaultBindingIntent() {        
+        IMocksControl control = EasyMock.createNiceControl();
+
+        Map<String, Object> intents = new HashMap<String, Object>();
+        BindingConfiguration feat1 = control.createMock(BindingConfiguration.class);
+        intents.put("A", new AbstractFeature() {});
+        intents.put("SOAP", feat1);
+        intents.put("SOAP.1_1", feat1);
+        intents.put("SOAP.1_2", control.createMock(BindingConfiguration.class));
+        final IntentMap intentMap = new IntentMap(intents);
+
+        List<Feature> features = new ArrayList<Feature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+        IntentManager intentManager = new IntentManagerImpl(intentMap);
+
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put("osgi.remote.requires.intents", "A");
+        //        ServiceEndpointDescription sd = 
+        //            new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
+        
+        List<String> effectiveIntents = 
+            Arrays.asList(intentManager.applyIntents(features, factory, props));
+        assertEquals(3, effectiveIntents.size());
+        assertTrue(effectiveIntents.contains("A"));
+        assertTrue(effectiveIntents.contains("SOAP"));
+        assertTrue(effectiveIntents.contains("SOAP.1_1"));
+    }
+    
+    public void testExplicitBindingIntent() {
+        IMocksControl control = EasyMock.createNiceControl();
+
+        Map<String, Object> intents = new HashMap<String, Object>();
+        BindingConfiguration feat1 = control.createMock(BindingConfiguration.class);
+        intents.put("A", new AbstractFeature() {});
+        intents.put("SOAP", feat1);
+        intents.put("SOAP.1_1", feat1);
+        intents.put("SOAP.1_2", control.createMock(BindingConfiguration.class));
+        final IntentMap intentMap = new IntentMap(intents);
+
+        List<Feature> features = new ArrayList<Feature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+
+        IntentManager intentManager = new IntentManagerImpl(intentMap);
+
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put("osgi.remote.requires.intents", "A SOAP.1_2");
+        //        ServiceEndpointDescription sd = 
+        //            new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
+        
+        List<String> effectiveIntents = 
+            Arrays.asList(intentManager.applyIntents(features, factory, props));
+        assertEquals(2, effectiveIntents.size());
+        assertTrue(effectiveIntents.contains("A"));
+        assertTrue(effectiveIntents.contains("SOAP.1_2"));        
+    }
+    
+    public void testInheritMasterIntentMapDefault() {
+        List<String> features = runTestInheritMasterIntentMap("A B");
+        
+        assertEquals(2, features.size());
+        assertTrue(features.contains("appFeatureA"));
+        assertTrue(features.contains("masterFeatureB"));
+    }
+    
+    public void testInheritMasterIntentMap() {
+        handlerProps.put(Constants.USE_MASTER_MAP, "true");
+        List<String> features = runTestInheritMasterIntentMap("A B");
+        
+        assertEquals(2, features.size());
+        assertTrue(features.contains("appFeatureA"));
+        assertTrue(features.contains("masterFeatureB"));
+    }
+
+    private List<String> runTestInheritMasterIntentMap(String requestedIntents) {
+        Map<String, Object> masterIntents = new HashMap<String, Object>();
+        masterIntents.put("A", new TestFeature("masterFeatureA"));
+        masterIntents.put("B", new TestFeature("masterFeatureB"));
+        final IntentMap intentMap = new IntentMap(masterIntents);
+        intentMap.put("A", new TestFeature("appFeatureA"));
+
+        IMocksControl control = EasyMock.createNiceControl();
+        List<Feature> features = new ArrayList<Feature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put("osgi.remote.requires.intents", requestedIntents);
+        //ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
+        
+        IntentManagerImpl intentManager = new IntentManagerImpl(intentMap);
+        intentManager.applyIntents(features, factory, props);
+
+        List<String> featureNames = new ArrayList<String>();
+        for (Feature f : features) {
+            featureNames.add(f.toString());
+        }
+        return featureNames;
+    }
+    
+    @Test
+    public void testProvidedIntents() {
+        Map<String, Object> masterIntents = new HashMap<String, Object>();
+        masterIntents.put("SOAP", "SOAP");
+        masterIntents.put("A", "Provided");
+        masterIntents.put("B", "PROVIDED");
+        final IntentMap intentMap = new IntentMap(masterIntents);
+
+        IMocksControl control = EasyMock.createNiceControl();
+        List<Feature> features = new ArrayList<Feature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+        
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put("osgi.remote.requires.intents", "B A");
+        //ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()),
props);
+        
+        IntentManager intentManager = new IntentManagerImpl(intentMap);
+        
+        Set<String> effectiveIntents = new HashSet<String>(Arrays.asList( 
+            intentManager.applyIntents(features, factory, props)));
+        Set<String> expectedIntents = new HashSet<String>(Arrays.asList(new String
[] {"A", "B", "SOAP"}));
+        assertEquals(expectedIntents, effectiveIntents);
+    }
+    
+
+    private static class TestFeature extends AbstractFeature {
+        private final String name;
+        
+        private TestFeature(String n) {
+            name = n;
+        }
+
+        @Override
+        public String toString() {
+            return name;
+        }
+    }
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/IntentManagerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=1412157&r1=1412156&r2=1412157&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 21 15:51:35 2012
@@ -30,7 +30,7 @@ import java.util.Map;
 import java.util.Properties;
 
 import org.apache.cxf.dosgi.dsw.handlers.ConfigurationTypeHandler;
-import org.apache.cxf.dosgi.dsw.qos.IntentMap;
+import org.apache.cxf.dosgi.dsw.qos.IntentManager;
 import org.easymock.IMocksControl;
 import org.easymock.classextension.EasyMock;
 import org.junit.Test;
@@ -59,8 +59,8 @@ public class RemoteServiceAdminCoreTest 
         ServiceReference sref = c.createMock(ServiceReference.class);
         EasyMock.expect(sref.getBundle()).andReturn(b).anyTimes();
 
-        IntentMap IntentMap = new IntentMap();
-		RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, IntentMap );
+        IntentManager intentManager = c.createMock(IntentManager.class);
+		RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, intentManager);
 
         c.replay();
 
@@ -91,8 +91,8 @@ public class RemoteServiceAdminCoreTest 
         EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
         EasyMock.expect(b.getSymbolicName()).andReturn("BundleName").anyTimes();
 
-        IntentMap intentMap = new IntentMap();
-		RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, intentMap ) {
+        IntentManager intentManager = c.createMock(IntentManager.class);
+        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, intentManager) {
             @Override
             protected void proxifyMatchingInterface(String interfaceName, ImportRegistrationImpl
imReg,
                                                     ConfigurationTypeHandler handler,
@@ -155,10 +155,9 @@ public class RemoteServiceAdminCoreTest 
         Bundle b = c.createMock(Bundle.class);
         BundleContext bc = c.createMock(BundleContext.class);
 
+        IntentManager intentManager = c.createMock(IntentManager.class);
         c.replay();
-
-        IntentMap IntentMap = new IntentMap();
-		RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, IntentMap );
+        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, intentManager);
 
         Properties serviceProperties = new Properties();
 
@@ -179,10 +178,10 @@ public class RemoteServiceAdminCoreTest 
         Bundle b = c.createMock(Bundle.class);
         BundleContext bc = c.createMock(BundleContext.class);
 
-        c.replay();
 
-        IntentMap intentMap = new IntentMap();
-		RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, intentMap );
+        IntentManager intentManager = c.createMock(IntentManager.class);
+        c.replay();
+        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc, intentManager);
 
         Properties serviceProperties = new Properties();
 

Modified: cxf/dosgi/trunk/samples/greeter/impl/src/main/java/org/apache/cxf/dosgi/samples/greeter/impl/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/samples/greeter/impl/src/main/java/org/apache/cxf/dosgi/samples/greeter/impl/Activator.java?rev=1412157&r1=1412156&r2=1412157&view=diff
==============================================================================
--- cxf/dosgi/trunk/samples/greeter/impl/src/main/java/org/apache/cxf/dosgi/samples/greeter/impl/Activator.java
(original)
+++ cxf/dosgi/trunk/samples/greeter/impl/src/main/java/org/apache/cxf/dosgi/samples/greeter/impl/Activator.java
Wed Nov 21 15:51:35 2012
@@ -32,7 +32,7 @@ public class Activator implements Bundle
     private ServiceRegistration registration;
 
     public void start(BundleContext bc) throws Exception {
-        Dictionary props = new Hashtable();
+        Dictionary<String, String> props = new Hashtable<String, String>();
 
         props.put("service.exported.interfaces", "*");
         props.put("service.exported.configs", "org.apache.cxf.ws");

Modified: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java?rev=1412157&r1=1412156&r2=1412157&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java
(original)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java
Wed Nov 21 15:51:35 2012
@@ -41,7 +41,7 @@ public class TestExportService extends A
     public static Option[] configure() throws Exception {
         return new Option[] {
                 MultiBundleTools.getDistroWithDiscovery(),
-                systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+                systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
                 mavenBundle().groupId("org.apache.servicemix.bundles" ).artifactId("org.apache.servicemix.bundles.junit").version("4.9_2"),
                 mavenBundle().groupId("org.apache.cxf.dosgi.samples").artifactId("cxf-dosgi-ri-samples-greeter-interface").versionAsInProject(),
                 mavenBundle().groupId("org.apache.cxf.dosgi.samples").artifactId("cxf-dosgi-ri-samples-greeter-impl").versionAsInProject(),



Mime
View raw message