2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.datastore.internal;
11 import java.util.concurrent.ConcurrentHashMap;
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;
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;
33 public class ClusteredDataStoreManagerTest {
35 private static ClusteredDataStoreManager clusteredDSMgr = null;
36 private IClusterGlobalServices icClusterGlbServices = mock(IClusterGlobalServices.class);
39 public static void construct() {
40 clusteredDSMgr = new ClusteredDataStoreManager();
41 assertNotNull(clusteredDSMgr);
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);
52 public void construct_init_AssertNoException() throws CacheExistException, CacheConfigException {
53 ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
55 ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
56 doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore();
57 clusteredDSManager.start();
62 public void construct_readOperationalData_AssertNoException() throws CacheExistException, CacheConfigException {
63 ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
65 ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
66 doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore();
67 Component c = mock(Component.class);
69 clusteredDSManager.start();
70 clusteredDSManager.setClusterGlobalServices(icClusterGlbServices);
71 CompositeNode o = mock(CompositeNode.class);
73 when(clusteredDSImpl.readOperationalData(any(InstanceIdentifier.class))).thenReturn(o);
74 assertEquals(o, clusteredDSManager.readOperationalData(any(InstanceIdentifier.class)));
78 public void construct_readConfigurationData_AssertNoException() throws CacheExistException, CacheConfigException {
79 ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
81 ClusteredDataStoreManager clusteredDSManager = spy(new ClusteredDataStoreManager());
82 doReturn(clusteredDSImpl).when(clusteredDSManager).createClusteredDataStore();
83 Component c = mock(Component.class);
85 clusteredDSManager.start();
86 clusteredDSManager.setClusterGlobalServices(icClusterGlbServices);
88 CompositeNode o = mock(CompositeNode.class);
90 when(clusteredDSImpl.readConfigurationData(any(InstanceIdentifier.class))).thenReturn(o);
91 assertEquals(o, clusteredDSManager.readConfigurationData(any(InstanceIdentifier.class)));
95 public void construct_requestCommit_AssertNoException() throws CacheExistException, CacheConfigException {
96 ClusteredDataStoreImpl clusteredDSImpl = mock(ClusteredDataStoreImpl.class);
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);
105 when(clusteredDSImpl.requestCommit(any(DataModification.class))).thenReturn(dataCommitTransaction);
106 assertEquals(dataCommitTransaction, clusteredDSManager.requestCommit(any(DataModification.class)));