Merge "Removing { } from NormalizedNodeJsonBodyWriter"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / DatastoreContextConfigAdminOverlayTest.java
1 /*
2  * Copyright (c) 2015 Brocade Communications 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 package org.opendaylight.controller.cluster.datastore;
9
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;
21
22 /**
23  * Unit tests for DatastoreContextConfigAdminOverlay.
24  *
25  * @author Thomas Pantelis
26  */
27 public class DatastoreContextConfigAdminOverlayTest {
28
29     @SuppressWarnings("unchecked")
30     @Test
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);
37
38         doReturn(mockServiceRef).when(mockBundleContext).getServiceReference(ConfigurationAdmin.class);
39         doReturn(mockConfigAdmin).when(mockBundleContext).getService(mockServiceRef);
40
41         doReturn(mockConfig).when(mockConfigAdmin).getConfiguration(DatastoreContextConfigAdminOverlay.CONFIG_ID);
42
43         doReturn(DatastoreContextConfigAdminOverlay.CONFIG_ID).when(mockConfig).getPid();
44
45         Dictionary<String, Object> properties = new Hashtable<>();
46         properties.put("property", "value");
47         doReturn(properties).when(mockConfig).getProperties();
48
49         try(DatastoreContextConfigAdminOverlay overlay = new DatastoreContextConfigAdminOverlay(
50                 mockIntrospector, mockBundleContext)) {
51         }
52
53         verify(mockIntrospector).update(properties);
54
55         verify(mockBundleContext).ungetService(mockServiceRef);
56     }
57 }