2 * Copyright (c) 2015 Brocade Communications 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
8 package org.opendaylight.controller.cluster.datastore;
10 import static org.mockito.Mockito.doReturn;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.verify;
13 import java.io.IOException;
14 import java.util.Dictionary;
15 import java.util.Hashtable;
16 import org.junit.Test;
17 import org.osgi.framework.BundleContext;
18 import org.osgi.framework.ServiceReference;
19 import org.osgi.service.cm.Configuration;
20 import org.osgi.service.cm.ConfigurationAdmin;
23 * Unit tests for DatastoreContextConfigAdminOverlay.
25 * @author Thomas Pantelis
27 public class DatastoreContextConfigAdminOverlayTest {
29 @SuppressWarnings("unchecked")
31 public void test() throws IOException {
32 BundleContext mockBundleContext = mock(BundleContext.class);
33 ServiceReference<ConfigurationAdmin> mockServiceRef = mock(ServiceReference.class);
34 ConfigurationAdmin mockConfigAdmin = mock(ConfigurationAdmin.class);
35 Configuration mockConfig = mock(Configuration.class);
36 DatastoreContextIntrospector mockIntrospector = mock(DatastoreContextIntrospector.class);
38 doReturn(mockServiceRef).when(mockBundleContext).getServiceReference(ConfigurationAdmin.class);
39 doReturn(mockConfigAdmin).when(mockBundleContext).getService(mockServiceRef);
41 doReturn(mockConfig).when(mockConfigAdmin).getConfiguration(DatastoreContextConfigAdminOverlay.CONFIG_ID);
43 doReturn(DatastoreContextConfigAdminOverlay.CONFIG_ID).when(mockConfig).getPid();
45 Dictionary<String, Object> properties = new Hashtable<>();
46 properties.put("property", "value");
47 doReturn(properties).when(mockConfig).getProperties();
49 try(DatastoreContextConfigAdminOverlay overlay = new DatastoreContextConfigAdminOverlay(
50 mockIntrospector, mockBundleContext)) {
53 verify(mockIntrospector).update(properties);
55 verify(mockBundleContext).ungetService(mockServiceRef);