}
/**
- * Initialize this command from command schema.
+ * Initialize this command from command schema and assumes schema is already validated.
*
* @throws OnapCommandRegistrationFailed
* Command Registration Exception
* ParameterNameConflict Exception
* @throws OnapCommandInvalidSchemaVersion
* InvalidSchemaVersion Exception
+ *
+ * @return List of error strings
*/
- public void initializeSchema(String schema) throws OnapCommandException {
+ public List<String> initializeSchema(String schema) throws OnapCommandException {
+ return this.initializeSchema(schema, false);
+ }
+
+ public List<String> initializeSchema(String schema, boolean validate) throws OnapCommandException {
this.setSchemaName(schema);
- OnapCommandSchemaLoaderUtils.loadSchema(this, schema, true, false);
- this.initializeProfileSchema();
+
+ List<String> errors = OnapCommandSchemaLoaderUtils.loadSchema(this, schema, true, validate);
+ errors.addAll(this.initializeProfileSchema());
this.isInitialzied = true;
- }
+ return errors;
+ }
/**
- * Any additional profile based such as http/swagger schema could be initialized.
+ * Any additional profile based such as http schema could be initialized.
*/
- protected void initializeProfileSchema() throws OnapCommandException {
+ protected List<String> initializeProfileSchema() throws OnapCommandException {
+ return new ArrayList<>();
}
/*
package org.onap.cli.fw;
import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import org.onap.cli.fw.error.OnapCommandInvalidRegistration;
import org.onap.cli.fw.error.OnapCommandNotFound;
import org.onap.cli.fw.error.OnapCommandProductVersionInvalid;
-import org.onap.cli.fw.error.OnapCommandRegistrationFailed;
import org.onap.cli.fw.error.OnapCommandRegistrationProductInfoMissing;
import org.onap.cli.fw.error.OnapUnsupportedSchemaProfile;
import org.onap.cli.fw.input.cache.OnapCommandParameterCache;
public class OnapCommandRegistrar {
private Map<String, Class<? extends OnapCommand>> registry = new HashMap<>();
+ private Map<String, Class<? extends OnapCommand>> registryProfilePlugins = new HashMap<>();
+
private Set<String> availableProductVersions = new HashSet<>();
private String enabledProductVersion = OnapCommandConfg.getEnabledProductVersion();
}
+ private void registerProfilePlugin(String profile, Class<? extends OnapCommand> cmd) {
+ this.registryProfilePlugins.put(profile, cmd);
+ }
+
/**
* Get global registrar.
*
return cmds;
}
+ public Class<? extends OnapCommand> getProfilePlugin(String profile) throws OnapUnsupportedSchemaProfile {
+ if (!this.registryProfilePlugins.containsKey(profile)) {
+ throw new OnapUnsupportedSchemaProfile(profile);
+ }
+
+ return this.registryProfilePlugins.get(profile);
+ }
+
public Set<String> getAvailableProductVersions() {
return this.availableProductVersions;
}
throw new OnapCommandNotFound(cmdName, version);
}
- OnapCommand cmd;
- try {
- Constructor<?> constr = cls.getConstructor();
- cmd = (OnapCommand) constr.newInstance();
-
- String schemaName = OnapCommandDiscoveryUtils.getSchemaInfo(cmdName, version).getSchemaName();
-
- cmd.initializeSchema(schemaName);
- } catch (OnapCommandException | NoSuchMethodException | SecurityException | InstantiationException
- | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- throw new OnapCommandRegistrationFailed(cmdName, e);
- }
+ OnapCommand cmd = OnapCommandDiscoveryUtils.loadCommandClass(cls);
+ String schemaName = OnapCommandDiscoveryUtils.getSchemaInfo(cmdName, version).getSchemaName();
+ cmd.initializeSchema(schemaName);
return cmd;
}
if (ano.schema() != null && !ano.schema().isEmpty()) {
map.put(ano.schema(), cmd);
} else if (ano.type() != null && !ano.type().isEmpty()) {
+ this.registerProfilePlugin(ano.type(), cmd);
map.put(ano.type(), cmd);
} else {
throw new OnapUnsupportedSchemaProfile(ano.schema());
}
private void autoDiscoverSchemas() throws OnapCommandException {
- List<SchemaInfo> schemas = OnapCommandDiscoveryUtils.discoverOrLoadSchemas();
+ List<SchemaInfo> schemas = OnapCommandDiscoveryUtils.discoverOrLoadSchemas(true);
Map<String, Class<OnapCommand>> plugins = this.autoDiscoverCommandPlugins();
for (SchemaInfo schema : schemas) {
- if (plugins.containsKey(schema.getSchemaProfile())) {
+ if (schema.isIgnore()) {
+ continue;
+ }
+
+ if (plugins.containsKey(schema.getSchemaName())) {
+ this.register(schema.getCmdName(), schema.getProduct(), plugins.get(schema.getSchemaName()));
+ } else if (plugins.containsKey(schema.getSchemaProfile())) {
this.register(schema.getCmdName(), schema.getProduct(), plugins.get(schema.getSchemaProfile()));
- } else if (plugins.containsKey(schema.getSchemaName())) {
- this.register(schema.getCmdName(), schema.getProduct(), plugins.get(schema.getSchemaName()));
} else {
throw new OnapUnsupportedSchemaProfile(schema.getSchemaURI());
}
}
@Override
- protected void initializeProfileSchema() throws OnapCommandException {
- OnapCommandSchemaLoaderUtils.loadHttpSchema(this, this.getSchemaName(), true, false);
+ protected List<String> initializeProfileSchema() throws OnapCommandException {
+ return OnapCommandSchemaLoaderUtils.loadHttpSchema(this, this.getSchemaName(), true, false);
}
@Override
@Override
protected void run() throws OnapCommandException {
- List<SchemaInfo> schemas = OnapCommandDiscoveryUtils.discoverSchemas();
- // Will override the existing json file
- OnapCommandDiscoveryUtils.persistSchemaInfo(schemas);
-
- for (int i = 0; i < schemas.size(); i++) {
- SchemaInfo schema = schemas.get(i);
- this.getResult().getRecordsMap().get("sr.no").getValues().add(String.valueOf(i + 1));
+ List<SchemaInfo> schemas = OnapCommandDiscoveryUtils.discoverOrLoadSchemas(true);
+ int i = 0;
+ for (SchemaInfo schema : schemas) {
+ if (schema.isIgnore()) {
+ continue;
+ }
+
+ i++;
+ this.getResult().getRecordsMap().get("sr.no").getValues().add(String.valueOf(i));
this.getResult().getRecordsMap().get("command").getValues().add(schema.getCmdName());
this.getResult().getRecordsMap().get("schema").getValues().add(schema.getSchemaName());
this.getResult().getRecordsMap().get("ocs-version").getValues().add(schema.getVersion());
package org.onap.cli.fw.cmd;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
import org.onap.cli.fw.OnapCommand;
+import org.onap.cli.fw.OnapCommandRegistrar;
import org.onap.cli.fw.OnapCommandSchema;
+import org.onap.cli.fw.conf.Constants;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.input.OnapCommandParameter;
+import org.onap.cli.fw.utils.OnapCommandDiscoveryUtils;
import org.onap.cli.fw.utils.OnapCommandSchemaLoaderUtils;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
/**
* Validate schema command.
*/
@Override
protected void run() throws OnapCommandException {
Map<String, OnapCommandParameter> paramMap = getParametersMap();
+
OnapCommandParameter locationParam = paramMap.get("schema-location");
String location = String.valueOf(locationParam.getValue());
+
OnapCommandParameter interSchemaParam = paramMap.get("internal-schema");
boolean isInternalSchema = Boolean.valueOf(String.valueOf(interSchemaParam.getValue()));
- if (isInternalSchema) {
+ if (isInternalSchema && location.startsWith("/")) {
location = location.substring(1);
}
- List<String> error = OnapCommandSchemaLoaderUtils.loadSchema(new OnapCommand() {
- @Override
- protected void run() throws OnapCommandException {
- }
- }, location, true, true);
+ OnapCommandParameter versionParam = paramMap.get("ocs-version");
+ String ocsVersion = String.valueOf(versionParam.getValue());
+ String type = OnapCommandDiscoveryUtils.identitySchemaProfileType(
+ OnapCommandSchemaLoaderUtils.validateSchemaVersion(location, ocsVersion));
- error.addAll(OnapCommandSchemaLoaderUtils.loadHttpSchema(new OnapHttpCommand(),
- location, true, true));
+ OnapCommand cmd = null;
+ if (type.equals(Constants.BASIC_SCHEMA_PROFILE)) {
+ cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {
+ }
+ };
+ } else {
+ cmd = OnapCommandDiscoveryUtils.loadCommandClass(OnapCommandRegistrar.getRegistrar().getProfilePlugin(type));
+ }
+ List<String> error = cmd.initializeSchema(location, true);
List<String> slNumber = new ArrayList<>();
for (int i = 1; i <= error.size(); i++) {
slNumber.add(String.valueOf(i));
}
- this.getResult().getRecords().get(0).setValues(slNumber);
- this.getResult().getRecords().get(1).setValues(error);
+ this.getResult().getRecordsMap().get("sl-no").setValues(slNumber);
+ this.getResult().getRecordsMap().get("error").setValues(error);
}
}
public static final String INFO_SERVICE = "service";
public static final String INFO_TYPE = "type";
public static final String INFO_AUTHOR = "author";
+ public static final String INFO_IGNORE = "ignore";
//parameters
public static final String PARAMETERS = "parameters";
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
+++ /dev/null
-/*
- * 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.error;
-
-/**
- * Command result initialization failed.
- *
- */
-public class OnapCommandExecutorInfoMissing extends OnapCommandException {
-
- private static final long serialVersionUID = 8580121615330415456L;
-
- public OnapCommandExecutorInfoMissing(String cmd) {
- super("0x6002", "Command " + cmd + " excutor info is missing from schema");
- }
-}
private static final long serialVersionUID = -3107017890769007297L;
- public OnapCommandParameterOptionConflict(String name) {
- super("0x7006", "Parameter option " + name + " is in conflict, only one option is allowed with given name");
+ public OnapCommandParameterOptionConflict(String schemaName, String name) {
+ super("0x7006", "In " + schemaName + ", Parameter option " + name + " is in conflict, only one option is allowed with given name");
}
}
private static final String ERROR_CODE = "0xb004";
- private static final String ERROR_MSG = "Unsupported schema profile";
+ private static final String ERROR_MSG = "Unsupported schema profile ";
public OnapUnsupportedSchemaProfile(String schema) {
super(ERROR_CODE, ERROR_MSG + schema);
private CommandType type = CommandType.CMD;
+ private boolean ignore = false;
+
public String getProduct() {
return product;
}
public void setCommandType(CommandType type) {
this.type = type;
}
+
+ public boolean isIgnore() {
+ return ignore;
+ }
+
+ public void setIgnore(boolean ignore) {
+ this.ignore = ignore;
+ }
+
+
}
\ No newline at end of file
package org.onap.cli.fw.input;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandInvalidParameterValue;
import org.onap.cli.fw.error.OnapCommandParameterMissing;
import org.onap.cli.fw.utils.OnapCommandUtils;
-import java.io.File;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Oclip Command's input parameter.
package org.onap.cli.fw.output;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.onap.cli.fw.conf.Constants;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandOutputFormatNotsupported;
import org.onap.cli.fw.output.print.OnapCommandPrint;
import org.onap.cli.fw.utils.OnapCommandUtils;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
/**
* Oclip Command result holds the final output of the command.
*
package org.onap.cli.fw.output;
-import org.onap.cli.fw.input.ParameterType;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.onap.cli.fw.input.ParameterType;
+
/**
* Oclip command output records, helps to define the title and its description while command is defined and during run
* time, it captures the value of the output as well.
package org.onap.cli.fw.output.print;
-import org.apache.commons.csv.CSVFormat;
-import org.apache.commons.csv.CSVPrinter;
-import org.onap.cli.fw.error.OnapCommandOutputPrintingFailed;
-import org.onap.cli.fw.output.PrintDirection;
-
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Map;
import java.util.StringTokenizer;
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVPrinter;
+import org.onap.cli.fw.error.OnapCommandOutputPrintingFailed;
+import org.onap.cli.fw.output.PrintDirection;
+
/**
* Oclip Command Table print.
*
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.onap.cli.fw.conf.OnapCommandConfg;
import org.onap.cli.fw.error.OnapCommandDiscoveryFailed;
import org.onap.cli.fw.error.OnapCommandException;
+import org.onap.cli.fw.error.OnapCommandInstantiationFailed;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
* exception
*/
public static SchemaInfo getSchemaInfo(String cmd, String version) throws OnapCommandException {
- List<SchemaInfo> list = OnapCommandDiscoveryUtils.discoverOrLoadSchemas();
+ List<SchemaInfo> list = OnapCommandDiscoveryUtils.discoverOrLoadSchemas(false);
SchemaInfo schemaInfo = null;
if (list != null) {
for (SchemaInfo schema : list) {
* @throws OnapCommandDiscoveryFailed
* exception
*/
- public static List<SchemaInfo> discoverOrLoadSchemas() throws OnapCommandException {
+ public static List<SchemaInfo> discoverOrLoadSchemas(boolean forceRefresh) throws OnapCommandException {
List<SchemaInfo> schemas = new ArrayList<>();
- if (OnapCommandConfg.isDiscoverAlways() || !OnapCommandDiscoveryUtils.isAlreadyDiscovered()) {
+ if (forceRefresh || OnapCommandConfg.isDiscoverAlways() || !OnapCommandDiscoveryUtils.isAlreadyDiscovered()) {
schemas = OnapCommandDiscoveryUtils.discoverSchemas();
if (!schemas.isEmpty()) {
OnapCommandDiscoveryUtils.persistSchemaInfo(schemas);
return resolver.getResources("classpath*:" + pattern);
}
- static String identitySchemaProfileType(Map<String, ?> schemaYamlMap) {
+ public static String identitySchemaProfileType(Map<String, ?> schemaYamlMap) {
for (String schemeType : OnapCommandConfg.getSchemaAttrInfo(Constants.SCHEMA_TYPES_SUPPORTED)) {
if (schemaYamlMap.get(schemeType) != null) {
for (Resource resource : res) {
try {
- resourceMap = loadSchema(resource);
+ resourceMap = OnapCommandSchemaLoaderUtils.loadSchema(resource);
} catch (OnapCommandException e) {
- OnapCommandUtils.LOG.error("Invalid schema " + resource.getURI().toString(), e);
+ OnapCommandUtils.LOG.error("Ignores invalid schema " + resource.getURI().toString(), e);
continue;
}
schema.setProduct(infoMap.get(Constants.INFO_PRODUCT).toString());
}
+ if (infoMap != null && infoMap.get(Constants.INFO_IGNORE) != null) {
+ schema.setIgnore(infoMap.get(Constants.INFO_IGNORE).toString());
+ }
schema.setSchemaProfile(identitySchemaProfileType(resourceMap));
extSchemas.add(schema);
return clss;
}
+ /**
+ * Instantiate command plugin
+ * @throws OnapCommandInstantiationFailed
+ */
+ public static OnapCommand loadCommandClass(Class <? extends OnapCommand> cls) throws OnapCommandInstantiationFailed {
+ try {
+ Constructor<?> constr = cls.getConstructor();
+ return (OnapCommand) constr.newInstance();
+ } catch (NoSuchMethodException | SecurityException | InstantiationException
+ | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ throw new OnapCommandInstantiationFailed(cls.getName(), e);
+ }
+
+ }
}
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_IGNORE;
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 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.Constants;
import org.onap.cli.fw.conf.OnapCommandConfg;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
inputStream = OnapCommandSchemaLoaderUtils.loadSchemaFromFile(schemaName);
}
- Map<String, ?> values = null;
- try {
- values = (Map<String, ?>) new Yaml().load(inputStream);
- } catch (Exception e) {
- throw new OnapCommandInvalidSchema(schemaName, e);
- }
+ Map<String, ?> values = OnapCommandSchemaLoaderUtils.loadSchema(inputStream, schemaName);
String schemaVersion = "";
if (values.keySet().contains(OPEN_CLI_SCHEMA_VERSION)) {
Object obj = values.get(OPEN_CLI_SCHEMA_VERSION);
if (includeDefault) {
Map<String, ?> defaultParameterMap = includeDefault ?
validateSchemaVersion(DEFAULT_PARAMETER_FILE_NAME, cmd.getSchemaVersion()) : new HashMap<>();
+ //mrkanag default_parameter is supported only for parameters.
+ if (defaultParameterMap.containsKey(INFO)) {
+ defaultParameterMap.remove(Constants.INFO);
+ }
+
errors.addAll(OnapCommandSchemaLoaderUtils.parseSchema(cmd, defaultParameterMap, validateSchema));
}
if (includeDefault) {
Map<String, ?> defaultParameterMap = includeDefault ?
validateSchemaVersion(DEFAULT_PARAMETER_HTTP_FILE_NAME, cmd.getSchemaVersion()) : new HashMap<>();
+
+ //mrkanag default_parameter is supported only for parameters.
+ if (defaultParameterMap.containsKey(INFO)) {
+ defaultParameterMap.remove(Constants.INFO);
+ }
+
errors.addAll(OnapCommandSchemaLoaderUtils.parseSchema(cmd, defaultParameterMap, validateSchema));
}
Object mode = infoMap.get(key1);
info.setAuthor(mode.toString());
break;
+
+ case INFO_IGNORE:
+ Object ignore = infoMap.get(key1);
+ info.setIgnore(ignore.toString().equalsIgnoreCase(Constants.BOOLEAN_TRUE));
+ break;
}
}
case SHORT_OPTION:
if (shortOptions.contains(parameter.get(key2))) {
- OnapCommandUtils.throwOrCollect(new OnapCommandParameterOptionConflict(parameter.get(key2)), exceptionList, validate);
+ OnapCommandUtils.throwOrCollect(new OnapCommandParameterOptionConflict(
+ cmd.getSchemaName(),
+ parameter.get(key2)), exceptionList, validate);
}
shortOptions.add(parameter.get(key2));
param.setShortOption(parameter.get(key2));
case LONG_OPTION:
if (longOptions.contains(parameter.get(key2))) {
- OnapCommandUtils.throwOrCollect(new OnapCommandParameterOptionConflict(parameter.get(key2)), exceptionList, validate);
+ OnapCommandUtils.throwOrCollect(new OnapCommandParameterOptionConflict(
+ cmd.getSchemaName(),
+ parameter.get(key2)), exceptionList, validate);
}
longOptions.add(parameter.get(key2));
param.setLongOption(parameter.get(key2));
return errorList;
}
- static InputStream loadSchemaFromFile(String schemaLocation) throws OnapCommandInvalidSchema {
+ public static InputStream loadSchemaFromFile(String schemaLocation) throws OnapCommandInvalidSchema {
File schemaFile = new File(schemaLocation);
try {
FileInputStream inputFileStream = new FileInputStream(schemaFile);
}
}
+ /**
+ * Get schema map.
+ *
+ * @param resource
+ * resource obj
+ * @return map
+ * @throws OnapCommandInvalidSchema
+ * exception
+ */
+ public static Map<String, ?> loadSchema(Resource resource) throws OnapCommandInvalidSchema {
+ try {
+ return OnapCommandSchemaLoaderUtils.loadSchema(resource.getInputStream(), resource.getFilename());
+ } catch (IOException e) {
+ throw new OnapCommandInvalidSchema(resource.getFilename(), e);
+ }
+
+ }
+
+ /**
+ * Get schema map.
+ *
+ * @param resource
+ * resource obj
+ * @return map
+ * @throws OnapCommandInvalidSchema
+ * exception
+ */
+ public static Map<String, ?> loadSchema(InputStream stream, String schemaName) throws OnapCommandInvalidSchema {
+ Map<String, ?> values = null;
+ try {
+ values = (Map<String, ?>) new Yaml().load(stream);
+ } catch (Exception e) {
+ throw new OnapCommandInvalidSchema(schemaName, e);
+ }
+
+ return values;
+ }
}
private String schemaProfile = Constants.BASIC_SCHEMA_PROFILE;
+ private String ignore = Constants.BOOLEAN_FALSE;
+
public String getSchemaName() {
return schemaName;
}
this.type = type;
}
+ public boolean isIgnore() {
+ return Constants.BOOLEAN_TRUE.equalsIgnoreCase(this.getIgnore());
+ }
+
+ public String getIgnore() {
+ return ignore;
+ }
+
+ public void setIgnore(String ignore) {
+ this.ignore = ignore;
+ }
}
open_cli_schema_version: 1.0
+
+info:
+ product: open-cli
+ service: default-param
+ ignore: true
+
parameters:
- name: help
type: string
open_cli_schema_version: 1.0
+
+info:
+ product: open-cli
+ service: default-param
+ ignore: true
+
parameters:
- name: host-username
type: string
short_option: i
long_option: internal-schema
is_optional: false
+ - name: ocs-version
+ type: string
+ description: OCS version
+ short_option: b
+ long_option: ocs-version
+ is_optional: true
+ default_value: 1.0
results:
direction: landscape
cli.schema.top_level_params_list=open_cli_schema_version,name,description,parameters,results,http,info
cli.schema.top_level_mandatory_list=open_cli_schema_version
-cli.schema.info_params_list=product,service,type,author
+cli.schema.info_params_list=product,service,type,author,ignore
cli.schema.info_params_mandatory_list=product,service
cli.schema.input_params_list=name,description,type,short_option,long_option, is_optional,default_value,is_secured,is_include
Enabled product : __ENABLED_PRODUCT_VERSIONS__
To enable a product, use one of following methods:
-1. In scripting mode, Set environment variable OPEN_CLI_PRODUCT_IN_USE
-2. In interactive mode, set the directive 'use <product>'
+1. In scripting mode, set environment variable OPEN_CLI_PRODUCT_IN_USE
+2. In interactive mode, use the directive 'use <product>'
import java.net.URL;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandHelpFailed;
import org.onap.cli.fw.error.OnapCommandNotFound;
-import org.onap.cli.fw.error.OnapCommandRegistrationFailed;
public class OnapCommandRegistrarTest {
package org.onap.cli.fw.cmd;
-import org.junit.Test;
-import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.output.OnapCommandResultAttribute;
+import static org.junit.Assert.assertTrue;
import java.util.List;
-import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+import org.onap.cli.fw.error.OnapCommandException;
+import org.onap.cli.fw.output.OnapCommandResultAttribute;
public class OnapSchemaRefreshCommandTest {
cmd.initializeSchema("schema-refresh.yaml");
cmd.execute();
- List<OnapCommandResultAttribute> oclipCommandResultAttribute = cmd.getResult()
+ List<OnapCommandResultAttribute> oclipCommandResultAttributes = cmd.getResult()
.getRecords();
- String s1Number = oclipCommandResultAttribute.get(0).getValues().get(0);
- String cmdName = oclipCommandResultAttribute.get(1).getValues().get(0);
- String cmdVer = oclipCommandResultAttribute.get(2).getValues().get(0);
- String cmdFile = oclipCommandResultAttribute.get(3).getValues().get(0);
- String version = oclipCommandResultAttribute.get(4).getValues().get(0);
- assertTrue(s1Number.equalsIgnoreCase("1"));
+ assertTrue(oclipCommandResultAttributes.size() > 1);
+
}
}
package org.onap.cli.fw.cmd;
+import org.junit.Ignore;
import org.junit.Test;
+import org.onap.cli.fw.OnapCommand;
+import org.onap.cli.fw.OnapCommandRegistrar;
import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.schema.ValidateSchemaTest;
+
public class OnapSchemaValidateCommandTest {
+ @Ignore
@Test
public void validateSchemaCommandTest1() throws OnapCommandException {
- OnapSchemaValidateCommand cmd = new OnapSchemaValidateCommand();
- cmd.initializeSchema("schema-validate.yaml");
- for (OnapCommandParameter param : cmd.getParameters()) {
- if ("host-username".equals(param.getName())) {
- param.setValue("test");
- } else if ("host-password".equals(param.getName())) {
- param.setValue("test");
- } else if ("host-url".equals(param.getName())) {
- param.setValue("test-url");
- } else if ("schema-location".equals(param.getName())) {
- param.setValue("schema-validate-pass.yaml");
- } else if ("internal-schema".equals(param.getName())) {
- param.setValue("true");
- }
- }
+ OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("schema-validate");
+ cmd.getParametersMap().get("schema-location").setValue("schema-validate-pass.yaml");
+ cmd.getParametersMap().get("internal-schema").setValue("true");
cmd.execute();
}
+ @Ignore
@Test
public void validateSchemaCommandTest2() throws OnapCommandException {
- OnapSchemaValidateCommand cmd = new OnapSchemaValidateCommand();
- cmd.initializeSchema("schema-validate.yaml");
- for (OnapCommandParameter param : cmd.getParameters()) {
- if ("host-username".equals(param.getName())) {
- param.setValue("test");
- } else if ("host-password".equals(param.getName())) {
- param.setValue("test");
- } else if ("host-url".equals(param.getName())) {
- param.setValue("test-url");
- } else if ("schema-location".equals(param.getName())) {
- param.setValue(
- ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-pass.yaml").getFile());
- }
- }
+ OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("schema-validate");
+ cmd.getParametersMap().get("schema-location").setValue(
+ ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-pass.yaml").getFile());
+ cmd.getParametersMap().get("internal-schema").setValue("true");
cmd.execute();
}
}
package org.onap.cli.fw.conf;
-import org.junit.Assert;
-import org.junit.Test;
-
import java.io.IOException;
import java.util.Properties;
+import org.junit.Assert;
+import org.junit.Test;
+
public class OnapCommandConfgTest {
@Test
@Test
public void oclipCommandExecutorInfoMissingTest() {
- OnapCommandExecutorInfoMissing failed = new OnapCommandExecutorInfoMissing("Test");
+ OnapCommandInstantiationFailed failed = new OnapCommandInstantiationFailed("Test");
- assertEquals("0x6002::Command Test excutor info is missing from schema", failed.getMessage());
+ assertEquals("0x6002::Failed to instantiate the command plugin Test", failed.getMessage());
}
@Test
@Test
public void oclipCommandParameterOptionConflictTest() {
- OnapCommandParameterOptionConflict failed = new OnapCommandParameterOptionConflict("option");
+ OnapCommandParameterOptionConflict failed = new OnapCommandParameterOptionConflict("test", "option");
- assertEquals("0x7006::Parameter option option is in conflict, only one option is allowed with given name",
+ assertEquals("0x7006::In test, Parameter option option is in conflict, only one option is allowed with given name",
failed.getMessage());
}
OnapCommandInvalidCommandType failed = new OnapCommandInvalidCommandType("test");
assertEquals("0x3003::Command type test is invalid", failed.getMessage());
- }
+ }
}
import static org.junit.Assert.assertTrue;
-import org.junit.Test;
-
import java.util.HashMap;
+import org.junit.Test;
+
public class HttpInputOutputTest {
@Test
package org.onap.cli.fw.http;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import mockit.Invocation;
-import mockit.Mock;
-import mockit.MockUp;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandHttpFailure;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
+import mockit.Invocation;
+import mockit.Mock;
+import mockit.MockUp;
public class OnapHttpConnectionTest {
HttpInput inp = null;
package org.onap.cli.fw.input;
-import org.junit.Test;
-import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.error.OnapCommandInvalidParameterValue;
+import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
-import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+import org.onap.cli.fw.error.OnapCommandException;
+import org.onap.cli.fw.error.OnapCommandInvalidParameterValue;
public class OnapCommandParameterTest {
import static org.junit.Assert.assertTrue;
+import java.util.Collections;
+
import org.junit.Test;
import org.onap.cli.fw.input.ParameterType;
-import java.util.Collections;
-
public class OnapCommandResultAttributeScopeTest {
@Test
public void oclipCommandResultAttributeTest() {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
import org.junit.Ignore;
import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.input.ParameterType;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
public class OnapCommandResultTest {
@Test
import static org.junit.Assert.assertEquals;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
import org.junit.Ignore;
import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandOutputPrintingFailed;
import org.onap.cli.fw.output.PrintDirection;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
public class OnapCommandPrintTest {
@Test
import static org.junit.Assert.assertEquals;
-import org.junit.Before;
-import org.junit.Test;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+
public class TableGeneratorTest {
private TableGenerator table;
package org.onap.cli.fw.schema;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
import org.junit.Test;
import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.cmd.OnapHttpCommand;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
import org.onap.cli.fw.utils.OnapCommandSchemaLoaderUtils;
-import java.util.List;
-
-import static org.junit.Assert.assertTrue;
-
public class ValidateSchemaTest {
@Test(expected = OnapCommandInvalidSchema.class)
--- /dev/null
+cli.ignore_auth=false
+cli.http.api_key_use_cookies=true
+cli.discover_always=true
+cli.product_name=open-cli
+cli.version=1.0
+
+#schema validation
+cli.schema.top_level_params_list=open_cli_schema_version,name,description,parameters,results,http,info
+cli.schema.top_level_mandatory_list=open_cli_schema_version
+
+cli.schema.info_params_list=product,service,type,author,ignore
+cli.schema.info_params_mandatory_list=product,service
+
+cli.schema.input_params_list=name,description,type,short_option,long_option, is_optional,default_value,is_secured,is_include
+cli.schema.input_params_mandatory_list=name,description,type
+
+cli.schema.result_params_list=name,description,scope,type,is_secured, default_value
+cli.schema.result_params_mandatory_list=name, description, type, scope
+
+#http
+cli.schema.http_sections=request,service,success_codes,result_map,sample_response
+cli.schema.http_mandatory_sections=request, success_codes
+
+cli.schema.http_request_params=uri,method,body,headers,queries,multipart_entity_name
+cli.schema.http_request_mandatory_params=uri,method
+
+cli.schema.service_params_list=name,version,auth,mode
+cli.schema.service_params_mandatory_list=auth,mode
+
+cli.schema.http_methods=post,get,delete,put,head
+
+cli.schema.boolean_values=true,false
+cli.schema.auth_values=none,basic
+cli.schema.mode_values=direct,catalog
+cli.command.type=cmd,auth,catalog
+
+# mrkanag Move this to db, once exteranl command registration is supported in place of discovery
+cli.schema.type.supported=http
+
description: name of the person
long_option: name
short_option: b
- default_value: ${DEMO_NAME}
+ default_value: ${env:DEMO_NAME}
type: string
is_optional: false
System.out.println(version);
System.out.println("==========================\n\n");
for (SchemaInfo sch : OnapCommandRegistrar.getRegistrar().listCommandInfo()) {
+ if (sch.isIgnore()) {
+ continue;
+ }
if (sch.getProduct().equals(version)) {
System.out.println(
"************************* validate '" + sch.getCmdName() + "' *******************************");
System.out.println("==========================\n\n");
int i = 1;
for (SchemaInfo sch : OnapCommandRegistrar.getRegistrar().listCommandInfo()) {
+ if (sch.isIgnore()) {
+ continue;
+ }
if (sch.getProduct().equals(version)) {
System.out.println("[" + i++ + "] " + sch.getCmdName());
System.out.println("-----------------------------------------------\n\n");