summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorpriyanka.akhade <priyanka.akhade@huawei.com>2020-04-13 13:16:29 +0000
committerpriyanka.akhade <priyanka.akhade@huawei.com>2020-05-04 06:43:16 +0000
commit1db7e72d979afa03bca38d3008f55246f8d6a6c1 (patch)
tree547661ba2a459201a5aa810e92dfa2941bff4f69 /main
parent2bb3344c6b3ec9bd77d1491d5beb579bdabc62f2 (diff)
Migrate to Yamlbeans
Issue-ID: CLI-248 Signed-off-by: priyanka.akhade <priyanka.akhade@huawei.com> Change-Id: I182c7a2e2f41bf09990e5b1ac0344f49af33e0c5
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