aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommand.java3
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java3
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java6
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/OnapSwaggerCommand.java97
-rw-r--r--framework/src/main/java/org/onap/cli/fw/run/OnapCommandExecutor.java71
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandSchemaLoader.java686
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java710
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommand.java100
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommandTest.java32
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommand.java75
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommandTest.java21
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommand.java79
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommandTest.java21
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommand.java78
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommandTest.java21
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapSwaggerCommandTest.java96
-rw-r--r--framework/src/test/java/org/onap/cli/fw/run/OnapCommandExecutorTest.java38
-rw-r--r--framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java26
-rw-r--r--framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java66
-rw-r--r--main/src/main/java/org/onap/cli/main/OnapCli.java4
-rw-r--r--main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java (renamed from main/src/main/java/org/onap/cli/main/utils/OnapCliUtils.java)119
-rw-r--r--main/src/test/java/org/onap/cli/main/OnapCliMainTest.java4
-rw-r--r--main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java36
23 files changed, 781 insertions, 1611 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
index 87c1ba74..3dfb5c37 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
@@ -39,6 +39,7 @@ import org.onap.cli.fw.output.OnapCommandResult;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
import org.onap.cli.fw.output.OnapCommandResultAttributeScope;
import org.onap.cli.fw.output.ResultType;
+import org.onap.cli.fw.utils.OnapCommandSchemaLoader;
import org.onap.cli.fw.utils.OnapCommandUtils;
/**
@@ -156,7 +157,7 @@ public abstract class OnapCommand {
*/
public void initializeSchema(String schema) throws OnapCommandException {
this.setSchemaName(schema);
- OnapCommandUtils.loadSchema(this, schema, true, false);
+ OnapCommandSchemaLoader.loadSchema(this, schema, true, false);
this.initializeProfileSchema();
this.isInitialzied = true;
}
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java
index 7ff38b64..01ce6247 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java
@@ -34,6 +34,7 @@ import org.onap.cli.fw.error.OnapCommandFailedMocoGenerate;
import org.onap.cli.fw.http.HttpInput;
import org.onap.cli.fw.http.HttpResult;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
+import org.onap.cli.fw.utils.OnapCommandSchemaLoader;
import org.onap.cli.fw.utils.OnapCommandUtils;
import org.onap.cli.http.mock.MockJsonGenerator;
import org.onap.cli.http.mock.MockRequest;
@@ -98,7 +99,7 @@ public class OnapHttpCommand extends OnapCommand {
@Override
protected void initializeProfileSchema() throws OnapCommandException {
- OnapCommandUtils.loadHttpSchema(this, this.getSchemaName(), true, false);
+ OnapCommandSchemaLoader.loadHttpSchema(this, this.getSchemaName(), true, false);
}
@Override
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java
index b3b9f357..c3088c53 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java
@@ -20,7 +20,7 @@ import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.OnapCommandSchema;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.input.OnapCommandParameter;
-import org.onap.cli.fw.utils.OnapCommandUtils;
+import org.onap.cli.fw.utils.OnapCommandSchemaLoader;
import java.util.ArrayList;
import java.util.List;
@@ -43,14 +43,14 @@ public class OnapSchemaValidateCommand extends OnapCommand {
location = location.substring(1);
}
- List<String> error = OnapCommandUtils.loadSchema(new OnapCommand() {
+ List<String> error = OnapCommandSchemaLoader.loadSchema(new OnapCommand() {
@Override
protected void run() throws OnapCommandException {
}
}, location, true, true);
- error.addAll(OnapCommandUtils.loadHttpSchema(new OnapHttpCommand(),
+ error.addAll(OnapCommandSchemaLoader.loadHttpSchema(new OnapHttpCommand(),
location, true, true));
List<String> slNumber = new ArrayList<>();
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapSwaggerCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapSwaggerCommand.java
deleted file mode 100644
index 57fe8412..00000000
--- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapSwaggerCommand.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-package org.onap.cli.fw.cmd;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import org.onap.cli.fw.OnapCommand;
-import org.onap.cli.fw.error.OnapCommandClientInitialzationFailed;
-import org.onap.cli.fw.error.OnapCommandResultInitialzationFailed;
-import org.onap.cli.fw.output.OnapCommandResultAttribute;
-import org.onap.cli.fw.run.OnapCommandExecutor;
-import org.onap.cli.fw.utils.OnapCommandUtils;
-
-public abstract class OnapSwaggerCommand extends OnapCommand {
-
-
- private OnapCommandExecutor cmdExecutor;
-
- public OnapCommandExecutor getExecutor() {
- return cmdExecutor;
- }
-
- public void setExecutor(OnapCommandExecutor executor) {
- this.cmdExecutor = executor;
- }
-
- /**
- * Initialize the given ApiClient object with AUTH token and base path.
- *
- * @param client
- * api client
- * @throws OnapCommandClientInitialzationFailed
- * client initialization failed
- */
- protected <T> T initializeApiClient(T client) throws OnapCommandClientInitialzationFailed {
- try {
- Method basePath = client.getClass().getMethod("setBasePath", String.class);
- //mrkanag set the basepath
- basePath.invoke(client, "/");
-
-// if (this.getAuthToken() != null) {
-// Method apiKey = client.getClass().getMethod("setApiKey", String.class);
-// apiKey.invoke(client, this.getAuthToken());
-// }
- return client;
- } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
- | InvocationTargetException e) {
- throw new OnapCommandClientInitialzationFailed(this.getName(), e);
- }
- }
-
- protected <T> void initializeResult(T obj) throws OnapCommandResultInitialzationFailed {
- this.getResult().setOutput(obj);
- if (obj instanceof List) {
- this.initializeListResult((List) obj);
- } else {
- this.initializeRow(obj);
- }
- }
-
- private <T> void initializeRow(T obj) throws OnapCommandResultInitialzationFailed {
- for (OnapCommandResultAttribute row : this.getResult().getRecords()) {
- String methodName = OnapCommandUtils.formMethodNameFromAttributeName(row.getName(), "get");
- Method get;
- try {
- get = obj.getClass().getMethod(methodName);
- row.getValues().add(get.invoke(obj).toString());
- } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
- | InvocationTargetException e) {
- throw new OnapCommandResultInitialzationFailed(this.getName(), e);
- }
- }
- }
-
- protected <T> void initializeListResult(List<T> rows) throws OnapCommandResultInitialzationFailed {
- this.getResult().setOutput(rows);
- for (T row : rows) {
- this.initializeRow(row);
- }
- }
-}
diff --git a/framework/src/main/java/org/onap/cli/fw/run/OnapCommandExecutor.java b/framework/src/main/java/org/onap/cli/fw/run/OnapCommandExecutor.java
deleted file mode 100644
index a3ff7bc8..00000000
--- a/framework/src/main/java/org/onap/cli/fw/run/OnapCommandExecutor.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-package org.onap.cli.fw.run;
-
-/**
- * Oclip Command executor.
- *
- */
-public class OnapCommandExecutor {
-
- private String apiName;
- private String clientName;
- private String entityName;
- private String methodName;
- private String exceptionName;
-
- public String getApi() {
- return this.apiName;
- }
-
- public void setApi(String api) {
- this.apiName = api;
- }
-
- public String getClient() {
- return this.clientName;
- }
-
- public void setClient(String client) {
- this.clientName = client;
- }
-
- public String getEntity() {
- return entityName;
- }
-
- public void setEntity(String entity) {
- this.entityName = entity;
- }
-
- public String getMethod() {
- return methodName;
- }
-
- public void setMethod(String method) {
- this.methodName = method;
- }
-
- public String getException() {
- return exceptionName;
- }
-
- public void setException(String exception) {
- this.exceptionName = exception;
- }
-
-}
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandSchemaLoader.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandSchemaLoader.java
new file mode 100644
index 00000000..439ec227
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandSchemaLoader.java
@@ -0,0 +1,686 @@
+/*
+ * Copyright 2017 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.
+ */
+
+package org.onap.cli.fw.utils;
+
+import static org.onap.cli.fw.conf.Constants.ATTRIBUTES;
+import static org.onap.cli.fw.conf.Constants.AUTH;
+import static org.onap.cli.fw.conf.Constants.AUTH_VALUES;
+import static org.onap.cli.fw.conf.Constants.BODY;
+import static org.onap.cli.fw.conf.Constants.COMMAND_TYPE_VALUES;
+import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_PASSWORD;
+import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_USERNAME;
+import static org.onap.cli.fw.conf.Constants.DEFAULT_PARAMETER_FILE_NAME;
+import static org.onap.cli.fw.conf.Constants.DEFAULT_PARAMETER_HTTP_FILE_NAME;
+import static org.onap.cli.fw.conf.Constants.DEFAULT_PARAMETER_NO_AUTH;
+import static org.onap.cli.fw.conf.Constants.DEFAULT_VALUE;
+import static org.onap.cli.fw.conf.Constants.DESCRIPTION;
+import static org.onap.cli.fw.conf.Constants.DIRECTION;
+import static org.onap.cli.fw.conf.Constants.HEADERS;
+import static org.onap.cli.fw.conf.Constants.HTTP;
+import static org.onap.cli.fw.conf.Constants.HTTP_MANDATORY_SECTIONS;
+import static org.onap.cli.fw.conf.Constants.HTTP_SECTIONS;
+import static org.onap.cli.fw.conf.Constants.INFO;
+import static org.onap.cli.fw.conf.Constants.INFO_AUTHOR;
+import static org.onap.cli.fw.conf.Constants.INFO_PARAMS_LIST;
+import static org.onap.cli.fw.conf.Constants.INFO_PARAMS_MANDATORY_LIST;
+import static org.onap.cli.fw.conf.Constants.INFO_PRODUCT;
+import static org.onap.cli.fw.conf.Constants.INFO_SERVICE;
+import static org.onap.cli.fw.conf.Constants.INFO_TYPE;
+import static org.onap.cli.fw.conf.Constants.INPUT_PARAMS_LIST;
+import static org.onap.cli.fw.conf.Constants.INPUT_PARAMS_MANDATORY_LIST;
+import static org.onap.cli.fw.conf.Constants.IS_INCLUDE;
+import static org.onap.cli.fw.conf.Constants.IS_OPTIONAL;
+import static org.onap.cli.fw.conf.Constants.IS_SECURED;
+import static org.onap.cli.fw.conf.Constants.LONG_OPTION;
+import static org.onap.cli.fw.conf.Constants.METHOD_TYPE;
+import static org.onap.cli.fw.conf.Constants.MODE;
+import static org.onap.cli.fw.conf.Constants.MODE_VALUES;
+import static org.onap.cli.fw.conf.Constants.MULTIPART_ENTITY_NAME;
+import static org.onap.cli.fw.conf.Constants.NAME;
+import static org.onap.cli.fw.conf.Constants.OPEN_CLI_SCHEMA_VERSION;
+import static org.onap.cli.fw.conf.Constants.PARAMETERS;
+import static org.onap.cli.fw.conf.Constants.QUERIES;
+import static org.onap.cli.fw.conf.Constants.REQUEST;
+import static org.onap.cli.fw.conf.Constants.RESULTS;
+import static org.onap.cli.fw.conf.Constants.RESULT_MAP;
+import static org.onap.cli.fw.conf.Constants.RESULT_PARAMS_LIST;
+import static org.onap.cli.fw.conf.Constants.RESULT_PARAMS_MANDATORY_LIST;
+import static org.onap.cli.fw.conf.Constants.SAMPLE_RESPONSE;
+import static org.onap.cli.fw.conf.Constants.SCHEMA_PATH_PATERN;
+import static org.onap.cli.fw.conf.Constants.SCOPE;
+import static org.onap.cli.fw.conf.Constants.SERVICE;
+import static org.onap.cli.fw.conf.Constants.SERVICE_PARAMS_LIST;
+import static org.onap.cli.fw.conf.Constants.SERVICE_PARAMS_MANDATORY_LIST;
+import static org.onap.cli.fw.conf.Constants.SHORT_OPTION;
+import static org.onap.cli.fw.conf.Constants.SUCCESS_CODES;
+import static org.onap.cli.fw.conf.Constants.TOP_LEVEL_MANDATORY_LIST;
+import static org.onap.cli.fw.conf.Constants.TOP_LEVEL_PARAMS_LIST;
+import static org.onap.cli.fw.conf.Constants.TYPE;
+import static org.onap.cli.fw.conf.Constants.URI;
+import static org.onap.cli.fw.conf.Constants.VERSION;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.onap.cli.fw.OnapCommand;
+import org.onap.cli.fw.ad.OnapService;
+import org.onap.cli.fw.cmd.CommandType;
+import org.onap.cli.fw.cmd.OnapHttpCommand;
+import org.onap.cli.fw.conf.OnapCommandConfg;
+import org.onap.cli.fw.error.OnapCommandException;
+import org.onap.cli.fw.error.OnapCommandInvalidSchema;
+import org.onap.cli.fw.error.OnapCommandInvalidSchemaVersion;
+import org.onap.cli.fw.error.OnapCommandParameterNameConflict;
+import org.onap.cli.fw.error.OnapCommandParameterOptionConflict;
+import org.onap.cli.fw.error.OnapCommandSchemaNotFound;
+import org.onap.cli.fw.info.OnapCommandInfo;
+import org.onap.cli.fw.input.OnapCommandParameter;
+import org.onap.cli.fw.input.ParameterType;
+import org.onap.cli.fw.output.OnapCommandResult;
+import org.onap.cli.fw.output.OnapCommandResultAttribute;
+import org.onap.cli.fw.output.OnapCommandResultAttributeScope;
+import org.onap.cli.fw.output.PrintDirection;
+import org.springframework.core.io.Resource;
+import org.yaml.snakeyaml.Yaml;
+
+public class OnapCommandSchemaLoader {
+
+ /**
+ * Validates schema version.
+ *
+ * @param schemaName schema name
+ * @param version schema version
+ * @return map
+ * @throws OnapCommandInvalidSchemaVersion invalid schema version exception
+ * @throws OnapCommandInvalidSchema invalid schema
+ * @throws OnapCommandSchemaNotFound schema not found
+ */
+ public static Map<String, ?> validateSchemaVersion(String schemaName, String version) throws OnapCommandException {
+ InputStream inputStream = OnapCommandUtils.class.getClassLoader().getResourceAsStream(schemaName);
+
+ try {
+ Resource resource = OnapCommandUtils.findResource(schemaName, SCHEMA_PATH_PATERN);
+
+ if (resource != null) {
+ inputStream = resource.getInputStream();
+ }
+
+ } catch (IOException e) {
+ throw new OnapCommandSchemaNotFound(schemaName, e);
+ }
+ if (inputStream == null) {
+ inputStream = OnapCommandUtils.loadSchemaFromFile(schemaName);
+ }
+
+ Map<String, ?> values = null;
+ try {
+ values = (Map<String, ?>) new Yaml().load(inputStream);
+ } catch (Exception e) {
+ throw new OnapCommandInvalidSchema(schemaName, e);
+ }
+ String schemaVersion = "";
+ if (values.keySet().contains(OPEN_CLI_SCHEMA_VERSION)) {
+ Object obj = values.get(OPEN_CLI_SCHEMA_VERSION);
+ schemaVersion = obj.toString();
+ }
+
+ if (!version.equals(schemaVersion)) {
+ throw new OnapCommandInvalidSchemaVersion(schemaVersion);
+ }
+
+ return values;
+ }
+
+ /**
+ * Retrieve OnapCommand from schema.
+ *
+ * @param cmd OnapCommand
+ * @param schemaName schema name
+ * @param includeDefault include if default
+ * @param validateSchema flag to represent validation
+ * @throws OnapCommandException on error
+ */
+ public static List<String> loadSchema(OnapCommand cmd, String schemaName, boolean includeDefault,
+ boolean validateSchema) throws OnapCommandException {
+ try {
+ List<String> errors = new ArrayList<>();
+ if (includeDefault) {
+ Map<String, ?> defaultParameterMap = includeDefault ?
+ validateSchemaVersion(DEFAULT_PARAMETER_FILE_NAME, cmd.getSchemaVersion()) : new HashMap<>();
+ errors.addAll(OnapCommandSchemaLoader.parseSchema(cmd, defaultParameterMap, validateSchema));
+ }
+
+ Map<String, List<Map<String, String>>> commandYamlMap =
+ (Map<String, List<Map<String, String>>>)validateSchemaVersion(schemaName, cmd.getSchemaVersion());
+
+ errors.addAll(OnapCommandSchemaLoader.parseSchema(cmd, commandYamlMap, validateSchema));
+
+ return errors;
+ } catch (OnapCommandException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new OnapCommandInvalidSchema(schemaName, e);
+ }
+ }
+
+ 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, ?> defaultParameterMap = includeDefault ?
+ validateSchemaVersion(DEFAULT_PARAMETER_HTTP_FILE_NAME, cmd.getSchemaVersion()) : new HashMap<>();
+ errors.addAll(OnapCommandSchemaLoader.parseSchema(cmd, defaultParameterMap, validateSchema));
+ }
+
+ Map<String, List<Map<String, String>>> commandYamlMap =
+ (Map<String, List<Map<String, String>>>)validateSchemaVersion(schemaName, cmd.getSchemaVersion());
+
+ errors.addAll(OnapCommandSchemaLoader.parseHttpSchema(cmd, commandYamlMap, validateSchema));
+
+ return errors;
+
+ } catch (OnapCommandException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new OnapCommandInvalidSchema(schemaName, e);
+ }
+ }
+
+ static List<String> parseSchema(OnapCommand cmd,
+ final Map<String, ?> values,
+ boolean validate) throws OnapCommandException {
+
+ List<String> exceptionList = new ArrayList<>();
+ List<String> shortOptions = new ArrayList<>();
+ List<String> longOptions = new ArrayList<>();
+
+ if (validate) {
+ OnapCommandUtils.validateTags(exceptionList, (Map<String, Object>) values, OnapCommandConfg.getSchemaAttrInfo(TOP_LEVEL_PARAMS_LIST),
+ OnapCommandConfg.getSchemaAttrInfo(TOP_LEVEL_MANDATORY_LIST), "root level");
+ }
+
+
+ List<String> sections = Arrays.asList(NAME, DESCRIPTION, INFO, PARAMETERS, RESULTS);
+
+ for (String key : sections) {
+
+ switch (key) {
+ case NAME:
+ Object val = values.get(key);
+ if (val != null) {
+ cmd.setName(val.toString());
+ }
+ break;
+
+ case DESCRIPTION:
+ Object description = values.get(key);
+ if (description != null) {
+ cmd.setDescription(description.toString());
+ }
+ break;
+
+ case INFO:
+ Map<String, String> infoMap = (Map<String, String>) values.get(key);
+
+ if (infoMap != null) {
+ if (validate) {
+ OnapCommandUtils.validateTags(exceptionList, (Map<String, Object>) values.get(key),
+ OnapCommandConfg.getSchemaAttrInfo(INFO_PARAMS_LIST),
+ OnapCommandConfg.getSchemaAttrInfo(INFO_PARAMS_MANDATORY_LIST), INFO);
+
+ HashMap<String, String> validationMap = new HashMap<>();
+ validationMap.put(INFO_TYPE, COMMAND_TYPE_VALUES);
+
+ for (String secKey : validationMap.keySet()) {
+ if (infoMap.containsKey(secKey)) {
+ Object obj = infoMap.get(secKey);
+ if (obj == null) {
+ exceptionList.add("Attribute '" + secKey + "' under '" + INFO + "' is empty");
+ } else {
+ String value = String.valueOf(obj);
+ if (!OnapCommandConfg.getSchemaAttrInfo(validationMap.get(secKey)).contains(value)) {
+ exceptionList.add("Attribute '" + secKey + "' contains invalid value. Valide values are "
+ + OnapCommandConfg.getSchemaAttrInfo(validationMap.get(key))); //
+ }
+ }
+ }
+ }
+ }
+
+ OnapCommandInfo info = new OnapCommandInfo();
+
+ for (Map.Entry<String, String> entry1 : infoMap.entrySet()) {
+ String key1 = entry1.getKey();
+
+ switch (key1) {
+ case INFO_PRODUCT:
+ info.setProduct(infoMap.get(key1));
+ break;
+
+ case INFO_SERVICE:
+ info.setService(infoMap.get(key1).toString());
+ break;
+
+ case INFO_TYPE:
+ Object obj = infoMap.get(key1);
+ info.setCommandType(CommandType.get(obj.toString()));
+ break;
+
+ case INFO_AUTHOR:
+ Object mode = infoMap.get(key1);
+ info.setAuthor(mode.toString());
+ break;
+ }
+ }
+
+ cmd.setInfo(info);
+ }
+ break;
+
+ case PARAMETERS:
+
+ List<Map<String, String>> parameters = (List) values.get(key);
+
+ if (parameters != null) {
+ Set<String> names = new HashSet<>();
+
+ //To support overriding of the parameters, if command is already
+ //having the same named parameters, means same parameter is
+ //Overridden from included template into current template
+ Set<String> existingParamNames = cmd.getParametersMap().keySet();
+
+ for (Map<String, String> parameter : parameters) {
+ boolean isOverriding = false;
+ OnapCommandParameter param = new OnapCommandParameter();
+
+ //Override the parameters from its base such as default parameters list
+ if (existingParamNames.contains(parameter.getOrDefault(NAME, ""))) {
+ param = cmd.getParametersMap().get(parameter.getOrDefault(NAME, ""));
+ isOverriding = true;
+ }
+
+ if (validate) {
+ OnapCommandUtils.validateTags(exceptionList, parameter, OnapCommandConfg.getSchemaAttrInfo(INPUT_PARAMS_LIST),
+ OnapCommandConfg.getSchemaAttrInfo(INPUT_PARAMS_MANDATORY_LIST), PARAMETERS);
+ }
+
+ for (Map.Entry<String, String> entry1 : parameter.entrySet()) {
+ String key2 = entry1.getKey();
+
+ switch (key2) {
+ case NAME:
+ if (names.contains(parameter.get(key2))) {
+ OnapCommandUtils.throwOrCollect(new OnapCommandParameterNameConflict(parameter.get(key2)), exceptionList, validate);
+ } else {
+ names.add(parameter.get(key2));
+ }
+
+ param.setName(parameter.get(key2));
+ break;
+
+ case DESCRIPTION:
+ param.setDescription(parameter.get(key2));
+ break;
+
+ case SHORT_OPTION:
+ if (shortOptions.contains(parameter.get(key2))) {
+ OnapCommandUtils.throwOrCollect(new OnapCommandParameterOptionConflict(parameter.get(key2)), exceptionList, validate);
+ }
+ shortOptions.add(parameter.get(key2));
+ param.setShortOption(parameter.get(key2));
+ break;
+
+ case LONG_OPTION:
+ if (longOptions.contains(parameter.get(key2))) {
+ OnapCommandUtils.throwOrCollect(new OnapCommandParameterOptionConflict(parameter.get(key2)), exceptionList, validate);
+ }
+ longOptions.add(parameter.get(key2));
+ param.setLongOption(parameter.get(key2));
+ break;
+
+ case DEFAULT_VALUE:
+ Object obj = parameter.get(key2);
+ param.setDefaultValue(obj.toString());
+ break;
+
+ case TYPE:
+ try {
+ param.setParameterType(ParameterType.get(parameter.get(key2)));
+ } catch (OnapCommandException ex) {
+ OnapCommandUtils.throwOrCollect(ex, exceptionList, validate);
+ }
+ break;
+
+ case IS_OPTIONAL:
+ if (validate) {
+ if (!OnapCommandUtils.validateBoolean(String.valueOf(parameter.get(key2)))) {
+ exceptionList.add(OnapCommandUtils.invalidBooleanValueMessage(parameter.get(NAME),
+ IS_SECURED, parameter.get(key2)));
+ }
+ }
+ if ("true".equalsIgnoreCase(String.valueOf(parameter.get(key2)))) {
+ param.setOptional(true);
+ } else {
+ param.setOptional(false);
+ }
+ break;
+
+ case IS_SECURED:
+ if (validate) {
+ if (!OnapCommandUtils.validateBoolean(String.valueOf(parameter.get(key2)))) {
+ exceptionList.add(OnapCommandUtils.invalidBooleanValueMessage(parameter.get(NAME),
+ IS_SECURED, parameter.get(key2)));
+ }
+ }
+
+ if ("true".equalsIgnoreCase(String.valueOf(parameter.get(key2)))) {
+ param.setSecured(true);
+ } else {
+ param.setSecured(false);
+ }
+ break;
+
+ case IS_INCLUDE:
+ if (validate) {
+ if (!OnapCommandUtils.validateBoolean(String.valueOf(parameter.get(key2)))) {
+ exceptionList.add(OnapCommandUtils.invalidBooleanValueMessage(parameter.get(NAME),
+ IS_INCLUDE, parameter.get(key2)));
+ }
+ }
+
+ if ("true".equalsIgnoreCase(String.valueOf(parameter.get(key2)))) {
+ param.setInclude(true);
+ } else {
+ param.setInclude(false);
+ }
+ break;
+ }
+ }
+
+ if ( !isOverriding) {
+ cmd.getParameters().add(param);
+ } else {
+ cmd.getParametersMap().replace(param.getName(), param);
+ }
+ }
+ }
+ break;
+
+ case RESULTS:
+ Map<String, ?> valueMap = (Map<String, ?>) values.get(key);
+ if (valueMap != null) {
+ OnapCommandResult result = new OnapCommandResult();
+ for (Map.Entry<String, ?> entry1 : valueMap.entrySet()) {
+ String key3 = entry1.getKey();
+
+ switch (key3) {
+ case DIRECTION:
+ try {
+ result.setPrintDirection(PrintDirection.get((String) valueMap.get(key3)));
+ } catch (OnapCommandException ex) {
+ OnapCommandUtils.throwOrCollect(ex, exceptionList, validate);
+ }
+ break;
+
+ case ATTRIBUTES:
+ List<Map<String, String>> attrs = (ArrayList) valueMap.get(key3);
+
+ for (Map<String, String> map : attrs) {
+ OnapCommandResultAttribute attr = new OnapCommandResultAttribute();
+ if (validate) {
+ OnapCommandUtils.validateTags(exceptionList, map, OnapCommandConfg.getSchemaAttrInfo(RESULT_PARAMS_LIST),
+ OnapCommandConfg.getSchemaAttrInfo(RESULT_PARAMS_MANDATORY_LIST), ATTRIBUTES);
+ }
+
+ Set<String> resultParamNames = new HashSet<>();
+
+ for (Map.Entry<String, String> entry4 : map.entrySet()) {
+ String key4 = entry4.getKey();
+
+ switch (key4) {
+ case NAME:
+ if (resultParamNames.contains(map.get(key4))) {
+ exceptionList.add("Attribute name='" + map.get(key4) + "' under '"
+ + ATTRIBUTES + ":' is already used, Take different one.");
+
+ } else {
+ attr.setName(map.get(key4));
+ resultParamNames.add(map.get(key4));
+ }
+ break;
+
+ case DESCRIPTION:
+ attr.setDescription(map.get(key4));
+ break;
+
+ case SCOPE:
+ try {
+ attr.setScope(OnapCommandResultAttributeScope.get(map.get(key4)));
+ } catch (OnapCommandException ex) {
+ OnapCommandUtils.throwOrCollect(ex, exceptionList, validate);
+ }
+ break;
+
+ case TYPE:
+ try {
+ attr.setType(ParameterType.get(map.get(key4)));
+ } catch (OnapCommandException ex) {
+ OnapCommandUtils.throwOrCollect(ex, exceptionList, validate);
+ }
+ break;
+
+ case DEFAULT_VALUE:
+ Object obj = map.get(key4);
+ attr.setDefaultValue(obj.toString());
+ break;
+
+ case IS_SECURED:
+ if (validate) {
+ if (!OnapCommandUtils.validateBoolean(String.valueOf(map.get(key4)))) {
+ exceptionList.add(OnapCommandUtils.invalidBooleanValueMessage(ATTRIBUTES,
+ IS_SECURED, map.get(key4)));
+ }
+ }
+ if ("true".equals(String.valueOf(map.get(key4)))) {
+ attr.setSecured(true);
+ } else {
+ attr.setSecured(false);
+ }
+ break;
+ }
+
+ }
+ result.getRecords().add(attr);
+ }
+ break;
+ }
+ }
+ cmd.setResult(result);
+ }
+ break;
+ }
+ }
+ return exceptionList;
+ }
+
+ /**
+ * Load the schema.
+ *
+ * @param cmd
+ * OnapHttpCommand
+ * @param schemaName
+ * schema name
+ * @throws OnapCommandException
+ * on error
+ */
+ static ArrayList<String> parseHttpSchema(OnapHttpCommand cmd,
+ final Map<String, ?> values,
+ boolean validate) throws OnapCommandException {
+ ArrayList<String> errorList = new ArrayList<>();
+ try {
+ Map<String, ?> valMap = (Map<String, ?>) values.get(HTTP);
+
+ if (valMap != null) {
+ if (validate) {
+ OnapCommandUtils.validateTags(errorList, valMap, OnapCommandConfg.getSchemaAttrInfo(HTTP_SECTIONS),
+ OnapCommandConfg.getSchemaAttrInfo(HTTP_MANDATORY_SECTIONS), PARAMETERS);
+ errorList.addAll(OnapCommandUtils.validateHttpSchemaSection(values));
+ }
+ for (Map.Entry<String, ?> entry1 : valMap.entrySet()) {
+ String key1 = entry1.getKey();
+
+ switch (key1) {
+ case REQUEST:
+ Map<String, ?> map = (Map<String, ?>) valMap.get(key1);
+
+ for (Map.Entry<String, ?> entry2 : map.entrySet()) {
+ try {
+ String key2 = entry2.getKey();
+
+ switch (key2) {
+ case URI:
+ Object obj = map.get(key2);
+ cmd.getInput().setUri(obj.toString());
+ break;
+ case METHOD_TYPE:
+ Object method = map.get(key2);
+ cmd.getInput().setMethod(method.toString());
+ break;
+ case BODY:
+ Object body = map.get(key2);
+ cmd.getInput().setBody(body.toString());
+ break;
+ case HEADERS:
+ Map<String, String> head = (Map<String, String>) map.get(key2);
+ cmd.getInput().setReqHeaders(head);
+ break;
+ case QUERIES:
+ Map<String, String> query = (Map<String, String>) map.get(key2);
+
+ cmd.getInput().setReqQueries(query);
+ break;
+ case MULTIPART_ENTITY_NAME:
+ Object multipartEntityName = map.get(key2);
+ cmd.getInput().setMultipartEntityName(multipartEntityName.toString());
+ break;
+ }
+ }catch (Exception ex) {
+ OnapCommandUtils.throwOrCollect(new OnapCommandInvalidSchema(cmd.getSchemaName(), ex), errorList, validate);
+ }
+ }
+ break;
+
+ case SERVICE:
+ Map<String, String> serviceMap = (Map<String, String>) valMap.get(key1);
+
+ if (serviceMap != null) {
+ if (validate) {
+ OnapCommandUtils.validateTags(errorList, (Map<String, Object>) valMap.get(key1),
+ OnapCommandConfg.getSchemaAttrInfo(SERVICE_PARAMS_LIST),
+ OnapCommandConfg.getSchemaAttrInfo(SERVICE_PARAMS_MANDATORY_LIST), SERVICE);
+
+ HashMap<String, String> validationMap = new HashMap<>();
+ validationMap.put(AUTH, AUTH_VALUES);
+ validationMap.put(MODE, MODE_VALUES);
+
+ for (String secKey : validationMap.keySet()) {
+ if (serviceMap.containsKey(secKey)) {
+ Object obj = serviceMap.get(secKey);
+ if (obj == null) {
+ errorList.add("Attribute '" + secKey + "' under '" + SERVICE + "' is empty");
+ } else {
+ String value = String.valueOf(obj);
+ if (!OnapCommandConfg.getSchemaAttrInfo(validationMap.get(secKey)).contains(value)) {
+ errorList.add("Attribute '" + secKey + "' contains invalid value. Valide values are "
+ + OnapCommandConfg.getSchemaAttrInfo(validationMap.get(key1))); //
+ }
+ }
+ }
+ }
+ }
+
+ OnapService srv = new OnapService();
+
+ for (Map.Entry<String, String> entry : serviceMap.entrySet()) {
+ String key = entry.getKey();
+
+ switch (key) {
+ case NAME:
+ srv.setName(serviceMap.get(key));
+ break;
+
+ case VERSION:
+ srv.setVersion(serviceMap.get(key).toString());
+ break;
+
+ case AUTH:
+ Object obj = serviceMap.get(key);
+ srv.setAuthType(obj.toString());
+
+ //On None type, username, password and no_auth are invalid
+ if (srv.isNoAuth()) {
+ cmd.getParametersMap().get(DEAFULT_PARAMETER_USERNAME).setInclude(false);
+ cmd.getParametersMap().get(DEAFULT_PARAMETER_PASSWORD).setInclude(false);
+ cmd.getParametersMap().get(DEFAULT_PARAMETER_NO_AUTH).setInclude(false);
+ }
+ break;
+
+ case MODE:
+ Object mode = serviceMap.get(key);
+ srv.setMode(mode.toString());
+ break;
+ }
+ }
+ cmd.setService(srv);
+ }
+ break;
+
+ case SUCCESS_CODES:
+ if (validate) {
+ OnapCommandUtils.validateHttpSccessCodes(errorList, (List<Object>) valMap.get(key1));
+ }
+ cmd.setSuccessStatusCodes((ArrayList) valMap.get(key1));
+ break;
+
+ case RESULT_MAP:
+ if (validate) {
+ OnapCommandUtils.validateHttpResultMap(errorList, values);
+ }
+ cmd.setResultMap((Map<String, String>) valMap.get(key1));
+ break;
+
+ case SAMPLE_RESPONSE:
+ // (mrkanag) implement sample response handling
+ break;
+ }
+ }
+ }
+ }catch (OnapCommandException e) {
+ OnapCommandUtils.throwOrCollect(e, errorList, validate);
+ }
+ return errorList;
+ }
+
+}
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 0f64ed3a..9a6f6366 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
@@ -16,56 +16,22 @@
package org.onap.cli.fw.utils;
-import static org.onap.cli.fw.conf.Constants.API;
import static org.onap.cli.fw.conf.Constants.ATTRIBUTES;
-import static org.onap.cli.fw.conf.Constants.AUTH;
-import static org.onap.cli.fw.conf.Constants.AUTH_VALUES;
import static org.onap.cli.fw.conf.Constants.BODY;
import static org.onap.cli.fw.conf.Constants.BOOLEAN_VALUE;
-import static org.onap.cli.fw.conf.Constants.CLIENT;
-import static org.onap.cli.fw.conf.Constants.COMMAND_TYPE_VALUES;
import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY;
import static org.onap.cli.fw.conf.Constants.DATA_PATH_JSON_PATTERN;
-import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_PASSWORD;
-import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_USERNAME;
-import static org.onap.cli.fw.conf.Constants.DEFAULT_PARAMETER_FILE_NAME;
-import static org.onap.cli.fw.conf.Constants.DEFAULT_PARAMETER_HTTP_FILE_NAME;
-import static org.onap.cli.fw.conf.Constants.DEFAULT_PARAMETER_NO_AUTH;
-import static org.onap.cli.fw.conf.Constants.DEFAULT_VALUE;
import static org.onap.cli.fw.conf.Constants.DESCRIPTION;
-import static org.onap.cli.fw.conf.Constants.DIRECTION;
import static org.onap.cli.fw.conf.Constants.DISCOVERY_FILE;
-import static org.onap.cli.fw.conf.Constants.ENTITY;
-import static org.onap.cli.fw.conf.Constants.EXCEPTION;
-import static org.onap.cli.fw.conf.Constants.EXECUTOR;
import static org.onap.cli.fw.conf.Constants.HEADERS;
import static org.onap.cli.fw.conf.Constants.HTTP;
import static org.onap.cli.fw.conf.Constants.HTTP_BODY_FAILED_PARSING;
import static org.onap.cli.fw.conf.Constants.HTTP_BODY_JSON_EMPTY;
-import static org.onap.cli.fw.conf.Constants.HTTP_MANDATORY_SECTIONS;
import static org.onap.cli.fw.conf.Constants.HTTP_METHODS;
import static org.onap.cli.fw.conf.Constants.HTTP_REQUEST_MANDATORY_PARAMS;
import static org.onap.cli.fw.conf.Constants.HTTP_REQUEST_PARAMS;
-import static org.onap.cli.fw.conf.Constants.HTTP_SECTIONS;
import static org.onap.cli.fw.conf.Constants.HTTP_SUCCESS_CODE_INVALID;
-import static org.onap.cli.fw.conf.Constants.INFO;
-import static org.onap.cli.fw.conf.Constants.INFO_AUTHOR;
-import static org.onap.cli.fw.conf.Constants.INFO_PARAMS_LIST;
-import static org.onap.cli.fw.conf.Constants.INFO_PARAMS_MANDATORY_LIST;
-import static org.onap.cli.fw.conf.Constants.INFO_PRODUCT;
-import static org.onap.cli.fw.conf.Constants.INFO_SERVICE;
-import static org.onap.cli.fw.conf.Constants.INFO_TYPE;
-import static org.onap.cli.fw.conf.Constants.INPUT_PARAMS_LIST;
-import static org.onap.cli.fw.conf.Constants.INPUT_PARAMS_MANDATORY_LIST;
-import static org.onap.cli.fw.conf.Constants.IS_INCLUDE;
-import static org.onap.cli.fw.conf.Constants.IS_OPTIONAL;
-import static org.onap.cli.fw.conf.Constants.IS_SECURED;
-import static org.onap.cli.fw.conf.Constants.LONG_OPTION;
import static org.onap.cli.fw.conf.Constants.METHOD;
-import static org.onap.cli.fw.conf.Constants.METHOD_TYPE;
-import static org.onap.cli.fw.conf.Constants.MODE;
-import static org.onap.cli.fw.conf.Constants.MODE_VALUES;
-import static org.onap.cli.fw.conf.Constants.MULTIPART_ENTITY_NAME;
import static org.onap.cli.fw.conf.Constants.NAME;
import static org.onap.cli.fw.conf.Constants.OPEN_CLI_SCHEMA_VERSION;
import static org.onap.cli.fw.conf.Constants.PARAMETERS;
@@ -73,24 +39,11 @@ import static org.onap.cli.fw.conf.Constants.QUERIES;
import static org.onap.cli.fw.conf.Constants.REQUEST;
import static org.onap.cli.fw.conf.Constants.RESULTS;
import static org.onap.cli.fw.conf.Constants.RESULT_MAP;
-import static org.onap.cli.fw.conf.Constants.RESULT_PARAMS_LIST;
-import static org.onap.cli.fw.conf.Constants.RESULT_PARAMS_MANDATORY_LIST;
-import static org.onap.cli.fw.conf.Constants.SAMPLE_RESPONSE;
import static org.onap.cli.fw.conf.Constants.SCHEMA_DIRECTORY;
import static org.onap.cli.fw.conf.Constants.SCHEMA_FILE_NOT_EXIST;
import static org.onap.cli.fw.conf.Constants.SCHEMA_FILE_WRONG_EXTN;
import static org.onap.cli.fw.conf.Constants.SCHEMA_PATH_PATERN;
-import static org.onap.cli.fw.conf.Constants.SCOPE;
-import static org.onap.cli.fw.conf.Constants.SERVICE;
-import static org.onap.cli.fw.conf.Constants.SERVICE_PARAMS_LIST;
-import static org.onap.cli.fw.conf.Constants.SERVICE_PARAMS_MANDATORY_LIST;
-import static org.onap.cli.fw.conf.Constants.SHORT_OPTION;
-import static org.onap.cli.fw.conf.Constants.SUCCESS_CODES;
-import static org.onap.cli.fw.conf.Constants.TOP_LEVEL_MANDATORY_LIST;
-import static org.onap.cli.fw.conf.Constants.TOP_LEVEL_PARAMS_LIST;
-import static org.onap.cli.fw.conf.Constants.TYPE;
import static org.onap.cli.fw.conf.Constants.URI;
-import static org.onap.cli.fw.conf.Constants.VERSION;
import java.io.File;
import java.io.FileInputStream;
@@ -114,10 +67,7 @@ import java.util.jar.Manifest;
import java.util.stream.Collectors;
import org.onap.cli.fw.OnapCommand;
-import org.onap.cli.fw.ad.OnapService;
-import org.onap.cli.fw.cmd.CommandType;
import org.onap.cli.fw.cmd.OnapHttpCommand;
-import org.onap.cli.fw.cmd.OnapSwaggerCommand;
import org.onap.cli.fw.conf.Constants;
import org.onap.cli.fw.conf.OnapCommandConfg;
import org.onap.cli.fw.error.OnapCommandDiscoveryFailed;
@@ -126,23 +76,15 @@ import org.onap.cli.fw.error.OnapCommandHelpFailed;
import org.onap.cli.fw.error.OnapCommandHttpHeaderNotFound;
import org.onap.cli.fw.error.OnapCommandHttpInvalidResponseBody;
import org.onap.cli.fw.error.OnapCommandHttpInvalidResultMap;
-import org.onap.cli.fw.error.OnapCommandInvalidParameterType;
import org.onap.cli.fw.error.OnapCommandInvalidParameterValue;
-import org.onap.cli.fw.error.OnapCommandInvalidPrintDirection;
-import org.onap.cli.fw.error.OnapCommandInvalidResultAttributeScope;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
-import org.onap.cli.fw.error.OnapCommandInvalidSchemaVersion;
import org.onap.cli.fw.error.OnapCommandLoadProfileFailed;
-import org.onap.cli.fw.error.OnapCommandParameterNameConflict;
import org.onap.cli.fw.error.OnapCommandParameterNotFound;
-import org.onap.cli.fw.error.OnapCommandParameterOptionConflict;
import org.onap.cli.fw.error.OnapCommandPersistProfileFailed;
import org.onap.cli.fw.error.OnapCommandResultEmpty;
import org.onap.cli.fw.error.OnapCommandResultMapProcessingFailed;
-import org.onap.cli.fw.error.OnapCommandSchemaNotFound;
import org.onap.cli.fw.http.HttpInput;
import org.onap.cli.fw.http.HttpResult;
-import org.onap.cli.fw.info.OnapCommandInfo;
import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.input.ParameterType;
import org.onap.cli.fw.input.cache.Param;
@@ -151,7 +93,6 @@ import org.onap.cli.fw.output.OnapCommandResultAttribute;
import org.onap.cli.fw.output.OnapCommandResultAttributeScope;
import org.onap.cli.fw.output.PrintDirection;
import org.onap.cli.fw.output.ResultType;
-import org.onap.cli.fw.run.OnapCommandExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
@@ -179,53 +120,7 @@ public class OnapCommandUtils {
}
- /**
- * Validates schema version.
- *
- * @param schemaName schema name
- * @param version schema version
- * @return map
- * @throws OnapCommandInvalidSchemaVersion invalid schema version exception
- * @throws OnapCommandInvalidSchema invalid schema
- * @throws OnapCommandSchemaNotFound schema not found
- */
- public static Map<String, ?> validateSchemaVersion(String schemaName, String version) throws OnapCommandException {
- InputStream inputStream = OnapCommandUtils.class.getClassLoader().getResourceAsStream(schemaName);
-
- try {
- Resource resource = findResource(schemaName, SCHEMA_PATH_PATERN);
-
- if (resource != null) {
- inputStream = resource.getInputStream();
- }
-
- } catch (IOException e) {
- throw new OnapCommandSchemaNotFound(schemaName, e);
- }
- if (inputStream == null) {
- inputStream = loadSchemaFromFile(schemaName);
- }
-
- Map<String, ?> values = null;
- try {
- values = (Map<String, ?>) new Yaml().load(inputStream);
- } catch (Exception e) {
- throw new OnapCommandInvalidSchema(schemaName, e);
- }
- String schemaVersion = "";
- if (values.keySet().contains(OPEN_CLI_SCHEMA_VERSION)) {
- Object obj = values.get(OPEN_CLI_SCHEMA_VERSION);
- schemaVersion = obj.toString();
- }
-
- if (!version.equals(schemaVersion)) {
- throw new OnapCommandInvalidSchemaVersion(schemaVersion);
- }
-
- return values;
- }
-
- private static InputStream loadSchemaFromFile(String schemaLocation) throws OnapCommandInvalidSchema {
+ static InputStream loadSchemaFromFile(String schemaLocation) throws OnapCommandInvalidSchema {
File schemaFile = new File(schemaLocation);
try {
FileInputStream inputFileStream = new FileInputStream(schemaFile);
@@ -242,594 +137,7 @@ public class OnapCommandUtils {
}
}
- /**
- * Retrieve OnapCommand from schema.
- *
- * @param cmd OnapCommand
- * @param schemaName schema name
- * @param includeDefault include if default
- * @param validateSchema flag to represent validation
- * @throws OnapCommandException on error
- */
- public static List<String> loadSchema(OnapCommand cmd, String schemaName, boolean includeDefault,
- boolean validateSchema) throws OnapCommandException {
- try {
- List<String> errors = new ArrayList<>();
- if (includeDefault) {
- Map<String, ?> defaultParameterMap = includeDefault ?
- validateSchemaVersion(DEFAULT_PARAMETER_FILE_NAME, cmd.getSchemaVersion()) : new HashMap<>();
- errors.addAll(parseSchema(cmd, defaultParameterMap, validateSchema));
- }
-
- Map<String, List<Map<String, String>>> commandYamlMap =
- (Map<String, List<Map<String, String>>>)validateSchemaVersion(schemaName, cmd.getSchemaVersion());
-
- errors.addAll(parseSchema(cmd, commandYamlMap, validateSchema));
-
- return errors;
- } catch (OnapCommandException e) {
- throw e;
- } catch (Exception e) {
- throw new OnapCommandInvalidSchema(schemaName, e);
- }
- }
-
-
- 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, ?> defaultParameterMap = includeDefault ?
- validateSchemaVersion(DEFAULT_PARAMETER_HTTP_FILE_NAME, cmd.getSchemaVersion()) : new HashMap<>();
- errors.addAll(parseSchema(cmd, defaultParameterMap, validateSchema));
- }
-
- Map<String, List<Map<String, String>>> commandYamlMap =
- (Map<String, List<Map<String, String>>>)validateSchemaVersion(schemaName, cmd.getSchemaVersion());
-
- errors.addAll(parseHttpSchema(cmd, commandYamlMap, validateSchema));
-
- return errors;
-
- } catch (OnapCommandException e) {
- throw e;
- } catch (Exception e) {
- throw new OnapCommandInvalidSchema(schemaName, e);
- }
- }
-
- private static List<String> parseSchema(OnapCommand cmd,
- final Map<String, ?> values,
- boolean validate) throws OnapCommandException {
-
- List<String> exceptionList = new ArrayList<>();
- List<String> shortOptions = new ArrayList<>();
- List<String> longOptions = new ArrayList<>();
-
- if (validate) {
- validateTags(exceptionList, (Map<String, Object>) values, OnapCommandConfg.getSchemaAttrInfo(TOP_LEVEL_PARAMS_LIST),
- OnapCommandConfg.getSchemaAttrInfo(TOP_LEVEL_MANDATORY_LIST), "root level");
- }
-
-
- List<String> sections = Arrays.asList(NAME, DESCRIPTION, INFO, PARAMETERS, RESULTS);
-
- for (String key : sections) {
-
- switch (key) {
- case NAME:
- Object val = values.get(key);
- if (val != null) {
- cmd.setName(val.toString());
- }
- break;
-
- case DESCRIPTION:
- Object description = values.get(key);
- if (description != null) {
- cmd.setDescription(description.toString());
- }
- break;
-
- case INFO:
- Map<String, String> infoMap = (Map<String, String>) values.get(key);
-
- if (infoMap != null) {
- if (validate) {
- validateTags(exceptionList, (Map<String, Object>) values.get(key),
- OnapCommandConfg.getSchemaAttrInfo(INFO_PARAMS_LIST),
- OnapCommandConfg.getSchemaAttrInfo(INFO_PARAMS_MANDATORY_LIST), INFO);
-
- HashMap<String, String> validationMap = new HashMap<>();
- validationMap.put(INFO_TYPE, COMMAND_TYPE_VALUES);
-
- for (String secKey : validationMap.keySet()) {
- if (infoMap.containsKey(secKey)) {
- Object obj = infoMap.get(secKey);
- if (obj == null) {
- exceptionList.add("Attribute '" + secKey + "' under '" + INFO + "' is empty");
- } else {
- String value = String.valueOf(obj);
- if (!OnapCommandConfg.getSchemaAttrInfo(validationMap.get(secKey)).contains(value)) {
- exceptionList.add("Attribute '" + secKey + "' contains invalid value. Valide values are "
- + OnapCommandConfg.getSchemaAttrInfo(validationMap.get(key))); //
- }
- }
- }
- }
- }
-
- OnapCommandInfo info = new OnapCommandInfo();
-
- for (Map.Entry<String, String> entry1 : infoMap.entrySet()) {
- String key1 = entry1.getKey();
-
- switch (key1) {
- case INFO_PRODUCT:
- info.setProduct(infoMap.get(key1));
- break;
-
- case INFO_SERVICE:
- info.setService(infoMap.get(key1).toString());
- break;
-
- case INFO_TYPE:
- Object obj = infoMap.get(key1);
- info.setCommandType(CommandType.get(obj.toString()));
- break;
-
- case INFO_AUTHOR:
- Object mode = infoMap.get(key1);
- info.setAuthor(mode.toString());
- break;
- }
- }
-
- cmd.setInfo(info);
- }
- break;
-
- case PARAMETERS:
-
- List<Map<String, String>> parameters = (List) values.get(key);
-
- if (parameters != null) {
- Set<String> names = new HashSet<>();
-
- //To support overriding of the parameters, if command is already
- //having the same named parameters, means same parameter is
- //Overridden from included template into current template
- Set<String> existingParamNames = cmd.getParametersMap().keySet();
-
- for (Map<String, String> parameter : parameters) {
- boolean isOverriding = false;
- OnapCommandParameter param = new OnapCommandParameter();
-
- //Override the parameters from its base such as default parameters list
- if (existingParamNames.contains(parameter.getOrDefault(NAME, ""))) {
- param = cmd.getParametersMap().get(parameter.getOrDefault(NAME, ""));
- isOverriding = true;
- }
-
- if (validate) {
- validateTags(exceptionList, parameter, OnapCommandConfg.getSchemaAttrInfo(INPUT_PARAMS_LIST),
- OnapCommandConfg.getSchemaAttrInfo(INPUT_PARAMS_MANDATORY_LIST), PARAMETERS);
- }
-
- for (Map.Entry<String, String> entry1 : parameter.entrySet()) {
- String key2 = entry1.getKey();
-
- switch (key2) {
- case NAME:
- if (names.contains(parameter.get(key2))) {
- throwOrCollect(new OnapCommandParameterNameConflict(parameter.get(key2)), exceptionList, validate);
- } else {
- names.add(parameter.get(key2));
- }
-
- param.setName(parameter.get(key2));
- break;
-
- case DESCRIPTION:
- param.setDescription(parameter.get(key2));
- break;
-
- case SHORT_OPTION:
- if (shortOptions.contains(parameter.get(key2))) {
- throwOrCollect(new OnapCommandParameterOptionConflict(parameter.get(key2)), exceptionList, validate);
- }
- shortOptions.add(parameter.get(key2));
- param.setShortOption(parameter.get(key2));
- break;
-
- case LONG_OPTION:
- if (longOptions.contains(parameter.get(key2))) {
- throwOrCollect(new OnapCommandParameterOptionConflict(parameter.get(key2)), exceptionList, validate);
- }
- longOptions.add(parameter.get(key2));
- param.setLongOption(parameter.get(key2));
- break;
-
- case DEFAULT_VALUE:
- Object obj = parameter.get(key2);
- param.setDefaultValue(obj.toString());
- break;
-
- case TYPE:
- try {
- param.setParameterType(ParameterType.get(parameter.get(key2)));
- } catch (OnapCommandException ex) {
- throwOrCollect(ex, exceptionList, validate);
- }
- break;
-
- case IS_OPTIONAL:
- if (validate) {
- if (!validateBoolean(String.valueOf(parameter.get(key2)))) {
- exceptionList.add(invalidBooleanValueMessage(parameter.get(NAME),
- IS_SECURED, parameter.get(key2)));
- }
- }
- if ("true".equalsIgnoreCase(String.valueOf(parameter.get(key2)))) {
- param.setOptional(true);
- } else {
- param.setOptional(false);
- }
- break;
-
- case IS_SECURED:
- if (validate) {
- if (!validateBoolean(String.valueOf(parameter.get(key2)))) {
- exceptionList.add(invalidBooleanValueMessage(parameter.get(NAME),
- IS_SECURED, parameter.get(key2)));
- }
- }
-
- if ("true".equalsIgnoreCase(String.valueOf(parameter.get(key2)))) {
- param.setSecured(true);
- } else {
- param.setSecured(false);
- }
- break;
-
- case IS_INCLUDE:
- if (validate) {
- if (!validateBoolean(String.valueOf(parameter.get(key2)))) {
- exceptionList.add(invalidBooleanValueMessage(parameter.get(NAME),
- IS_INCLUDE, parameter.get(key2)));
- }
- }
-
- if ("true".equalsIgnoreCase(String.valueOf(parameter.get(key2)))) {
- param.setInclude(true);
- } else {
- param.setInclude(false);
- }
- break;
- }
- }
-
- if ( !isOverriding) {
- cmd.getParameters().add(param);
- } else {
- cmd.getParametersMap().replace(param.getName(), param);
- }
- }
- }
- break;
-
- case RESULTS:
- Map<String, ?> valueMap = (Map<String, ?>) values.get(key);
- if (valueMap != null) {
- OnapCommandResult result = new OnapCommandResult();
- for (Map.Entry<String, ?> entry1 : valueMap.entrySet()) {
- String key3 = entry1.getKey();
-
- switch (key3) {
- case DIRECTION:
- try {
- result.setPrintDirection(PrintDirection.get((String) valueMap.get(key3)));
- } catch (OnapCommandException ex) {
- throwOrCollect(ex, exceptionList, validate);
- }
- break;
-
- case ATTRIBUTES:
- List<Map<String, String>> attrs = (ArrayList) valueMap.get(key3);
-
- for (Map<String, String> map : attrs) {
- OnapCommandResultAttribute attr = new OnapCommandResultAttribute();
- if (validate) {
- validateTags(exceptionList, map, OnapCommandConfg.getSchemaAttrInfo(RESULT_PARAMS_LIST),
- OnapCommandConfg.getSchemaAttrInfo(RESULT_PARAMS_MANDATORY_LIST), ATTRIBUTES);
- }
-
- Set<String> resultParamNames = new HashSet<>();
-
- for (Map.Entry<String, String> entry4 : map.entrySet()) {
- String key4 = entry4.getKey();
-
- switch (key4) {
- case NAME:
- if (resultParamNames.contains(map.get(key4))) {
- exceptionList.add("Attribute name='" + map.get(key4) + "' under '"
- + ATTRIBUTES + ":' is already used, Take different one.");
-
- } else {
- attr.setName(map.get(key4));
- resultParamNames.add(map.get(key4));
- }
- break;
-
- case DESCRIPTION:
- attr.setDescription(map.get(key4));
- break;
-
- case SCOPE:
- try {
- attr.setScope(OnapCommandResultAttributeScope.get(map.get(key4)));
- } catch (OnapCommandException ex) {
- throwOrCollect(ex, exceptionList, validate);
- }
- break;
-
- case TYPE:
- try {
- attr.setType(ParameterType.get(map.get(key4)));
- } catch (OnapCommandException ex) {
- throwOrCollect(ex, exceptionList, validate);
- }
- break;
-
- case DEFAULT_VALUE:
- Object obj = map.get(key4);
- attr.setDefaultValue(obj.toString());
- break;
-
- case IS_SECURED:
- if (validate) {
- if (!validateBoolean(String.valueOf(map.get(key4)))) {
- exceptionList.add(invalidBooleanValueMessage(ATTRIBUTES,
- IS_SECURED, map.get(key4)));
- }
- }
- if ("true".equals(String.valueOf(map.get(key4)))) {
- attr.setSecured(true);
- } else {
- attr.setSecured(false);
- }
- break;
- }
-
- }
- result.getRecords().add(attr);
- }
- break;
- }
- }
- cmd.setResult(result);
- }
- break;
- }
- }
- return exceptionList;
- }
-
- /**
- * Load the schema.
- *
- * @param cmd
- * OnapSwaggerBasedCommand
- * @param schemaName
- * schema name
- * @throws OnapCommandParameterNameConflict
- * param name conflict exception
- * @throws OnapCommandParameterOptionConflict
- * param option conflict exception
- * @throws OnapCommandInvalidParameterType
- * invalid param type exception
- * @throws OnapCommandInvalidPrintDirection
- * invalid print direction exception
- * @throws OnapCommandInvalidResultAttributeScope
- * invalid scope exception
- * @throws OnapCommandSchemaNotFound
- * schema not found
- * @throws OnapCommandInvalidSchema
- * invalid schema
- * @throws OnapCommandInvalidSchemaVersion
- * invalid schema version
- */
- public static void loadSchema(OnapSwaggerCommand cmd, String schemaName) throws OnapCommandException {
- try {
- Map<String, ?> values = (Map<String, ?>) validateSchemaVersion(schemaName, cmd.getSchemaVersion());
- Map<String, String> valueMap = (Map<String, String>) values.get(EXECUTOR);
- OnapCommandExecutor exec = new OnapCommandExecutor();
-
- for (Map.Entry<String, String> entry1 : valueMap.entrySet()) {
- String key1 = entry1.getKey();
-
- if (API.equals(key1)) {
- exec.setApi(valueMap.get(key1));
- } else if (CLIENT.equals(key1)) {
- exec.setClient(valueMap.get(key1));
- } else if (ENTITY.equals(key1)) {
- exec.setEntity(valueMap.get(key1));
- } else if (EXCEPTION.equals(key1)) {
- exec.setException(valueMap.get(key1));
- } else if (METHOD.equals(key1)) {
- exec.setMethod(valueMap.get(key1));
- }
- }
-
- cmd.setExecutor(exec);
- } catch (OnapCommandException e) {
- throw e;
- } catch (Exception e) {
- throw new OnapCommandInvalidSchema(schemaName, e);
- }
- }
-
- /**
- * Load the schema.
- *
- * @param cmd
- * OnapHttpCommand
- * @param schemaName
- * schema name
- * @throws OnapCommandException
- * on error
- */
- private static ArrayList<String> parseHttpSchema(OnapHttpCommand cmd,
- final Map<String, ?> values,
- boolean validate) throws OnapCommandException {
- ArrayList<String> errorList = new ArrayList<>();
- try {
- Map<String, ?> valMap = (Map<String, ?>) values.get(HTTP);
-
- if (valMap != null) {
- if (validate) {
- validateTags(errorList, valMap, OnapCommandConfg.getSchemaAttrInfo(HTTP_SECTIONS),
- OnapCommandConfg.getSchemaAttrInfo(HTTP_MANDATORY_SECTIONS), PARAMETERS);
- errorList.addAll(validateHttpSchemaSection(values));
- }
- for (Map.Entry<String, ?> entry1 : valMap.entrySet()) {
- String key1 = entry1.getKey();
-
- switch (key1) {
- case REQUEST:
- Map<String, ?> map = (Map<String, ?>) valMap.get(key1);
-
- for (Map.Entry<String, ?> entry2 : map.entrySet()) {
- try {
- String key2 = entry2.getKey();
-
- switch (key2) {
- case URI:
- Object obj = map.get(key2);
- cmd.getInput().setUri(obj.toString());
- break;
- case METHOD_TYPE:
- Object method = map.get(key2);
- cmd.getInput().setMethod(method.toString());
- break;
- case BODY:
- Object body = map.get(key2);
- cmd.getInput().setBody(body.toString());
- break;
- case HEADERS:
- Map<String, String> head = (Map<String, String>) map.get(key2);
- cmd.getInput().setReqHeaders(head);
- break;
- case QUERIES:
- Map<String, String> query = (Map<String, String>) map.get(key2);
-
- cmd.getInput().setReqQueries(query);
- break;
- case MULTIPART_ENTITY_NAME:
- Object multipartEntityName = map.get(key2);
- cmd.getInput().setMultipartEntityName(multipartEntityName.toString());
- break;
- }
- }catch (Exception ex) {
- throwOrCollect(new OnapCommandInvalidSchema(cmd.getSchemaName(), ex), errorList, validate);
- }
- }
- break;
-
- case SERVICE:
- Map<String, String> serviceMap = (Map<String, String>) valMap.get(key1);
-
- if (serviceMap != null) {
- if (validate) {
- validateTags(errorList, (Map<String, Object>) valMap.get(key1),
- OnapCommandConfg.getSchemaAttrInfo(SERVICE_PARAMS_LIST),
- OnapCommandConfg.getSchemaAttrInfo(SERVICE_PARAMS_MANDATORY_LIST), SERVICE);
-
- HashMap<String, String> validationMap = new HashMap<>();
- validationMap.put(AUTH, AUTH_VALUES);
- validationMap.put(MODE, MODE_VALUES);
-
- for (String secKey : validationMap.keySet()) {
- if (serviceMap.containsKey(secKey)) {
- Object obj = serviceMap.get(secKey);
- if (obj == null) {
- errorList.add("Attribute '" + secKey + "' under '" + SERVICE + "' is empty");
- } else {
- String value = String.valueOf(obj);
- if (!OnapCommandConfg.getSchemaAttrInfo(validationMap.get(secKey)).contains(value)) {
- errorList.add("Attribute '" + secKey + "' contains invalid value. Valide values are "
- + OnapCommandConfg.getSchemaAttrInfo(validationMap.get(key1))); //
- }
- }
- }
- }
- }
-
- OnapService srv = new OnapService();
-
- for (Map.Entry<String, String> entry : serviceMap.entrySet()) {
- String key = entry.getKey();
-
- switch (key) {
- case NAME:
- srv.setName(serviceMap.get(key));
- break;
-
- case VERSION:
- srv.setVersion(serviceMap.get(key).toString());
- break;
-
- case AUTH:
- Object obj = serviceMap.get(key);
- srv.setAuthType(obj.toString());
-
- //On None type, username, password and no_auth are invalid
- if (srv.isNoAuth()) {
- cmd.getParametersMap().get(DEAFULT_PARAMETER_USERNAME).setInclude(false);
- cmd.getParametersMap().get(DEAFULT_PARAMETER_PASSWORD).setInclude(false);
- cmd.getParametersMap().get(DEFAULT_PARAMETER_NO_AUTH).setInclude(false);
- }
- break;
-
- case MODE:
- Object mode = serviceMap.get(key);
- srv.setMode(mode.toString());
- break;
- }
- }
- cmd.setService(srv);
- }
- break;
-
- case SUCCESS_CODES:
- if (validate) {
- validateHttpSccessCodes(errorList, (List<Object>) valMap.get(key1));
- }
- cmd.setSuccessStatusCodes((ArrayList) valMap.get(key1));
- break;
-
- case RESULT_MAP:
- if (validate) {
- validateHttpResultMap(errorList, values);
- }
- cmd.setResultMap((Map<String, String>) valMap.get(key1));
- break;
-
- case SAMPLE_RESPONSE:
- // (mrkanag) implement sample response handling
- break;
- }
- }
- }
- }catch (OnapCommandException e) {
- throwOrCollect(e, errorList, validate);
- }
- return errorList;
- }
-
-
- private static void throwOrCollect(OnapCommandException ex, List<String> list, boolean shouldCollectException)
+ static void throwOrCollect(OnapCommandException ex, List<String> list, boolean shouldCollectException)
throws OnapCommandException {
if (shouldCollectException) {
list.add(ex.getMessage());
@@ -838,7 +146,7 @@ public class OnapCommandUtils {
}
}
- private static void validateTags(List<String> schemaErrors, Map<String, ?> yamlMap, List<String> totalParams,
+ static void validateTags(List<String> schemaErrors, Map<String, ?> yamlMap, List<String> totalParams,
List<String> mandatoryParams, String section) {
// mrkanag capture invalid entries as well
for (String param : totalParams) {
@@ -865,7 +173,7 @@ public class OnapCommandUtils {
* string
* @return boolean
*/
- protected static boolean validateBoolean(String toValidate) {
+ static boolean validateBoolean(String toValidate) {
return OnapCommandConfg.getSchemaAttrInfo(BOOLEAN_VALUE).contains(toValidate.toLowerCase());
}
@@ -873,7 +181,7 @@ public class OnapCommandUtils {
return "The section '" + section + ":' cann't be null or empty";
}
- private static String invalidBooleanValueMessage(String section, String attribute, String value) {
+ static String invalidBooleanValueMessage(String section, String attribute, String value) {
return "The value '" + value + "' of '" + attribute + "' present under '" + section + "' should be boolean";
}
@@ -974,7 +282,7 @@ public class OnapCommandUtils {
return set;
}
- private static void validateHttpResultMap(List<String> errorList, Map<String, ?> values) throws OnapCommandException {
+ static void validateHttpResultMap(List<String> errorList, Map<String, ?> values) throws OnapCommandException {
Map<String, ?> valMap = (Map<String, ?>) values.get(HTTP);
List<Map<String, String>> attributes = (List<Map<String, String>>) ((Map<String, ?>)values.get(RESULTS)).get(ATTRIBUTES);
Set<String> resultMapParams = ((Map<String, String>) valMap.get(RESULT_MAP)).keySet();
@@ -990,7 +298,7 @@ public class OnapCommandUtils {
}
}
- private static void validateHttpSccessCodes(List<String> errorList, List<Object> requestSuccessCodes) {
+ static void validateHttpSccessCodes(List<String> errorList, List<Object> requestSuccessCodes) {
if (requestSuccessCodes == null || requestSuccessCodes.isEmpty()) {
errorList.add(HTTP_SUCCESS_CODE_INVALID);
@@ -1008,9 +316,7 @@ public class OnapCommandUtils {
}
-
- private static ArrayList<String> validateHttpSchemaSection(Map<String, ?> values) {
-
+ static ArrayList<String> validateHttpSchemaSection(Map<String, ?> values) {
ArrayList<String> errorList = new ArrayList<>();
Map<String, ?> map = (Map<String, ?>) values.get(HTTP);
Map<String, Object> requestMap = (Map<String, Object>) map.get(REQUEST);
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommand.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommand.java
deleted file mode 100644
index 89367f1d..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommand.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-package org.onap.cli.fw.cmd;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-
-import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.error.OnapCommandExecutionFailed;
-import org.onap.cli.fw.error.OnapCommandExecutorInfoMissing;
-import org.onap.cli.fw.error.OnapCommandResultInitialzationFailed;
-import org.onap.cli.fw.utils.OnapCommandUtils;
-
-public class OnapCreateSwaggerBasedCommand extends OnapSwaggerCommand {
-
- private <T> T initializeEntity(T obj, List<String> prps) throws OnapCommandResultInitialzationFailed {
- for (int i = 1; i < prps.size(); i++) {
- String paramName = prps.get(i).trim();
- String prpName = paramName;
- // paramName(prpName)
- if (prpName.contains("(")) {
- paramName = prpName.substring(0, prpName.indexOf("("));
- prpName = prpName.substring(prpName.indexOf("(") + 1, prpName.indexOf(")"));
- }
- String methodName = OnapCommandUtils.formMethodNameFromAttributeName(prpName, "set");
-
- try {
- Method set = obj.getClass().getMethod(methodName, String.class);
- set.invoke(obj, this.getParametersMap().get(paramName).getValue());
- } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
- | InvocationTargetException e) {
- throw new OnapCommandResultInitialzationFailed(this.getName(), e);
- }
- }
- return obj;
- }
-
- @Override
- protected void run() throws OnapCommandException {
- if (this.getExecutor() == null) {
- throw new OnapCommandExecutorInfoMissing(this.getName());
- }
-
- try {
- // Initialize client
- Class clientClaz = Class.forName(this.getExecutor().getClient());
- Object client = clientClaz.getConstructor().newInstance();
- this.initializeApiClient(client);
-
- // Initialize api
- Class apiCls = Class.forName(this.getExecutor().getApi());
- Object api = apiCls.getConstructor(clientClaz).newInstance(client);
-
- // invoke method
- List<String> methodTokens = Arrays.asList(this.getExecutor().getMethod().split(","));
-
- List<String> entityTokens = Arrays.asList(this.getExecutor().getEntity().split(","));
- Class entityCls = Class.forName(entityTokens.get(0));
- Object entity = entityCls.newInstance();
- Method method = api.getClass().getMethod(methodTokens.get(0), entityCls);
- Object result = method.invoke(api, this.initializeEntity(entity, entityTokens));
-
- // initialize result
- this.initializeResult(result);
- } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
- throw new OnapCommandExecutionFailed(this.getName(), e);
- } catch (OnapCommandException e) {
- throw e;
- } catch (Exception e) {
- try {
- Class execCls = Class.forName(this.getExecutor().getException());
- Method execMethod = execCls.getClass().getMethod("getCode");
- if (execCls.isInstance(e)) {
- throw new OnapCommandExecutionFailed(this.getName(), e, (Integer) execMethod.invoke(e));
- }
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | ClassNotFoundException | NoSuchMethodException | SecurityException e1) {
- throw new OnapCommandExecutionFailed(this.getName(), e1.getMessage());
- }
- throw new OnapCommandExecutionFailed(this.getName(), e.getMessage());
- }
- }
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommandTest.java
deleted file mode 100644
index ec4b91d4..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommandTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-package org.onap.cli.fw.cmd;
-
-import org.junit.Test;
-import org.onap.cli.fw.OnapCommand;
-import org.onap.cli.fw.error.OnapCommandException;
-
-public class OnapCreateSwaggerBasedCommandTest {
-
- @Test
- public void runTest() throws OnapCommandException {
- OnapCommand cmd = new OnapCreateSwaggerBasedCommand();
- cmd.initializeSchema("sample-test-schema-swagger.yaml");
- //cmd.execute();
- }
-
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommand.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommand.java
deleted file mode 100644
index 1db954c6..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommand.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-package org.onap.cli.fw.cmd;
-
-import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.error.OnapCommandExecutionFailed;
-import org.onap.cli.fw.error.OnapCommandExecutorInfoMissing;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Helps to make delete rest calls on top of swagger generated java client. For example following one shows how MSB
- * service list is achieved here exec: ... method: deleteMicroService, [input param name given under Parameters]
- *
- */
-public class OnapDeleteSwaggerBasedCommand extends OnapSwaggerCommand {
-
- @Override
- protected void run() throws OnapCommandException {
- if (this.getExecutor() == null) {
- throw new OnapCommandExecutorInfoMissing(this.getName());
- }
-
- try {
- // Initialize client
- Class clientCls = Class.forName(this.getExecutor().getClient());
- Object client = clientCls.getConstructor().newInstance();
- this.initializeApiClient(client);
-
- // Initialize api
- Class apiCls = Class.forName(this.getExecutor().getApi());
- Object api = apiCls.getConstructor(clientCls).newInstance(client);
-
- // invoke method
- List<String> methodTokens = Arrays.asList(this.getExecutor().getMethod().split(","));
-
- Method method = api.getClass().getMethod(methodTokens.get(0), String.class);
- method.invoke(api, this.getParametersMap().get(methodTokens.get(1)).getValue());
- } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
- throw new OnapCommandExecutionFailed(this.getName(), e);
- } catch (OnapCommandException e) {
- throw e;
- } catch (Exception e) {
- try {
- Class execCls = Class.forName(this.getExecutor().getException());
- Method execMethod = execCls.getClass().getMethod("getCode");
- if (execCls.isInstance(e)) {
- throw new OnapCommandExecutionFailed(this.getName(), e, (Integer) execMethod.invoke(e));
- }
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | ClassNotFoundException | NoSuchMethodException | SecurityException e1) {
- throw new OnapCommandExecutionFailed(this.getName(), e1.getMessage());
- }
- throw new OnapCommandExecutionFailed(this.getName(), e.getMessage());
- }
- }
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommandTest.java
deleted file mode 100644
index a242a683..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommandTest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-package org.onap.cli.fw.cmd;
-
-public class OnapDeleteSwaggerBasedCommandTest {
-
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommand.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommand.java
deleted file mode 100644
index 8ed86564..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommand.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-package org.onap.cli.fw.cmd;
-
-import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.error.OnapCommandExecutionFailed;
-import org.onap.cli.fw.error.OnapCommandExecutorInfoMissing;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Helps to make get rest calls on top of swagger generated java client. For example following one shows how MSB service
- * list is achieved here exec: ... method: getMicroService, [input param name given under Parameters]
- *
- */
-public class OnapGetSwaggerBasedCommand extends OnapSwaggerCommand {
-
- @Override
- protected void run() throws OnapCommandException {
- if (this.getExecutor() == null) {
- throw new OnapCommandExecutorInfoMissing(this.getName());
- }
-
- try {
- // Initialize client
- Class clientCls = Class.forName(this.getExecutor().getClient());
- Object client = clientCls.getConstructor().newInstance();
- this.initializeApiClient(client);
-
- // Initialize api
- Class apiCls = Class.forName(this.getExecutor().getApi());
- Object api = apiCls.getConstructor(clientCls).newInstance(client);
-
- // invoke method
- List<String> methodTokens = Arrays.asList(this.getExecutor().getMethod().split(","));
-
- Method method = api.getClass().getMethod(methodTokens.get(0), String.class);
- Object result = method.invoke(api, this.getParametersMap().get(methodTokens.get(1)).getValue());
-
- // initialize result
- this.initializeResult(result);
-
- } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
- throw new OnapCommandExecutionFailed(this.getName(), e);
- } catch (OnapCommandException e) {
- throw e;
- } catch (Exception e) {
- try {
- Class execCls = Class.forName(this.getExecutor().getException());
- Method execMethod = execCls.getClass().getMethod("getCode");
- if (execCls.isInstance(e)) {
- throw new OnapCommandExecutionFailed(this.getName(), e, (Integer) execMethod.invoke(e));
- }
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | ClassNotFoundException | NoSuchMethodException | SecurityException e1) {
- throw new OnapCommandExecutionFailed(this.getName(), e1.getMessage());
- }
- throw new OnapCommandExecutionFailed(this.getName(), e.getMessage());
- }
- }
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommandTest.java
deleted file mode 100644
index 5c301a62..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommandTest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-package org.onap.cli.fw.cmd;
-
-public class OnapGetSwaggerBasedCommandTest {
-
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommand.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommand.java
deleted file mode 100644
index a5795e75..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommand.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-package org.onap.cli.fw.cmd;
-
-import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.error.OnapCommandExecutionFailed;
-import org.onap.cli.fw.error.OnapCommandExecutorInfoMissing;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-/**
- * Helps to make list rest calls on top of swagger generated java client. For example following one shows how MSB
- * service list is achived here exec: api:
- * org.onap.common_services.microservice_bus.apiroute_service.client.api.MSBServiceResourceApi client:
- * org.onap.common_services.microservice_bus.apiroute_service.client.invoker.ApiClient method: getMicroService
- * exception: org.onap.common_services.microservice_bus.apiroute_service.client.invoker.ApiException
- *
- */
-public class OnapListSwaggerBasedCommand extends OnapSwaggerCommand {
-
- @Override
- protected void run() throws OnapCommandException {
- if (this.getExecutor() == null) {
- throw new OnapCommandExecutorInfoMissing(this.getName());
- }
-
- try {
- // Initialize client
- Class clientCls = Class.forName(this.getExecutor().getClient());
- Object client = clientCls.getConstructor().newInstance();
- this.initializeApiClient(client);
-
- // Initialize api
- Class apiCls = Class.forName(this.getExecutor().getApi());
- Object api = apiCls.getConstructor(clientCls).newInstance(client);
-
- // invoke method
- Method method = api.getClass().getMethod(this.getExecutor().getMethod());
- Object result = method.invoke(api);
-
- // initialize result
- this.initializeResult(result);
-
- } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
- throw new OnapCommandExecutionFailed(this.getName(), e);
- } catch (OnapCommandException e) {
- throw e;
- } catch (Exception e) {
- try {
- Class execCls = Class.forName(this.getExecutor().getException());
- Method execMethod = execCls.getClass().getMethod("getCode");
- if (execCls.isInstance(e)) {
- throw new OnapCommandExecutionFailed(this.getName(), e, (Integer) execMethod.invoke(e));
- }
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | ClassNotFoundException | NoSuchMethodException | SecurityException e1) {
- throw new OnapCommandExecutionFailed(this.getName(), e1.getMessage());
- }
- throw new OnapCommandExecutionFailed(this.getName(), e.getMessage());
- }
- }
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommandTest.java
deleted file mode 100644
index 5683153c..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommandTest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-package org.onap.cli.fw.cmd;
-
-public class OnapListSwaggerBasedCommandTest {
-
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapSwaggerCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapSwaggerCommandTest.java
deleted file mode 100644
index 47e3e050..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapSwaggerCommandTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-package org.onap.cli.fw.cmd;
-
-import org.junit.Test;
-import org.onap.cli.fw.OnapCommand;
-import org.onap.cli.fw.error.OnapCommandClientInitialzationFailed;
-import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.error.OnapCommandResultInitialzationFailed;
-import org.onap.cli.fw.input.OnapCommandParameter;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public class OnapSwaggerCommandTest {
-
- @Test(expected = OnapCommandResultInitialzationFailed.class)
- public void initializeResultTest1() throws OnapCommandException {
- OnapSwaggerCommandImpl swagger = new OnapSwaggerCommandImpl();
- swagger.initializeSchema("onap-test-schema.yaml");
- List<String> obj = new ArrayList<>();
- obj.add("name");
- obj.add("get");
- swagger.initializeResult(obj);
-
- Set<String> obj1 = new HashSet<>();
- obj.add("name");
- obj.add("get");
- swagger.initializeResult(obj1);
- }
-
- @Test(expected = OnapCommandResultInitialzationFailed.class)
- public void initializeResultTest2() throws OnapCommandException {
- OnapSwaggerCommandImpl swagger = new OnapSwaggerCommandImpl();
- swagger.initializeSchema("onap-test-schema.yaml");
- Set<String> obj1 = new HashSet<>();
- obj1.add("name");
- obj1.add("get");
- swagger.initializeResult(obj1);
- }
-
- @Test
- public void initializeResultTest3() throws OnapCommandException {
- OnapSwaggerCommandImpl swagger = new OnapSwaggerCommandImpl();
- swagger.initializeSchema("onap-test-schema.yaml");
- ApiClient cit = new ApiClient();
- cit.setApiKey("apiKey");
- cit.setBasePath("basePath");
- swagger.initializeApiClient(cit);
- }
-
- class OnapSwaggerCommandImpl extends OnapSwaggerCommand {
- protected void run() throws OnapCommandException {
- }
-
- }
-
- class ApiClient {
-
- private String basePath;
- private String apiKey;
-
- public String getBasePath() {
- return basePath;
- }
-
- public void setBasePath(String basePath) {
- this.basePath = basePath;
- }
-
- public String getApiKey() {
- return apiKey;
- }
-
- public void setApiKey(String apiKey) {
- this.apiKey = apiKey;
- }
-
- }
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/run/OnapCommandExecutorTest.java b/framework/src/test/java/org/onap/cli/fw/run/OnapCommandExecutorTest.java
deleted file mode 100644
index 1236365c..00000000
--- a/framework/src/test/java/org/onap/cli/fw/run/OnapCommandExecutorTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-package org.onap.cli.fw.run;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class OnapCommandExecutorTest {
-
- @Test
- public void commandExecutorTest() {
- OnapCommandExecutor exec = new OnapCommandExecutor();
- exec.setApi("api");
- exec.setClient("client");
- exec.setEntity("entity");
- exec.setException("exception");
- exec.setMethod("method");
-
- Assert.assertTrue(
- exec.getApi().equals("api") && exec.getClient().equals("client") && exec.getEntity().equals("entity")
- && exec.getMethod().equals("method") && exec.getException().equals("exception"));
- }
-
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java b/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java
index 654b20cd..87612e62 100644
--- a/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java
@@ -21,7 +21,7 @@ import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.cmd.OnapHttpCommand;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
-import org.onap.cli.fw.utils.OnapCommandUtils;
+import org.onap.cli.fw.utils.OnapCommandSchemaLoader;
import java.util.List;
@@ -36,7 +36,7 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "fdsfds.yaml", true, true);
+ OnapCommandSchemaLoader.loadSchema(cmd, "fdsfds.yaml", true, true);
}
@Test(expected = OnapCommandInvalidSchema.class)
@@ -45,7 +45,7 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "fdsfds", true, true);
+ OnapCommandSchemaLoader.loadSchema(cmd, "fdsfds", true, true);
}
@Test(expected = OnapCommandInvalidSchema.class)
@@ -54,7 +54,7 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd,
+ OnapCommandSchemaLoader.loadSchema(cmd,
ValidateSchemaTest.class.getClassLoader().getResource("open-cli.properties").getFile(),
true, true);
}
@@ -65,7 +65,7 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "schema-invalid-file-null.yaml", true, true);
+ OnapCommandSchemaLoader.loadSchema(cmd, "schema-invalid-file-null.yaml", true, true);
}
@Test
@@ -74,7 +74,7 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "schema-validate-pass.yaml", true, true);
+ OnapCommandSchemaLoader.loadSchema(cmd, "schema-validate-pass.yaml", true, true);
}
@@ -84,7 +84,7 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "schema-invalid-file.yaml", true, true);
+ OnapCommandSchemaLoader.loadSchema(cmd, "schema-invalid-file.yaml", true, true);
}
@Test
@@ -94,31 +94,31 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- List<String> errorList1 = OnapCommandUtils.loadSchema(cmd1, "schema-validate-http.yaml", true, true);
+ List<String> errorList1 = OnapCommandSchemaLoader.loadSchema(cmd1, "schema-validate-http.yaml", true, true);
assertTrue(errorList1.size() > 0);
OnapCommand cmd2 = new OnapCommand() {
@Override
protected void run() throws OnapCommandException {}
};
- List<String> errorList2 = OnapCommandUtils.loadSchema(cmd2, "schema-validate-basic.yaml", true, true);
+ List<String> errorList2 = OnapCommandSchemaLoader.loadSchema(cmd2, "schema-validate-basic.yaml", true, true);
assertTrue(errorList2.size() > 0);
OnapCommand cmd3 = new OnapCommand() {
@Override
protected void run() throws OnapCommandException {}
};
- List<String> errorList3 = OnapCommandUtils.loadSchema(cmd2, "schema-validate-invalidschematype.yaml", true, true);
+ List<String> errorList3 = OnapCommandSchemaLoader.loadSchema(cmd2, "schema-validate-invalidschematype.yaml", true, true);
assertTrue(errorList3.size() > 0);
OnapCommand cmd4 = new OnapCommand() {
@Override
protected void run() throws OnapCommandException {}
};
- List<String> errorList4 = OnapCommandUtils.loadSchema(cmd2, "schema-validate-invalid.yaml", true, true);
+ List<String> errorList4 = OnapCommandSchemaLoader.loadSchema(cmd2, "schema-validate-invalid.yaml", true, true);
OnapHttpCommand oclipHttpCommand = new OnapHttpCommand();
- errorList4.addAll(OnapCommandUtils.loadHttpSchema(oclipHttpCommand,
+ errorList4.addAll(OnapCommandSchemaLoader.loadHttpSchema(oclipHttpCommand,
"schema-validate-invalid.yaml", true, true));
assertTrue(errorList4.size() > 0);
@@ -126,7 +126,7 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- List<String> errorList5 = OnapCommandUtils.loadSchema(cmd5, "schema-validate-pass.yaml", true, true);
+ List<String> errorList5 = OnapCommandSchemaLoader.loadSchema(cmd5, "schema-validate-pass.yaml", true, true);
assertTrue(errorList5.size() == 0);
}
diff --git a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
index 419c4edc..fd0373bd 100644
--- a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
@@ -38,7 +38,6 @@ import org.junit.runners.MethodSorters;
import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.OnapCommandSchema;
import org.onap.cli.fw.cmd.OnapHttpCommand;
-import org.onap.cli.fw.cmd.OnapSwaggerCommand;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandHelpFailed;
import org.onap.cli.fw.error.OnapCommandHttpHeaderNotFound;
@@ -58,7 +57,6 @@ import org.onap.cli.fw.info.OnapCommandInfo;
import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.input.ParameterType;
import org.onap.cli.fw.output.OnapCommandResult;
-import org.onap.cli.fw.run.OnapCommandExecutor;
import org.springframework.core.io.Resource;
import mockit.Invocation;
@@ -70,12 +68,12 @@ public class OnapCommandUtilsTest {
@Test(expected = OnapCommandInvalidSchema.class)
public void oclipCommandUtilsInputStreamNullTest() throws OnapCommandException {
- OnapCommandUtils.validateSchemaVersion("sample-test1-schema-http1.yaml", "1.0");
+ OnapCommandSchemaLoader.validateSchemaVersion("sample-test1-schema-http1.yaml", "1.0");
}
@Test
public void oclipCommandUtilsInputStreamNotNullTest() throws OnapCommandException {
- Map<String, ?> map = OnapCommandUtils.validateSchemaVersion("sample-test1-schema-http.yaml", "1.0");
+ Map<String, ?> map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test1-schema-http.yaml", "1.0");
assertTrue(map != null);
}
@@ -93,7 +91,7 @@ public class OnapCommandUtilsTest {
@Test
public void schemaFileNotFoundTest() throws OnapCommandException {
- Map<String, ?> map = OnapCommandUtils.validateSchemaVersion("sample-test-schema.yaml", "1.0");
+ Map<String, ?> map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test-schema.yaml", "1.0");
assertTrue(map.size() > 0);
}
@@ -102,7 +100,7 @@ public class OnapCommandUtilsTest {
public void invalidSchemaFileTest() throws OnapCommandException {
Map<String, ?> map = null;
try {
- map = OnapCommandUtils.validateSchemaVersion("sample-test-schema1.yaml", "1.0");
+ map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test-schema1.yaml", "1.0");
} catch (OnapCommandInvalidSchemaVersion e) {
fail("Test should not have thrown this exception : " + e.getMessage());
} catch (OnapCommandInvalidSchema e) {
@@ -116,7 +114,7 @@ public class OnapCommandUtilsTest {
public void validateWrongSchemaVersionTest() throws OnapCommandException {
Map<String, ?> map = null;
try {
- map = OnapCommandUtils.validateSchemaVersion("sample-test-invalid-schema.yaml", "1.0");
+ map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test-invalid-schema.yaml", "1.0");
} catch (OnapCommandInvalidSchemaVersion e) {
fail("Test should not have thrown this exception : " + e.getMessage());
} catch (OnapCommandInvalidSchema e) {
@@ -130,7 +128,7 @@ public class OnapCommandUtilsTest {
public void validateSchemaVersionTest() throws OnapCommandException {
Map<String, ?> map = null;
try {
- map = OnapCommandUtils.validateSchemaVersion("sample-test-schema.yaml", "1.1");
+ map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test-schema.yaml", "1.1");
} catch (OnapCommandInvalidSchemaVersion e) {
assertEquals("0xb003::Command schema open_cli_schema_version 1.0 is invalid or missing", e.getMessage());
} catch (OnapCommandInvalidSchema e) {
@@ -143,32 +141,32 @@ public class OnapCommandUtilsTest {
@Test
public void loadOnapCommandSchemaWithOutDefaultTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", false, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", false, false);
assertTrue("sample-test".equals(cmd.getName()) && cmd.getParameters().size() == 9);
}
@Test(expected = OnapCommandParameterNameConflict.class)
public void loadOnapCommandSchemaWithDuplicateNameTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-name.yaml", false, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-invalid-schema-duplicate-name.yaml", false, false);
}
@Test(expected = OnapCommandParameterOptionConflict.class)
public void loadOnapCommandSchemaWithDuplicateShortOptionTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-shortoption.yaml", false, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-invalid-schema-duplicate-shortoption.yaml", false, false);
}
@Test(expected = OnapCommandParameterOptionConflict.class)
public void loadOnapCommandSchemaWithDuplicateLongOptionTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-longoption.yaml", false, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-invalid-schema-duplicate-longoption.yaml", false, false);
}
@Test
public void loadOnapCommandSchemaWithDefaultTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", true, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", true, false);
assertTrue("sample-test".equals(cmd.getName()) && cmd.getParameters().size() > 9);
for (OnapCommandParameter com : cmd.getParameters()) {
@@ -182,7 +180,7 @@ public class OnapCommandUtilsTest {
@Test
public void loadOnapCommandSchemaAuthRequiredTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema-auth-required.yaml", true, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema-auth-required.yaml", true, false);
assertTrue("sample-test".equals(cmd.getName()));
Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters());
@@ -190,33 +188,11 @@ public class OnapCommandUtilsTest {
}
@Test
- public void loadSwaggerBasedSchemaExceptionTest() throws OnapCommandException {
- OnapSwaggerCommand cmd = new OnapSwaggerBasedCommandSample();
- try {
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml");
- } catch (OnapCommandInvalidSchema e) {
- assertEquals("0xb001", e.getErrorCode());
- }
- }
-
- @Test
- public void loadSwaggerBasedSchemaTest() throws OnapCommandException {
- OnapSwaggerCommand cmd = new OnapSwaggerBasedCommandSample();
- try {
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema-swagger.yaml");
- OnapCommandExecutor exe = cmd.getExecutor();
- assertTrue(exe != null);
- } catch (OnapCommandInvalidSchema e) {
- assertTrue(e.getMessage().contains("0xb001::Command schema sample-test-schema.yaml is invalid"));
- }
- }
-
- @Test
public void loadHttpBasedSchemaExceptionTest() throws OnapCommandException {
OnapHttpCommand cmd = new OnapHttpCommandSample();
cmd.setName("sample-test-http");
try {
- OnapCommandUtils.loadHttpSchema(cmd, "sample-test-schema.yaml", true, false);
+ OnapCommandSchemaLoader.loadHttpSchema(cmd, "sample-test-schema.yaml", true, false);
} catch (OnapCommandParameterNameConflict | OnapCommandParameterOptionConflict
| OnapCommandInvalidParameterType | OnapCommandInvalidPrintDirection
| OnapCommandInvalidResultAttributeScope | OnapCommandSchemaNotFound | OnapCommandInvalidSchema
@@ -230,7 +206,7 @@ public class OnapCommandUtilsTest {
OnapHttpCommand cmd = new OnapHttpCommandSample();
cmd.setName("sample-create-http");
try {
- OnapCommandUtils.loadHttpSchema(cmd, "sample-test-schema-http.yaml", true, true);
+ OnapCommandSchemaLoader.loadHttpSchema(cmd, "sample-test-schema-http.yaml", true, true);
assertTrue(cmd.getSuccessStatusCodes().size() == 2);
} catch (OnapCommandParameterNameConflict | OnapCommandParameterOptionConflict
| OnapCommandInvalidParameterType | OnapCommandInvalidPrintDirection
@@ -243,7 +219,7 @@ public class OnapCommandUtilsTest {
@Test
public void helpCommandTest() throws IOException, OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", true, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", true, false);
String actualResult = OnapCommandUtils.help(cmd);
@@ -386,7 +362,7 @@ public class OnapCommandUtilsTest {
mockPrintMethodException();
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", true, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", true, false);
OnapCommandUtils.help(cmd);
@@ -396,7 +372,7 @@ public class OnapCommandUtilsTest {
@Test
public void test() throws OnapCommandException {
OnapCommandSampleInfo cmd = new OnapCommandSampleInfo();
- OnapCommandUtils.loadSchema(cmd, "sample-test-info.yaml", true, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-info.yaml", true, false);
OnapCommandInfo info = cmd.getInfo();
assert info != null;
}
@@ -415,14 +391,6 @@ public class OnapCommandUtilsTest {
}
}
- @OnapCommandSchema(schema = "sample-test-schema-swagger.yaml")
- class OnapSwaggerBasedCommandSample extends OnapSwaggerCommand {
-
- @Override
- protected void run() throws OnapCommandException {
- }
- }
-
@OnapCommandSchema(schema = "sample-test-schema-http.yaml")
class OnapHttpCommandSample extends OnapHttpCommand {
diff --git a/main/src/main/java/org/onap/cli/main/OnapCli.java b/main/src/main/java/org/onap/cli/main/OnapCli.java
index 77de4408..15f845b6 100644
--- a/main/src/main/java/org/onap/cli/main/OnapCli.java
+++ b/main/src/main/java/org/onap/cli/main/OnapCli.java
@@ -38,7 +38,7 @@ import org.onap.cli.fw.output.PrintDirection;
import org.onap.cli.fw.output.ResultType;
import org.onap.cli.main.conf.OnapCliConstants;
import org.onap.cli.main.interactive.StringCompleter;
-import org.onap.cli.main.utils.OnapCliUtils;
+import org.onap.cli.main.utils.OnapCliArgsParser;
import org.onap.cli.sample.yaml.SampleYamlGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -356,7 +356,7 @@ public class OnapCli {
}
}
- OnapCliUtils.populateParams(cmd.getParameters(), args);
+ OnapCliArgsParser.populateParams(cmd.getParameters(), args);
OnapCommandResult result = cmd.execute();
this.print(result.getDebugInfo());
diff --git a/main/src/main/java/org/onap/cli/main/utils/OnapCliUtils.java b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
index 99cfa7dd..725459e9 100644
--- a/main/src/main/java/org/onap/cli/main/utils/OnapCliUtils.java
+++ b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
@@ -41,12 +41,12 @@ import java.util.Map;
* Oclip CLI utilities.
*
*/
-public class OnapCliUtils {
+public class OnapCliArgsParser {
/**
* private Constructor.
*/
- private OnapCliUtils() {
+ private OnapCliArgsParser() {
}
@@ -93,52 +93,56 @@ public class OnapCliUtils {
int positionalIdx = 0;
// Skip the first args oclip cmd name, so start from 1
for (int i = 1; i < args.size(); i++) {
- // check if short option exist
- // (mrkanag) Optimize the below code to handle short and long options in one iteration
- // now its redundant
- if (shortOptionMap.containsKey(args.get(i))) {
+ String paramName = null;
+ if (shortOptionMap.containsKey(args.get(i))) {
+ paramName = shortOptionMap.get(args.get(i));
+ } else if (longOptionMap.containsKey(args.get(i))) {
+ paramName = longOptionMap.get(args.get(i));
+ }
+
+ if (paramName != null) {
// end of the list or if its option rather than a value
if ((i + 1) == args.size() || args.get(i + 1).startsWith("-")) {
- if (paramMap.get(shortOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.BOOL)) {
- paramMap.get(shortOptionMap.get(args.get(i))).setValue("true");
+ if (paramMap.get(paramName).getParameterType().equals(ParameterType.BOOL)) {
+ paramMap.get(paramName).setValue("true");
continue;
}
throw new OnapCliArgumentValueMissing(args.get(i));
}
- if (paramMap.get(shortOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.JSON)) {
- paramMap.get(shortOptionMap.get(args.get(i))).setValue(readJsonStringFromUrl(args.get(i + 1),
- paramMap.get(shortOptionMap.get(args.get(i))).getName()));
+ if (paramMap.get(paramName).getParameterType().equals(ParameterType.JSON)) {
+ paramMap.get(paramName).setValue(readJsonStringFromUrl(args.get(i + 1),
+ paramMap.get(paramName).getName()));
i++;
continue;
- } if (paramMap.get(shortOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.TEXT)) {
- paramMap.get(shortOptionMap.get(args.get(i))).setValue(readTextStringFromUrl(args.get(i + 1),
- paramMap.get(shortOptionMap.get(args.get(i))).getName()));
+ } if (paramMap.get(paramName).getParameterType().equals(ParameterType.TEXT)) {
+ paramMap.get(paramName).setValue(readTextStringFromUrl(args.get(i + 1),
+ paramMap.get(paramName).getName()));
i++;
continue;
- } else if (paramMap.get(shortOptionMap.get(args.get(i))).getParameterType()
+ } else if (paramMap.get(paramName).getParameterType()
.equals(ParameterType.ARRAY)) {
- Object value = paramMap.get(shortOptionMap.get(args.get(i))).getValue();
+ Object value = paramMap.get(paramName).getValue();
List<String> list;
if (value == "") {
list = new ArrayList<>();
} else {
- list = convertJsonToListString(paramMap.get(shortOptionMap.get(args.get(i))).getName(),
+ list = convertJsonToListString(paramMap.get(paramName).getName(),
value.toString());
}
list.add(args.get(i + 1));
- paramMap.get(shortOptionMap.get(args.get(i))).setValue(list);
+ paramMap.get(paramName).setValue(list);
i++;
continue;
- } else if (paramMap.get(shortOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.MAP)) {
- Object value = paramMap.get(shortOptionMap.get(args.get(i))).getValue();
+ } else if (paramMap.get(paramName).getParameterType().equals(ParameterType.MAP)) {
+ Object value = paramMap.get(paramName).getValue();
Map<String, String> map;
if (value == "") {
map = new HashMap<>();
} else {
- map = convertJsonToMapString(paramMap.get(shortOptionMap.get(args.get(i))).getName(),
+ map = convertJsonToMapString(paramMap.get(paramName).getName(),
value.toString());
}
@@ -146,83 +150,16 @@ public class OnapCliUtils {
String[] argArr = arg.split("=");
if (argArr.length != 2) {
- throw new OnapCliInvalidArgument(paramMap.get(shortOptionMap.get(args.get(i))).getName());
+ throw new OnapCliInvalidArgument(paramMap.get(paramName).getName());
}
map.put(argArr[0], argArr[1]);
- paramMap.get(shortOptionMap.get(args.get(i))).setValue(map);
+ paramMap.get(paramName).setValue(map);
i++;
continue;
}
- paramMap.get(shortOptionMap.get(args.get(i))).setValue(args.get(i + 1));
-
- i++;
- continue;
- }
-
- // check if long option exist
- if (longOptionMap.containsKey(args.get(i))) {
- // end of the list or if its option rather than a value
- if ((i + 1) == args.size() || args.get(i + 1).startsWith("-")) {
- if (paramMap.get(longOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.BOOL)) {
- paramMap.get(longOptionMap.get(args.get(i))).setValue("true");
- continue;
- }
- throw new OnapCliArgumentValueMissing(args.get(i));
- }
-
- if (paramMap.get(longOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.JSON)) {
- paramMap.get(longOptionMap.get(args.get(i))).setValue(readJsonStringFromUrl(args.get(i + 1),
- paramMap.get(longOptionMap.get(args.get(i))).getName()));
- i++;
- continue;
- } else if (paramMap.get(longOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.TEXT)) {
- paramMap.get(longOptionMap.get(args.get(i))).setValue(readTextStringFromUrl(args.get(i + 1),
- paramMap.get(longOptionMap.get(args.get(i))).getName()));
- i++;
- continue;
- } else if (paramMap.get(longOptionMap.get(args.get(i))).getParameterType()
- .equals(ParameterType.ARRAY)) {
- Object value = paramMap.get(longOptionMap.get(args.get(i))).getValue();
- List<String> list;
- if (value == "") {
- list = new ArrayList<>();
- } else {
- list = convertJsonToListString(paramMap.get(longOptionMap.get(args.get(i))).getName(),
- value.toString());
- }
- list.add(args.get(i + 1));
- paramMap.get(longOptionMap.get(args.get(i))).setValue(list);
- i++;
- continue;
- } else if (paramMap.get(longOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.MAP)) {
-
- Object value = paramMap.get(longOptionMap.get(args.get(i))).getValue();
-
- Map<String, String> map;
-
- if (value == "") {
- map = new HashMap<>();
- } else {
- map = convertJsonToMapString(paramMap.get(longOptionMap.get(args.get(i))).getName(),
- value.toString());
- }
-
- String arg = args.get(i + 1);
- String[] argArr = arg.split("=");
-
- if (argArr.length != 2) {
- throw new OnapCliInvalidArgument(paramMap.get(longOptionMap.get(args.get(i))).getName());
- }
-
- map.put(argArr[0], argArr[1]);
- paramMap.get(longOptionMap.get(args.get(i))).setValue(map);
- i++;
- continue;
- }
-
- paramMap.get(longOptionMap.get(args.get(i))).setValue(args.get(i + 1));
+ paramMap.get(paramName).setValue(args.get(i + 1));
i++;
continue;
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 6eb2e11f..d720ed95 100644
--- a/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
+++ b/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
@@ -31,7 +31,7 @@ import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.OnapCommandRegistrar;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandHelpFailed;
-import org.onap.cli.main.utils.OnapCliUtils;
+import org.onap.cli.main.utils.OnapCliArgsParser;
import jline.console.ConsoleReader;
import mockit.Invocation;
@@ -120,7 +120,7 @@ public class OnapCliMainTest {
OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("sample-create");
List<String> args = new ArrayList<>(Arrays.asList(new String[] { "sample-create", "--service-name", "test-service", "-i", "ip1", "-i",
"ip2", "-o", "port1=value1", "-o", "port2=value2" }));
- OnapCliUtils.populateParams(cmd.getParameters(), args);
+ OnapCliArgsParser.populateParams(cmd.getParameters(), args);
}
@Test
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 1ea1a22d..ad1a7ccc 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
@@ -63,7 +63,7 @@ public class OnapCliUtilsTest {
String[] args = new String[] { "sample-create", "--host-username", "admin", "--host-password", "123",
"--host-url", "a@b.com", "--string-param", "blah", "--long-opt", "10" };
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
Assert.assertEquals("host-username", expectedList.get(2), param1.getValue());
@@ -82,7 +82,7 @@ public class OnapCliUtilsTest {
paramslist.add(paramargs);
String[] args = new String[] { "positional-args", "http://localhost:8082/file.txt" };
paramargs.setParameterType(ParameterType.STRING);
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
Assert.assertEquals("positional-args", expectedList.get(1), paramslist.get(0).getValue());
}
@@ -97,7 +97,7 @@ public class OnapCliUtilsTest {
String[] args = new String[] { "sample-create", "--bool" };
boolparam.setParameterType(ParameterType.BOOL);
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
@@ -113,7 +113,7 @@ public class OnapCliUtilsTest {
String[] args = new String[] { "sample-create", "-b", };
boolparam.setParameterType(ParameterType.BOOL);
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
}
@@ -128,7 +128,7 @@ public class OnapCliUtilsTest {
String[] args = new String[] { "sample-create", "--text-param" , "text"};
boolparam.setParameterType(ParameterType.TEXT);
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
@@ -144,7 +144,7 @@ public class OnapCliUtilsTest {
String[] args = new String[] { "sample-create", "-e" , "text"};
boolparam.setParameterType(ParameterType.TEXT);
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
}
@@ -159,7 +159,7 @@ public class OnapCliUtilsTest {
File resourcesDirectory = new File("src/test/resources/sampletest.json");
String[] args = new String[] { "sample-create", "-j", "file:" + resourcesDirectory };
jsonparam.setParameterType(ParameterType.JSON);
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
}
@@ -174,7 +174,7 @@ public class OnapCliUtilsTest {
File resourcesDirectory = new File("src/test/resources/sampletest.json");
String[] args = new String[] { "sample-create", "--json-param", "file:" + resourcesDirectory };
jsonparam.setParameterType(ParameterType.JSON);
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
}
@@ -212,7 +212,7 @@ public class OnapCliUtilsTest {
String[] args11 = new String[] { "sample-create", "-u", "admin", "-p", "123", "-r", "a@b.com", "-c", "blah",
"-l", "10", };
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args11));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args11));
List<String> expectedList = Arrays.asList(args11);
@@ -234,7 +234,7 @@ public class OnapCliUtilsTest {
paramslist.add(arrayval);
arrayval.setParameterType(ParameterType.ARRAY);
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
@@ -250,7 +250,7 @@ public class OnapCliUtilsTest {
paramslist.add(param1);
param1.setParameterType(ParameterType.MAP);
- OnapCliUtils.populateParams(paramslist,
+ OnapCliArgsParser.populateParams(paramslist,
Arrays.asList("show", "--map", "param1=value1", "--map", "param2=value2"));
Assert.assertEquals("{\"param1\":\"value1\",\"param2\":\"value2\"}", paramslist.get(0).getValue().toString());
@@ -266,7 +266,7 @@ public class OnapCliUtilsTest {
paramslist.add(param1);
param1.setParameterType(ParameterType.MAP);
- OnapCliUtils.populateParams(paramslist, Arrays.asList("show", "--map", "param1=value1", "--map", "param2"));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList("show", "--map", "param1=value1", "--map", "param2"));
Assert.assertEquals("{\"param1\":\"value1\",\"param2\"}", paramslist.get(0).getValue().toString());
}
@@ -279,7 +279,7 @@ public class OnapCliUtilsTest {
List<OnapCommandParameter> paramslist = new ArrayList<>();
paramslist.add(param1);
param1.setParameterType(ParameterType.MAP);
- OnapCliUtils.populateParams(paramslist, Arrays.asList("show", "-o", "param1=value1", "-o", "param2"));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList("show", "-o", "param1=value1", "-o", "param2"));
Assert.assertEquals("{\"param1\":\"value1\",\"param2\"}", paramslist.get(0).getValue().toString());
}
@@ -292,7 +292,7 @@ public class OnapCliUtilsTest {
String[] args = new String[] { "positional-args", "http://localhost:8082/file.txt",
"http://localhost:8082/file.txt" };
paramargs.setParameterType(ParameterType.STRING);
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
Assert.assertEquals("positional-args", expectedList.get(1), paramslist.get(0).getValue());
}
@@ -307,7 +307,7 @@ public class OnapCliUtilsTest {
String[] args = new String[] { "sample-create", "-b", "-b", "-h" };
boolparam.setParameterType(ParameterType.BOOL);
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
Assert.assertEquals("true", paramslist.get(0).getValue());
}
@@ -322,7 +322,7 @@ public class OnapCliUtilsTest {
String[] args = new String[] { "sample-create", "--bool", "--bool", "--help" };
boolparam.setParameterType(ParameterType.BOOL);
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
Assert.assertEquals("true", paramslist.get(0).getValue());
}
@@ -337,7 +337,7 @@ public class OnapCliUtilsTest {
File resourcesDirectory = new File("src/test/resources/sampletest.json");
String[] args = new String[] { "sample-create", "--json-param", "file:" + resourcesDirectory, "--json-param" };
jsonparam.setParameterType(ParameterType.JSON);
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
Assert.assertEquals("--json-param", paramslist.get(0).getValue());
@@ -353,7 +353,7 @@ public class OnapCliUtilsTest {
File resourcesDirectory = new File("src/test/resources/sampletest.json");
String[] args = new String[] { "sample-create", "-j", "file:" + resourcesDirectory, "-j" };
jsonparam.setParameterType(ParameterType.JSON);
- OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
Assert.assertEquals("--json-param", paramslist.get(0).getValue());