1 package org.opendaylight.controller.datastore.internal;
3 import org.apache.felix.dm.Component;
4 import org.junit.BeforeClass;
6 import org.opendaylight.controller.clustering.services.CacheConfigException;
7 import org.opendaylight.controller.clustering.services.CacheExistException;
8 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
9 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction;
10 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
11 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
13 import static junit.framework.Assert.assertNotNull;
14 import static org.junit.Assert.assertEquals;
15 import static org.mockito.Matchers.any;
16 import static org.mockito.Mockito.doReturn;
17 import static org.mockito.Mockito.doThrow;
18 import static org.mockito.Mockito.mock;
19 import static org.mockito.Mockito.spy;
20 import static org.mockito.Mockito.when;
22 public class ClusteredDataStoreManagerTest {
24 private static ClusteredDataStoreManager clusteredDSMgr = null;
25 private IClusterGlobalServices icClusterGlbServices = mock(IClusterGlobalServices.class);
28 public static void construct(){
29 clusteredDSMgr = new ClusteredDataStoreManager();
30 assertNotNull(clusteredDSMgr);
34 public void construct_OnSetClusterGlobalServices_AssertNoException(){
35 icClusterGlbServices = mock(IClusterGlobalServices.class);
37 clusteredDSMgr.setClusterGlobalServices(icClusterGlbServices);
41 public void construct_OnUnSetClusterGlobalServices_AssertNoException(){
42 IClusterGlobalServices icClusterGlbServices = mock(IClusterGlobalServices.class);
44 clusteredDSMgr.unsetClusterGlobalServices(icClusterGlbServices);
48 public void construct_init_AssertNoException() throws CacheExistException,CacheConfigException{
49 ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
51 ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
52 doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
53 Component c = mock(Component.class);
55 clusteredDSManager.init(c);
58 @Test(expected = IllegalStateException.class)
59 public void construct_init_AssertCacheExistException() throws CacheExistException,CacheConfigException{
60 ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
61 doThrow(CacheExistException.class).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
62 Component c = mock(Component.class);
64 clusteredDSManager.init(c);
67 @Test(expected = IllegalStateException.class)
68 public void construct_init_AssertCacheConfigException() throws CacheExistException,CacheConfigException{
69 ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
70 doThrow(CacheConfigException.class).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
71 Component c = mock(Component.class);
73 clusteredDSManager.init(c);
77 public void construct_readOperationalData_AssertNoException() throws CacheExistException,CacheConfigException{
78 ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
80 ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
81 doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
82 Component c = mock(Component.class);
84 clusteredDSManager.init(c);
86 Object o = mock(Object.class);
88 when(clusteredDSImpl.readOperationalData(any(InstanceIdentifier.class))).thenReturn(o);
89 assertEquals(o,clusteredDSManager.readOperationalData(any(InstanceIdentifier.class)));
94 public void construct_readConfigurationData_AssertNoException() throws CacheExistException,CacheConfigException{
95 ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
97 ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
98 doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
99 Component c = mock(Component.class);
101 clusteredDSManager.init(c);
102 Object o = mock(Object.class);
104 when(clusteredDSImpl.readConfigurationData(any(InstanceIdentifier.class))).thenReturn(o);
105 assertEquals(o,clusteredDSManager.readConfigurationData(any(InstanceIdentifier.class)));
109 public void construct_requestCommit_AssertNoException() throws CacheExistException,CacheConfigException{
110 ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
112 ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
113 doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
114 Component c = mock(Component.class);
116 clusteredDSManager.init(c);
117 DataCommitTransaction dataCommitTransaction = mock(DataCommitTransaction.class);
119 when(clusteredDSImpl.requestCommit(any(DataModification.class))).thenReturn(dataCommitTransaction);
120 assertEquals(dataCommitTransaction,clusteredDSManager.requestCommit(any(DataModification.class)));