Merge "Updating ZeroMQ connector implementation. Its a work inprogress. The current...
authorEd Warnicke <eaw@cisco.com>
Fri, 8 Nov 2013 20:55:05 +0000 (20:55 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 8 Nov 2013 20:55:05 +0000 (20:55 +0000)
opendaylight/md-sal/clustered-data-store/implementation/src/main/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreManager.java
opendaylight/md-sal/clustered-data-store/implementation/src/test/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreManagerTest.java [new file with mode: 0644]

index 42ed2bb98ad033f9be58899e8bf38cfe3991cd91..e6acdb0c3be0a0221c63a014bf11d7bcaeeb00ce 100644 (file)
@@ -61,11 +61,15 @@ public class ClusteredDataStoreManager implements ClusteredDataStore {
      */
     void init(Component c) {
         try {
-            clusteredDataStore = new ClusteredDataStoreImpl(clusterGlobalServices);
+               //Adding creation of the clustered data store in its own method to make the method unit testable
+            clusteredDataStore = createClusteredDataStore(c);
         } catch (CacheExistException e) {
             throw new IllegalStateException("could not construct clusteredDataStore");
         } catch (CacheConfigException e) {
             throw new IllegalStateException("could not construct clusteredDataStore");
         }
     }
+    protected ClusteredDataStoreImpl createClusteredDataStore(Component c) throws CacheExistException,CacheConfigException{
+       return  new ClusteredDataStoreImpl(clusterGlobalServices);
+    }
 }
diff --git a/opendaylight/md-sal/clustered-data-store/implementation/src/test/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreManagerTest.java b/opendaylight/md-sal/clustered-data-store/implementation/src/test/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreManagerTest.java
new file mode 100644 (file)
index 0000000..84b07e7
--- /dev/null
@@ -0,0 +1,122 @@
+package org.opendaylight.controller.datastore.internal;
+
+import org.apache.felix.dm.Component;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.clustering.services.CacheConfigException;
+import org.opendaylight.controller.clustering.services.CacheExistException;
+import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
+import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.DataModification;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import static junit.framework.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+public class ClusteredDataStoreManagerTest {
+       
+       private  static ClusteredDataStoreManager clusteredDSMgr = null;
+       private IClusterGlobalServices icClusterGlbServices =  mock(IClusterGlobalServices.class);
+        
+       @BeforeClass
+       public static void construct(){
+               clusteredDSMgr = new ClusteredDataStoreManager();
+        assertNotNull(clusteredDSMgr);
+       }
+        
+       @Test
+       public void construct_OnSetClusterGlobalServices_AssertNoException(){
+               icClusterGlbServices =  mock(IClusterGlobalServices.class);
+                
+               clusteredDSMgr.setClusterGlobalServices(icClusterGlbServices);
+        }
+        
+        @Test
+        public void construct_OnUnSetClusterGlobalServices_AssertNoException(){
+                IClusterGlobalServices icClusterGlbServices =  mock(IClusterGlobalServices.class);
+                
+                clusteredDSMgr.unsetClusterGlobalServices(icClusterGlbServices);
+        }
+        
+        @Test
+        public void construct_init_AssertNoException() throws CacheExistException,CacheConfigException{
+                ClusteredDataStoreImpl clusteredDSImpl =  mock(ClusteredDataStoreImpl.class);
+                
+                ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
+                doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
+                Component c = mock(Component.class);
+                
+                clusteredDSManager.init(c);
+        }
+        
+        @Test(expected = IllegalStateException.class)
+        public void construct_init_AssertCacheExistException() throws CacheExistException,CacheConfigException{
+                ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
+                doThrow(CacheExistException.class).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
+                Component c = mock(Component.class);
+                
+                clusteredDSManager.init(c);
+        }
+        
+        @Test(expected = IllegalStateException.class)
+        public void construct_init_AssertCacheConfigException() throws CacheExistException,CacheConfigException{
+                ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
+                doThrow(CacheConfigException.class).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
+                Component c = mock(Component.class);
+                
+                clusteredDSManager.init(c);
+        }
+        
+        @Test
+        public void construct_readOperationalData_AssertNoException() throws CacheExistException,CacheConfigException{
+                ClusteredDataStoreImpl clusteredDSImpl =  mock(ClusteredDataStoreImpl.class);
+                
+                ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
+                doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
+                Component c = mock(Component.class);
+                
+                clusteredDSManager.init(c);
+                
+                Object o = mock(Object.class);
+                
+                when(clusteredDSImpl.readOperationalData(any(InstanceIdentifier.class))).thenReturn(o);
+                assertEquals(o,clusteredDSManager.readOperationalData(any(InstanceIdentifier.class)));
+        }
+        
+        
+        @Test
+        public void construct_readConfigurationData_AssertNoException() throws CacheExistException,CacheConfigException{
+                ClusteredDataStoreImpl clusteredDSImpl =  mock(ClusteredDataStoreImpl.class);
+                
+                ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
+                doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
+                Component c = mock(Component.class);
+                
+                clusteredDSManager.init(c);
+                Object o = mock(Object.class);
+                
+                when(clusteredDSImpl.readConfigurationData(any(InstanceIdentifier.class))).thenReturn(o);
+                assertEquals(o,clusteredDSManager.readConfigurationData(any(InstanceIdentifier.class)));
+        }
+        
+        @Test
+        public void construct_requestCommit_AssertNoException() throws CacheExistException,CacheConfigException{
+                ClusteredDataStoreImpl clusteredDSImpl =  mock(ClusteredDataStoreImpl.class);
+                
+                ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
+                doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
+                Component c = mock(Component.class);
+                
+                clusteredDSManager.init(c);
+                DataCommitTransaction dataCommitTransaction = mock(DataCommitTransaction.class);
+                
+                when(clusteredDSImpl.requestCommit(any(DataModification.class))).thenReturn(dataCommitTransaction);
+                assertEquals(dataCommitTransaction,clusteredDSManager.requestCommit(any(DataModification.class)));
+        }
+}