Author: davidb
Date: Fri Aug 21 11:37:47 2009
New Revision: 806505

URL: http://svn.apache.org/viewvc?rev=806505&view=rev
Log:
Allow the use of all default properties with Discovery.
The way information in Discovery is interpreted is enhanced.
* When service.exported.configs is not found, org.apache.cxf.ws is assumed
* When service.exported.configs contains org.apache.cxf.ws and 
org.apache.cxf.ws.address is not set, the value of 
osgi.remote.endpoint.location is assumed.

Modified:
    
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java
    
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java
    
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java

Modified: 
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java
URL: 
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java?rev=806505&r1=806504&r2=806505&view=diff
==============================================================================
--- 
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java
 (original)
+++ 
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImpl.java
 Fri Aug 21 11:37:47 2009
@@ -30,6 +30,7 @@
 import org.apache.zookeeper.ZooKeeper;
 import org.osgi.service.discovery.DiscoveredServiceNotification;
 import org.osgi.service.discovery.DiscoveredServiceTracker;
+import org.osgi.service.discovery.ServicePublication;
 
 public class InterfaceDataMonitorListenerImpl implements DataMonitorListener {
     private static final Logger LOG = 
Logger.getLogger(InterfaceDataMonitorListenerImpl.class.getName());
@@ -66,6 +67,15 @@
                     m.put(entry.getKey().toString(), entry.getValue());
                 }
                 
+                // Put in some reasonable defaults, if not specified
+                if (!m.containsKey("service.exported.configs")) {
+                    m.put("service.exported.configs", "org.apache.cxf.ws");
+                }
+                if 
(Util.getMultiValueProperty(m.get("service.exported.configs")).contains("org.apache.cxf.ws")
 &&
+                    !m.containsKey("org.apache.cxf.ws.address")) {
+                    m.put("org.apache.cxf.ws.address", 
m.get(ServicePublication.ENDPOINT_LOCATION));                    
+                }
+                
                 newNodes.put(child, m);
                 Map<String, Object> prevVal = prevNodes.remove(child);
                 if (prevVal == null) {

Modified: 
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java
URL: 
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java?rev=806505&r1=806504&r2=806505&view=diff
==============================================================================
--- 
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java
 (original)
+++ 
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceDataMonitorListenerImplTest.java
 Fri Aug 21 11:37:47 2009
@@ -18,6 +18,7 @@
   */
 package org.apache.cxf.dosgi.discovery.zookeeper;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -32,6 +33,7 @@
 import org.osgi.service.discovery.DiscoveredServiceNotification;
 import org.osgi.service.discovery.DiscoveredServiceTracker;
 import org.osgi.service.discovery.ServiceEndpointDescription;
+import org.osgi.service.discovery.ServicePublication;
 
 public class InterfaceDataMonitorListenerImplTest extends TestCase {
     public void testChange() throws Exception {
@@ -47,6 +49,7 @@
         //----------------------------------------------------------------
         Properties initial = new Properties();
         initial.put("a", "b");     
+        initial.put(ServicePublication.ENDPOINT_LOCATION, 
"http://somehost:12345/some/context";);
         ByteArrayOutputStream propBytes = new ByteArrayOutputStream();
         initial.store(propBytes, "");
         
@@ -67,8 +70,14 @@
         assertEquals(DiscoveredServiceNotification.AVAILABLE, dsn.getType());
         assertEquals(0, dsn.getFilters().size());
         ServiceEndpointDescription sed = dsn.getServiceEndpointDescription();
-        assertEquals(Collections.singleton(String.class.getName()), 
sed.getProvidedInterfaces());        
-        assertEquals(initial, sed.getProperties());
+        assertEquals(Collections.singleton(String.class.getName()), 
sed.getProvidedInterfaces());    
+        
+        Properties expected = new Properties();
+        expected.load(new ByteArrayInputStream(propBytes.toByteArray()));
+        expected.put("service.exported.configs", "org.apache.cxf.ws");
+        expected.put("org.apache.cxf.ws.address", 
"http://somehost:12345/some/context";);
+        
+        assertEquals(expected, sed.getProperties());
         EasyMock.verify(zk);
         
         // Again with the same data
@@ -90,6 +99,8 @@
         //----------------------------------------------------------------
         Properties modified = new Properties();
         modified.put("c", "d");
+        modified.put(ServicePublication.ENDPOINT_LOCATION, 
"http://somehost:999/some/context";);
+        modified.put("service.exported.configs", "org.apache.cxf.rs");
         ByteArrayOutputStream modBytes = new ByteArrayOutputStream();
         modified.store(modBytes, "");
         
@@ -115,11 +126,21 @@
         EasyMock.verify(zk);
 
         //----------------------------------------------------------------
-        // Test DiscoveredServiceNotification.UNAVAILABLE
+        // Test DiscoveredServiceNotification.MODIFIED2
         //----------------------------------------------------------------
+        Properties modified2 = new Properties();
+        modified2.put("c", "d2");
+        modified2.put(ServicePublication.ENDPOINT_LOCATION, 
"http://somehost:112/some/context";);
+        modified2.put("service.exported.configs", "org.apache.cxf.ws");
+        modified2.put("org.apache.cxf.ws.address", "http://somewhereelse/123";);
+        ByteArrayOutputStream modBytes2 = new ByteArrayOutputStream();
+        modified2.store(modBytes2, "");
+        
         EasyMock.reset(zk);
         
EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), 
false))
-            .andReturn(Collections.<String>emptyList());
+            .andReturn(Arrays.asList("x#y#z"));
+        
EasyMock.expect(zk.getData(Util.getZooKeeperPath(String.class.getName()) + 
"/x#y#z", false, null))
+            .andReturn(modBytes2.toByteArray());
         EasyMock.replay(zk);
 
         dsnCallbacks.clear();
@@ -128,11 +149,32 @@
         assertEquals(1, dsnCallbacks.size());
         DiscoveredServiceNotification dsn3 = dsnCallbacks.iterator().next();
         assertEquals(Collections.singleton(String.class.getName()), 
dsn3.getInterfaces());
-        assertEquals(DiscoveredServiceNotification.UNAVAILABLE, 
dsn3.getType());
+        assertEquals(DiscoveredServiceNotification.MODIFIED, dsn3.getType());
         assertEquals(0, dsn3.getFilters().size());
         ServiceEndpointDescription sed3 = dsn3.getServiceEndpointDescription();
         assertEquals(Collections.singleton(String.class.getName()), 
sed3.getProvidedInterfaces());        
-        assertEquals(modified, sed3.getProperties());
+        assertEquals(modified2, sed3.getProperties());
+        
+        EasyMock.verify(zk);
+        //----------------------------------------------------------------
+        // Test DiscoveredServiceNotification.UNAVAILABLE
+        //----------------------------------------------------------------
+        EasyMock.reset(zk);
+        
EasyMock.expect(zk.getChildren(Util.getZooKeeperPath(String.class.getName()), 
false))
+            .andReturn(Collections.<String>emptyList());
+        EasyMock.replay(zk);
+
+        dsnCallbacks.clear();
+        assertEquals("Precondition failed", 0, dsnCallbacks.size());
+        dml.change();
+        assertEquals(1, dsnCallbacks.size());
+        DiscoveredServiceNotification dsn4 = dsnCallbacks.iterator().next();
+        assertEquals(Collections.singleton(String.class.getName()), 
dsn4.getInterfaces());
+        assertEquals(DiscoveredServiceNotification.UNAVAILABLE, 
dsn4.getType());
+        assertEquals(0, dsn4.getFilters().size());
+        ServiceEndpointDescription sed4 = dsn4.getServiceEndpointDescription();
+        assertEquals(Collections.singleton(String.class.getName()), 
sed4.getProvidedInterfaces());        
+        assertEquals(modified2, sed4.getProperties());
         
         EasyMock.verify(zk);
         

Modified: 
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java
URL: 
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java?rev=806505&r1=806504&r2=806505&view=diff
==============================================================================
--- 
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java
 (original)
+++ 
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitorTest.java
 Fri Aug 21 11:37:47 2009
@@ -53,6 +53,7 @@
         assertSame(dst, listener.discoveredServiceTracker);
     }
     
+    @SuppressWarnings("unchecked")
     public void testInterfaceMonitor() throws Exception {
         Properties s1Props = new Properties();
         s1Props.put("a", "b");
@@ -95,10 +96,11 @@
             ServiceEndpointDescription sed = 
dsn.getServiceEndpointDescription();
             assertEquals(Collections.singleton(String.class.getName()), 
sed.getProvidedInterfaces());
             Map<?, ?> m = sed.getProperties();
-            if (s1Props.equals(m)) {
+            if (m.entrySet().containsAll(s1Props.entrySet())) {
                 s1Found = true;
             }
-            if (s2Props.equals(m)) {
+            
+            if (m.entrySet().containsAll(s2Props.entrySet())) {
                 s2Found = true;
             }            
         }
@@ -128,7 +130,7 @@
         assertEquals(Collections.singleton(String.class.getName()), 
dsn.getInterfaces());
         ServiceEndpointDescription sed = dsn.getServiceEndpointDescription();
         assertEquals(Collections.singleton(String.class.getName()), 
sed.getProvidedInterfaces());
-        assertEquals(s2Props, sed.getProperties());        
+        
assertTrue(sed.getProperties().entrySet().containsAll(s2Props.entrySet()));
     }
     
     public void testInterfaceMonitorNoExist() throws Exception {


Reply via email to