aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/test/java
diff options
context:
space:
mode:
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>2017-07-31 00:45:06 +0530
committersubhash kumar singh <subhash.kumar.singh@huawei.com>2017-08-04 15:47:47 +0530
commite45e668a4f6bdeca4ddc4071c4f37822792d65ed (patch)
tree3d0d24e02a96e56ef4c68bbfdad539ced6b6bab0 /framework/src/test/java
parent31439b63b92b8124588a6262e1d9d0a89cdd46e9 (diff)
Fix invalid help parameters
Introduce new section "default_parameter" to add "include" and "exclude" parameter from defalut parameter list. Following is a example for the parameter section to use it: xyz.yaml: ... default_parameters: include: - parameter1 - parameter2 ... exclude: - parameter3 - parameter4 ... parameters: - parameter5 .... .... Issue-Id: CLI-20 Change-Id: I99fd91a130739f2007fdd85a23c76d4e1b30c542 Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
Diffstat (limited to 'framework/src/test/java')
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommandTest.java43
-rw-r--r--framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java121
2 files changed, 139 insertions, 25 deletions
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommandTest.java
index 1c09c0d3..eda6a591 100644
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommandTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommandTest.java
@@ -18,7 +18,11 @@ package org.onap.cli.fw.cmd;
import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.input.OnapCommandParameter;
+import org.onap.cli.fw.output.OnapCommandResultAttribute;
+
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
public class OnapSchemaRefreshCommandTest {
@@ -26,31 +30,20 @@ public class OnapSchemaRefreshCommandTest {
public void validateSchemaCommandTest1() throws OnapCommandException {
OnapSchemaRefreshCommand cmd = new OnapSchemaRefreshCommand();
cmd.initializeSchema("schema-refresh.yaml");
- for (OnapCommandParameter param : cmd.getParameters()) {
- if ("onap-username".equals(param.getName())) {
- param.setValue("test");
- } else if ("onap-password".equals(param.getName())) {
- param.setValue("test");
- } else if ("msb-url".equals(param.getName())) {
- param.setValue("test-url");
- }
- }
cmd.execute();
- }
- @Test
- public void validateSchemaCommandTest2() throws OnapCommandException {
- OnapSchemaRefreshCommand cmd = new OnapSchemaRefreshCommand();
- cmd.initializeSchema("schema-refresh.yaml");
- for (OnapCommandParameter param : cmd.getParameters()) {
- if ("onap-username".equals(param.getName())) {
- param.setValue("test");
- } else if ("onap-password".equals(param.getName())) {
- param.setValue("test");
- } else if ("msb-url".equals(param.getName())) {
- param.setValue("test-url");
- }
- }
- cmd.execute();
+ List<OnapCommandResultAttribute> onapCommandResultAttribute = cmd.getResult()
+ .getRecords();
+
+ String s1Number = onapCommandResultAttribute.get(0).getValues().get(0);
+ String cmdName = onapCommandResultAttribute.get(1).getValues().get(0);
+ String cmdFile = onapCommandResultAttribute.get(2).getValues().get(0);
+ String version = onapCommandResultAttribute.get(3).getValues().get(0);
+
+ assertTrue(s1Number.equalsIgnoreCase("1"));
+ assertTrue(cmdName.equalsIgnoreCase("sample-test1"));
+ assertTrue(cmdFile.equalsIgnoreCase("sample-test1-schema-http.yaml"));
+ assertTrue(version.equalsIgnoreCase("1.0"));
+
}
}
diff --git a/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java b/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java
new file mode 100644
index 00000000..bd2ad0d1
--- /dev/null
+++ b/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.cli.fw.defaultParameter;
+
+import org.junit.Test;
+import org.onap.cli.fw.OnapCommand;
+import org.onap.cli.fw.error.OnapCommandException;
+import org.onap.cli.fw.error.OnapCommandInvalidDefaultParameter;
+import org.onap.cli.fw.error.OnapCommandInvalidSchema;
+import org.onap.cli.fw.utils.OnapCommandUtils;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+
+public class TestDefaultParameterSection {
+ @Test
+ public void checkOnlyInclude() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+
+ OnapCommandUtils.loadSchema(cmd, "sample-test-include-param.yaml", true);
+ List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
+ assertTrue(parameters.contains("onap-username"));
+ assertTrue(parameters.contains("onap-password"));
+ assertTrue(parameters.contains("msb-url"));
+ }
+
+ @Test
+ public void checkOnlyExclude() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+
+ OnapCommandUtils.loadSchema(cmd, "sample-test-exclude-param.yaml", true);
+ List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
+ assertFalse(parameters.contains("onap-username"));
+ assertTrue(parameters.contains("onap-password"));
+ assertFalse(parameters.contains("msb-url"));
+ }
+
+ @Test
+ public void checkBothIncludeAndExclude() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+
+ OnapCommandUtils.loadSchema(cmd, "sample-test-include-exclude.yaml", true);
+ List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
+
+ assertTrue(parameters.contains("onap-username"));
+ assertFalse(parameters.contains("onap-password"));
+ assertFalse(parameters.contains("msb-url"));
+ }
+
+ @Test
+ public void checkDefaultSectionAbsent() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+
+ OnapCommandUtils.loadSchema(cmd, "onap-test-schema.yaml", true);
+ List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
+
+ assertTrue(parameters.contains("onap-username"));
+ assertTrue(parameters.contains("onap-password"));
+ assertTrue(parameters.contains("msb-url"));
+ }
+
+ @Test(expected = OnapCommandInvalidDefaultParameter.class)
+ public void checkInvalidDefaultArgument() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+
+ OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-default-parameter.yaml", true);
+ }
+
+ @Test(expected = OnapCommandInvalidDefaultParameter.class)
+ public void checkInvalidDefaultArgumentNotExist() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+
+ OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-default-params-not-exist.yaml", true);
+ }
+
+ @Test(expected = OnapCommandInvalidSchema.class)
+ public void checkDefaltwithNoExcludeAndInclude() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+
+ OnapCommandUtils.loadSchema(cmd, "sample-test-import-def-param-false.yaml", true);
+ }
+}