2 * Copyright (c) 2016 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.netconf.util;
11 import java.net.InetSocketAddress;
12 import java.util.Dictionary;
13 import java.util.Hashtable;
14 import org.junit.Assert;
15 import org.junit.Test;
17 public class NetconfConfigurationImplTest {
20 public void testUpdated() throws Exception {
21 final NetconfConfigurationImpl config = new NetconfConfigurationImpl("127.0.0.1", "8383",
23 "./configuration/RSA.pk");
24 Assert.assertEquals(new InetSocketAddress("0.0.0.0", 1830), config.getSshServerAddress());
25 Assert.assertEquals(new InetSocketAddress("127.0.0.1", 8383), config.getTcpServerAddress());
26 Assert.assertEquals("./configuration/RSA.pk", config.getPrivateKeyPath());
27 final Dictionary<String, String> newValues = new Hashtable<>();
28 final String newSshIp = "192.168.1.1";
29 final String newTcpIp = "192.168.1.2";
30 final int newSshPort = 1234;
31 final int newTcpPort = 4567;
32 final String newSshKeyPath = "./new_folder/configuration/RSA.pk";
33 newValues.put("ssh-address", newSshIp);
34 newValues.put("ssh-port", Integer.toString(newSshPort));
35 newValues.put("tcp-address", newTcpIp);
36 newValues.put("tcp-port", Integer.toString(newTcpPort));
37 newValues.put("ssh-pk-path", newSshKeyPath);
38 config.updated(newValues);
39 Assert.assertEquals(new InetSocketAddress(newSshIp, newSshPort), config.getSshServerAddress());
40 Assert.assertEquals(new InetSocketAddress(newTcpIp, newTcpPort), config.getTcpServerAddress());
41 Assert.assertEquals(newSshKeyPath, config.getPrivateKeyPath());
45 public void testUpdatedNull() throws Exception {
46 final NetconfConfigurationImpl config = new NetconfConfigurationImpl("127.0.0.1", "8383",
48 "./configuration/RSA.pk");
49 Assert.assertEquals(new InetSocketAddress("0.0.0.0", 1830), config.getSshServerAddress());
50 Assert.assertEquals(new InetSocketAddress("127.0.0.1", 8383), config.getTcpServerAddress());
51 Assert.assertEquals("./configuration/RSA.pk", config.getPrivateKeyPath());
52 final Dictionary<String, String> nullDictionary = null;
53 config.updated(nullDictionary);
54 Assert.assertEquals(new InetSocketAddress("0.0.0.0", 1830), config.getSshServerAddress());
55 Assert.assertEquals(new InetSocketAddress("127.0.0.1", 8383), config.getTcpServerAddress());
56 Assert.assertEquals("./configuration/RSA.pk", config.getPrivateKeyPath());