Change in sal.connectionservice.notifyNodeDisconnectFromMaster
[controller.git] / opendaylight / md-sal / clustered-data-store / implementation / src / test / java / org / opendaylight / controller / datastore / internal / ClusteredDataStoreManagerTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.datastore.internal;
10
11 import java.util.concurrent.ConcurrentHashMap;
12
13 import org.apache.felix.dm.Component;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16 import org.opendaylight.controller.clustering.services.CacheConfigException;
17 import org.opendaylight.controller.clustering.services.CacheExistException;
18 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
19 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction;
20 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
21 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
22 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
23
24 import static junit.framework.Assert.assertNotNull;
25 import static org.junit.Assert.assertEquals;
26 import static org.mockito.Matchers.any;
27 import static org.mockito.Mockito.doReturn;
28 import static org.mockito.Mockito.doThrow;
29 import static org.mockito.Mockito.mock;
30 import static org.mockito.Mockito.spy;
31 import static org.mockito.Mockito.when;
32
33 public class ClusteredDataStoreManagerTest {
34
35     private static ClusteredDataStoreManager clusteredDSMgr = null;
36     private IClusterGlobalServices icClusterGlbServices = mock(IClusterGlobalServices.class);
37
38     @BeforeClass
39     public static void construct() {
40         clusteredDSMgr = new ClusteredDataStoreManager();
41         assertNotNull(clusteredDSMgr);
42     }
43
44     @Test
45     public void construct_OnSetClusterGlobalServices_AssertNoException() {
46         doReturn(new ConcurrentHashMap<InstanceIdentifier, CompositeNode>()).when(icClusterGlbServices).getCache(ClusteredDataStoreImpl.CONFIGURATION_DATA_CACHE);
47         doReturn(new ConcurrentHashMap<InstanceIdentifier, CompositeNode>()).when(icClusterGlbServices).getCache(ClusteredDataStoreImpl.OPERATIONAL_DATA_CACHE);
48         clusteredDSMgr.setClusterGlobalServices(icClusterGlbServices);
49     }
50
51     @Test
52     public void construct_init_AssertNoException() throws CacheExistException, CacheConfigException {
53         ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
54
55         ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
56         doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore();
57         clusteredDSManager.start();
58     }
59
60
61     @Test
62     public void construct_readOperationalData_AssertNoException() throws CacheExistException, CacheConfigException {
63         ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
64
65         ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
66         doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore();
67         Component c = mock(Component.class);
68         
69         clusteredDSManager.start();
70         clusteredDSManager.setClusterGlobalServices(icClusterGlbServices);
71         CompositeNode o = mock(CompositeNode.class);
72
73         when(clusteredDSImpl.readOperationalData(any(InstanceIdentifier.class))).thenReturn(o);
74         assertEquals(o, clusteredDSManager.readOperationalData(any(InstanceIdentifier.class)));
75     }
76
77     @Test
78     public void construct_readConfigurationData_AssertNoException() throws CacheExistException, CacheConfigException {
79         ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
80
81         ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
82         doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore();
83         Component c = mock(Component.class);
84
85         clusteredDSManager.start();
86         clusteredDSManager.setClusterGlobalServices(icClusterGlbServices);
87         
88         CompositeNode o = mock(CompositeNode.class);
89
90         when(clusteredDSImpl.readConfigurationData(any(InstanceIdentifier.class))).thenReturn(o);
91         assertEquals(o, clusteredDSManager.readConfigurationData(any(InstanceIdentifier.class)));
92     }
93
94     @Test
95     public void construct_requestCommit_AssertNoException() throws CacheExistException, CacheConfigException {
96         ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
97
98         ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
99         doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore();
100         IClusterGlobalServices globalServices = mock(IClusterGlobalServices.class);
101         clusteredDSManager.setClusterGlobalServices(globalServices);
102         clusteredDSManager.start();
103         DataCommitTransaction dataCommitTransaction = mock(DataCommitTransaction.class);
104
105         when(clusteredDSImpl.requestCommit(any(DataModification.class))).thenReturn(dataCommitTransaction);
106         assertEquals(dataCommitTransaction, clusteredDSManager.requestCommit(any(DataModification.class)));
107     }
108 }