Merge "BUG 1839 - HTTP delete of non existing data"
[controller.git] / opendaylight / netconf / netconf-util / src / test / java / org / opendaylight / controller / netconf / util / osgi / NetconfConfigUtilTest.java
1 /*
2  * Copyright (c) 2014 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.netconf.util.osgi;
10
11 import com.google.common.base.Optional;
12 import io.netty.channel.local.LocalAddress;
13 import java.net.InetSocketAddress;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.controller.netconf.util.NetconfUtil;
17 import org.osgi.framework.BundleContext;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 import static org.mockito.Matchers.anyString;
22 import static org.mockito.Mockito.doReturn;
23 import static org.mockito.Mockito.mock;
24
25 public class NetconfConfigUtilTest {
26
27     private BundleContext bundleContext;
28
29     @Before
30     public void setUp() throws Exception {
31         bundleContext = mock(BundleContext.class);
32     }
33
34     @Test
35     public void testNetconfConfigUtil() throws Exception {
36         assertEquals(NetconfConfigUtil.getNetconfLocalAddress(), new LocalAddress("netconf"));
37
38         doReturn("").when(bundleContext).getProperty("netconf.connectionTimeoutMillis");
39         assertEquals(NetconfConfigUtil.extractTimeoutMillis(bundleContext), 5000);
40
41         doReturn("a").when(bundleContext).getProperty("netconf.connectionTimeoutMillis");
42         assertEquals(NetconfConfigUtil.extractTimeoutMillis(bundleContext), 5000);
43     }
44
45     @Test
46     public void testgetPrivateKeyKey() throws Exception {
47         assertEquals(NetconfConfigUtil.getPrivateKeyKey(), "netconf.ssh.pk.path");
48     }
49
50     @Test
51     public void testgetNetconfServerAddressKey() throws Exception {
52         NetconfConfigUtil.InfixProp prop = NetconfConfigUtil.InfixProp.tcp;
53         assertEquals(NetconfConfigUtil.getNetconfServerAddressKey(prop), "netconf.tcp.address");
54     }
55
56     @Test
57     public void testExtractNetconfServerAddress() throws Exception {
58         NetconfConfigUtil.InfixProp prop = NetconfConfigUtil.InfixProp.tcp;
59         doReturn("").when(bundleContext).getProperty(anyString());
60         assertEquals(NetconfConfigUtil.extractNetconfServerAddress(bundleContext, prop), Optional.absent());
61     }
62
63     @Test
64     public void testExtractNetconfServerAddress2() throws Exception {
65         NetconfConfigUtil.InfixProp prop = NetconfConfigUtil.InfixProp.tcp;
66         doReturn("1.1.1.1").when(bundleContext).getProperty("netconf.tcp.address");
67         doReturn("20").when(bundleContext).getProperty("netconf.tcp.port");
68         Optional<InetSocketAddress> inetSocketAddressOptional = NetconfConfigUtil.extractNetconfServerAddress(bundleContext, prop);
69         assertTrue(inetSocketAddressOptional.isPresent());
70         assertEquals(inetSocketAddressOptional.get(), new InetSocketAddress("1.1.1.1", 20));
71     }
72
73     @Test
74     public void testGetPrivateKeyPath() throws Exception {
75         doReturn("path").when(bundleContext).getProperty("netconf.ssh.pk.path");
76         assertEquals(NetconfConfigUtil.getPrivateKeyPath(bundleContext), "path");
77     }
78
79     @Test(expected = IllegalStateException.class)
80     public void testGetPrivateKeyPath2() throws Exception {
81         doReturn(null).when(bundleContext).getProperty("netconf.ssh.pk.path");
82         assertEquals(NetconfConfigUtil.getPrivateKeyPath(bundleContext), "path");
83     }
84 }