Netconf test fixes

Change-Id: I4bb5ef17262ea631ef00b2f674dd0b7b5436767e
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfControllerImpl.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfControllerImpl.java
index a1797d7..0728bd9 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfControllerImpl.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfControllerImpl.java
@@ -130,7 +130,7 @@
     public void activate(ComponentContext context) {
         cfgService.registerProperties(getClass());
         modified(context);
-        Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
+        Security.addProvider(new BouncyCastleProvider());
         log.info("Started");
     }
 
diff --git a/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfSessionImplTest.java b/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfSessionImplTest.java
index 6e609e1..e0386f7 100644
--- a/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfSessionImplTest.java
+++ b/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfSessionImplTest.java
@@ -65,9 +65,8 @@
  */
 public class NetconfSessionImplTest {
     private static final Logger log = LoggerFactory
-            .getLogger(NetconfStreamThread.class);
+            .getLogger(NetconfSessionImplTest.class);
 
-    private static final int PORT_NUMBER = TestTools.findAvailablePort(50830);
     private static final String TEST_USERNAME = "netconf";
     private static final String TEST_PASSWORD = "netconf123";
     private static final String TEST_HOSTNAME = "127.0.0.1";
@@ -99,6 +98,7 @@
 
     @BeforeClass
     public static void setUp() throws Exception {
+        int portNumber = TestTools.findAvailablePort(50830);
         sshServerNetconf = SshServer.setUpDefaultServer();
         sshServerNetconf.setPasswordAuthenticator(
                 new PasswordAuthenticator() {
@@ -110,14 +110,14 @@
                         return TEST_USERNAME.equals(username) && TEST_PASSWORD.equals(password);
                     }
                 });
-        sshServerNetconf.setPort(PORT_NUMBER);
+        sshServerNetconf.setPort(portNumber);
         SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
         provider.setFile(new File(TEST_SERFILE));
         sshServerNetconf.setKeyPairProvider(provider);
         sshServerNetconf.setSubsystemFactories(
                 Arrays.<NamedFactory<Command>>asList(new NetconfSshdTestSubsystem.Factory()));
         sshServerNetconf.open();
-        log.info("SSH Server opened on port {}", PORT_NUMBER);
+        log.info("SSH Server opened on port {}", portNumber);
 
         NetconfController netconfCtl = new NetconfControllerImpl();
         NetconfControllerImpl.netconfConnectTimeout = NetconfControllerImpl.DEFAULT_CONNECT_TIMEOUT_SECONDS;
@@ -125,7 +125,7 @@
         NetconfControllerImpl.netconfReplyTimeout = NetconfControllerImpl.DEFAULT_REPLY_TIMEOUT_SECONDS;
 
         NetconfDeviceInfo deviceInfo1 = new NetconfDeviceInfo(
-                TEST_USERNAME, TEST_PASSWORD, Ip4Address.valueOf(TEST_HOSTNAME), PORT_NUMBER);
+                TEST_USERNAME, TEST_PASSWORD, Ip4Address.valueOf(TEST_HOSTNAME), portNumber);
 
         session1 = new NetconfSessionImpl(deviceInfo1, ImmutableList.of("urn:ietf:params:netconf:base:1.0"));
         log.info("Started NETCONF Session {} with test SSHD server in Unit Test", session1.getSessionId());
@@ -135,7 +135,7 @@
                 NetconfSessionMinaImplTest.DEFAULT_CAPABILITIES.toArray()));
 
         NetconfDeviceInfo deviceInfo2 = new NetconfDeviceInfo(
-                TEST_USERNAME, TEST_PASSWORD, Ip4Address.valueOf(TEST_HOSTNAME), PORT_NUMBER);
+                TEST_USERNAME, TEST_PASSWORD, Ip4Address.valueOf(TEST_HOSTNAME), portNumber);
         deviceInfo2.setConnectTimeoutSec(OptionalInt.of(11));
         deviceInfo2.setReplyTimeoutSec(OptionalInt.of(10));
         deviceInfo2.setIdleTimeoutSec(OptionalInt.of(12));
diff --git a/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImplTest.java b/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImplTest.java
index 7e78b80..ada609b 100644
--- a/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImplTest.java
+++ b/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImplTest.java
@@ -22,6 +22,7 @@
 import org.apache.sshd.server.auth.password.PasswordAuthenticator;
 import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
 import org.apache.sshd.server.session.ServerSession;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -35,6 +36,7 @@
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
+import java.security.Security;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
@@ -63,9 +65,8 @@
  */
 public class NetconfSessionMinaImplTest {
     private static final Logger log = LoggerFactory
-            .getLogger(NetconfStreamThread.class);
+            .getLogger(NetconfSessionMinaImplTest.class);
 
-    private static final int PORT_NUMBER = TestTools.findAvailablePort(50830);
     private static final String TEST_USERNAME = "netconf";
     private static final String TEST_PASSWORD = "netconf123";
     private static final String TEST_HOSTNAME = "127.0.0.1";
@@ -123,6 +124,8 @@
 
     @BeforeClass
     public static void setUp() throws Exception {
+        Security.addProvider(new BouncyCastleProvider());
+        int portNumber = TestTools.findAvailablePort(50830);
         sshServerNetconf = SshServer.setUpDefaultServer();
         sshServerNetconf.setPasswordAuthenticator(
                 new PasswordAuthenticator() {
@@ -134,17 +137,17 @@
                         return TEST_USERNAME.equals(username) && TEST_PASSWORD.equals(password);
                     }
                 });
-        sshServerNetconf.setPort(PORT_NUMBER);
+        sshServerNetconf.setPort(portNumber);
         SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
         provider.setFile(new File(TEST_SERFILE));
         sshServerNetconf.setKeyPairProvider(provider);
         sshServerNetconf.setSubsystemFactories(
                 Arrays.<NamedFactory<Command>>asList(new NetconfSshdTestSubsystem.Factory()));
         sshServerNetconf.open();
-        log.info("SSH Server opened on port {}", PORT_NUMBER);
+        log.info("SSH Server opened on port {}", portNumber);
 
         NetconfDeviceInfo deviceInfo = new NetconfDeviceInfo(
-                TEST_USERNAME, TEST_PASSWORD, Ip4Address.valueOf(TEST_HOSTNAME), PORT_NUMBER);
+                TEST_USERNAME, TEST_PASSWORD, Ip4Address.valueOf(TEST_HOSTNAME), portNumber);
 
         session1 = new NetconfSessionMinaImpl(deviceInfo, ImmutableList.of("urn:ietf:params:netconf:base:1.0"));
         log.info("Started NETCONF Session {} with test SSHD server in Unit Test", session1.getSessionId());