aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framework/pom.xml21
-rw-r--r--framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java15
-rw-r--r--framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java35
3 files changed, 61 insertions, 10 deletions
diff --git a/framework/pom.xml b/framework/pom.xml
index c23451d4..9eb5bf8a 100644
--- a/framework/pom.xml
+++ b/framework/pom.xml
@@ -99,6 +99,27 @@
<version>2.8.2</version>
</dependency>
<dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.11.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>2.11.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-yaml</artifactId>
+ <version>2.11.0</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
diff --git a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java
index 5527f94f..6850fe3f 100644
--- a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java
+++ b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java
@@ -32,6 +32,8 @@ import org.onap.cli.fw.error.OnapCommandOutputPrintingFailed;
import org.onap.cli.fw.output.OnapCommandPrintDirection;
import com.google.gson.JsonParser;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
@@ -275,20 +277,13 @@ public class OnapCommandPrint {
}
}
-
- /*
- required vulnerable fix
- jackson-dataformat-yaml:YAMLMapper is a sub component of jackson-databind
- jackson-databind is replaced with gson
- JIRA: CLI-251
- */
+
public String printYaml() throws OnapCommandOutputPrintingFailed {
- /* try {
+ try {
return new YAMLMapper().writeValueAsString(new ObjectMapper().readTree(this.printJson()));
} catch (IOException e) {
throw new OnapCommandOutputPrintingFailed(e); // NOSONAR
}
- */
- return ""; //NOSONAR
+
}
}
diff --git a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java
index f46fc911..cf274f23 100644
--- a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java
@@ -235,4 +235,39 @@ public class OnapCommandResultTest {
assertEquals(expRes,result);
}
+
+ @Test
+ public void printYamlTest() throws OnapCommandException {
+ OnapCommandResult res = new OnapCommandResult();
+ res.setDebugInfo("debugInfo");
+ res.setIncludeSeparator(true);
+ res.setIncludeTitle(true);
+ res.setOutput("Output");
+ res.setPrintDirection(OnapCommandPrintDirection.LANDSCAPE);
+
+ OnapCommandResultAttribute att = new OnapCommandResultAttribute();
+ att.setName("param");
+ att.setDescription("description");
+ att.setType(OnapCommandParameterType.YAML);
+ att.setValues(
+ new ArrayList<String>(Arrays.asList(new String[] { "{\"id\": \"0001\",\"value\": \"result\"}" })));
+ List<OnapCommandResultAttribute> list = new ArrayList<OnapCommandResultAttribute>();
+ list.add(att);
+ res.setRecords(list);
+ res.setScope(OnapCommandResultAttributeScope.LONG);
+ res.setType(OnapCommandResultType.YAML);
+ String result = res.print();
+ String expRes="---\n- param:\n id: \"0001\"\n value: \"result\"\n";
+ assertEquals(expRes,result);
+
+ att.setValues(
+ new ArrayList<String>(Arrays.asList(new String[] { "{\"id\": \"0001\": \"value\": }" })));
+ list = new ArrayList<OnapCommandResultAttribute>();
+ list.add(att);
+ res.setRecords(list);
+ result = res.print();
+ expRes="---\n- param: null\n";
+ assertEquals(expRes,result);
+
+ }
}