Bring some reliability in the eclipse and maven mixed builds
[controller.git] / opendaylight / md-sal / clustered-data-store / implementation / src / test / java / org / opendaylight / controller / datastore / internal / ClusteredDataStoreManagerTest.java
1 package org.opendaylight.controller.datastore.internal;
2
3 import org.apache.felix.dm.Component;
4 import org.junit.BeforeClass;
5 import org.junit.Test;
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;
12
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;
21
22 public class ClusteredDataStoreManagerTest {
23         
24         private  static ClusteredDataStoreManager clusteredDSMgr = null;
25         private IClusterGlobalServices icClusterGlbServices =  mock(IClusterGlobalServices.class);
26          
27         @BeforeClass
28         public static void construct(){
29                 clusteredDSMgr = new ClusteredDataStoreManager();
30         assertNotNull(clusteredDSMgr);
31         }
32          
33         @Test
34         public void construct_OnSetClusterGlobalServices_AssertNoException(){
35                 icClusterGlbServices =  mock(IClusterGlobalServices.class);
36                  
37                 clusteredDSMgr.setClusterGlobalServices(icClusterGlbServices);
38          }
39          
40          @Test
41          public void construct_OnUnSetClusterGlobalServices_AssertNoException(){
42                  IClusterGlobalServices icClusterGlbServices =  mock(IClusterGlobalServices.class);
43                  
44                  clusteredDSMgr.unsetClusterGlobalServices(icClusterGlbServices);
45          }
46          
47          @Test
48          public void construct_init_AssertNoException() throws CacheExistException,CacheConfigException{
49                  ClusteredDataStoreImpl clusteredDSImpl =  mock(ClusteredDataStoreImpl.class);
50                  
51                  ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
52                  doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
53                  Component c = mock(Component.class);
54                  
55                  clusteredDSManager.init(c);
56          }
57          
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);
63                  
64                  clusteredDSManager.init(c);
65          }
66          
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);
72                  
73                  clusteredDSManager.init(c);
74          }
75          
76          @Test
77          public void construct_readOperationalData_AssertNoException() throws CacheExistException,CacheConfigException{
78                  ClusteredDataStoreImpl clusteredDSImpl =  mock(ClusteredDataStoreImpl.class);
79                  
80                  ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
81                  doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
82                  Component c = mock(Component.class);
83                  
84                  clusteredDSManager.init(c);
85                  
86                  Object o = mock(Object.class);
87                  
88                  when(clusteredDSImpl.readOperationalData(any(InstanceIdentifier.class))).thenReturn(o);
89                  assertEquals(o,clusteredDSManager.readOperationalData(any(InstanceIdentifier.class)));
90          }
91          
92          
93          @Test
94          public void construct_readConfigurationData_AssertNoException() throws CacheExistException,CacheConfigException{
95                  ClusteredDataStoreImpl clusteredDSImpl =  mock(ClusteredDataStoreImpl.class);
96                  
97                  ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
98                  doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
99                  Component c = mock(Component.class);
100                  
101                  clusteredDSManager.init(c);
102                  Object o = mock(Object.class);
103                  
104                  when(clusteredDSImpl.readConfigurationData(any(InstanceIdentifier.class))).thenReturn(o);
105                  assertEquals(o,clusteredDSManager.readConfigurationData(any(InstanceIdentifier.class)));
106          }
107          
108          @Test
109          public void construct_requestCommit_AssertNoException() throws CacheExistException,CacheConfigException{
110                  ClusteredDataStoreImpl clusteredDSImpl =  mock(ClusteredDataStoreImpl.class);
111                  
112                  ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
113                  doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
114                  Component c = mock(Component.class);
115                  
116                  clusteredDSManager.init(c);
117                  DataCommitTransaction dataCommitTransaction = mock(DataCommitTransaction.class);
118                  
119                  when(clusteredDSImpl.requestCommit(any(DataModification.class))).thenReturn(dataCommitTransaction);
120                  assertEquals(dataCommitTransaction,clusteredDSManager.requestCommit(any(DataModification.class)));
121          }
122 }