Closed nested JSON writers
[netconf.git] / netconf / netconf-util / src / test / java / org / opendaylight / netconf / util / osgi / NetconfConfigurationTest.java
1 /*
2  * Copyright (c) 2016 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.netconf.util.osgi;
10
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;
16
17 public class NetconfConfigurationTest {
18
19     @Test
20     public void testUpdated() throws Exception {
21         final NetconfConfiguration config = new NetconfConfiguration();
22         Assert.assertEquals(new InetSocketAddress("0.0.0.0", 1830), config.getSshServerAddress());
23         Assert.assertEquals(new InetSocketAddress("127.0.0.1", 8383), config.getTcpServerAddress());
24         Assert.assertEquals("./configuration/RSA.pk", config.getPrivateKeyPath());
25         final Dictionary<String, String> newValues = new Hashtable<>();
26         final String newSshIp = "192.168.1.1";
27         final String newTcpIp = "192.168.1.2";
28         final int newSshPort = 1234;
29         final int newTcpPort = 4567;
30         final String newSshKeyPath = "./new_folder/configuration/RSA.pk";
31         newValues.put("ssh-address", newSshIp);
32         newValues.put("ssh-port", Integer.toString(newSshPort));
33         newValues.put("tcp-address", newTcpIp);
34         newValues.put("tcp-port", Integer.toString(newTcpPort));
35         newValues.put("ssh-pk-path", newSshKeyPath);
36         config.updated(newValues);
37         Assert.assertEquals(new InetSocketAddress(newSshIp, newSshPort), config.getSshServerAddress());
38         Assert.assertEquals(new InetSocketAddress(newTcpIp, newTcpPort), config.getTcpServerAddress());
39         Assert.assertEquals(newSshKeyPath, config.getPrivateKeyPath());
40     }
41
42     @Test
43     public void testUpdatedNull() throws Exception {
44         final NetconfConfiguration config = new NetconfConfiguration();
45         Assert.assertEquals(new InetSocketAddress("0.0.0.0", 1830), config.getSshServerAddress());
46         Assert.assertEquals(new InetSocketAddress("127.0.0.1", 8383), config.getTcpServerAddress());
47         Assert.assertEquals("./configuration/RSA.pk", config.getPrivateKeyPath());
48         final Dictionary<String, String> nullDictionary = null;
49         config.updated(nullDictionary);
50         Assert.assertEquals(new InetSocketAddress("0.0.0.0", 1830), config.getSshServerAddress());
51         Assert.assertEquals(new InetSocketAddress("127.0.0.1", 8383), config.getTcpServerAddress());
52         Assert.assertEquals("./configuration/RSA.pk", config.getPrivateKeyPath());
53     }
54 }