cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r765553 - in /cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src: main/java/org/apache/cxf/dosgi/discovery/zookeeper/ test/java/org/apache/cxf/dosgi/discovery/zookeeper/
Date Thu, 16 Apr 2009 10:04:25 GMT
Author: davidb
Date: Thu Apr 16 10:04:25 2009
New Revision: 765553

URL: http://svn.apache.org/viewvc?rev=765553&view=rev
Log:
Test for the Discovery Bean class.

Modified:
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveryBean.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorTest.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveryBeanTest.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizerTest.java

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveryBean.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveryBean.java?rev=765553&r1=765552&r2=765553&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveryBean.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveryBean.java
Thu Apr 16 10:04:25 2009
@@ -18,6 +18,8 @@
   */
 package org.apache.cxf.dosgi.discovery.zookeeper;
 
+import java.io.IOException;
+
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
@@ -32,11 +34,10 @@
 public class DiscoveryBean implements BundleContextAware, InitializingBean, DisposableBean,
Watcher {
     private BundleContext bundleContext;
     private DiscoveryServiceImpl discoveryService;
-    private ZooKeeper zooKeeper;
 
-    private FindInZooKeeperCustomizer finderCustomizer;
-    private ServiceTracker lookupTracker;
-    private ServiceTracker publicationTracker;
+    ServiceTracker lookupTracker;
+    ServiceTracker publicationTracker;
+    ZooKeeper zooKeeper;
         
     public void setBundleContext(BundleContext bc) {
         bundleContext = bc;
@@ -49,18 +50,21 @@
     public void afterPropertiesSet() throws Exception {
         String hostPort = discoveryService.getZooKeeperHost() + ":" + 
                           discoveryService.getZooKeeperPort();
-        zooKeeper = new ZooKeeper(hostPort, discoveryService.getZooKeeperTimeout(), this);
+        zooKeeper = createZooKeeper(hostPort);
         
         publicationTracker = new ServiceTracker(bundleContext, ServicePublication.class.getName(),

                 new PublishToZooKeeperCustomizer(bundleContext, zooKeeper));
         publicationTracker.open();
         
-        finderCustomizer = new FindInZooKeeperCustomizer(bundleContext, zooKeeper);
         lookupTracker = new ServiceTracker(bundleContext, DiscoveredServiceTracker.class.getName(),
-                finderCustomizer);
+                new FindInZooKeeperCustomizer(bundleContext, zooKeeper));
         lookupTracker.open();        
     }
 
+    ZooKeeper createZooKeeper(String hostPort) throws IOException {
+        return new ZooKeeper(hostPort, discoveryService.getZooKeeperTimeout(), this);
+    }
+
     public void destroy() throws Exception {
         lookupTracker.close();
         publicationTracker.close();

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorTest.java?rev=765553&r1=765552&r2=765553&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorTest.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/DataMonitorTest.java
Thu Apr 16 10:04:25 2009
@@ -28,7 +28,6 @@
 
 import junit.framework.TestCase;
 
-import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.AsyncCallback.StatCallback;
 import org.apache.zookeeper.KeeperException.Code;

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveryBeanTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveryBeanTest.java?rev=765553&r1=765552&r2=765553&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveryBeanTest.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/DiscoveryBeanTest.java
Thu Apr 16 10:04:25 2009
@@ -18,8 +18,84 @@
   */
 package org.apache.cxf.dosgi.discovery.zookeeper;
 
+import java.io.IOException;
+
 import junit.framework.TestCase;
 
+import org.apache.zookeeper.ZooKeeper;
+import org.easymock.classextension.EasyMock;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.discovery.DiscoveredServiceTracker;
+import org.osgi.service.discovery.ServicePublication;
+import org.osgi.util.tracker.ServiceTracker;
+
 public class DiscoveryBeanTest extends TestCase {
-    public void testTodo() {}
+    public void testDiscoveryBean() throws Exception {
+        final StringBuilder sb = new StringBuilder();
+        DiscoveryBean db = new DiscoveryBean() {
+            @Override
+            ZooKeeper createZooKeeper(String hostPort) throws IOException {
+                sb.append(hostPort);
+                ZooKeeper zk = EasyMock.createMock(ZooKeeper.class);
+                EasyMock.replay(zk);
+                return zk;
+            }            
+        };
+        
+        DiscoveryServiceImpl ds = new DiscoveryServiceImpl();
+        ds.setZooKeeperHost("myhost.mymachine.mytld");
+        ds.setZooKeeperPort(1234);
+        db.setDiscoveryServiceBean(ds);
+        
+        BundleContext bc = EasyMock.createMock(BundleContext.class);
+        expectServiceTrackerCalls(bc, ServicePublication.class.getName());
+        expectServiceTrackerCalls(bc, DiscoveredServiceTracker.class.getName());
+        EasyMock.replay(bc);
+        db.setBundleContext(bc);
+        
+        assertNull("Precondition failed", db.lookupTracker);
+        assertNull("Precondition failed", db.publicationTracker);
+        db.afterPropertiesSet();
+        assertNotNull(db.lookupTracker);
+        assertNotNull(db.publicationTracker);
+        EasyMock.verify(bc);
+        
+        EasyMock.verify(db.zooKeeper);
+        EasyMock.reset(db.zooKeeper);
+        db.zooKeeper.close();
+        EasyMock.expectLastCall();
+        EasyMock.replay(db.zooKeeper);
+        
+        ServiceTracker st1 = EasyMock.createMock(ServiceTracker.class);
+        st1.close();
+        EasyMock.expectLastCall();
+        EasyMock.replay(st1);
+        ServiceTracker st2 = EasyMock.createMock(ServiceTracker.class);
+        st2.close();
+        EasyMock.expectLastCall();
+        EasyMock.replay(st2);
+        
+        db.lookupTracker = st1;
+        db.publicationTracker = st2;
+        
+        db.destroy();        
+    }
+
+    private void expectServiceTrackerCalls(BundleContext bc, String objectClass)
+            throws InvalidSyntaxException {
+        Filter filter = EasyMock.createNiceMock(Filter.class);
+        EasyMock.replay(filter);
+        
+        EasyMock.expect(bc.createFilter("(objectClass=" + objectClass + ")"))
+            .andReturn(filter).anyTimes();
+        bc.addServiceListener((ServiceListener) EasyMock.anyObject(), 
+            EasyMock.eq("(objectClass=" + objectClass + ")"));
+        EasyMock.expectLastCall().anyTimes();
+        EasyMock.expect(bc.getServiceReferences(objectClass, null))
+            .andReturn(new ServiceReference [0]).anyTimes();
+    }
 }

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizerTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizerTest.java?rev=765553&r1=765552&r2=765553&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizerTest.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/FindInZooKeeperCustomizerTest.java
Thu Apr 16 10:04:25 2009
@@ -19,7 +19,6 @@
 package org.apache.cxf.dosgi.discovery.zookeeper;
 
 import java.util.Collections;
-import java.util.Map;
 
 import junit.framework.TestCase;
 



Mime
View raw message