aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src
diff options
context:
space:
mode:
authorpriyanka.akhade <priyanka.akhade@huawei.com>2020-02-28 05:47:34 +0000
committerpriyanka.akhade <priyanka.akhade@huawei.com>2020-02-29 11:26:08 +0000
commit132177fb71c08f157fb42037f9dd26ceb2d0ba43 (patch)
treef47d3c4d950e98d5bcf104aa8952f39a84e3ba6d /framework/src
parent4f1d279e42a3326cdc97e1eacaf0fdb58ee944e7 (diff)
Migrate to gson
Issue-ID: CLI-247 Signed-off-by: priyanka.akhade <priyanka.akhade@huawei.com> Change-Id: If66134db5503382fb45210ece883402fc130ac93
Diffstat (limited to 'framework/src')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java11
-rw-r--r--framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java17
-rw-r--r--framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java21
-rw-r--r--framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaInfo.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java24
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java34
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java33
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java11
-rw-r--r--framework/src/main/resources/log4j.properties30
-rw-r--r--framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java29
-rw-r--r--framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java29
-rw-r--r--framework/src/test/java/org/onap/cli/fw/store/OnapCommandArtifactStoreTest.java39
12 files changed, 189 insertions, 91 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java
index d73df4fb..29994d09 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java
@@ -22,7 +22,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
import org.onap.cli.fw.conf.OnapCommandConstants;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandHelpFailed;
@@ -45,8 +44,9 @@ import org.onap.cli.fw.utils.OnapCommandUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
/**
* Oclip Command.
@@ -55,6 +55,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public abstract class OnapCommand {
private static Logger log = LoggerFactory.getLogger(OnapCommand.class);
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
private String cmdDescription;
@@ -180,8 +181,8 @@ public abstract class OnapCommand {
}
try {
- return new ObjectMapper().writeValueAsString(args);
- } catch (JsonProcessingException e) {
+ return gson.toJson(args);
+ } catch (Exception e) { // NOSONAR
log.error("exception occured {}", e.getMessage());
return "{}";
}
diff --git a/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java b/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java
index 3b13c9f8..d0b3c5f4 100644
--- a/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java
+++ b/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java
@@ -16,14 +16,14 @@
package org.onap.cli.fw.input;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandInvalidParameterValue;
import org.onap.cli.fw.error.OnapCommandParameterMissing;
import org.onap.cli.fw.utils.OnapCommandUtils;
import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -38,6 +38,11 @@ import java.util.UUID;
public class OnapCommandParameter {
/*
+ * Used locally for json conversion
+ */
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
+
+ /*
* Name, for positional parameters, the place is decided from schema file definition
*/
private String cmdName;
@@ -211,16 +216,16 @@ public class OnapCommandParameter {
switch (parameterType) {
case MAP:
try {
- defaultValue = new ObjectMapper().readValue(processedValue, Map.class);
- } catch (IOException e) {
+ defaultValue = gson.fromJson(processedValue, Map.class);
+ } catch (Exception e) { // NOSONAR
throw new OnapCommandInvalidParameterValue("Invalid default value for " + this.getName(), e);
}
break;
case ARRAY:
try {
- defaultValue = new ObjectMapper().readValue(processedValue, List.class);
- } catch (IOException e) {
+ defaultValue = gson.fromJson(processedValue, List.class);
+ } catch (Exception e) { // NOSONAR
throw new OnapCommandInvalidParameterValue("Invalid default value for " + this.getName(), e);
}
break;
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 834dea06..c4be02e3 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
@@ -28,12 +28,11 @@ import java.util.StringTokenizer;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
-import org.onap.cli.fw.conf.OnapCommandConstants;
import org.onap.cli.fw.error.OnapCommandOutputPrintingFailed;
import org.onap.cli.fw.output.OnapCommandPrintDirection;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
@@ -44,6 +43,8 @@ import net.minidev.json.JSONValue;
*/
public class OnapCommandPrint {
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
+
public static final int MAX_COLUMN_LENGTH = 50;
private OnapCommandPrintDirection direction;
@@ -272,8 +273,8 @@ public class OnapCommandPrint {
array.add(rowO);
}
try {
- return new ObjectMapper().readTree(array.toJSONString()).toString();
- } catch (IOException e) {
+ return gson.toJson(array.toJSONString()).toString();
+ } catch (Exception e) { // NOSONAR
// TODO Auto-generated catch block
return array.toJSONString();
}
@@ -281,11 +282,19 @@ 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 "";
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaInfo.java b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaInfo.java
index ff8d85f1..d87f4ef9 100644
--- a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaInfo.java
+++ b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaInfo.java
@@ -26,13 +26,11 @@ import org.onap.cli.fw.cmd.OnapCommandType;
import org.onap.cli.fw.conf.OnapCommandConstants;
import org.onap.cli.fw.info.OnapCommandState;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* OnapCommandSchemaInfo is used in discovery caching.
*
*/
-@JsonIgnoreProperties(ignoreUnknown = true)
public class OnapCommandSchemaInfo implements Comparable<OnapCommandSchemaInfo> {
/**
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
index 2e63b03e..d43b51d8 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
@@ -43,10 +43,14 @@ import org.onap.cli.fw.error.OnapCommandArtifactNotFound;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.stream.JsonReader;
+import java.io.FileReader;
public class OnapCommandArtifactStore {
private static Logger log = LoggerFactory.getLogger(OnapCommandArtifactStore.class);
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
private static boolean storeReady = false;
@@ -180,8 +184,8 @@ public class OnapCommandArtifactStore {
artifact.setCreateAt(dateFormatter.format(new Date()));
artifact.setLastUpdatedAt(artifact.getCreateAt());
- FileUtils.writeStringToFile(new File(storePath), new ObjectMapper().writeValueAsString(artifact));
- } catch (NoSuchAlgorithmException | IOException e) {
+ FileUtils.writeStringToFile(new File(storePath), gson.toJson(artifact));
+ } catch (Exception e) { // NOSONAR
//It is expected that this never occurs
log.error("Failed to store the artifact at " + storePath);
}
@@ -197,8 +201,8 @@ public class OnapCommandArtifactStore {
}
try {
- return new ObjectMapper().readValue(FileUtils.readFileToString(aFile), Artifact.class);
- } catch (IOException e) {
+ return gson.fromJson(FileUtils.readFileToString(aFile), Artifact.class);
+ } catch (Exception e) { // NOSONAR
//It is expected that this never occurs
log.error("Failed to retrieve the artifact at " + storePath);
}
@@ -234,9 +238,9 @@ public class OnapCommandArtifactStore {
return name.matches(SP);
}
}*/)) {
- try {
- artifacts.add(new ObjectMapper().readValue(file, Artifact.class));
- } catch (IOException e) {
+ try (JsonReader jsonReader = new JsonReader(new FileReader(file))){
+ artifacts.add(gson.fromJson(jsonReader, Artifact.class));
+ } catch (Exception e) { // NOSONAR
//It is expected that this never occurs
log.error("While seraching Failed to retrieve the artifact at " + file.getAbsolutePath());
}
@@ -303,12 +307,12 @@ public class OnapCommandArtifactStore {
artifact.setMetadata(existing.getMetadata());
}
- FileUtils.writeStringToFile(new File(newStorePath), new ObjectMapper().writeValueAsString(artifact));
+ FileUtils.writeStringToFile(new File(newStorePath), gson.toJson(artifact));
if (!newStorePath.equalsIgnoreCase(existingStorePath)) {
this.deleteArtifact(name, category);
}
- } catch (NoSuchAlgorithmException | IOException e) {
+ } catch (Exception e) { // NOSONAR
//It is expected that this never occurs
log.error("Failed to update the artifact at " + existingStorePath);
}
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
index 09ecf05a..68d57c77 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
@@ -33,15 +33,23 @@ import org.onap.cli.fw.conf.OnapCommandConstants;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandPersistProfileFailed;
import org.onap.cli.fw.error.OnapCommandProfileLoadFailed;
-import org.onap.cli.fw.error.OnapCommandProfileNotFound;
import org.onap.cli.fw.input.cache.OnapCommandParamEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import java.io.FileWriter;
+import java.io.FileReader;
+import java.io.Writer;
+import java.io.Reader;
+
+
public class OnapCommandProfileStore {
private static Logger log = LoggerFactory.getLogger(OnapCommandProfileStore.class);
+ private Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
private Map<String, Map<String, String>> paramCache = new HashMap<>();
private static OnapCommandProfileStore single = null;
@@ -165,11 +173,10 @@ public class OnapCommandProfileStore {
public void persistProfile(List<OnapCommandParamEntity> params, String profileName) throws OnapCommandPersistProfileFailed {
if (params != null) {
String dataDir = getDataStorePath();
- try {
File file = new File(dataDir + File.separator + profileName + DATA_PATH_PROFILE_JSON);
- ObjectMapper mapper = new ObjectMapper();
- mapper.writerWithDefaultPrettyPrinter().writeValue(file, params);
- } catch (IOException e1) {
+ try (Writer writer = new FileWriter(file)){
+ gson.toJson(params, writer);
+ } catch (Exception e1) { // NOSONAR
throw new OnapCommandPersistProfileFailed(e1);
}
}
@@ -178,17 +185,18 @@ public class OnapCommandProfileStore {
public List<OnapCommandParamEntity> loadParamFromCache(String profileName) throws OnapCommandException {
List<OnapCommandParamEntity> params = new ArrayList<>();
String dataDir = getDataStorePath();
- try {
- File file = new File(dataDir + File.separator + profileName + DATA_PATH_PROFILE_JSON);
- if (file.exists()) {
- ObjectMapper mapper = new ObjectMapper();
- OnapCommandParamEntity[] list = mapper.readValue(file, OnapCommandParamEntity[].class);
+ File file = new File(dataDir + File.separator + profileName + DATA_PATH_PROFILE_JSON);
+ if (file.exists()) {
+ try (Reader jsonReader = new FileReader(file)){
+
+ OnapCommandParamEntity[] list = gson.fromJson(jsonReader,
+ OnapCommandParamEntity[].class);
params.addAll(Arrays.asList(list));
// } else {
// throw new OnapCommandProfileNotFound(profileName);
+ } catch (Exception e) { // NOSONAR
+ throw new OnapCommandProfileLoadFailed(e);
}
- } catch (IOException e) {
- throw new OnapCommandProfileLoadFailed(e);
}
return params;
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
index a94087ec..105f68dc 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
@@ -58,10 +58,16 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.yaml.snakeyaml.Yaml;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.stream.JsonReader;
+import java.io.FileReader;
+import java.io.Writer;
+import java.io.FileWriter;
+
public class OnapCommandDiscoveryUtils {
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
/**
* Fetch a particular schema details.
@@ -90,10 +96,10 @@ public class OnapCommandDiscoveryUtils {
throw new OnapCommandNotFound(cmd, version);
return schemaInfo;
- }
+ }
/**
- * Load the previous discovered json file.
+ * Load the previous discovered json file.
*
* @return list
* @throws OnapCommandInvalidSchema
@@ -148,12 +154,11 @@ public class OnapCommandDiscoveryUtils {
if (!OnapCommandDiscoveryUtils.isAlreadyDiscovered()) return schemas;
String dataDir = OnapCommandDiscoveryUtils.getDataStorePath();
- try {
- File file = new File(dataDir + File.separator + DISCOVERY_FILE);
- ObjectMapper mapper = new ObjectMapper();
- OnapCommandSchemaInfo[] list = mapper.readValue(file, OnapCommandSchemaInfo[].class);
+ File file = new File(dataDir + File.separator + DISCOVERY_FILE);
+ try (JsonReader jsonReader = new JsonReader(new FileReader(file))){
+ OnapCommandSchemaInfo[] list = gson.fromJson(jsonReader, OnapCommandSchemaInfo[].class);
schemas.addAll(Arrays.asList(list));
- } catch (IOException e) {
+ } catch (Exception e) { // NOSONAR
throw new OnapCommandDiscoveryFailed(dataDir,
DISCOVERY_FILE, e);
}
@@ -189,10 +194,10 @@ public class OnapCommandDiscoveryUtils {
FileUtils.forceMkdir(new File(dataDir));
File file = new File(dataDir + File.separator + DISCOVERY_FILE);
- ObjectMapper mapper = new ObjectMapper();
- mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
- mapper.writerWithDefaultPrettyPrinter().writeValue(file, schemas);
- } catch (IOException e1) {
+ try(Writer writer = new FileWriter(file)){
+ gson.toJson(schemas,writer);
+ }
+ } catch (Exception e1) { // NOSONAR
throw new OnapCommandDiscoveryFailed(dataDir,
DISCOVERY_FILE, e1);
}
@@ -552,7 +557,7 @@ public class OnapCommandDiscoveryUtils {
* @throws OnapCommandInvalidSchema
* exception
*/
- public static Map<String, ?> loadYaml(String filePath) throws OnapCommandInvalidSchema {
+ public static Map<String, ?> loadYaml(String filePath) throws OnapCommandInvalidSchema {
Map<String, ?> values = null;
try {
values = (Map<String, Object>) new Yaml().load(FileUtils.readFileToString(new File(filePath)));
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
index 96f864e0..043ec8ed 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
@@ -46,10 +46,11 @@ import org.onap.cli.fw.input.OnapCommandParameterType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import com.jayway.jsonpath.JsonPath;
+
/**
* Provides helper method to parse Yaml files and produce required objects.
*
@@ -57,6 +58,8 @@ import com.jayway.jsonpath.JsonPath;
public class OnapCommandUtils {
static Logger log = LoggerFactory.getLogger(OnapCommandUtils.class);
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
+
/**
* Private constructor.
*/
@@ -336,13 +339,13 @@ public class OnapCommandUtils {
currentIdx = idxE + 2;
} else if (OnapCommandParameterType.MAP.equals(param.getParameterType())) {
try {
- String value = new ObjectMapper().writeValueAsString(params.get(paramName).getValue());
+ String value = gson.toJson(params.get(paramName).getValue());
if ((idxS == 0) && (currentIdx == 0)) {
result = value;
} else {
result += line.substring(currentIdx, idxS - 1) + value;
}
- } catch (JsonProcessingException e) { // NOSONAR
+ } catch (Exception e) { // NOSONAR
//never occur as map is coverted to json string here
}
diff --git a/framework/src/main/resources/log4j.properties b/framework/src/main/resources/log4j.properties
deleted file mode 100644
index d535098e..00000000
--- a/framework/src/main/resources/log4j.properties
+++ /dev/null
@@ -1,30 +0,0 @@
-# Copyright 2018 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.
-
-log4j.rootLogger=ERROR, file
-log4j.logger.org.onap.cli=ERROR, file
-log4j.logger.org.open.infc.grpc.server=INFO, file, stdout
-# Direct log messages to stdout
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.Target=System.out
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
-
-# Redirect log messages to a log file, support file rolling.
-log4j.appender.file=org.apache.log4j.RollingFileAppender
-log4j.appender.file.File=${OPEN_CLI_HOME}/logs/open-cli.log
-log4j.appender.file.MaxFileSize=5MB
-log4j.appender.file.MaxBackupIndex=10
-log4j.appender.file.layout=org.apache.log4j.PatternLayout
-log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
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 18959e8e..1bf42e00 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
@@ -129,4 +129,33 @@ public class OnapCommandParameterTest {
param.validate();
}
+ @Test
+ public void parameterObjTestForGson() throws OnapCommandInvalidParameterValue {
+ OnapCommandParameter param = new OnapCommandParameter();
+ param.setDefaultValue("defaultValue");
+ param.setDescription("description");
+ param.setLongOption("longOption");
+ param.setName("name");
+ param.setOptional(true);
+ param.setParameterType(OnapCommandParameterType.JSON);
+ param.setSecured(false);
+ param.setShortOption("shortOption");
+ param.setValue("value");
+
+ param.setParameterType(OnapCommandParameterType.ARRAY);
+ List<String> list = Arrays.asList("1", "2", "3");
+ param.setValue(list);
+ assertTrue(((List)param.getValue()).containsAll(list));
+
+ param.setRawDefaultValue("[\"1\", \"2\", \"3\", \"4\"]");
+ assertTrue(((List<String>)param.getDefaultValue())
+ .containsAll(Arrays.asList("1", "2", "3", "4")));
+
+ param.setParameterType(OnapCommandParameterType.MAP);
+ param.setRawDefaultValue("{\"testKey\":\"testValue\"}");
+ assertTrue(((Map<String, String>)param.getDefaultValue()).values().containsAll(
+ Arrays.asList("testValue")
+ ));
+ }
+
}
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 a4458670..97fc9e01 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
@@ -28,7 +28,11 @@ import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.input.OnapCommandParameterType;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
public class OnapCommandResultTest {
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
@Test
@Ignore
@@ -206,5 +210,30 @@ public class OnapCommandResultTest {
assertEquals(expRes, result);
}
+ @Test
+ public void commandResultPrintLandscapeJsonTestForGson() 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.JSON);
+ 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.JSON);
+
+ String result = res.print();
+ String expRes="[{\"param\":{\"id\":\"0001\",\"value\":\"result\"}}]";
+ assertEquals(gson.toJson(expRes),result);
+
+ }
}
diff --git a/framework/src/test/java/org/onap/cli/fw/store/OnapCommandArtifactStoreTest.java b/framework/src/test/java/org/onap/cli/fw/store/OnapCommandArtifactStoreTest.java
index 1a4d982a..45186b38 100644
--- a/framework/src/test/java/org/onap/cli/fw/store/OnapCommandArtifactStoreTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/store/OnapCommandArtifactStoreTest.java
@@ -28,7 +28,13 @@ import java.io.File;
import java.util.HashMap;
import java.util.Map;
-import static org.junit.Assert.*;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
public class OnapCommandArtifactStoreTest {
OnapCommandArtifactStore onapCommandArtifactStore;
@@ -83,4 +89,35 @@ public class OnapCommandArtifactStoreTest {
public void listArtifactTest() throws OnapCommandArtifactNotFound {
assertNotNull(onapCommandArtifactStore.listArtifact("category","namePattern"));
}
+ @Test
+ public void createArtifactTestForGson() throws OnapCommandArtifactContentChecksumNotMatch, OnapCommandArtifactAlreadyExist, OnapCommandArtifactContentNotExist, OnapCommandArtifactNotFound {
+ assertNotNull(onapCommandArtifactStore.createArtifact(artifact));
+ String artifactPath=System.getProperty("user.dir")+File.separator+"data/artifacts";
+ File artifactFile= new File(artifactPath+File.separator+"artifact__category.json");
+ assertTrue(artifactFile.exists());
+ onapCommandArtifactStore.deleteArtifact("artifact","category");
+
+ }
+
+ @Test
+ public void listArtifactTestForGson() throws OnapCommandArtifactNotFound {
+ String basePath= System.getProperty("user.dir")+File.separator+"data/artifacts/testFile.json";
+ File testFile = new File(basePath);
+ if (!testFile.exists()) {
+ try {
+ testFile.createNewFile();
+ try(BufferedWriter writer = new BufferedWriter(new FileWriter(testFile))) {
+ String content = "{\"name\": \"name\",\"description\": \"description\",\"categoty\": \"categoty\"," +
+ "\"checksum\": \"checksum\",\"size\": 100,\"createAt\": \"createAt\"" +
+ ",\"lastUpdatedAt\":\"lastUpdatedAt\",\"path\": \"path\",\"metadata\": {}}";
+ writer.write(content);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ assertNotNull(onapCommandArtifactStore.listArtifact("category","namePattern"));
+
+ testFile.delete();
+ }
} \ No newline at end of file