cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r917537 [3/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/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=917537&r1=917536&r2=917537&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 Mon Mar  1 14:06:34 2010
@@ -18,13 +18,21 @@
   */
 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.IntentMap;
+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;
@@ -230,47 +238,48 @@
 //        assertEquals(expected, dp.getExposedProperties(sr));
 //    }
 //    
-//    public void testCreateServerWithAddressProprety() {
-//        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
-//        EasyMock.replay(dswContext);
-//
-//        String myService = "Hi";                
-//        final ServerFactoryBean sfb = createMockServerFactoryBean();
-//        
-//        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
-//        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(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 []{};
-//            }
-//        };
-//        
-//        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_ADDRESS_PROPERTY, "http://alternate_host:80/myString");
-//        ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Runnable.class.getName(), props);
-//        
-//        assertEquals("Precondition failed", 0, dp.getExposedServices().size());
-//        p.createServer(sr, dswContext, callingContext, sd, String.class, myService);
-//        assertEquals(1, dp.getExposedServices().size());
-//        assertSame(sr, dp.getExposedServices().iterator().next());
-//        
-//        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://alternate_host:80/myString");
-//        assertEquals(expected, dp.getExposedProperties(sr));
-//    }    
-//
+    public void testCreateServerWithAddressProprety() {
+        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(dswContext);
+
+        String myService = "Hi";                
+        final ServerFactoryBean sfb = createMockServerFactoryBean();
+        
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(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 []{};
+            }
+        };
+        
+        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_ADDRESS_PROPERTY, "http://alternate_host:80/myString");
+        
+        ExportRegistrationImpl exReg = new ExportRegistrationImpl(sr,null,null);
+        
+        p.createServer(exReg, dswContext, callingContext, props, String.class, myService);
+        
+        
+        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://alternate_host:80/myString", edProps.get(RemoteConstants.ENDPOINT_ID));
+        
+    }    
+
     private ServerFactoryBean createMockServerFactoryBean() {
         ReflectionServiceFactoryBean sf = EasyMock.createNiceMock(ReflectionServiceFactoryBean.class);
         EasyMock.replay(sf);
@@ -321,366 +330,366 @@
         EasyMock.replay(server);
         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<AbstractFeature> features = new ArrayList<AbstractFeature>();
-//        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-//        control.replay();
-//
-//        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
-//        AbstractPojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, 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, sd));
-//        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<AbstractFeature> features = new ArrayList<AbstractFeature>();
-//        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-//        control.replay();
-//
-//        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
-//        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, 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, sd));
-//        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<AbstractFeature> features = new ArrayList<AbstractFeature>();
-//        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-//        control.replay();
-//
-//        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
-//        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, 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, sd);
-//            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<AbstractFeature> features = new ArrayList<AbstractFeature>();
-//        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-//        control.replay();
-//        
-//        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
-//        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, 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, sd));
-//        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<AbstractFeature> features = new ArrayList<AbstractFeature>();
-//        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-//        control.replay();
-//        
-//        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
-//        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, 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, sd));
-//        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<AbstractFeature> features = new ArrayList<AbstractFeature>();
-//        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-//        control.replay();
-//        
-//        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
-//        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dswContext, dp, 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, sd));
-//        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<AbstractFeature> features = new ArrayList<AbstractFeature>();
-//        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-//        control.replay();
-//
-//        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
-//
-//        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, dp, 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, sd);
-//
-//        List<String> featureNames = new ArrayList<String>();
-//        for (AbstractFeature 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<AbstractFeature> features = new ArrayList<AbstractFeature>();
-//        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
-//        control.replay();
-//        
-//        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
-//
-//        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, dp, 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, sd)));
-//        Set<String> expectedIntents = new HashSet<String>(Arrays.asList(new String [] {"A", "B"}));
-//        assertEquals(expectedIntents, effectiveIntents);
-//    }
+    
+    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<AbstractFeature> features = new ArrayList<AbstractFeature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+
+        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
+        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<AbstractFeature> features = new ArrayList<AbstractFeature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+
+        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
+        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<AbstractFeature> features = new ArrayList<AbstractFeature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+
+        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
+        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<AbstractFeature> features = new ArrayList<AbstractFeature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+        
+        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
+        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<AbstractFeature> features = new ArrayList<AbstractFeature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+        
+        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
+        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<AbstractFeature> features = new ArrayList<AbstractFeature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+        
+        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
+        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<AbstractFeature> features = new ArrayList<AbstractFeature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+
+        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
+
+        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 (AbstractFeature 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<AbstractFeature> features = new ArrayList<AbstractFeature>();
+        AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class);
+        control.replay();
+        
+        RemoteServiceAdminCore dp = new RemoteServiceAdminCore(dswContext);
+
+        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 testServiceExposedAdminEvent() throws Exception {
 //        EventAdmin ea = EasyMock.createMock(EventAdmin.class);

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=917537&r1=917536&r2=917537&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 Mon Mar  1 14:06:34 2010
@@ -1,21 +1,21 @@
 /** 
-  * 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. 
-  */
+ * 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 java.util.Dictionary;
@@ -45,165 +45,154 @@
 public class RemoteServiceAdminCoreTest {
 
     @Test
-    public void dontExportOwnServiceProxies(){
-        
+    public void dontExportOwnServiceProxies() {
+
         IMocksControl c = EasyMock.createNiceControl();
         Bundle b = c.createMock(Bundle.class);
         BundleContext bc = c.createMock(BundleContext.class);
-        
-        
+
         EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
-        
+
         Dictionary d = new Properties();
         EasyMock.expect(b.getHeaders()).andReturn(d).anyTimes();
-        
+
         ServiceReference sref = c.createMock(ServiceReference.class);
         EasyMock.expect(sref.getBundle()).andReturn(b).anyTimes();
-        
+
         RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc);
-        
-        
+
         c.replay();
-        
-        
-        // must return null as sref if from the same bundle 
-        assertNull(rsaCore.exportService(sref, null));
-        
-        // must be empty ... 
-        assertEquals(rsaCore.getExportedServices().size(),0);
-        
+
+        // must return an empty List as sref if from the same bundle
+        List exRefs = rsaCore.exportService(sref, null);
+
+        assertNotNull(exRefs);
+        assertEquals(0, exRefs.size());
+
+        // must be empty ...
+        assertEquals(rsaCore.getExportedServices().size(), 0);
+
         c.verify();
-        
+
     }
-    
-    
+
     @SuppressWarnings("unchecked")
     @Test
-    public void testImport(){
-        
+    public void testImport() {
+
         IMocksControl c = EasyMock.createNiceControl();
         Bundle b = c.createMock(Bundle.class);
         BundleContext bc = c.createMock(BundleContext.class);
-        
+
         Dictionary d = new Properties();
         EasyMock.expect(b.getHeaders()).andReturn(d).anyTimes();
-        
+
         EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
         EasyMock.expect(b.getSymbolicName()).andReturn("BundleName").anyTimes();
-        
-        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc){
+
+        RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc) {
             @Override
             protected void proxifyMatchingInterface(String interfaceName, ImportRegistrationImpl imReg,
                                                     ConfigurationTypeHandler handler,
                                                     BundleContext requestingContext) {
 
-                
-                
             }
         };
-        
+
         Map p = new HashMap();
         p.put(RemoteConstants.ENDPOINT_ID, "http://google.de");
-        p.put(Constants.OBJECTCLASS, new String[] {"es.schaaf.my.class"});
+        p.put(Constants.OBJECTCLASS, new String[] {
+            "es.schaaf.my.class"
+        });
         p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "unsupportetConfiguration");
         EndpointDescription endpoint = new EndpointDescription(p);
-        
-        
+
         c.replay();
-        
+
         // must be null as the endpoint doesn't contain any usable configurations
         assertNull(rsaCore.importService(endpoint));
-        // must be empty ... 
-        assertEquals(rsaCore.getImportedEndpoints().size(),0);
-        
-        
+        // must be empty ...
+        assertEquals(0, rsaCore.getImportedEndpoints().size());
+
         p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "org.apache.cxf.ws");
         endpoint = new EndpointDescription(p);
-        
-        
+
         ImportRegistration ireg = rsaCore.importService(endpoint);
         assertNotNull(ireg);
-        
-        assertEquals(rsaCore.getImportedEndpoints().size(),1);
-        
-        
+
+        assertEquals(1, rsaCore.getImportedEndpoints().size());
+
         // lets import the same endpoint once more -> should get a copy of the ImportRegistration
         ImportRegistration ireg2 = rsaCore.importService(endpoint);
         assertNotNull(ireg2);
-        assertEquals(rsaCore.getImportedEndpoints().size(),1);
-        
-        assertEquals(ireg,(rsaCore.getImportedEndpoints().toArray())[0]);
-
-        assertEquals(ireg.getImportReference().getImportedEndpoint(),ireg2.getImportReference().getImportedEndpoint());
-        
-        
+        assertEquals(2,rsaCore.getImportedEndpoints().size());
+
+        assertEquals(ireg, (rsaCore.getImportedEndpoints().toArray())[0]);
+
+        assertEquals(ireg.getImportReference().getImportedEndpoint(), ireg2.getImportReference()
+            .getImportedEndpoint());
+
         // remove the registration ....
-        
-        // first call shouldn't remove the import ... 
+
+        // first call shouldn't remove the import ...
         ireg2.close();
-        assertEquals(1,rsaCore.getImportedEndpoints().size());
-        
+        assertEquals(1, rsaCore.getImportedEndpoints().size());
+
         // second call should really close and remove the import ...
         ireg.close();
-        assertEquals(0,rsaCore.getImportedEndpoints().size());
-        
-        
+        assertEquals(0, rsaCore.getImportedEndpoints().size());
+
         c.verify();
-        
-        
+
     }
-    
+
     @Test
-    public void testDefaultConfigurationType(){
-        
+    public void testDefaultConfigurationType() {
+
         IMocksControl c = EasyMock.createNiceControl();
         Bundle b = c.createMock(Bundle.class);
         BundleContext bc = c.createMock(BundleContext.class);
-        
+
         c.replay();
-        
+
         RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc);
-        
+
         Properties serviceProperties = new Properties();
-        
-        List<String> types  = rsaCore.determineConfigurationTypes(serviceProperties);
-        
+
+        List<String> types = rsaCore.determineConfigurationTypes(serviceProperties);
+
         c.verify();
-        
+
         assertNotNull(types);
-        assertEquals(types.size(),rsaCore.supportedConfigurationTypes.size());
-        
-        for (String type : types) {
-            assertTrue(rsaCore.supportedConfigurationTypes.contains(type));
-        }
+        assertEquals(1, types.size());
+
+        assertTrue(types.contains(org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE));
     }
-    
-    
+
     @Test
-    public void testSpecificConfigurationType(){
-        
+    public void testSpecificConfigurationType() {
+
         IMocksControl c = EasyMock.createNiceControl();
         Bundle b = c.createMock(Bundle.class);
         BundleContext bc = c.createMock(BundleContext.class);
-        
+
         c.replay();
-        
+
         RemoteServiceAdminCore rsaCore = new RemoteServiceAdminCore(bc);
-        
-        
-        
+
         Properties serviceProperties = new Properties();
-        
-        serviceProperties.setProperty(RemoteConstants.SERVICE_EXPORTED_CONFIGS, org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE);
-        
-        List<String> types  = rsaCore.determineConfigurationTypes(serviceProperties);
-        
+
+        serviceProperties.setProperty(RemoteConstants.SERVICE_EXPORTED_CONFIGS,
+                                      org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE);
+
+        List<String> types = rsaCore.determineConfigurationTypes(serviceProperties);
+
         c.verify();
-        
+
         assertNotNull(types);
-        assertEquals(1,types.size());
-        
+        assertEquals(1, types.size());
+
         assertTrue(types.contains(org.apache.cxf.dosgi.dsw.Constants.WS_CONFIG_TYPE));
     }
-    
+
 }

Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ExportServiceTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ExportServiceTest.java?rev=917537&r1=917536&r2=917537&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ExportServiceTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ExportServiceTest.java Mon Mar  1 14:06:34 2010
@@ -22,9 +22,11 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
 
 import org.easymock.IAnswer;
-import org.easymock.IMocksControl;
+import org.easymock.classextension.IMocksControl;
 import org.easymock.classextension.EasyMock;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -53,12 +55,16 @@
     @Test
     public void testServiceExport() throws Exception {
 
+        final Semaphore sema = new Semaphore(1);
+        sema.acquire(); 
+        
         String scope = "(objectClass=abc)";
      
         IMocksControl c = EasyMock.createNiceControl();
-          
+        
+        
         BundleContext bctx = c.createMock(BundleContext.class);
-
+        
         Bundle topMgrBundle = c.createMock(Bundle.class);
         
         RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);
@@ -102,6 +108,7 @@
 
             public Object answer() throws Throwable {
                 System.out.println("Call made !!!");
+                sema.release();
                 return null;
             }
             
@@ -113,8 +120,6 @@
             EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
 
                 public Object answer() throws Throwable {
-                    // TODO Auto-generated method stub
-
                     System.out.println("->   addServiceListener: "
                                        + EasyMock.getCurrentArguments()[1]);
                     ServiceListener sl = (ServiceListener)EasyMock.getCurrentArguments()[0];
@@ -137,8 +142,6 @@
             EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
 
                 public Object answer() throws Throwable {
-                    // TODO Auto-generated method stub
-
                     System.out.println("->   addServiceListener ");
 
                     ServiceListener sl = (ServiceListener)EasyMock.getCurrentArguments()[0];
@@ -173,18 +176,17 @@
 
         }
 
-
+        
         c.replay();
 
-//        TopologyManager tm = new TopologyManager(bctx);
-//        tm.start();
+        //        TopologyManager tm = new TopologyManager(bctx);
+        //        tm.start();
 
         Activator a = new Activator();
         a.start(bctx);
         
-        try {
-            Thread.sleep(100);
-        } catch (InterruptedException e) {}
+        // Wait until the EndpointListener.endpointAdded call was made as the controlflow is asynchronous
+        sema.tryAcquire(30, TimeUnit.SECONDS);
         
         c.verify();
 



Mime
View raw message