Fix https://sonar.onap.org/issues/search#issues=AWBUkk6L-08if2a6vTgG
Change-Id: I5257f208b4df95129fcadfd5952988d8efdd8203
Issue-ID: APPC-383
Signed-off-by: Tomek Kaminski <tomasz.kaminski@nokia.com>
ChannelSftp sftp = (ChannelSftp) sftpSession.openChannel("sftp");
debugLog.printRTAriDebug(fn, "Connecting....");
sftp.connect();
ChannelSftp sftp = (ChannelSftp) sftpSession.openChannel("sftp");
debugLog.printRTAriDebug(fn, "Connecting....");
sftp.connect();
- InputStream in = null;
- in = sftp.get(fullFilePathName);
+ InputStream in = sftp.get(fullFilePathName);
String sftpFileString = readInputStreamAsString(in);
debugLog.printRTAriDebug(fn, "Retreived successfully");
String sftpFileString = readInputStreamAsString(in);
debugLog.printRTAriDebug(fn, "Retreived successfully");
- // debugLog.printRTAriDebug (fn, "sftpFileString="+sftpFileString);
- sftpSession.disconnect();
- sftpSession = null;
- return (sftpFileString);
} catch (Exception e) {
debugLog.printRTAriDebug(fn, "Caught an Exception, e=" + e);
} catch (Exception e) {
debugLog.printRTAriDebug(fn, "Caught an Exception, e=" + e);
- sftpSession.disconnect();
- sftpSession = null;
- // dbLog.storeData("ErrorMsg= sftp threw an Exception. error is:"+e);
throw new IOException(e.toString());
throw new IOException(e.toString());
+ } finally {
+ if(sftpSession != null) {
+ sftpSession.disconnect();
+ }
package org.onap.appc.ccadaptor;
package org.onap.appc.ccadaptor;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.powermock.reflect.Whitebox;
public class ConfigComponentAdaptorTest {
import org.powermock.reflect.Whitebox;
public class ConfigComponentAdaptorTest {
@Test
public void testGetCliRunningConfig(){
Properties props = null;
@Test
public void testGetCliRunningConfig(){
Properties props = null;
SvcLogicContext ctx = new SvcLogicContext();
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
SvcLogicContext ctx = new SvcLogicContext();
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
- cca.configure(key, parameters, ctx);
+ cca.configure(key, parameters, ctx);
@Test
public void testDownloadCliConfig(){
Properties props = null;
@Test
public void testDownloadCliConfig(){
Properties props = null;
SvcLogicContext ctx = new SvcLogicContext();
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
SvcLogicContext ctx = new SvcLogicContext();
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
- cca.configure(key, parameters, ctx);
+ cca.configure(key, parameters, ctx);
@Test
public void testXmlDownload(){
Properties props = null;
@Test
public void testXmlDownload(){
Properties props = null;
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
cca.configure(key, parameters, ctx);
}
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
cca.configure(key, parameters, ctx);
}
@Test
public void testXmlGetrunningconfig(){
Properties props = null;
@Test
public void testXmlGetrunningconfig(){
Properties props = null;
SvcLogicContext ctx = new SvcLogicContext();
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
SvcLogicContext ctx = new SvcLogicContext();
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
- cca.configure(key, parameters, ctx);
+ cca.configure(key, parameters, ctx);
@Test
public void testEscapeSql(){
Properties props = null;
@Test
public void testEscapeSql(){
Properties props = null;
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
cca.configure(key, parameters, ctx);
}
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
cca.configure(key, parameters, ctx);
}
@Test
public void testAll(){
Properties props = null;
@Test
public void testAll(){
Properties props = null;
SvcLogicContext ctx = new SvcLogicContext();
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
SvcLogicContext ctx = new SvcLogicContext();
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
- cca.configure(key, parameters, ctx);
+ cca.configure(key, parameters, ctx);
-
- @Test(expected=Exception.class)
public void testAll1(){
Properties props = null;
ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
public void testAll1(){
Properties props = null;
ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
parameters.put("Host_ip_address", "test");
SvcLogicContext ctx = new SvcLogicContext();
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
parameters.put("Host_ip_address", "test");
SvcLogicContext ctx = new SvcLogicContext();
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
- cca.configure(key, parameters, ctx);
+ cca.configure(key, parameters, ctx);
@Test(expected=Exception.class)
public void testAll2(){
Properties props = null;
@Test(expected=Exception.class)
public void testAll2(){
Properties props = null;
parameters.put("Host_ip_address", "test");
SvcLogicContext ctx = new SvcLogicContext();
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
parameters.put("Host_ip_address", "test");
SvcLogicContext ctx = new SvcLogicContext();
ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
- cca.configure(key, parameters, ctx);
+ cca.configure(key, parameters, ctx);
@Test
public void testGetStringBetweenQuotes() throws Exception{
Properties props = null;
@Test
public void testGetStringBetweenQuotes() throws Exception{
Properties props = null;
String result =Whitebox.invokeMethod(cca, "getStringBetweenQuotes","\"testvalue\"");
Assert.assertEquals("testvalue", result);
}
String result =Whitebox.invokeMethod(cca, "getStringBetweenQuotes","\"testvalue\"");
Assert.assertEquals("testvalue", result);
}
@Test
public void testBuildXmlRequest() throws Exception{
Properties props = null;
ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
Map<String, String> param = new HashMap<String,String>();
@Test
public void testBuildXmlRequest() throws Exception{
Properties props = null;
ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
Map<String, String> param = new HashMap<String,String>();
- Whitebox.invokeMethod(cca, "buildXmlRequest",param,"template");
+ Whitebox.invokeMethod(cca, "buildXmlRequest",param,"template");
@Test
public void testTrimResponse() throws Exception{
Properties props = null;
@Test
public void testTrimResponse() throws Exception{
Properties props = null;
String result =Whitebox.invokeMethod(cca, "trimResponse","testData");
Assert.assertEquals("", result);
}
String result =Whitebox.invokeMethod(cca, "trimResponse","testData");
Assert.assertEquals("", result);
}
@Test
public void testBuildNetworkData2() throws Exception{
Properties props = null;
@Test
public void testBuildNetworkData2() throws Exception{
Properties props = null;
String result =Whitebox.invokeMethod(cca, "buildNetworkData2",ctx,"template","operation");
Assert.assertEquals("template", result);
}
String result =Whitebox.invokeMethod(cca, "buildNetworkData2",ctx,"template","operation");
Assert.assertEquals("template", result);
}
//@Test
public void testGetLastFewLinesOfFile() throws Exception{
Properties props = null;
ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
//@Test
public void testGetLastFewLinesOfFile() throws Exception{
Properties props = null;
ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
- Whitebox.invokeMethod(cca, "readFile","test");
+ Whitebox.invokeMethod(cca, "readFile","test");
@Test
public void testConnect() throws Exception{
Properties props = null;
@Test
public void testConnect() throws Exception{
Properties props = null;
cca.activate("key", ctx);
}
cca.activate("key", ctx);
}
@Test(expected=Exception.class)
public void testActivate() throws Exception{
Properties props = null;
@Test(expected=Exception.class)
public void testActivate() throws Exception{
Properties props = null;
String result =Whitebox.invokeMethod(cca, "activate",ctx,true);
Assert.assertEquals("template", result);
}
String result =Whitebox.invokeMethod(cca, "activate",ctx,true);
Assert.assertEquals("template", result);
}
@Test(expected=Exception.class)
public void testAudit() throws Exception{
Properties props = null;
@Test(expected=Exception.class)
public void testAudit() throws Exception{
Properties props = null;
String result =Whitebox.invokeMethod(cca, "audit",ctx,"test");
Assert.assertEquals("template", result);
}
String result =Whitebox.invokeMethod(cca, "audit",ctx,"test");
Assert.assertEquals("template", result);
}
@Test(expected=Exception.class)
public void testPrepare() throws Exception{
Properties props = null;
@Test(expected=Exception.class)
public void testPrepare() throws Exception{
Properties props = null;