diff options
Diffstat (limited to 'framework/src/test')
5 files changed, 44 insertions, 21 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(""); diff --git a/framework/src/test/resources/sample-test-schema.yaml b/framework/src/test/resources/sample-test-schema.yaml index 0387e48c..98964a60 100644 --- a/framework/src/test/resources/sample-test-schema.yaml +++ b/framework/src/test/resources/sample-test-schema.yaml @@ -76,8 +76,10 @@ results: scope: short type: string is_secured: true + default_value: req-$s{uuid} - name: output-2 description: Onap output attribute marked in long scope: short is_secured: false - type: string
\ No newline at end of file + type: string + default_value: Hello ${string-param} !
\ No newline at end of file |