From f78405fa2d752fe29b1f86e527d741b75b388fcb Mon Sep 17 00:00:00 2001 From: Jakub Dudycz Date: Mon, 19 Feb 2018 15:29:43 +0100 Subject: ConfigComponentAdaptor sonar fixes part 2 Change-Id: I1eab3df281f394337fe33c0df07ff26da4302cbd Issue-ID: APPC-648 Signed-off-by: Jakub Dudycz --- .../appc/ccadaptor/ConfigComponentAdaptorTest.java | 174 ++++++++++++--------- 1 file changed, 97 insertions(+), 77 deletions(-) (limited to 'appc-config/appc-config-adaptor/provider/src/test') diff --git a/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java b/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java index e4f3a644e..3e41664da 100644 --- a/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java +++ b/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java @@ -24,11 +24,15 @@ package org.onap.appc.ccadaptor; -import java.io.IOException; +import static org.onap.appc.ccadaptor.ConfigComponentAdaptor.GET_CONFIG_TEMPLATE_PARAM; +import static org.onap.appc.ccadaptor.ConfigComponentAdaptor.HOST_IP_PARAM; +import static org.onap.appc.ccadaptor.ConfigComponentAdaptor.PASSWORD_PARAM; +import static org.onap.appc.ccadaptor.ConfigComponentAdaptor.PORT_NUMBER_PARAM; +import static org.onap.appc.ccadaptor.ConfigComponentAdaptor.USERNAME_PARAM; + import java.util.HashMap; import java.util.Map; import java.util.Properties; - import org.junit.Assert; import org.junit.Test; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; @@ -38,184 +42,200 @@ public class ConfigComponentAdaptorTest { @Test - public void testGetCliRunningConfig(){ + public void testGetCliRunningConfig() { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); String Get_config_template = ("get_config_template"); String key = "GetCliRunningConfig"; - Map parameters = new HashMap(); - parameters.put("Host_ip_address", "test"); - parameters.put("User_name", "test"); - parameters.put("Password", "password"); - parameters.put("Port_number", "22"); - parameters.put("Get_config_template", Get_config_template); + Map parameters = new HashMap<>(); + parameters.put(HOST_IP_PARAM, "test"); + parameters.put(USERNAME_PARAM, "test"); + parameters.put(PASSWORD_PARAM, "password"); + parameters.put(PORT_NUMBER_PARAM, "22"); + parameters.put(GET_CONFIG_TEMPLATE_PARAM, Get_config_template); SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test"); + 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 testDownloadCliConfig(){ + public void testDownloadCliConfig() { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); String Get_config_template = ("get_config_template"); String key = "DownloadCliConfig"; - Map parameters = new HashMap(); - parameters.put("Host_ip_address", "test"); - parameters.put("User_name", "test"); - parameters.put("Password", "password"); - parameters.put("Port_number", "22"); - parameters.put("Get_config_template", Get_config_template); + Map parameters = new HashMap<>(); + parameters.put(HOST_IP_PARAM, "test"); + parameters.put(USERNAME_PARAM, "test"); + parameters.put(PASSWORD_PARAM, "password"); + parameters.put(PORT_NUMBER_PARAM, "22"); + parameters.put(GET_CONFIG_TEMPLATE_PARAM, Get_config_template); SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test"); + 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 testXmlDownload(){ + public void testXmlDownload() { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); String Get_config_template = ("get_config_template"); String key = "xml-download"; - Map parameters = new HashMap(); - parameters.put("Host_ip_address", "test"); - parameters.put("User_name", "test"); - parameters.put("Password", "password"); - parameters.put("Port_number", "22"); - parameters.put("Get_config_template", Get_config_template); + Map parameters = new HashMap<>(); + parameters.put(HOST_IP_PARAM, "test"); + parameters.put(USERNAME_PARAM, "test"); + parameters.put(PASSWORD_PARAM, "password"); + parameters.put(PORT_NUMBER_PARAM, "22"); + parameters.put(GET_CONFIG_TEMPLATE_PARAM, Get_config_template); SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test"); + 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(){ + public void testXmlGetrunningconfig() { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); String Get_config_template = ("get_config_template"); String key = "xml-getrunningconfig"; - Map parameters = new HashMap(); - parameters.put("Host_ip_address", "test"); - parameters.put("User_name", "test"); - parameters.put("Password", "password"); - parameters.put("Port_number", "22"); - parameters.put("Get_config_template", Get_config_template); + Map parameters = new HashMap<>(); + parameters.put(HOST_IP_PARAM, "test"); + parameters.put(USERNAME_PARAM, "test"); + parameters.put(PASSWORD_PARAM, "password"); + parameters.put(PORT_NUMBER_PARAM, "22"); + parameters.put(GET_CONFIG_TEMPLATE_PARAM, Get_config_template); SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test"); + 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 testEscapeSql(){ + public void testEscapeSql() { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); String Get_config_template = ("get_config_template"); String key = "escapeSql"; - Map parameters = new HashMap(); - parameters.put("Host_ip_address", "test"); - parameters.put("User_name", "test"); - parameters.put("Password", "password"); - parameters.put("Port_number", "22"); - parameters.put("Get_config_template", Get_config_template); + Map parameters = new HashMap<>(); + parameters.put(HOST_IP_PARAM, "test"); + parameters.put(USERNAME_PARAM, "test"); + parameters.put(PASSWORD_PARAM, "password"); + parameters.put(PORT_NUMBER_PARAM, "22"); + parameters.put(GET_CONFIG_TEMPLATE_PARAM, Get_config_template); SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test"); + 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(){ + public void testAll() { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); String Get_config_template = ("test"); String Download_config_template = ("test"); String key = "GetCliRunningConfig"; - Map parameters = new HashMap(); - parameters.put("Host_ip_address", "test"); - parameters.put("User_name", "test"); - parameters.put("Password", "password"); - parameters.put("Port_number", "22"); + Map parameters = new HashMap<>(); + parameters.put(HOST_IP_PARAM, "test"); + parameters.put(USERNAME_PARAM, "test"); + parameters.put(PASSWORD_PARAM, "password"); + parameters.put(PORT_NUMBER_PARAM, "22"); parameters.put("Protocol", "netconf"); parameters.put("Contents", "Contents"); - parameters.put("Get_config_template", Get_config_template); + parameters.put(GET_CONFIG_TEMPLATE_PARAM, Get_config_template); parameters.put("Download_config_template", Download_config_template); parameters.put("Config_contents", "test"); SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test"); + 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 testAll1(){ + public void testAll1() { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); String key = "get"; - Map parameters = new HashMap(); + Map parameters = new HashMap<>(); 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"); + 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 testAll2(){ + public void testAll2() { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); String key = "cli"; - Map parameters = new HashMap(); + Map parameters = new HashMap(); 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"); + 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 testGetStringBetweenQuotes() throws Exception{ + public void testGetStringBetweenQuotes() throws Exception { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); - String result =Whitebox.invokeMethod(cca, "getStringBetweenQuotes","\"testvalue\""); + String result = Whitebox.invokeMethod(cca, "getStringBetweenQuotes", "\"testvalue\""); Assert.assertEquals("testvalue", result); } @Test - public void testBuildXmlRequest() throws Exception{ + public void testBuildXmlRequest() throws Exception { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); - Map param = new HashMap(); - Whitebox.invokeMethod(cca, "buildXmlRequest",param,"template"); + Map param = new HashMap<>(); + Whitebox.invokeMethod(cca, "buildXmlRequest", param, "template"); } @Test - public void testTrimResponse() throws Exception{ + public void testTrimResponse() throws Exception { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); - String result =Whitebox.invokeMethod(cca, "trimResponse","testData"); + String result = Whitebox.invokeMethod(cca, "trimResponse", "testData"); Assert.assertEquals("", result); } @Test - public void testBuildNetworkData2() throws Exception{ + public void testBuildNetworkData2() throws Exception { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); SvcLogicContext ctx = new SvcLogicContext(); - String result =Whitebox.invokeMethod(cca, "buildNetworkData2",ctx,"template","operation"); + String result = Whitebox.invokeMethod(cca, "buildNetworkData2", ctx, "template", "operation"); Assert.assertEquals("template", result); } //@Test - public void testGetLastFewLinesOfFile() throws Exception{ + 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{ + public void testConnect() throws Exception { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); SvcLogicContext ctx = new SvcLogicContext(); @@ -223,30 +243,30 @@ public class ConfigComponentAdaptorTest { } - @Test(expected=Exception.class) - public void testActivate() throws Exception{ + @Test(expected = Exception.class) + public void testActivate() throws Exception { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); SvcLogicContext ctx = new SvcLogicContext(); - String result =Whitebox.invokeMethod(cca, "activate",ctx,true); + String result = Whitebox.invokeMethod(cca, "activate", ctx, true); Assert.assertEquals("template", result); } - @Test(expected=Exception.class) - public void testAudit() throws Exception{ + @Test(expected = Exception.class) + public void testAudit() throws Exception { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); SvcLogicContext ctx = new SvcLogicContext(); - String result =Whitebox.invokeMethod(cca, "audit",ctx,"test"); + String result = Whitebox.invokeMethod(cca, "audit", ctx, "test"); Assert.assertEquals("template", result); } - @Test(expected=Exception.class) - public void testPrepare() throws Exception{ + @Test(expected = Exception.class) + public void testPrepare() throws Exception { Properties props = null; ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); SvcLogicContext ctx = new SvcLogicContext(); - String result =Whitebox.invokeMethod(cca, "prepare",ctx,"test","test"); + String result = Whitebox.invokeMethod(cca, "prepare", ctx, "test", "test"); Assert.assertEquals("template", result); } } -- cgit 1.2.3-korg