+++ /dev/null
-# 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
<version>2.2.0</version>
</dependency>
<dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>2.9.4</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.dataformat</groupId>
- <artifactId>jackson-dataformat-yaml</artifactId>
- <version>2.9.4</version>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.8.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
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;
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.
public abstract class OnapCommand {
private static Logger log = LoggerFactory.getLogger(OnapCommand.class);
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
private String cmdDescription;
}
try {
- return new ObjectMapper().writeValueAsString(args);
- } catch (JsonProcessingException e) {
+ return gson.toJson(args);
+ } catch (Exception e) { // NOSONAR
log.error("exception occured {}", e.getMessage());
return "{}";
}
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;
*/
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
*/
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;
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;
*/
public class OnapCommandPrint {
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
+
public static final int MAX_COLUMN_LENGTH = 50;
private OnapCommandPrintDirection direction;
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();
}
}
}
+ /*
+ 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 "";
}
}
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> {
/**
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;
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);
}
}
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);
}
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());
}
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);
}
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;
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);
}
}
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;
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.
throw new OnapCommandNotFound(cmd, version);
return schemaInfo;
- }
+ }
/**
- * Load the previous discovered json file.
+ * Load the previous discovered json file.
*
* @return list
* @throws OnapCommandInvalidSchema
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);
}
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);
}
* @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)));
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.
*
public class OnapCommandUtils {
static Logger log = LoggerFactory.getLogger(OnapCommandUtils.class);
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
+
/**
* Private constructor.
*/
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
}
+++ /dev/null
-# 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
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")
+ ));
+ }
+
}
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
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);
+
+ }
}
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;
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
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.16</version>
- </dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.7.16</version>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+++ /dev/null
-# 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=DEBUG, file
-log4j.logger.org.open.infc=DEBUG, file
-
-# 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
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 io.grpc.Server;
import io.grpc.ServerBuilder;
public class OpenInterfaceGrpcServer {
private static final Logger logger = LoggerFactory.getLogger(OpenInterfaceGrpcServer.class.getName());
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
private static final String CONF_FILE = "oclip-grpc-server.properties";
private static final String CONF_SERVER_PORT = "oclip.grpc_server_port";
reply.setSuccess(cmd.getResult().isPassed());
try {
- reply.putAttrs(OnapCommandConstants.RESULTS, new ObjectMapper().readTree(printOut).toString());
- } catch (IOException e) {
+ reply.putAttrs(OnapCommandConstants.RESULTS, gson.fromJson(printOut,String.class));
+ } catch (Exception e) { // NOSONAR
reply.putAttrs(OnapCommandConstants.RESULTS, printOut);
}
+++ /dev/null
-# 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=DEBUG, file, stdout
-log4j.logger.org.open.infc=DEBUG, 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
import org.onap.cli.main.error.OnapCliInvalidArgument;
import org.yaml.snakeyaml.Yaml;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.reflect.TypeToken;
-import net.minidev.json.JSONObject;
+import java.io.Reader;
+import java.io.InputStreamReader;
+import java.io.FileReader;
/**
* Oclip CLI utilities.
*
*/
public class OnapCliArgsParser {
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
/**
* private Constructor.
}
public static String readJsonStringFromUrl(String input, String argName) throws OnapCliInvalidArgument {
- ObjectMapper mapper = new ObjectMapper();
+ String jsonValue;
try {
File file = new File(input);
if (file.isFile()) {
- return mapper.readValue(file, JSONObject.class).toJSONString();
+ try(Reader reader = new FileReader(file)){
+ jsonValue = gson.fromJson(reader, JsonElement.class).toString();
+ }
+ return jsonValue;
} else if (input.startsWith("file:") || input.startsWith("http:") || input.startsWith("ftp:")) {
URL jsonUrl = new URL(input);
- return mapper.readValue(jsonUrl, JSONObject.class).toJSONString();
+ try(Reader reader = new InputStreamReader(jsonUrl.openStream())){
+ jsonValue = gson.fromJson(reader, JsonElement.class).toString();
+ }
+ return jsonValue;
} else {
- return mapper.readValue(input, JSONObject.class).toJSONString();
+ return gson.fromJson(input, JsonElement.class).toString();
}
- } catch (IOException e) {
+ } catch (Exception e) { // NOSONAR
throw new OnapCliInvalidArgument(argName, e);
}
}
}
public static List<String> convertJsonToListString(String arg, String json) throws OnapCliInvalidArgument {
- TypeReference<List<String>> mapType = new TypeReference<List<String>>() {
+ TypeToken<List<String>> mapType = new TypeToken<List<String>>() {
};
try {
- return new ObjectMapper().readValue(json, mapType);
- } catch (IOException e) {
+ return gson.fromJson(json, mapType.getType());
+ } catch (Exception e) { // NOSONAR
throw new OnapCliInvalidArgument(arg, e);
}
}
public static Map<String, String> convertJsonToMapString(String arg, String json) throws OnapCliInvalidArgument {
- TypeReference<Map<String, String>> mapType = new TypeReference<Map<String, String>>() {
+ TypeToken<Map<String, String>> mapType = new TypeToken<Map<String, String>>() {
};
try {
- return new ObjectMapper().readValue(json, mapType);
- } catch (IOException e) {
+ return gson.fromJson(json, mapType.getType());
+ } catch (Exception e) { // NOSONAR
throw new OnapCliInvalidArgument(arg, e);
}
}
--- /dev/null
+# Copyright 2020 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.
+
+open_cli_schema_version: 1.0
+name: create-user
+description: |
+ Place this OCS YAML under $OPEN_CLI_HOME/open-cli-schema folder. Then run the commands
+ oclip schema-refresh
+
+ It is used to create a new user record at https://reqres.in.
+
+ Sample usage:
+ oclip --product test create-user --host-url https://reqres.in --user-name Priyanka --job-role Developer
+
+info:
+ product: test
+ service: ut
+ author: Priyanka Akhade priyanka.akhade@huawei.com
+
+parameters:
+ - name: name
+ description: User name
+ type: string
+ short_option: n
+ long_option: user-name
+ is_optional: false
+ - name: job
+ description: job role
+ type: string
+ short_option: r
+ long_option: job-role
+ is_optional: true
+ default_value: Software Engineer
+
+results:
+ direction: landscape
+ attributes:
+ - name: ID
+ description: user id
+ scope: short
+ type: string
+ - name: NAME
+ description: user name
+ scope: short
+ type: string
+ - name : DESIGNATION
+ description: job role
+ scope: short
+ type: string
+http:
+ service:
+ auth: none
+ mode: direct
+ request:
+ uri: /api/users
+ method: POST
+ body: '{
+ "name":"${name}",
+ "job":"${job}"
+ }'
+ success_codes:
+ - 201
+ result_map:
+ ID: $b{$.id}
+ NAME: $b{$.name}
+ DESIGNATION: $b{$.job}
--- /dev/null
+# Copyright 2020 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.
+
+open_cli_schema_version: 1.0
+name: delete-user
+description: |
+ Place this OCS YAML under $OPEN_CLI_HOME/open-cli-schema folder. Then run the commands
+ oclip schema-refresh
+
+ It is used to delete a user record at https://reqres.in.
+
+ Sample usage:
+ oclip --product test delete-user --host-url https://reqres.in
+
+info:
+ product: test
+ service: ut
+ author: Priyanka Akhade priyanka.akhade@huawei.com
+
+
+results:
+ direction: landscape
+
+http:
+ service:
+ auth: none
+ mode: direct
+ request:
+ uri: /api/users/2
+ method: DELETE
+ success_codes:
+ - 204
--- /dev/null
+# Copyright 2020 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.
+
+open_cli_schema_version: 1.0
+name: list-users
+description: |
+ Place this OCS YAML under $OPEN_CLI_HOME/open-cli-schema folder. Then run the commands
+ oclip schema-refresh
+
+ It is used to display the users' details from https://reqres.in.
+
+ Sample usage:
+ oclip --product test list-users --host-url https://reqres.in
+
+info:
+ product: test
+ service: ut
+ author: Priyanka Akhade priyanka.akhade@huawei.com
+
+results:
+ direction: landscape
+ attributes:
+ - name: FIRST_NAME
+ description: FirstName
+ scope: short
+ type: string
+ - name: LAST_NAME
+ description: LastName
+ scope: short
+ type: string
+ - name: EMAIL
+ description: Email
+ scope: short
+ type: string
+http:
+ service:
+ auth: none
+ mode: direct
+ request:
+ uri: /api/users?page=2
+ method: GET
+ success_codes:
+ - 200
+ result_map:
+ FIRST_NAME: $b{$.data.[*].first_name}
+ LAST_NAME: $b{$.data.[*].last_name}
+ EMAIL: $b{$.data.[*].email}
--- /dev/null
+# Copyright 2020 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.
+
+open_cli_schema_version: 1.0
+name: single-user
+description: |
+ Place this OCS YAML under $OPEN_CLI_HOME/open-cli-schema folder. Then run the commands
+ oclip schema-refresh
+
+ It is used to display the specific user's details from https://reqres.in.
+
+ Sample usage:
+ oclip --product test single-user --host-url https://reqres.in
+
+info:
+ product: test
+ service: ut
+ author: Priyanka Akhade priyanka.akhade@huawei.com
+
+results:
+ direction: landscape
+ attributes:
+ - name: FIRST_NAME
+ description: demo response
+ scope: short
+ type: string
+ - name: LAST_NAME
+ description: LastName
+ scope: short
+ type: string
+ - name: EMAIL
+ description: Email
+ scope: short
+ type: string
+http:
+ service:
+ auth: none
+ mode: direct
+ request:
+ uri: /api/users/2
+ method: GET
+ success_codes:
+ - 200
+ result_map:
+ FIRST_NAME: $b{$.data.first_name}
+ LAST_NAME: $b{$.data.last_name}
+ EMAIL: $b{$.data.email}
--- /dev/null
+# Copyright 2020 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.
+
+open_cli_schema_version: 1.0
+name: update-user
+description: |
+ Place this OCS YAML under $OPEN_CLI_HOME/open-cli-schema folder. Then run the commands
+ oclip schema-refresh
+
+ It is used to update the specific user's details at https://reqres.in.
+
+ Sample usage:
+ oclip --product test update-user --host-url https://reqres.in --user-name Priyanka --job-role Tester
+
+info:
+ product: test
+ service: ut
+ author: Priyanka Akhade priyanka.akhade@huawei.com
+
+parameters:
+ - name: name
+ description: User name
+ type: string
+ short_option: n
+ long_option: user-name
+ is_optional: false
+ - name: job
+ description: job role
+ type: string
+ short_option: r
+ long_option: job-role
+ is_optional: true
+ default_value: Software Engineer
+
+results:
+ direction: landscape
+ attributes:
+ - name: NAME
+ description: user name
+ scope: short
+ type: string
+ - name : DESIGNATION
+ description: job role
+ scope: short
+ type: string
+ - name : UPDATED_AT
+ description: updated DateTime
+ scope: short
+ type: string
+http:
+ service:
+ auth: none
+ mode: direct
+ request:
+ uri: /api/users/2
+ method: PUT
+ body: '{
+ "name":"${name}",
+ "job":"${job}"
+ }'
+ success_codes:
+ - 200
+ result_map:
+ NAME: $b{$.name}
+ DESIGNATION: $b{$.job}
+ UPDATED_AT: $b{$.updatedAt}
<version>2.2.0</version>
</dependency>
<dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>2.9.4</version>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.onap.cli</groupId>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
</exclusion>
+ <!--JIRA: CLI-253-->
+ <exclusion>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
import org.springframework.core.io.Resource;
import org.yaml.snakeyaml.Yaml;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import com.github.dreamhead.moco.HttpServer;
import com.github.dreamhead.moco.Moco;
import com.github.dreamhead.moco.ResponseHandler;
private Runner runner;
private Map<String, Object> mocoServerConfigs = new HashMap();
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
public MocoServer(String mockFile) throws OnapCommandException {
Resource resource = null;
if(response.get(OnapCommandHttpConstants.VERIFY_RESPONSE_JSON) != null) {
try {
mocoServerConfigs.put(OnapCommandHttpConstants.VERIFY_RESPONSE_JSON,
- new ObjectMapper().writeValueAsString(response.get(OnapCommandHttpConstants.VERIFY_RESPONSE_JSON)));
- } catch (JsonProcessingException e) {
+ gson.toJson(response.get(OnapCommandHttpConstants.VERIFY_RESPONSE_JSON)));
+ } catch (Exception e) { // NOSONAR
throw new OnapCommandException("Invalid mocking file" + mockFile, e);
}
}
package org.onap.cli.fw.http.schema;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import org.onap.cli.fw.schema.OnapCommandSchemaLoader;
import org.onap.cli.fw.utils.OnapCommandUtils;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-import net.minidev.json.JSONObject;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
public class OnapCommandSchemaHttpLoader {
private static final String ATTRIBUTE = "Attribute '";
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
private OnapCommandSchemaHttpLoader() {
// to follow standards !
}
- public static List<String> loadHttpSchema(OnapHttpCommand cmd, String schemaName, boolean includeDefault,
- boolean validateSchema) throws OnapCommandException {
+ public static List<String> loadHttpSchema(OnapHttpCommand cmd, String schemaName, boolean includeDefault, boolean validateSchema) throws OnapCommandException {
try {
List<String> errors = new ArrayList<>();
if (includeDefault) {
}
Map<String, List<Map<String, String>>> commandYamlMap =
- (Map<String, List<Map<String, String>>>)OnapCommandSchemaLoader.validateSchemaVersion(schemaName, cmd.getSchemaVersion());
+ (Map<String, List<Map<String, String>>>) OnapCommandSchemaLoader.validateSchemaVersion(schemaName, cmd.getSchemaVersion());
errors.addAll(parseHttpSchema(cmd, commandYamlMap, validateSchema));
errorList.add(OnapCommandHttpConstants.HTTP_BODY_JSON_EMPTY);
} else {
try {
- new ObjectMapper().readValue(body, JSONObject.class);
- } catch (IOException e1) { // NOSONAR
+ gson.fromJson(body, JsonElement.class);
+ } catch (Exception e1) { // NOSONAR
errorList.add(OnapCommandHttpConstants.HTTP_BODY_FAILED_PARSING);
}
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
public class OnapCommandHttpUtils {
static Logger LOG = LoggerFactory.getLogger(OnapCommandHttpUtils.class);
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
/**
* Set argument to param value.
}
}
- public static void normalizeJson(JsonNode node) {
- Iterator<JsonNode> it = node.iterator();
+ public static void normalizeJson(JsonElement node) {
+ Iterator<Entry<String, JsonElement>> it = node.getAsJsonObject().entrySet().iterator();
+
while (it.hasNext()) {
- JsonNode child = it.next();
- if (child.isTextual() && child.asText().equals(""))
+ JsonElement child = it.next().getValue();
+ if (child.isJsonPrimitive() && child.getAsJsonPrimitive().isString() && child.getAsJsonPrimitive().getAsString().equals(""))
it.remove();
- else if (child.isNull())
+ else if (child.isJsonNull())
it.remove();
- else
+ else if (child.isJsonObject())
normalizeJson(child);
+ else if (child.isJsonArray()) {
+ for (JsonElement ele:child.getAsJsonArray()) {
+ if (ele.isJsonObject())
+ normalizeJson(ele);
+ }
+ }
}
}
public static String normalizeJson(String json) throws OnapCommandHttpInvalidRequestBody {
- ObjectMapper mapper = new ObjectMapper();
- JsonNode node;
+ JsonElement node;
try {
- node = mapper.readTree(json);
+ node = gson.fromJson(json,JsonElement.class);
normalizeJson(node);
- return mapper.writeValueAsString(node);
+ return gson.toJson(node);
} catch (Exception e) { //NOSONAR
throw new OnapCommandHttpInvalidRequestBody(e);
}
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j</artifactId>
<version>2.5.6</version>
- </dependency>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+++ /dev/null
-# 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, stdout
-
-log4j.logger.org.onap.cli=DEBUG, 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
<scope>test</scope>
</dependency>
<dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>2.9.4</version>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.8.2</version>
</dependency>
</dependencies>
<build><plugins>
import java.io.IOException;
import java.util.Arrays;
-import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.ObjectWriter;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import java.io.FileWriter;
+
public class MockJsonGenerator {
- public static void generateMocking(MockRequest mockRequest, MockResponse mockResponse,
- String jsonFilePath) throws IOException {
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
+
+ public static void generateMocking(MockRequest mockRequest, MockResponse mockResponse, String jsonFilePath) throws IOException {
MockObject mockObject = new MockObject();
mockObject.setRequest(mockRequest);
mockObject.setResponse(mockResponse);
- ObjectMapper mapper = new ObjectMapper();
- ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter());
- writer.writeValue(new File(jsonFilePath),
- Arrays.asList(mockObject));
+ try(FileWriter writer = new FileWriter(jsonFilePath)){
+ gson.toJson(Arrays.asList(mockObject), writer);
+ }catch (Exception e){ // NOSONAR
+ //
+ }
}
}
import java.net.URL;
import java.util.Map;
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
public class MockRequest {
private String method;
private String uri;
private Map<String, String> headers;
- private JsonNode json;
+ private JsonElement json;
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
public String getMethod() {
return method;
this.headers = headers;
}
- public JsonNode getJson() {
+ public JsonElement getJson() {
return json;
}
public void setJson(String json) throws IOException {
if (!json.isEmpty()) {
try {
- ObjectMapper objectMapper = new ObjectMapper();
- this.json = objectMapper.readTree(json);
+ this.json = gson.fromJson(json,JsonElement.class);
} catch (Exception e) {
- this.json = new ObjectMapper().readTree("{}");
+ this.json = gson.fromJson("{}",JsonElement.class);
}
}
import java.io.IOException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
public class MockResponse {
private int status;
- private JsonNode json;
+ private JsonElement json;
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
public int getStatus() {
return status;
this.status = status;
}
- public JsonNode getJson() {
+ public JsonElement getJson() {
return json;
}
public void setJson(String json) throws IOException {
if (json != null && !json.isEmpty()) {
try {
- ObjectMapper objectMapper = new ObjectMapper();
- this.json = objectMapper.readTree(json);
+ this.json = gson.fromJson(json,JsonElement.class);
} catch (Exception e) {
- this.json = new ObjectMapper().readTree("{}");
+ this.json = gson.fromJson("{}", JsonElement.class);
}
}
}
package org.onap.cli.validation;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.io.File;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
public class OnapValidationTest {
public static final String SAMPLE_VERSION = "open_cli_sample_version";
OnapCli cli = new OnapCli();
private static Logger LOG = LoggerFactory.getLogger(OnapValidationTest.class);
+ private static Gson gson = new GsonBuilder().serializeNulls().create();
private void handle(String[] args) {
cli.resetExitCode();
onapCli.handle();
assertEquals(OnapCliConstants.EXIT_SUCCESS, onapCli.getExitCode());
}
+ @Test
+ public void testOnapCommandSchemaInfoForUnknownFields(){
+ OnapCommandSchemaInfo ocsi = new OnapCommandSchemaInfo();
+ String testExp = "{\"schemaName\":\"testSchema\",\"schemaURI\":\"testUri\",\"unknownField\":\"unknown\"}";
+ ocsi= gson.fromJson(testExp,OnapCommandSchemaInfo.class);
+ assertNotNull(ocsi);
+ }
}