Merge "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
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.datastore.internal;
11
12 import org.apache.felix.dm.Component;
13 import org.junit.BeforeClass;
14 import org.junit.Test;
15 import org.opendaylight.controller.clustering.services.CacheConfigException;
16 import org.opendaylight.controller.clustering.services.CacheExistException;
17 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
18 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction;
19 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21
22 import static junit.framework.Assert.assertNotNull;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Mockito.doReturn;
26 import static org.mockito.Mockito.doThrow;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.spy;
29 import static org.mockito.Mockito.when;
30
31 public class ClusteredDataStoreManagerTest {
32         
33         private  static ClusteredDataStoreManager clusteredDSMgr = null;
34         private IClusterGlobalServices icClusterGlbServices =  mock(IClusterGlobalServices.class);
35          
36         @BeforeClass
37         public static void construct(){
38                 clusteredDSMgr = new ClusteredDataStoreManager();
39         assertNotNull(clusteredDSMgr);
40         }
41          
42         @Test
43         public void construct_OnSetClusterGlobalServices_AssertNoException(){
44                 icClusterGlbServices =  mock(IClusterGlobalServices.class);
45                  
46                 clusteredDSMgr.setClusterGlobalServices(icClusterGlbServices);
47          }
48          
49          @Test
50          public void construct_OnUnSetClusterGlobalServices_AssertNoException(){
51                  IClusterGlobalServices icClusterGlbServices =  mock(IClusterGlobalServices.class);
52                  
53                  clusteredDSMgr.unsetClusterGlobalServices(icClusterGlbServices);
54          }
55          
56          @Test
57          public void construct_init_AssertNoException() throws CacheExistException,CacheConfigException{
58                  ClusteredDataStoreImpl clusteredDSImpl =  mock(ClusteredDataStoreImpl.class);
59                  
60                  ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
61                  doReturn(clusteredDSImpl).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_AssertCacheExistException() throws CacheExistException,CacheConfigException{
69                  ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
70                  doThrow(CacheExistException.class).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
71                  Component c = mock(Component.class);
72                  
73                  clusteredDSManager.init(c);
74          }
75          
76          @Test(expected = IllegalStateException.class)
77          public void construct_init_AssertCacheConfigException() throws CacheExistException,CacheConfigException{
78                  ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
79                  doThrow(CacheConfigException.class).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
80                  Component c = mock(Component.class);
81                  
82                  clusteredDSManager.init(c);
83          }
84          
85          @Test
86          public void construct_readOperationalData_AssertNoException() throws CacheExistException,CacheConfigException{
87                  ClusteredDataStoreImpl clusteredDSImpl =  mock(ClusteredDataStoreImpl.class);
88                  
89                  ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
90                  doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
91                  Component c = mock(Component.class);
92                  
93                  clusteredDSManager.init(c);
94                  
95                  Object o = mock(Object.class);
96                  
97                  when(clusteredDSImpl.readOperationalData(any(InstanceIdentifier.class))).thenReturn(o);
98                  assertEquals(o,clusteredDSManager.readOperationalData(any(InstanceIdentifier.class)));
99          }
100          
101          
102          @Test
103          public void construct_readConfigurationData_AssertNoException() throws CacheExistException,CacheConfigException{
104                  ClusteredDataStoreImpl clusteredDSImpl =  mock(ClusteredDataStoreImpl.class);
105                  
106                  ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
107                  doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
108                  Component c = mock(Component.class);
109                  
110                  clusteredDSManager.init(c);
111                  Object o = mock(Object.class);
112                  
113                  when(clusteredDSImpl.readConfigurationData(any(InstanceIdentifier.class))).thenReturn(o);
114                  assertEquals(o,clusteredDSManager.readConfigurationData(any(InstanceIdentifier.class)));
115          }
116          
117          @Test
118          public void construct_requestCommit_AssertNoException() throws CacheExistException,CacheConfigException{
119                  ClusteredDataStoreImpl clusteredDSImpl =  mock(ClusteredDataStoreImpl.class);
120                  
121                  ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
122                  doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
123                  Component c = mock(Component.class);
124                  
125                  clusteredDSManager.init(c);
126                  DataCommitTransaction dataCommitTransaction = mock(DataCommitTransaction.class);
127                  
128                  when(clusteredDSImpl.requestCommit(any(DataModification.class))).thenReturn(dataCommitTransaction);
129                  assertEquals(dataCommitTransaction,clusteredDSManager.requestCommit(any(DataModification.class)));
130          }
131 }