summaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2018-12-11 16:57:24 +0000
committerTakamune Cho <takamune.cho@att.com>2018-12-13 15:00:57 +0000
commit70da33f00f68fe04e0baf51e592071096213eebd (patch)
treee75ae8de5869f10c3b21aaf85fc2870b9b1ec4ea /appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main
parent73dcc9677a000d0ea7b900db6fc1fb0689863b0a (diff)
Fix for APPC-1271
Replaced slow running tests which wait for timeout Testing time reduced from 22 seconds to 0.5 seconds Improved tests and line coverage increased from 26% to 96% Issue-ID: APPC-1271 Change-Id: I88713e5c819e5ce1bf695f6de3834db7c3007285 Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main')
-rw-r--r--appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/NetconfClientJsch.java19
1 files changed, 15 insertions, 4 deletions
diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/NetconfClientJsch.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/NetconfClientJsch.java
index 92569d5e0..03c33d813 100644
--- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/NetconfClientJsch.java
+++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/NetconfClientJsch.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2018 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,6 +31,8 @@ import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.List;
import java.util.Properties;
@@ -62,7 +66,7 @@ public class NetconfClientJsch implements NetconfClient {
String password = connectionDetails.getPassword();
try {
JSch.setLogger(new JSchLogger());
- JSch jsch = new JSch();
+ JSch jsch = getJSch();
session = jsch.getSession(EncryptionTool.getInstance().decrypt(username), host, port);
session.setPassword(EncryptionTool.getInstance().decrypt(password));
session.setConfig("StrictHostKeyChecking", "no");
@@ -131,10 +135,9 @@ public class NetconfClientJsch implements NetconfClient {
private void createConnection(NetconfConnectionDetails connectionDetails) throws APPCException {
try {
-// session.setServerAliveCountMax(0); // If this is not set to '0', then socket timeout on all reads will not work!!!!
channel = session.openChannel("subsystem");
((ChannelSubsystem)channel).setSubsystem("netconf");
- netconfAdapter = new NetconfAdapter(channel.getInputStream(), channel.getOutputStream());
+ netconfAdapter = getNetconfAdapter(channel.getInputStream(), channel.getOutputStream());
channel.connect(CHANNEL_CONNECT_TIMEOUT);
hello(connectionDetails.getCapabilities());
} catch(Exception e) {
@@ -146,7 +149,7 @@ public class NetconfClientJsch implements NetconfClient {
private void hello(List<String> capabilities) throws IOException {
String helloIn = netconfAdapter.receiveMessage();
if(helloIn == null) {
- throw new IOException("Expected hello message, but nothing received error from netconf device");
+ throw new IOException("Expected hello message, but nothing received from netconf device");
}
if(helloIn.contains("<rpc-error>")) {
throw new IOException("Expected hello message, but received error from netconf device:\n" + helloIn);
@@ -172,4 +175,12 @@ public class NetconfClientJsch implements NetconfClient {
throw new IOException("Error response from netconf device: \n" + response);
}
}
+
+ protected JSch getJSch() {
+ return new JSch();
+ }
+
+ protected NetconfAdapter getNetconfAdapter(InputStream inputStream, OutputStream outputStream) throws IOException {
+ return new NetconfAdapter(inputStream, outputStream);
+ }
}