diff options
author | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2017-09-20 14:58:43 +0530 |
---|---|---|
committer | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2017-11-14 14:37:55 +0530 |
commit | 4b04eaa325a972ec38a7d317a60faff1664c8d39 (patch) | |
tree | a14ff8fe984a499e15661ced75895fa060cc49d1 /framework/src/test/java/org | |
parent | 8782d93af5c1a65dfe1f07aabe6afa69d6f3e155 (diff) |
Add default_value for output attributes
Special enteries are $s{uuit} and $s{env:EVN-VAR}
Issue-Id: CLI-66
Change-Id: I6c16d8815f4934b7759adee3a41372303cef9a65
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'framework/src/test/java/org')
4 files changed, 41 insertions, 20 deletions
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 e50490f4..fc3e772d 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 @@ -16,23 +16,32 @@ package org.onap.cli.cmd.sample; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + import org.junit.Test; +import org.onap.cli.fw.OnapCommand; +import org.onap.cli.fw.OnapCommandRegistrar; import org.onap.cli.fw.conf.Constants; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandExecutionFailed; import org.onap.cli.fw.error.OnapCommandNotInitialized; import org.onap.cli.fw.input.OnapCommandParameter; import org.onap.cli.fw.input.ParameterType; - -import java.util.ArrayList; -import java.util.List; +import org.onap.cli.fw.output.OnapCommandResultAttribute; public class OnapCommandSampleTest { @Test public void sampleTestVersion() { - OnapCommandSample sample = new OnapCommandSample(); - + try { + + OnapCommand sample = OnapCommandRegistrar.getRegistrar().get("sample-test"); + List<OnapCommandParameter> parameters = new ArrayList(); OnapCommandParameter v = new OnapCommandParameter(); v.setName(Constants.DEFAULT_PARAMETER_VERSION); @@ -66,8 +75,9 @@ public class OnapCommandSampleTest { @Test public void sampleTest() { - OnapCommandSample sample = new OnapCommandSample(); + try { + OnapCommand sample = OnapCommandRegistrar.getRegistrar().get("sample-test"); List<OnapCommandParameter> parameters = new ArrayList(); OnapCommandParameter v = new OnapCommandParameter(); v.setName(Constants.DEFAULT_PARAMETER_VERSION); @@ -103,7 +113,17 @@ public class OnapCommandSampleTest { parameters.add(m); sample.setParameters(parameters); sample.execute(); - } catch (OnapCommandException e) { + + //validate whether output attributes default value got initialized as part of execute() + OnapCommandResultAttribute attr = sample.getResult().getRecordsMap().get("output-1"); + String attrValue = attr.getValues().get(0); + UUID.fromString(attrValue.substring(4)); + attr = sample.getResult().getRecordsMap().get("output-2"); + attrValue = attr.getValues().get(0); + assertEquals(attrValue, "test"); + } catch (IllegalArgumentException e){ + fail("Failed to replace the output default value on output-1"); + } catch (OnapCommandException e) { } } diff --git a/framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java b/framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java index 12ff2085..1f830464 100644 --- a/framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java +++ b/framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java @@ -50,6 +50,8 @@ public class TestCommandValidate { @Test(expected = OnapCommandParameterMissing.class) public void testNoAuthArgFalse() throws OnapCommandException { OnapCommandUtils.loadSchema(cmd, "sample-test-include-param.yaml", true, false); + OnapCommandParameter msbParam = cmd.getParameters().stream().filter(p -> p.getName().equalsIgnoreCase("host-url")).findFirst().get(); + msbParam.setValue(""); cmd.validate(); } } diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommand.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommand.java index 069ae35f..89367f1d 100644 --- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommand.java +++ b/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommand.java @@ -16,18 +16,17 @@ package org.onap.cli.fw.cmd; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.List; + import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandExecutionFailed; import org.onap.cli.fw.error.OnapCommandExecutorInfoMissing; -import org.onap.cli.fw.error.OnapCommandInvalidParameterValue; import org.onap.cli.fw.error.OnapCommandResultInitialzationFailed; import org.onap.cli.fw.utils.OnapCommandUtils; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.List; - public class OnapCreateSwaggerBasedCommand extends OnapSwaggerCommand { private <T> T initializeEntity(T obj, List<String> prps) throws OnapCommandResultInitialzationFailed { @@ -45,7 +44,7 @@ public class OnapCreateSwaggerBasedCommand extends OnapSwaggerCommand { Method set = obj.getClass().getMethod(methodName, String.class); set.invoke(obj, this.getParametersMap().get(paramName).getValue()); } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException | OnapCommandInvalidParameterValue e) { + | InvocationTargetException e) { throw new OnapCommandResultInitialzationFailed(this.getName(), e); } } 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 e11bfed8..6137b9dc 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 @@ -60,24 +60,24 @@ public class OnapCommandParameterTest { param.setValue(map); assertTrue("{\"One\":\"1\",\"Two\":\"2\",\"Three\":\"3\"}".equals(param.getValue())); - param.setDefaultValue("${defaultValue}"); - assertTrue(null == param.getDefaultValue()); + param.setDefaultValue("$s{env:defaultValue}"); + assertTrue("env:defaultValue".equals(param.getDefaultValue())); } @Test public void parameterEnvDefaultValueObjTest() { OnapCommandParameter param = new OnapCommandParameter(); - param.setDefaultValue("${DAFAULT_VALUE}"); - boolean isDefaultValueAnEnv = param.isDefaultValueAnEnv(); + param.setDefaultValue("$s{env:DAFAULT_VALUE}"); + boolean isDefaultValueAnEnv = param.isRawDefaultValueAnEnv(); assertTrue(isDefaultValueAnEnv); - String envValue = param.getEnvVarNameFromDefaultValue(); + String envValue = param.getEnvVarNameFromrRawDefaultValue(); assertTrue("DAFAULT_VALUE".equals(envValue)); } @Test - public void parameterValidateTest() { + public void parameterValidateTest() throws OnapCommandInvalidParameterValue { OnapCommandParameter param = new OnapCommandParameter(); param.setOptional(false); param.setValue(""); |