summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java5
-rw-r--r--main/src/test/java/org/onap/cli/main/OnapCliMainTest.java9
-rw-r--r--main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java24
3 files changed, 36 insertions, 2 deletions
diff --git a/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
index 3dcb74ed..d0885def 100644
--- a/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
+++ b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
@@ -33,7 +33,7 @@ import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.input.OnapCommandParameterType;
import org.onap.cli.main.error.OnapCliArgumentValueMissing;
import org.onap.cli.main.error.OnapCliInvalidArgument;
-import org.yaml.snakeyaml.Yaml;
+import com.esotericsoftware.yamlbeans.YamlReader;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -239,7 +239,8 @@ public class OnapCliArgsParser {
File file = new File(input);
if (file.isFile()) {
String value = FileUtils.readFileToString(file);
- new Yaml().load(value);
+ YamlReader reader = new YamlReader(value);
+ value = (String) reader.read();
return value;
} else {
return input;
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 634a8d7a..0fb83287 100644
--- a/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
+++ b/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
@@ -30,6 +30,10 @@ import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandHelpFailed;
import org.onap.cli.fw.registrar.OnapCommandRegistrar;
+import java.util.Map;
+import org.onap.cli.fw.error.OnapCommandInvalidSchema;
+import org.onap.cli.fw.utils.OnapCommandDiscoveryUtils;
+import static org.junit.Assert.assertFalse;
public class OnapCliMainTest {
@@ -213,4 +217,9 @@ public class OnapCliMainTest {
fail("Directive help failed to run");
}
}
+ @Test
+ public void testLoadYamlForYamlReader() throws OnapCommandInvalidSchema {
+ Map<String,?> map = OnapCommandDiscoveryUtils.loadYaml("src/test/resources/open-cli-schema/sample-test-schema.yaml");
+ assertFalse(map.isEmpty());
+ }
}
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 0c92a1a3..e74981fb 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
@@ -395,4 +395,28 @@ public class OnapCliUtilsTest {
Assert.assertTrue(((List<String>) arrParam.getValue())
.containsAll(Arrays.asList("test1", "test2")));
}
+ @Test
+ public void testReadYamlStringFromUrl() throws OnapCommandException {
+ OnapCommandParameter param1 = new OnapCommandParameter();
+ param1.setLongOption("yaml");
+ param1.setName("name");
+ param1.setParameterType(OnapCommandParameterType.YAML);
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
+ paramslist.add(param1);
+ OnapCliArgsParser.populateParams(paramslist,
+ Arrays.asList("--yaml", "name", "--yaml", "test-schema"));
+ Assert.assertTrue(paramslist.iterator().next().getValue().equals("test-schema"));
+ }
+ @Test
+ public void testReadYamlStringFromUrlForFile() throws OnapCommandException {
+ OnapCommandParameter param1 = new OnapCommandParameter();
+ param1.setLongOption("yaml");
+ param1.setName("name");
+ param1.setParameterType(OnapCommandParameterType.YAML);
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
+ paramslist.add(param1);
+ OnapCliArgsParser.populateParams(paramslist,
+ Arrays.asList("--yaml", "main/src/test/resources/open-cli-schema/sample-test-schema.yaml", "--yaml", "test-schema"));
+ Assert.assertTrue(paramslist.iterator().next().getValue().equals("test-schema"));
+ }
} \ No newline at end of file