3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
10 package org.opendaylight.controller.datastore.internal;
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;
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;
31 public class ClusteredDataStoreManagerTest {
33 private static ClusteredDataStoreManager clusteredDSMgr = null;
34 private IClusterGlobalServices icClusterGlbServices = mock(IClusterGlobalServices.class);
37 public static void construct(){
38 clusteredDSMgr = new ClusteredDataStoreManager();
39 assertNotNull(clusteredDSMgr);
43 public void construct_OnSetClusterGlobalServices_AssertNoException(){
44 icClusterGlbServices = mock(IClusterGlobalServices.class);
46 clusteredDSMgr.setClusterGlobalServices(icClusterGlbServices);
50 public void construct_OnUnSetClusterGlobalServices_AssertNoException(){
51 IClusterGlobalServices icClusterGlbServices = mock(IClusterGlobalServices.class);
53 clusteredDSMgr.unsetClusterGlobalServices(icClusterGlbServices);
57 public void construct_init_AssertNoException() throws CacheExistException,CacheConfigException{
58 ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
60 ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
61 doReturn(clusteredDSImpl).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_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);
73 clusteredDSManager.init(c);
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);
82 clusteredDSManager.init(c);
86 public void construct_readOperationalData_AssertNoException() throws CacheExistException,CacheConfigException{
87 ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
89 ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
90 doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
91 Component c = mock(Component.class);
93 clusteredDSManager.init(c);
95 Object o = mock(Object.class);
97 when(clusteredDSImpl.readOperationalData(any(InstanceIdentifier.class))).thenReturn(o);
98 assertEquals(o,clusteredDSManager.readOperationalData(any(InstanceIdentifier.class)));
103 public void construct_readConfigurationData_AssertNoException() throws CacheExistException,CacheConfigException{
104 ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
106 ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
107 doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
108 Component c = mock(Component.class);
110 clusteredDSManager.init(c);
111 Object o = mock(Object.class);
113 when(clusteredDSImpl.readConfigurationData(any(InstanceIdentifier.class))).thenReturn(o);
114 assertEquals(o,clusteredDSManager.readConfigurationData(any(InstanceIdentifier.class)));
118 public void construct_requestCommit_AssertNoException() throws CacheExistException,CacheConfigException{
119 ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
121 ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
122 doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore(any(Component.class));
123 Component c = mock(Component.class);
125 clusteredDSManager.init(c);
126 DataCommitTransaction dataCommitTransaction = mock(DataCommitTransaction.class);
128 when(clusteredDSImpl.requestCommit(any(DataModification.class))).thenReturn(dataCommitTransaction);
129 assertEquals(dataCommitTransaction,clusteredDSManager.requestCommit(any(DataModification.class)));