diff options
19 files changed, 229 insertions, 166 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java b/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java index 72902ad3..ade5c998 100644 --- a/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java +++ b/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java @@ -98,13 +98,13 @@ public class OnapCommandParameterCache { private void persist() { List<OnapCommandParamEntity> params = new ArrayList<>(); - for (String p: this.paramCache.keySet()) { - for (String name: this.paramCache.get(p).keySet()) { + for (Map.Entry<String, Map<String, String>> p: this.paramCache.entrySet()) { + for (Map.Entry<String, String> paramEntry: p.getValue().entrySet()) { OnapCommandParamEntity param = new OnapCommandParamEntity(); - param.setProduct(p); - param.setName(name); - param.setValue(this.paramCache.get(p).get(name)); + param.setProduct(p.getKey()); + param.setName(paramEntry.getKey()); + param.setValue(paramEntry.getValue()); params.add(param); } diff --git a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java index b225a3a0..eef0ebc4 100644 --- a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java +++ b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java @@ -40,8 +40,9 @@ public class OnapCommandSample extends OnapCommand { @Override protected void run() throws OnapCommandException { - if (this.failCase) + if (this.failCase) { throw new OnapCommandExecutionFailed("Test case to fail"); + } } } diff --git a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java index 4009dcb0..3e32f3e1 100644 --- a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java +++ b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java @@ -39,18 +39,17 @@ public class OnapCommandSampleTest { public void sampleTestVersion() { try { + Set<OnapCommandParameter> parameters = new HashSet(); + OnapCommandParameter version = new OnapCommandParameter(); + version.setName(OnapCommandConstants.DEFAULT_PARAMETER_VERSION); + version.setValue(true); + parameters.add(version); + OnapCommandParameter hlp = new OnapCommandParameter(); + hlp.setName(OnapCommandConstants.DEFAULT_PARAMETER_HELP); + hlp.setValue(false); + parameters.add(hlp); OnapCommand sample = OnapCommandRegistrar.getRegistrar().get("sample-test"); - - Set<OnapCommandParameter> parameters = new HashSet(); - OnapCommandParameter v = new OnapCommandParameter(); - v.setName(OnapCommandConstants.DEFAULT_PARAMETER_VERSION); - v.setValue(true); - parameters.add(v); - OnapCommandParameter h = new OnapCommandParameter(); - h.setName(OnapCommandConstants.DEFAULT_PARAMETER_HELP); - h.setValue(false); - parameters.add(h); sample.setParameters(parameters); sample.execute(); } catch (OnapCommandException e) { @@ -59,14 +58,16 @@ public class OnapCommandSampleTest { @Test public void sampleTestHelp() { - OnapCommandSample sample = new OnapCommandSample(); try { + OnapCommandParameter ver = new OnapCommandParameter(); + ver.setName(OnapCommandConstants.DEFAULT_PARAMETER_HELP); + ver.setValue(true); + ver.setParameterType(OnapCommandParameterType.BOOL); + Set<OnapCommandParameter> parameters = new HashSet(); - OnapCommandParameter v = new OnapCommandParameter(); - v.setName(OnapCommandConstants.DEFAULT_PARAMETER_HELP); - v.setValue(true); - v.setParameterType(OnapCommandParameterType.BOOL); - parameters.add(v); + parameters.add(ver); + + OnapCommandSample sample = new OnapCommandSample(); sample.setParameters(parameters); sample.execute(); } catch (OnapCommandException e) { @@ -77,33 +78,33 @@ public class OnapCommandSampleTest { public void sampleTest() { try { - OnapCommand sample = OnapCommandRegistrar.getRegistrar().get("sample-test"); Set<OnapCommandParameter> parameters = new HashSet(); - OnapCommandParameter v = new OnapCommandParameter(); - v.setName(OnapCommandConstants.DEFAULT_PARAMETER_VERSION); - v.setValue(false); - parameters.add(v); - OnapCommandParameter h = new OnapCommandParameter(); - h.setName(OnapCommandConstants.DEFAULT_PARAMETER_HELP); - h.setValue(false); - parameters.add(h); - OnapCommandParameter f = new OnapCommandParameter(); - f.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_FORMAT); - f.setValue("table"); - parameters.add(f); - OnapCommandParameter l = new OnapCommandParameter(); - l.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_ATTR_LONG); - l.setValue(true); - parameters.add(l); - OnapCommandParameter t = new OnapCommandParameter(); - t.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_NO_TITLE); - t.setValue(true); - parameters.add(t); - OnapCommandParameter d = new OnapCommandParameter(); - d.setName(OnapCommandConstants.DEFAULT_PARAMETER_DEBUG); - d.setValue(true); - parameters.add(d); + OnapCommandParameter ver = new OnapCommandParameter(); + ver.setName(OnapCommandConstants.DEFAULT_PARAMETER_VERSION); + ver.setValue(false); + parameters.add(ver); + OnapCommandParameter hlp = new OnapCommandParameter(); + hlp.setName(OnapCommandConstants.DEFAULT_PARAMETER_HELP); + hlp.setValue(false); + parameters.add(hlp); + OnapCommandParameter fmt = new OnapCommandParameter(); + fmt.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_FORMAT); + fmt.setValue("table"); + parameters.add(fmt); + OnapCommandParameter lng = new OnapCommandParameter(); + lng.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_ATTR_LONG); + lng.setValue(true); + parameters.add(lng); + OnapCommandParameter title = new OnapCommandParameter(); + title.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_NO_TITLE); + title.setValue(true); + parameters.add(title); + OnapCommandParameter denug = new OnapCommandParameter(); + denug.setName(OnapCommandConstants.DEFAULT_PARAMETER_DEBUG); + denug.setValue(true); + parameters.add(denug); + OnapCommand sample = OnapCommandRegistrar.getRegistrar().get("sample-test"); sample.setParameters(parameters); sample.execute(); @@ -114,7 +115,7 @@ public class OnapCommandSampleTest { attr = sample.getResult().getRecordsMap().get("output-2"); attrValue = attr.getValues().get(0); assertEquals(attrValue, "test"); - } catch (IllegalArgumentException e){ + } catch (IllegalArgumentException e) { fail("Failed to replace the output default value on output-1"); } catch (OnapCommandException e) { } @@ -126,30 +127,30 @@ public class OnapCommandSampleTest { sample.failCase = true; Set<OnapCommandParameter> parameters = new HashSet(); - OnapCommandParameter v = new OnapCommandParameter(); - v.setName(OnapCommandConstants.DEFAULT_PARAMETER_VERSION); - v.setValue(false); - parameters.add(v); - OnapCommandParameter h = new OnapCommandParameter(); - h.setName(OnapCommandConstants.DEFAULT_PARAMETER_HELP); - h.setValue(false); - parameters.add(h); - OnapCommandParameter f = new OnapCommandParameter(); - f.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_FORMAT); - f.setValue("table"); - parameters.add(f); - OnapCommandParameter l = new OnapCommandParameter(); - l.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_ATTR_LONG); - l.setValue(true); - parameters.add(l); - OnapCommandParameter t = new OnapCommandParameter(); - t.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_NO_TITLE); - t.setValue(true); - parameters.add(t); - OnapCommandParameter d = new OnapCommandParameter(); - d.setName(OnapCommandConstants.DEFAULT_PARAMETER_DEBUG); - d.setValue(true); - parameters.add(d); + OnapCommandParameter ver = new OnapCommandParameter(); + ver.setName(OnapCommandConstants.DEFAULT_PARAMETER_VERSION); + ver.setValue(false); + parameters.add(ver); + OnapCommandParameter hlp = new OnapCommandParameter(); + hlp.setName(OnapCommandConstants.DEFAULT_PARAMETER_HELP); + hlp.setValue(false); + parameters.add(hlp); + OnapCommandParameter ffmt = new OnapCommandParameter(); + ffmt.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_FORMAT); + ffmt.setValue("table"); + parameters.add(ffmt); + OnapCommandParameter lng = new OnapCommandParameter(); + lng.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_ATTR_LONG); + lng.setValue(true); + parameters.add(lng); + OnapCommandParameter titl = new OnapCommandParameter(); + titl.setName(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_NO_TITLE); + titl.setValue(true); + parameters.add(titl); + OnapCommandParameter debug = new OnapCommandParameter(); + debug.setName(OnapCommandConstants.DEFAULT_PARAMETER_DEBUG); + debug.setValue(true); + parameters.add(debug); sample.setParameters(parameters); sample.execute(); } diff --git a/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java b/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java index 58c0f432..2dcb9ce4 100644 --- a/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java +++ b/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java @@ -182,8 +182,9 @@ public class OnapCommandErrorTest { public void oclipCommandParameterOptionConflictTest() { OnapCommandParameterOptionConflict failed = new OnapCommandParameterOptionConflict("test", "option"); - assertEquals("0x7006::In test, Parameter option option is in conflict, only one option is allowed with given name", - failed.getMessage()); + assertEquals("0x7006::In test, Parameter option option is in conflict, " + + "only one option is allowed with given name", + failed.getMessage()); } @Test diff --git a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java index 5a6e6458..18959e8e 100644 --- a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java +++ b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java @@ -45,7 +45,8 @@ public class OnapCommandParameterTest { assertTrue(param.getDefaultValue().equals("defaultValue") && param.getDescription().equals("description") && param.getLongOption().equals("longOption") && param.getName().equals("name") && param.getShortOption().equals("shortOption") && param.getValue().equals("value") - && param.isOptional() && !param.isSecured() && param.getParameterType().equals(OnapCommandParameterType.JSON)); + && param.isOptional() && !param.isSecured() + && param.getParameterType().equals(OnapCommandParameterType.JSON)); assertTrue("value".equals(param.getValue())); diff --git a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java index 667ed02a..8e474635 100644 --- a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java +++ b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java @@ -44,7 +44,8 @@ public class OnapCommandResultTest { res.setDebug(true); assertTrue("debugInfo".equals(res.getDebugInfo()) && res.isIncludeSeparator() - && "Output".equals(res.getOutput()) && OnapCommandPrintDirection.LANDSCAPE.equals(res.getPrintDirection()) + && "Output".equals(res.getOutput()) + && OnapCommandPrintDirection.LANDSCAPE.equals(res.getPrintDirection()) && res.getRecords().isEmpty() && OnapCommandResultAttributeScope.LONG.equals(res.getScope()) && OnapCommandResultType.TABLE.equals(res.getType())); diff --git a/framework/src/test/java/org/onap/cli/fw/output/ResultTypeTest.java b/framework/src/test/java/org/onap/cli/fw/output/ResultTypeTest.java index a6590b3d..622bdcae 100644 --- a/framework/src/test/java/org/onap/cli/fw/output/ResultTypeTest.java +++ b/framework/src/test/java/org/onap/cli/fw/output/ResultTypeTest.java @@ -24,10 +24,12 @@ import org.junit.Test; public class ResultTypeTest { @Test public void resultTypeGetTest() { - assertTrue(OnapCommandResultType.TABLE.equals(OnapCommandResultType.get("table")) && OnapCommandResultType.CSV.equals(OnapCommandResultType.get("csv")) - && OnapCommandResultType.JSON.equals(OnapCommandResultType.get("json")) && OnapCommandResultType.YAML.equals(OnapCommandResultType.get("yaml")) + assertTrue( + OnapCommandResultType.TABLE.equals(OnapCommandResultType.get("table")) + && OnapCommandResultType.CSV.equals(OnapCommandResultType.get("csv")) + && OnapCommandResultType.JSON.equals(OnapCommandResultType.get("json")) + && OnapCommandResultType.YAML.equals(OnapCommandResultType.get("yaml")) && OnapCommandResultType.TEXT.equals(OnapCommandResultType.get("text"))); - } @Test diff --git a/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java b/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java index 812e58e2..850d31e7 100644 --- a/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java +++ b/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import org.junit.Ignore; import org.junit.Test; @@ -44,39 +43,34 @@ public class OnapCommandPrintTest { @Test public void printTableTest() throws OnapCommandOutputPrintingFailed { OnapCommandPrint pr = new OnapCommandPrint(); - List<String> getColumnsData = new ArrayList<String>(); + pr.setDirection(OnapCommandPrintDirection.LANDSCAPE); pr.setPrintTitle(true); pr.addColumn("name2", new ArrayList<String>(Arrays.asList(new String[] { "value2" }))); String exp = "+--------+\n|name2 |\n+--------+\n|value2 |\n+--------+\n"; String result = pr.printTable(true); - getColumnsData = pr.getColumn("name2"); assertEquals(exp, result); } @Test public void printTableNullColumnHeaderTest() throws OnapCommandOutputPrintingFailed { OnapCommandPrint pr = new OnapCommandPrint(); - List<String> getColumnsData = new ArrayList<String>(); pr.setDirection(OnapCommandPrintDirection.LANDSCAPE); pr.setPrintTitle(true); pr.addColumn("name2", new ArrayList<String>(Arrays.asList(new String[] { "value2" }))); String exp = "+--------+\n|name2 |\n+--------+\n|value2 |\n+--------+\n"; String result = pr.printTable(true); - getColumnsData = pr.getColumn(null); assertEquals(exp, result); } @Test public void printTableEmptyColumnValuesTest() throws OnapCommandOutputPrintingFailed { OnapCommandPrint pr = new OnapCommandPrint(); - List<String> getColumnsData = new ArrayList<String>(); pr.setDirection(OnapCommandPrintDirection.LANDSCAPE); pr.setPrintTitle(true); pr.addColumn("name2", new ArrayList<String>(Arrays.asList(new String[] { "" }))); String exp = "+--------+\n|name2 |\n+--------+\n| |\n+--------+\n"; String result = pr.printTable(true); - getColumnsData = pr.getColumn("name2"); assertEquals(exp, result); } } diff --git a/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java b/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java index d70c1521..b7989157 100644 --- a/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java +++ b/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java @@ -91,20 +91,18 @@ public class OnapCommandRegistrarTest { @Test public void testProfile() throws OnapCommandException { try { - OnapCommandRegistrar.getRegistrar().setProfile("test234", new ArrayList<String>(), new ArrayList<String>()); - OnapCommandRegistrar.getRegistrar().addParamCache("a", "b"); - OnapCommandRegistrar.getRegistrar().getParamCache(); - OnapCommandRegistrar.getRegistrar().removeParamCache("a"); - - OnapCommandRegistrar.getRegistrar().setInteractiveMode(false); - assertTrue(!OnapCommandRegistrar.getRegistrar().isInteractiveMode()); - - OnapCommandRegistrar.getRegistrar().setEnabledProductVersion("open-cli"); - assertEquals("open-cli", OnapCommandRegistrar.getRegistrar().getEnabledProductVersion()); - OnapCommandRegistrar.getRegistrar().getAvailableProductVersions(); - assertTrue(OnapCommandRegistrar.getRegistrar().listCommandsForEnabledProductVersion().contains("sample-test")); - - assertTrue(OnapCommandRegistrar.getRegistrar().listCommandInfo().size() > 2); + OnapCommandRegistrar.getRegistrar().setProfile("test234", new ArrayList<String>(), new ArrayList<String>()); + OnapCommandRegistrar.getRegistrar().addParamCache("a", "b"); + OnapCommandRegistrar.getRegistrar().getParamCache(); + OnapCommandRegistrar.getRegistrar().removeParamCache("a"); + OnapCommandRegistrar.getRegistrar().setInteractiveMode(false); + assertTrue(!OnapCommandRegistrar.getRegistrar().isInteractiveMode()); + OnapCommandRegistrar.getRegistrar().setEnabledProductVersion("open-cli"); + assertEquals("open-cli", OnapCommandRegistrar.getRegistrar().getEnabledProductVersion()); + OnapCommandRegistrar.getRegistrar().getAvailableProductVersions(); + assertTrue( + OnapCommandRegistrar.getRegistrar().listCommandsForEnabledProductVersion().contains("sample-test")); + assertTrue(OnapCommandRegistrar.getRegistrar().listCommandInfo().size() > 2); } catch (Exception e) { fail("failed to test the profile"); } @@ -121,7 +119,7 @@ public class OnapCommandRegistrarTest { } @OnapCommandSchema(schema = "sample-test-schema.yaml") -class OnapCommandTest extends OnapCommand { +final class OnapCommandTest extends OnapCommand { public OnapCommandTest() { @@ -136,7 +134,7 @@ class OnapCommandTest extends OnapCommand { } @OnapCommandSchema(schema = "test-schema.yaml") -class OnapCommandTest1 extends OnapCommand { +final class OnapCommandTest1 extends OnapCommand { public OnapCommandTest1() { diff --git a/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java b/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java index a33b785c..5831c272 100644 --- a/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java +++ b/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java @@ -110,7 +110,8 @@ public class ValidateSchemaTest { @Override protected void run() throws OnapCommandException {} }; - List<String> errorList3 = OnapCommandSchemaLoader.loadSchema(cmd2, "schema-validate-invalidschematype.yaml", true, true); + List<String> errorList3 = OnapCommandSchemaLoader.loadSchema(cmd2, + "schema-validate-invalidschematype.yaml", true, true); assertTrue(errorList3.size() > 0); diff --git a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java index 1d7c2422..c038e2dc 100644 --- a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java +++ b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java @@ -17,13 +17,29 @@ package org.onap.cli.fw.utils; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + import mockit.Invocation; import mockit.Mock; import mockit.MockUp; + import org.junit.FixMethodOrder; import org.junit.Ignore; import org.junit.Test; import org.junit.runners.MethodSorters; + import org.onap.cli.fw.cmd.OnapCommand; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandHelpFailed; @@ -39,19 +55,6 @@ import org.onap.cli.fw.schema.OnapCommandSchema; import org.onap.cli.fw.schema.OnapCommandSchemaInfo; import org.onap.cli.fw.schema.OnapCommandSchemaLoader; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class OnapCommandUtilsTest { diff --git a/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java b/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java index 6d7dbdd2..634a8d7a 100644 --- a/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java +++ b/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java @@ -16,22 +16,21 @@ package org.onap.cli.main; +import static org.junit.Assert.fail; + +import java.io.IOException; + + import jline.console.ConsoleReader; import mockit.Invocation; import mockit.Mock; import mockit.MockUp; import org.junit.Test; -import org.onap.cli.fw.cmd.OnapCommand; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandHelpFailed; import org.onap.cli.fw.registrar.OnapCommandRegistrar; -import org.onap.cli.fw.schema.OnapCommandSchemaLoader; -import java.io.IOException; -import java.util.List; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; public class OnapCliMainTest { @@ -87,7 +86,7 @@ public class OnapCliMainTest { } @Test - public void testHandleSampleCommandFailure() throws OnapCommandException{ + public void testHandleSampleCommandFailure() throws OnapCommandException { this.handle(new String[] { "sample-test", "--string-param"}); } @@ -211,7 +210,7 @@ public class OnapCliMainTest { try { OnapCli.getDirectiveHelp(); } catch (OnapCommandHelpFailed e) { - fail("Directive help failed to run"); + fail("Directive help failed to run"); } } } diff --git a/main/src/test/java/org/onap/cli/main/interactive/StringCompleterTest.java b/main/src/test/java/org/onap/cli/main/interactive/StringCompleterTest.java index 9d5cbf17..32f3be8a 100644 --- a/main/src/test/java/org/onap/cli/main/interactive/StringCompleterTest.java +++ b/main/src/test/java/org/onap/cli/main/interactive/StringCompleterTest.java @@ -18,11 +18,11 @@ package org.onap.cli.main.interactive; import static org.junit.Assert.assertTrue; -import org.junit.Test; - import java.util.ArrayList; import java.util.Arrays; +import org.junit.Test; + public class StringCompleterTest { @Test diff --git a/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java b/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java index c3627ca2..2c74cf05 100644 --- a/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java +++ b/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java @@ -17,12 +17,9 @@ package org.onap.cli.main.utils; import java.io.File; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; -import java.util.Map; -import java.util.Optional; import java.util.Set; import org.junit.Assert; @@ -65,8 +62,13 @@ public class OnapCliUtilsTest { paramslist.add(param4); paramslist.add(param5); - String[] args = new String[] { "sample-create", "--host-username", "admin", "--host-password", "123", - "--host-url", "a@b.com", "--string-param", "blah", "--long-opt", "10" }; + String[] args = new String[] { + "sample-create", + "--host-username", "admin", + "--host-password", "123", + "--host-url", "a@b.com", + "--string-param", "blah", + "--long-opt", "10" }; OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List<String> expectedList = Arrays.asList(args); @@ -214,8 +216,13 @@ public class OnapCliUtilsTest { paramslist.add(param4); paramslist.add(param5); - String[] args11 = new String[] { "sample-create", "-u", "admin", "-p", "123", "-r", "a@b.com", "-c", "blah", - "-l", "10", }; + String[] args11 = new String[] { + "sample-create", + "-u", "admin", + "-p", "123", + "-r", "a@b.com", + "-c", "blah", + "-l", "10", }; OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args11)); List<String> expectedList = Arrays.asList(args11); @@ -257,7 +264,8 @@ public class OnapCliUtilsTest { OnapCliArgsParser.populateParams(paramslist, Arrays.asList("show", "--map", "param1=value1", "--map", "param2=value2")); - Assert.assertEquals("{param1=value1, param2=value2}", paramslist.iterator().next().getValue().toString()); + Assert.assertEquals("{param1=value1, param2=value2}", + paramslist.iterator().next().getValue().toString()); } @Test(expected = OnapCliInvalidArgument.class) @@ -270,8 +278,10 @@ public class OnapCliUtilsTest { paramslist.add(param1); param1.setParameterType(OnapCommandParameterType.MAP); - OnapCliArgsParser.populateParams(paramslist, Arrays.asList("show", "--map", "param1=value1", "--map", "param2")); - Assert.assertEquals("{\"param1\":\"value1\",\"param2\"}", paramslist.iterator().next().getValue().toString()); + OnapCliArgsParser.populateParams(paramslist, + Arrays.asList("show", "--map", "param1=value1", "--map", "param2")); + Assert.assertEquals("{\"param1\":\"value1\",\"param2\"}", + paramslist.iterator().next().getValue().toString()); } @Test(expected = OnapCliInvalidArgument.class) @@ -283,8 +293,10 @@ public class OnapCliUtilsTest { Set<OnapCommandParameter> paramslist = new HashSet<>(); paramslist.add(param1); param1.setParameterType(OnapCommandParameterType.MAP); - OnapCliArgsParser.populateParams(paramslist, Arrays.asList("show", "-o", "param1=value1", "-o", "param2")); - Assert.assertEquals("{\"param1\":\"value1\",\"param2\"}", paramslist.iterator().next().getValue().toString()); + OnapCliArgsParser.populateParams(paramslist, + Arrays.asList("show", "-o", "param1=value1", "-o", "param2")); + Assert.assertEquals("{\"param1\":\"value1\",\"param2\"}", + paramslist.iterator().next().getValue().toString()); } @Test(expected = OnapCliInvalidArgument.class) @@ -293,12 +305,15 @@ public class OnapCliUtilsTest { paramargs.setName("http://localhost:8082/file.txt"); Set<OnapCommandParameter> paramslist = new HashSet<>(); paramslist.add(paramargs); - String[] args = new String[] { "positional-args", "http://localhost:8082/file.txt", - "http://localhost:8082/file.txt" }; + String[] args = new String[] { + "positional-args", + "http://localhost:8082/file.txt", + "http://localhost:8082/file.txt" }; paramargs.setParameterType(OnapCommandParameterType.STRING); OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List<String> expectedList = Arrays.asList(args); - Assert.assertEquals("positional-args", expectedList.get(1), paramslist.iterator().next().getValue()); + Assert.assertEquals("positional-args", + expectedList.get(1), paramslist.iterator().next().getValue()); } @Test(expected = OnapCliInvalidArgument.class) @@ -339,7 +354,9 @@ public class OnapCliUtilsTest { Set<OnapCommandParameter> paramslist = new HashSet<>(); paramslist.add(jsonparam); File resourcesDirectory = new File("src/test/resources/sampletest.json"); - String[] args = new String[] { "sample-create", "--json-param", "file:" + resourcesDirectory, "--json-param" }; + String[] args = new String[] { + "sample-create", "--json-param", + "file:" + resourcesDirectory, "--json-param" }; jsonparam.setParameterType(OnapCommandParameterType.JSON); OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List<String> expectedList = Arrays.asList(args); diff --git a/profiles/http/src/test/java/org/onap/cli/fw/http/HttpInputOutputTest.java b/profiles/http/src/test/java/org/onap/cli/fw/http/HttpInputOutputTest.java index 7a7a31c7..597a3280 100644 --- a/profiles/http/src/test/java/org/onap/cli/fw/http/HttpInputOutputTest.java +++ b/profiles/http/src/test/java/org/onap/cli/fw/http/HttpInputOutputTest.java @@ -43,9 +43,9 @@ public class HttpInputOutputTest { inp.setReqHeaders(new HashMap<String, String>()); inp.setReqQueries(new HashMap<String, String>()); - assertTrue( - "\nURL: uri\nMethod: method\nRequest Queries: {}\nRequest Body: body\nRequest Headers: {}\nRequest Cookies: {}\nbinaryData=false\nContext={}" - .equals(inp.toString())); + String msg = "\nURL: uri\nMethod: method\nRequest Queries: {}\nRequest Body: body\nRequest Headers: " + + "{}\nRequest Cookies: {}\nbinaryData=false\nContext={}"; + assertTrue(msg.equals(inp.toString())); } @Test diff --git a/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java b/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java index fe29936a..fab02ff2 100644 --- a/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java +++ b/profiles/http/src/test/java/org/onap/cli/fw/http/OnapHttpConnectionTest.java @@ -22,6 +22,10 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import mockit.Invocation; +import mockit.Mock; +import mockit.MockUp; + import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpUriRequest; @@ -34,9 +38,6 @@ import org.onap.cli.fw.http.connect.HttpResult; import org.onap.cli.fw.http.connect.OnapHttpConnection; import org.onap.cli.fw.http.error.OnapCommandHttpFailure; -import mockit.Invocation; -import mockit.Mock; -import mockit.MockUp; public class OnapHttpConnectionTest { HttpInput inp = null; diff --git a/profiles/http/src/test/java/org/onap/cli/fw/http/auth/OnapAuthClientCommandBasedTest.java b/profiles/http/src/test/java/org/onap/cli/fw/http/auth/OnapAuthClientCommandBasedTest.java index d3059449..174c066c 100644 --- a/profiles/http/src/test/java/org/onap/cli/fw/http/auth/OnapAuthClientCommandBasedTest.java +++ b/profiles/http/src/test/java/org/onap/cli/fw/http/auth/OnapAuthClientCommandBasedTest.java @@ -33,14 +33,16 @@ public class OnapAuthClientCommandBasedTest { @Before public void setup() throws OnapCommandProductVersionInvalid, OnapCommandException { - OnapCommandRegistrar.getRegistrar().setEnabledProductVersion(OnapCommandConfig.getPropertyValue(OnapCommandConstants.OPEN_CLI_PRODUCT_NAME)); + OnapCommandRegistrar.getRegistrar().setEnabledProductVersion( + OnapCommandConfig.getPropertyValue(OnapCommandConstants.OPEN_CLI_PRODUCT_NAME)); } @Test public void yesCatalogYesAuthTest() throws OnapCommandException { try { OnapHttpCommand cmd = getCommand("sample-test-schema-yes-auth-yes-catalog.yaml"); - cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_HOST_URL).setValue("http://localhost:8080"); + cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_HOST_URL) + .setValue("http://localhost:8080"); cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_USERNAME).setValue("test"); cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_PASSWORD).setValue("password"); @@ -55,7 +57,8 @@ public class OnapAuthClientCommandBasedTest { public void yesCatalogNoAuthTest() throws OnapCommandException { try { OnapHttpCommand cmd = getCommand("sample-test-schema-no-auth-yes-catalog.yaml"); - cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_HOST_URL).setValue("http://localhost:8080"); + cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_HOST_URL) + .setValue("http://localhost:8080"); cmd.execute(); } catch (OnapCommandException e) { @@ -68,7 +71,8 @@ public class OnapAuthClientCommandBasedTest { public void noCatalogYesAuthTest() throws OnapCommandException { try { OnapHttpCommand cmd = getCommand("sample-test-schema-yes-auth-no-catalog.yaml"); - cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_HOST_URL).setValue("http://localhost:8080"); + cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_HOST_URL) + .setValue("http://localhost:8080"); cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_USERNAME).setValue("test"); cmd.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_PASSWORD).setValue("password"); @@ -109,7 +113,8 @@ public class OnapAuthClientCommandBasedTest { protected void processRequest() throws OnapCommandException { if (!this.getService().isModeDirect()) { String url = this.authClient.getServiceUrl(); - assert url.equals(this.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_HOST_URL).getValue() + "/"); + assert url.equals(this.getParametersMap().get(OnapCommandHttpConstants.DEAFULT_PARAMETER_HOST_URL) + .getValue() + "/"); } } }; @@ -118,4 +123,4 @@ public class OnapAuthClientCommandBasedTest { return cmd; } - } +} diff --git a/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java b/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java index 13b2db42..6e03e74b 100644 --- a/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java +++ b/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java @@ -101,7 +101,11 @@ public class OnapCommandUtilsTest { public void populateOutputsTest() throws OnapCommandException { HttpResult output = new HttpResult(); output.setBody( - "{\"serviceName\":\"test\",\"version\":\"v1\",\"url\":\"/api/test/v1\",\"protocol\":\"REST\",\"visualRange\":\"1\",\"lb_policy\":\"hash\",\"nodes\":[{\"ip\":\"127.0.0.1\",\"port\":\"8012\",\"ttl\":0,\"nodeId\":\"test_127.0.0.1_8012\",\"expiration\":\"2017-02-10T05:33:25Z\",\"created_at\":\"2017-02-10T05:33:25Z\",\"updated_at\":\"2017-02-10T05:33:25Z\"}],\"status\":\"1\"}"); + "{\"serviceName\":\"test\",\"version\":\"v1\",\"url\":\"/api/test/v1\",\"protocol\":\"REST\"," + + "\"visualRange\":\"1\",\"lb_policy\":\"hash\",\"nodes\":[{\"ip\":\"127.0.0.1\",\"port\":\"8012\"," + + "\"ttl\":0,\"nodeId\":\"test_127.0.0.1_8012\",\"expiration\":\"2017-02-10T05:33:25Z\"," + + "\"created_at\":\"2017-02-10T05:33:25Z\",\"updated_at\":\"2017-02-10T05:33:25Z\"}]," + + "\"status\":\"1\"}"); Map<String, String> mapHead = new HashMap<>(); mapHead.put("head1", "value1"); output.setRespHeaders(mapHead); @@ -120,7 +124,8 @@ public class OnapCommandUtilsTest { input1 = OnapCommandHttpUtils.populateOutputs(params, output); } catch (OnapCommandHttpInvalidResponseBody e) { assertEquals( - "0x3004::Http response body does not have json entry {$.serviceName, Missing property in path $['{$']", + "0x3004::Http response body does not have json entry {$.serviceName, " + + "Missing property in path $['{$']", e.getMessage()); } output.setBody("{}"); @@ -140,8 +145,35 @@ public class OnapCommandUtilsTest { @Test public void testJsonEmptyCheck() throws OnapCommandHttpInvalidRequestBody { - String sample = "{\"request\":{\"method\":\"\",\"uri\":\"/onboarding-api/v1.0/vendor-license-models/cf2d907d998e44698ce3b4cded5f66a7/versions/2.0/license-agreements\",\"headers\":{\"Authorization\":\"Basic Y3MwMDA4OmRlbW8xMjM0NTYh\",\"X-FromAppId\":\"onap-cli\",\"Accept\":\"application/json\",\"USER_ID\":\"cs0008\",\"X-TransactionId\":\"req-66a37478-d840-44f8-b436-56f4a3b6f640\",\"Content-Type\":\"application/json\"},\"json\":null},\"response\":{\"status\":200,\"json\":{\"listCount\":2,\"results\":[{\"name\":\"sf\",\"description\":\"sdfgdf\",\"licenseTerm\":{\"choice\":\"Fixed_Term\",\"other\":null},\"id\":\"1e2edfccaca847f896070d0fac26667a\",\"featureGroupsIds\":[\"3a2fb75b52a54e9c8093e7c154210f9e\"]},{\"name\":\"kanag-cli-la\",\"description\":\"kanag cli la\",\"licenseTerm\":{\"choice\":\"Fixed_Term\",\"other\":\"\"},\"id\":\"77e151d0503b45ecb7e40f5f5f1a887e\",\"featureGroupsIds\":[\"3a2fb75b52a54e9c8093e7c154210f9e\"]}]}}}"; - String result = "{\"request\":{\"uri\":\"/onboarding-api/v1.0/vendor-license-models/cf2d907d998e44698ce3b4cded5f66a7/versions/2.0/license-agreements\",\"headers\":{\"Authorization\":\"Basic Y3MwMDA4OmRlbW8xMjM0NTYh\",\"X-FromAppId\":\"onap-cli\",\"Accept\":\"application/json\",\"USER_ID\":\"cs0008\",\"X-TransactionId\":\"req-66a37478-d840-44f8-b436-56f4a3b6f640\",\"Content-Type\":\"application/json\"}},\"response\":{\"status\":200,\"json\":{\"listCount\":2,\"results\":[{\"name\":\"sf\",\"description\":\"sdfgdf\",\"licenseTerm\":{\"choice\":\"Fixed_Term\"},\"id\":\"1e2edfccaca847f896070d0fac26667a\",\"featureGroupsIds\":[\"3a2fb75b52a54e9c8093e7c154210f9e\"]},{\"name\":\"kanag-cli-la\",\"description\":\"kanag cli la\",\"licenseTerm\":{\"choice\":\"Fixed_Term\"},\"id\":\"77e151d0503b45ecb7e40f5f5f1a887e\",\"featureGroupsIds\":[\"3a2fb75b52a54e9c8093e7c154210f9e\"]}]}}}"; + String sample = "{\"request\":{\"method\":\"\",\"uri\":\"/onboarding-api/v1.0/" + + "vendor-license-models/cf2d907d998e44698ce3b4cded5f66a7/versions/2.0/license-agreements\"," + + "\"headers\":{\"Authorization\":\"Basic Y3MwMDA4OmRlbW8xMjM0NTYh\",\"X-FromAppId\":\"onap-cli\"," + + "\"Accept\":\"application/json\",\"USER_ID\":\"cs0008\"," + + "\"X-TransactionId\":\"req-66a37478-d840-44f8-b436-56f4a3b6f640\"," + + "\"Content-Type\":\"application/json\"},\"json\":null}," + + "\"response\":{\"status\":200,\"json\":{\"listCount\":2," + + "\"results\":[{\"name\":\"sf\",\"description\":\"sdfgdf\"," + + "\"licenseTerm\":{\"choice\":\"Fixed_Term\",\"other\":null}," + + "\"id\":\"1e2edfccaca847f896070d0fac26667a\"," + + "\"featureGroupsIds\":[\"3a2fb75b52a54e9c8093e7c154210f9e\"]}," + + "{\"name\":\"kanag-cli-la\",\"description\":\"kanag cli la\"," + + "\"licenseTerm\":{\"choice\":\"Fixed_Term\",\"other\":\"\"}," + + "\"id\":\"77e151d0503b45ecb7e40f5f5f1a887e\"," + + "\"featureGroupsIds\":[\"3a2fb75b52a54e9c8093e7c154210f9e\"]}]}}}"; + String result = "{\"request\":{\"uri\":" + + "\"/onboarding-api/v1.0/vendor-license-models/cf2d907d998e44698ce3b4cded5f66a7/" + + "versions/2.0/license-agreements\",\"headers\":" + + "{\"Authorization\":\"Basic Y3MwMDA4OmRlbW8xMjM0NTYh\"," + + "\"X-FromAppId\":\"onap-cli\",\"Accept\":\"application/json\"," + + "\"USER_ID\":\"cs0008\",\"X-TransactionId\":\"req-66a37478-d840-44f8-b436-56f4a3b6f640\"," + + "\"Content-Type\":\"application/json\"}},\"response\":{\"status\":200," + + "\"json\":{\"listCount\":2,\"results\":[{\"name\":\"sf\"," + + "\"description\":\"sdfgdf\",\"licenseTerm\":{\"choice\":\"Fixed_Term\"}," + + "\"id\":\"1e2edfccaca847f896070d0fac26667a\",\"featureGroupsIds\":" + + "[\"3a2fb75b52a54e9c8093e7c154210f9e\"]},{\"name\":\"kanag-cli-la\"," + + "\"description\":\"kanag cli la\",\"licenseTerm\":{\"choice\":\"Fixed_Term\"}," + + "\"id\":\"77e151d0503b45ecb7e40f5f5f1a887e\",\"featureGroupsIds\":" + + "[\"3a2fb75b52a54e9c8093e7c154210f9e\"]}]}}}"; assertEquals(result, OnapCommandHttpUtils.normalizeJson(sample)); } } diff --git a/profiles/snmp/src/test/java/org/onap/cli/fw/snmp/cmd/OnapSnmpCommandTest.java b/profiles/snmp/src/test/java/org/onap/cli/fw/snmp/cmd/OnapSnmpCommandTest.java index 00c985d5..2fd83f9d 100644 --- a/profiles/snmp/src/test/java/org/onap/cli/fw/snmp/cmd/OnapSnmpCommandTest.java +++ b/profiles/snmp/src/test/java/org/onap/cli/fw/snmp/cmd/OnapSnmpCommandTest.java @@ -16,11 +16,22 @@ package org.onap.cli.fw.snmp.cmd; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + import mockit.Mock; import mockit.MockUp; -import org.junit.*; + +import org.junit.Test; import org.onap.cli.fw.error.OnapCommandException; -import org.onap.cli.fw.error.OnapCommandInvalidParameterValue; import org.onap.cli.fw.input.OnapCommandParameter; import org.onap.cli.fw.input.OnapCommandParameterType; import org.onap.cli.fw.output.OnapCommandResult; @@ -34,10 +45,6 @@ import org.snmp4j.smi.OID; import org.snmp4j.smi.OctetString; import org.snmp4j.smi.VariableBinding; -import java.io.IOException; -import java.util.*; - -import static org.junit.Assert.*; public class OnapSnmpCommandTest { @@ -91,7 +98,6 @@ public class OnapSnmpCommandTest { snmpCmd.run(); OnapCommandResult result = snmpCmd.getResult(); - assertEquals("snmp", result.getRecordsMap().get("system-desc") - .getValues().get(0)); + assertEquals("snmp", result.getRecordsMap().get("system-desc").getValues().get(0)); } }
\ No newline at end of file |