cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From egl...@apache.org
Subject svn commit: r706195 - in /cxf/sandbox/dosgi/dsw/cxf-dsw/src: main/java/org/apache/cxf/dosgi/dsw/ main/java/org/apache/cxf/dosgi/dsw/service/ test/java/org/apache/cxf/dosgi/dsw/ test/java/org/apache/cxf/dosgi/dsw/handlers/ test/java/org/apache/cxf/dosgi...
Date Mon, 20 Oct 2008 10:14:17 GMT
Author: eglynn
Date: Mon Oct 20 03:14:17 2008
New Revision: 706195

URL: http://svn.apache.org/viewvc?rev=706195&view=rev
Log:
Applying another patch for CXF-1876 on behalf of David Bosschaert

Added:
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHookTest.java
  (with props)
Modified:
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImpl.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java
    cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java?rev=706195&r1=706194&r2=706195&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java Mon
Oct 20 03:14:17 2008
@@ -52,7 +52,7 @@
     private ExecutorService execService = 
         new ThreadPoolExecutor(5, 10, 50, TimeUnit.SECONDS, 
                                new LinkedBlockingQueue<Runnable>());
-    private CxfDistributionProvider dpService;
+    CxfDistributionProvider dpService;
     
     public void start(BundleContext context) {
         bc = context; 

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImpl.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImpl.java?rev=706195&r1=706194&r2=706195&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImpl.java
(original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImpl.java
Mon Oct 20 03:14:17 2008
@@ -36,14 +36,14 @@
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
 public class DistributionProviderImpl implements DistributionProvider, CxfDistributionProvider
{
-    private EventAdmin eventAdmin;
+    private Set<EventAdmin> eventAdmins = new HashSet<EventAdmin>(); 
     
     private Map<ServiceReference, Map<String, String>> publicationProperties
= 
         new HashMap<ServiceReference, Map<String,String>>();
     private Set<ServiceReference> exposedServices = new HashSet<ServiceReference>();

     private Set<ServiceReference> remoteServices = new HashSet<ServiceReference>();
 
-    private final ServiceTracker tracker; 
+    private final ServiceTracker tracker;
             
     public DistributionProviderImpl(BundleContext bc) {
         tracker = new ServiceTracker(bc, EventAdmin.class.getName(), new MyTrackerCustomizer());
@@ -94,8 +94,13 @@
     }
 
     @SuppressWarnings("unchecked")
-    private void postAdminEvent(String topic, ServiceReference serviceReference) {
-        if (eventAdmin != null) {
+    private void postAdminEvent(String topic, ServiceReference serviceReference) {      
 
+        Set<EventAdmin> eas = null;
+        synchronized (eventAdmins) {
+            eas = new HashSet<EventAdmin>(eventAdmins);
+        }
+        
+        for (EventAdmin eventAdmin : eas) {
             Dictionary ht = new Hashtable();
             addEventEntry(ht, EventConstants.SERVICE, serviceReference);
             addEventEntry(ht, EventConstants.SERVICE_ID, serviceReference.getProperty(org.osgi.framework.Constants.SERVICE_ID));
@@ -112,24 +117,38 @@
         }
     }    
 
+    public void addEventAdmin(EventAdmin ea) {
+        synchronized(eventAdmins) {
+            eventAdmins.add(ea);
+        }
+    }
+
     public void addRemoteService(ServiceReference sr) {
         synchronized (remoteServices) {
             remoteServices.add(sr);
         }
     }
 
+    public void removeEventAdmin(EventAdmin ea) {
+        synchronized(eventAdmins) {
+            eventAdmins.remove(ea);
+        }
+    }
+
     private class MyTrackerCustomizer implements ServiceTrackerCustomizer {
         public Object addingService(ServiceReference sr) {
             Object svc = sr.getBundle().getBundleContext().getService(sr);
             if (svc instanceof EventAdmin) {
-                eventAdmin = (EventAdmin) svc;
+                addEventAdmin((EventAdmin) svc);
             }
             return svc;
         }
 
-        public void modifiedService(ServiceReference sr, Object arg1) {}
-        public void removedService(ServiceReference sr, Object arg1) {
-            eventAdmin = null;
+        public void modifiedService(ServiceReference sr, Object svc) {}
+        public void removedService(ServiceReference sr, Object svc) {
+            if (svc != null) {
+                removeEventAdmin((EventAdmin) svc);
+            }
         }
     }
 }

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java?rev=706195&r1=706194&r2=706195&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
(original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
Mon Oct 20 03:14:17 2008
@@ -21,9 +21,59 @@
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.distribution.DistributionProvider;
 
-
 public class ActivatorTest extends TestCase{
     @SuppressWarnings("unchecked")
+    private BundleContext getMockBundleContext() {
+        IMocksControl control = EasyMock.createNiceControl();
+        
+        Bundle b = control.createMock(Bundle.class);
+        Hashtable<String, String> ht = new Hashtable<String, String>();
+        EasyMock.expect(b.getHeaders()).andReturn(ht).anyTimes();
+        
+        final Map<Object, Dictionary> services = new HashMap<Object, Dictionary>();
+        BundleContext bc = control.createMock(BundleContext.class);
+        EasyMock.expect(bc.registerService(
+            (String) EasyMock.anyObject(),
+            EasyMock.anyObject(), 
+            (Dictionary) EasyMock.anyObject())).andAnswer(new IAnswer<ServiceRegistration>()
{
+                public ServiceRegistration answer() throws Throwable {
+                    services.put(EasyMock.getCurrentArguments()[1],
+                        (Dictionary) EasyMock.getCurrentArguments()[2]);
+                    return null;
+                }                
+            }).anyTimes();            
+
+        EasyMock.expect(b.getBundleContext()).andReturn(bc).anyTimes();
+        EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
+        control.replay();
+        return bc;
+    }
+
+    public void testCreateAndShutdownDistributionProviderService() {
+        BundleContext bc = getMockBundleContext();
+        
+        Activator a = new Activator() {
+            @Override
+            IntentMap getIntentMap() {
+                IntentMap intentMap = new IntentMap();
+                intentMap.setIntents(new HashMap<String, Object>());
+                return intentMap;                
+            }            
+        };   
+        
+        assertNull("Precondition failed", a.dpService);
+        a.start(bc);
+        assertNotNull(a.dpService);
+        
+        CxfDistributionProvider mockDP = EasyMock.createMock(CxfDistributionProvider.class);
+        mockDP.shutdown();
+        EasyMock.replay(mockDP);
+        a.dpService = mockDP;
+        a.stop(bc);
+        EasyMock.verify(mockDP);
+    }
+    
+    @SuppressWarnings("unchecked")
     public void testCreateDistributionProviderService() {
         IMocksControl control = EasyMock.createNiceControl();
         

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java?rev=706195&r1=706194&r2=706195&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java (original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/TestUtils.java Mon
Oct 20 03:14:17 2008
@@ -20,7 +20,6 @@
 package org.apache.cxf.dosgi.dsw;
 
 import org.easymock.classextension.EasyMock;
-import org.junit.Ignore;
 import org.osgi.service.discovery.ServiceEndpointDescription;
 
 public final class TestUtils {

Modified: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java?rev=706195&r1=706194&r2=706195&view=diff
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
(original)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandlerTest.java
Mon Oct 20 03:14:17 2008
@@ -48,6 +48,9 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.discovery.ServiceEndpointDescription;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.event.EventConstants;
 
 
 public class PojoConfigurationTypeHandlerTest extends TestCase {
@@ -409,6 +412,124 @@
         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);
+        ea.postEvent((Event) EasyMock.anyObject());
+        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+            public Object answer() throws Throwable {
+                Event e = (Event) EasyMock.getCurrentArguments()[0];
+                assertEquals("org/osgi/service/distribution/DistributionProvider/service/exposed",
e.getTopic());                
+                List<String> keys = Arrays.asList(e.getPropertyNames());
+                assertTrue(keys.contains(EventConstants.SERVICE));
+                assertNotNull(e.getProperty(EventConstants.SERVICE));
+                assertTrue(keys.contains(EventConstants.SERVICE_ID));
+                assertEquals(17L, e.getProperty(EventConstants.SERVICE_ID));
+                assertTrue(keys.contains(EventConstants.SERVICE_OBJECTCLASS));
+                assertEquals(Arrays.asList(String.class.getName()), 
+                             Arrays.asList((Object []) e.getProperty(EventConstants.SERVICE_OBJECTCLASS)));
+                return null;
+            }
+        });            
+        EasyMock.replay(ea);
+        
+        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(dswContext);
+
+        String myService = "Hi";                
+        final ServerFactoryBean sfb = createMockServerFactoryBean();
+        DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
+        dp.addEventAdmin(ea);
+        
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps)
{
+            @Override
+            ServerFactoryBean createServerFactoryBean() {
+                return sfb;
+            }
+
+            @Override
+            String[] applyIntents(BundleContext dswContext, BundleContext callingContext,
+                List<AbstractFeature> features, AbstractEndpointFactory factory, ServiceEndpointDescription
sd) {
+                return new String []{};
+            }
+        };
+        
+        final Map<String, Object> props = new HashMap<String, Object>();
+        props.put(org.osgi.framework.Constants.SERVICE_ID, 17L);
+        props.put(org.osgi.framework.Constants.OBJECTCLASS, new String [] {String.class.getName()});
+        props.put("boo", "baa");
+        ServiceReference sr = EasyMock.createNiceMock(ServiceReference.class);
+        EasyMock.expect(sr.getPropertyKeys()).andReturn(props.keySet().toArray(new String
[] {})).anyTimes();
+        EasyMock.expect(sr.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>()
{
+            public Object answer() throws Throwable {
+                return props.get(EasyMock.getCurrentArguments()[0]);
+            }            
+        }).anyTimes();
+        BundleContext callingContext = EasyMock.createNiceMock(BundleContext.class);
+        ServiceEndpointDescription sd = TestUtils.mockServiceDescription("Foo");
+        EasyMock.replay(sr);
+        EasyMock.replay(callingContext);
+        EasyMock.replay(sd);
+
+        p.createServer(sr, dswContext, callingContext, sd, String.class, myService);
+        EasyMock.verify(ea);
+    }
+
+    public void testServiceUnsatisfiedAdminEvent() throws Exception {
+        EventAdmin ea = EasyMock.createMock(EventAdmin.class);
+        ea.postEvent((Event) EasyMock.anyObject());
+        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+            public Object answer() throws Throwable {
+                Event e = (Event) EasyMock.getCurrentArguments()[0];
+                assertEquals("org/osgi/service/distribution/DistributionProvider/service/unsatisfied",
e.getTopic());                
+                return null;
+            }
+        });            
+        EasyMock.replay(ea);
+        
+        BundleContext dswContext = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.replay(dswContext);
+
+        String myService = "Hi";                
+        final ServerFactoryBean sfb = createMockServerFactoryBean();
+        DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
+        dp.addEventAdmin(ea);
+        
+        PojoConfigurationTypeHandler p = new PojoConfigurationTypeHandler(dp, handlerProps)
{
+            @Override
+            ServerFactoryBean createServerFactoryBean() {
+                return sfb;
+            }
+
+            @Override
+            String[] applyIntents(BundleContext dswContext, BundleContext callingContext,
+                List<AbstractFeature> features, AbstractEndpointFactory factory, ServiceEndpointDescription
sd) {
+                throw new IntentUnsatifiedException("XYZ");
+            }
+        };
+        
+        final Map<String, Object> props = new HashMap<String, Object>();
+        ServiceReference sr = EasyMock.createNiceMock(ServiceReference.class);
+        EasyMock.expect(sr.getPropertyKeys()).andReturn(props.keySet().toArray(new String
[] {})).anyTimes();
+        EasyMock.expect(sr.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>()
{
+            public Object answer() throws Throwable {
+                return props.get(EasyMock.getCurrentArguments()[0]);
+            }            
+        }).anyTimes();
+        BundleContext callingContext = EasyMock.createNiceMock(BundleContext.class);
+        ServiceEndpointDescription sd = TestUtils.mockServiceDescription("Foo");
+        EasyMock.replay(sr);
+        EasyMock.replay(callingContext);
+        EasyMock.replay(sd);
+
+        try {
+            p.createServer(sr, dswContext, callingContext, sd, String.class, myService);
+            fail("Should have thrown an IntentUnsatifiedException");
+        } catch (IntentUnsatifiedException iue) {
+            // good
+        }
+        EasyMock.verify(ea);
+    }
 
     private static class TestFeature extends AbstractFeature {
         private final String name;

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHookTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHookTest.java?rev=706195&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHookTest.java
(added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHookTest.java
Mon Oct 20 03:14:17 2008
@@ -0,0 +1,51 @@
+/** 
+  * Licensed to the Apache Software Foundation (ASF) under one 
+  * or more contributor license agreements. See the NOTICE file 
+  * distributed with this work for additional information 
+  * regarding copyright ownership. The ASF licenses this file 
+  * to you under the Apache License, Version 2.0 (the 
+  * "License"); you may not use this file except in compliance 
+  * with the License. You may obtain a copy of the License at 
+  * 
+  * http://www.apache.org/licenses/LICENSE-2.0 
+  * 
+  * Unless required by applicable law or agreed to in writing, 
+  * software distributed under the License is distributed on an 
+  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
+  * KIND, either express or implied. See the License for the 
+  * specific language governing permissions and limitations 
+  * under the License. 
+  */
+package org.apache.cxf.dosgi.dsw.hooks;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.service.CxfDistributionProvider;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.discovery.ServiceEndpointDescription;
+
+public class AbstractClientHookTest extends TestCase {
+    public void testOSGiRemoteProperty() throws Exception {
+        IMocksControl control = EasyMock.createNiceControl();
+        BundleContext bc = control.createMock(BundleContext.class);
+        CxfDistributionProvider dp = control.createMock(CxfDistributionProvider.class);
+        ServiceEndpointDescription sed = control.createMock(ServiceEndpointDescription.class);
+        EasyMock.expect(sed.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
+        control.replay();
+        
+        AbstractClientHook ch = new AbstractClientHook(bc, dp) {
+            @Override
+            protected String getIdentificationProperty() {
+                return "ID";
+            }            
+        };
+        Map<String, Object> props = ch.getProperties(sed);
+        assertTrue(Boolean.valueOf((String) props.get(Constants.REMOTE_PROPERTY_PREFIX)));
+    }
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHookTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHookTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message