diff options
Diffstat (limited to 'framework')
11 files changed, 119 insertions, 116 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 { |