diff options
Diffstat (limited to 'framework')
17 files changed, 159 insertions, 67 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionListCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionListCommand.java index 5470472c..349fb52e 100644 --- a/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionListCommand.java +++ b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionListCommand.java @@ -37,7 +37,7 @@ public class OnapCommandExceutionListCommand extends OnapCommand { protected void run() throws OnapCommandException { Map<String, String> map = new HashMap<>(); - for (String input: Arrays.asList(new String []{"request-id", "product", "service", "command", "profile", "start-time", "end-time"})) { + for (String input: Arrays.asList("request-id", "product", "service", "command", "profile", "start-time", "end-time")) { String value = getParametersMap().get(input).getValue().toString(); if (value != null && !value.isEmpty()) { map.put(input, value); diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapProductsListCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapProductsListCommand.java index 10d9c448..42dc27e2 100644 --- a/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapProductsListCommand.java +++ b/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapProductsListCommand.java @@ -59,7 +59,7 @@ public class OnapProductsListCommand extends OnapCommand { if (stream != null) { Map<String, ?> map = OnapCommandDiscoveryUtils.loadYaml(stream); Map<String, String> productMap = (Map<String, String>) map.get("product"); - String description = (String) productMap.get(OnapCommandConstants.DESCRIPTION); + String description = productMap.get(OnapCommandConstants.DESCRIPTION); this.getResult().getRecordsMap().get("description").getValues().add(description.trim()); } else { this.getResult().getRecordsMap().get("description").getValues().add(""); diff --git a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultAttribute.java b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultAttribute.java index 76af42d7..307e1b98 100644 --- a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultAttribute.java +++ b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultAttribute.java @@ -94,7 +94,7 @@ public class OnapCommandResultAttribute { public List<String> getValues() { if (this.values.isEmpty() && !this.defaultValue.isEmpty()) { - return Arrays.asList(new String [] {this.defaultValue}); + return Arrays.asList(this.defaultValue); } return values; } diff --git a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultType.java b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultType.java index ebd13ebd..a1029ca2 100644 --- a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultType.java +++ b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResultType.java @@ -31,11 +31,7 @@ public enum OnapCommandResultType { * @return boolean */ public static boolean isTabularForm(String type) { - if (type.equalsIgnoreCase(TABLE.name())) { - return true; - } - - return false; + return type.equalsIgnoreCase(TABLE.name()); } /** diff --git a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java index 8d707906..7a125ce5 100644 --- a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java +++ b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java @@ -238,7 +238,7 @@ public class OnapCommandPrint { public Object getJsonNodeOrString(String value) { try { - return (JSONObject) JSONValue.parse(value); + return JSONValue.parse(value); } catch (Exception e) { return value; } diff --git a/framework/src/main/java/org/onap/cli/fw/output/print/TableGenerator.java b/framework/src/main/java/org/onap/cli/fw/output/print/TableGenerator.java index 8be7952d..389a98fe 100644 --- a/framework/src/main/java/org/onap/cli/fw/output/print/TableGenerator.java +++ b/framework/src/main/java/org/onap/cli/fw/output/print/TableGenerator.java @@ -80,7 +80,7 @@ public class TableGenerator { for (int cellIndex = 0; cellIndex < row.size(); cellIndex++) { Object cell = row.get(cellIndex); String finalCell = ""; - if (cell != null && cell instanceof List) { + if (cell instanceof List) { List<String> list = (List<String>) cell; if (splitCellIndex < list.size()) { finalCell = list.get(splitCellIndex); diff --git a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java index 41be2332..4f6e4ea5 100644 --- a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java +++ b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java @@ -346,11 +346,7 @@ public class OnapCommandSchemaLoader { IS_OPTIONAL, String.valueOf(parameter.get(key2)))); } - if (BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))) { - param.setOptional(true); - } else { - param.setOptional(false); - } + param.setOptional(BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))); break; case IS_SECURED: @@ -361,11 +357,7 @@ public class OnapCommandSchemaLoader { } } - if (BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))) { - param.setSecured(true); - } else { - param.setSecured(false); - } + param.setSecured(BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))); break; case IS_INCLUDE: @@ -374,11 +366,7 @@ public class OnapCommandSchemaLoader { IS_INCLUDE, String.valueOf(parameter.get(key2)))); } - if (BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))) { - param.setInclude(true); - } else { - param.setInclude(false); - } + param.setInclude(BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))); break; case IS_DEFAULT_PARAM: @@ -389,11 +377,7 @@ public class OnapCommandSchemaLoader { } } - if (BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))) { - param.setDefaultParam(true); - } else { - param.setDefaultParam(false); - } + param.setDefaultParam(BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))); break; } } @@ -477,11 +461,7 @@ public class OnapCommandSchemaLoader { IS_SECURED, String.valueOf(map.get(key4)))); } } - if (BOOLEAN_TRUE.equals(String.valueOf(map.get(key4)))) { - attr.setSecured(true); - } else { - attr.setSecured(false); - } + attr.setSecured(BOOLEAN_TRUE.equals(String.valueOf(map.get(key4)))); break; case IS_DEFAULT_ATTR: @@ -491,11 +471,7 @@ public class OnapCommandSchemaLoader { IS_DEFAULT_ATTR, String.valueOf(map.get(key4)))); } } - if (BOOLEAN_TRUE.equals(String.valueOf(map.get(key4)))) { - attr.setDefaultAttr(true); - } else { - attr.setDefaultAttr(false); - } + attr.setDefaultAttr(BOOLEAN_TRUE.equals(String.valueOf(map.get(key4)))); break; } diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java index 9e230ff3..b0ebbda5 100644 --- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java +++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java @@ -59,17 +59,17 @@ public class OnapCommandExecutionStore { private static String SEPARATOR = "__"; private enum SearchMode { - find, - file //for developer mode + FIND, + FILE //for developer mode } - private static SearchMode SEARCH_MODE = SearchMode.file; + private static SearchMode SEARCH_MODE = SearchMode.FILE; static { String mode = OnapCommandConfig.getPropertyValue(OnapCommandConstants.OPEN_CLI_EXECUTION_SEARCH_MODE); - if (mode.equalsIgnoreCase(SearchMode.find.name())) - SEARCH_MODE = SearchMode.find; + if (mode.equalsIgnoreCase(SearchMode.FIND.name())) + SEARCH_MODE = SearchMode.FIND; } public static class ExecutionStoreContext { @@ -334,7 +334,7 @@ public class OnapCommandExecutionStore { try { List <String> dirs = new ArrayList<>(); - if (System.getProperty("os.name").toLowerCase().startsWith("windows") || SEARCH_MODE.equals(SearchMode.file)) { + if (System.getProperty("os.name").toLowerCase().startsWith("windows") || SEARCH_MODE.equals(SearchMode.FILE)) { for (File f: new File(getBasePath()).listFiles()) { if(search.containsKey(EXECUTIONID)) { if (f.getName().startsWith(search.get(EXECUTIONID))) @@ -379,7 +379,7 @@ public class OnapCommandExecutionStore { searchString.append("*"); } - for (String term: Arrays.asList(new String []{"product", "service", "command", "profile"})) { + for (String term: Arrays.asList("product", "service", "command", "profile")) { searchString.append("__"); if (search.get(term) != null && !search.get(term).isEmpty()) { searchString.append(search.get(term)); @@ -453,8 +453,7 @@ public class OnapCommandExecutionStore { @Override public boolean accept(File dir, String name) { - if (name.startsWith(executionId)) return true; - return false; + return name.startsWith(executionId); } }); diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java index 7a4dc49f..0db96956 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java @@ -57,8 +57,6 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; import com.esotericsoftware.yamlbeans.YamlReader; -import com.esotericsoftware.yamlbeans.YamlException; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.stream.JsonReader; @@ -86,7 +84,7 @@ public class OnapCommandDiscoveryUtils { public static OnapCommandSchemaInfo getSchemaInfo(String cmd, String version) throws OnapCommandException { List<OnapCommandSchemaInfo> list = OnapCommandDiscoveryUtils.discoverOrLoadSchemas(false); OnapCommandSchemaInfo schemaInfo = null; - if (list != null) { + if (list != null) { //NOSONAR for (OnapCommandSchemaInfo schema : list) { if (cmd.equals(schema.getCmdName()) && version.equals(schema.getProduct())) { schemaInfo = schema; @@ -237,7 +235,7 @@ public class OnapCommandDiscoveryUtils { */ public static Resource findResource(String fileName, String pattern) throws IOException { Resource[] resources = OnapCommandDiscoveryUtils.findResources(pattern); - if (resources != null && resources.length > 0) { + if (resources != null && resources.length > 0) { //NOSONAR for (Resource res : resources) { if (res.getFilename().equals(fileName)) { return res; @@ -305,7 +303,7 @@ public class OnapCommandDiscoveryUtils { //default_input_parameters_http.yaml String profileName = resource.getFilename().substring( DEAFULT_INPUT_PARAMETERS_NAME.length() + 1, - resource.getFilename().indexOf(".")); + resource.getFilename().indexOf('.')); if (deafultResourceMap.containsKey(PARAMETERS)) { List<Object> params = new ArrayList<>(); for (Map<String, ?> p: (List<Map<String, ?>>) deafultResourceMap.get(PARAMETERS)) { @@ -491,7 +489,7 @@ public class OnapCommandDiscoveryUtils { OnapCommandSchemaInfo schemaInfo = getSchemaInfo(cmd, version); List<String> sampleFiles = new ArrayList<>(); - if (schemaInfo != null && !schemaInfo.getSampleFiles().isEmpty()) { + if (schemaInfo != null && !schemaInfo.getSampleFiles().isEmpty()) { //NOSONAR sampleFiles.addAll(schemaInfo.getSampleFiles()); } @@ -584,8 +582,6 @@ public class OnapCommandDiscoveryUtils { try(InputStreamReader inputStreamReader = new InputStreamReader(inputStream);){ YamlReader reader = new YamlReader(inputStreamReader); values = (Map<String, ?>) reader.read(); - } catch (YamlException e) { - throw new OnapCommandInvalidSchema(inputStream.getClass().getName(),e.getMessage()); } catch (IOException e) { throw new OnapCommandInvalidSchema(inputStream.getClass().getName(),e.getMessage()); } diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java index 323e9e76..e1150888 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java @@ -183,7 +183,7 @@ public class OnapCommandHelperUtils { resultTable.getRecords().add(attrHelp); } - if (cmd.getResult().getRecords().size() > 0) { + if (!cmd.getResult().getRecords().isEmpty()) { try { help.append("\n\nResults::\n\n" + resultTable.print()); } catch (OnapCommandException e) { 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 814f5139..ea8e6480 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 @@ -124,7 +124,7 @@ public class OnapCommandUtils { if (idxS == -1) { break; } - int idxE = line.indexOf("}", idxS); + int idxE = line.indexOf('}', idxS); String paramName = line.substring(idxS + 2, idxE); paramNames.add(paramName.trim()); @@ -213,7 +213,7 @@ public class OnapCommandUtils { resultLine.append(line.substring(currentIdx)); break; } - int idxE = line.indexOf("}", idxS); + int idxE = line.indexOf('}', idxS); String attr = line.substring(idxS + 3, idxE); attr = attr.trim(); @@ -246,7 +246,7 @@ public class OnapCommandUtils { resultSpl.append(lineSpl.substring(currentIdx)); break; } - int idxE = lineSpl.indexOf("}", idxS); + int idxE = lineSpl.indexOf('}', idxS); String splEntry = lineSpl.substring(idxS + 3, idxE); splEntry = splEntry.trim(); @@ -319,7 +319,7 @@ public class OnapCommandUtils { result.append(line.substring(currentIdx)); break; } - int idxE = line.indexOf("}", idxS); + int idxE = line.indexOf('}', idxS); String paramName = line.substring(idxS + 2, idxE); paramName = paramName.trim(); if (!params.containsKey(paramName)) { diff --git a/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java b/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java index bb37c470..69df6075 100644 --- a/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java +++ b/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java @@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.nio.charset.StandardCharsets; public class ProcessRunner { private static Logger log = LoggerFactory.getLogger(ProcessRunner.class); @@ -127,7 +128,7 @@ public class ProcessRunner { public void run() { try { IOUtils.copy(stdoutP, stdout); - } catch (IOException e) { + } catch (IOException e) { // NOSONAR } } }); @@ -136,7 +137,7 @@ public class ProcessRunner { public void run() { try { IOUtils.copy(stderrP, stderr); - } catch (IOException e) { + } catch (IOException e) { // NOSONAR } } }); @@ -153,10 +154,10 @@ public class ProcessRunner { } if (readOutput) - this.output = new String(((ByteArrayOutputStream)this.getStdout()).toByteArray(), "UTF-8"); + this.output = new String(((ByteArrayOutputStream)this.getStdout()).toByteArray(), StandardCharsets.UTF_8); if (readError) - this.error = new String(((ByteArrayOutputStream)this.getStderr()).toByteArray(), "UTF-8");; + this.error = new String(((ByteArrayOutputStream)this.getStderr()).toByteArray(), StandardCharsets.UTF_8); p.destroy(); diff --git a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java index 3e32f3e1..60aa5e7d 100644 --- a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java +++ b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java @@ -114,7 +114,7 @@ public class OnapCommandSampleTest { UUID.fromString(attrValue.substring(4)); attr = sample.getResult().getRecordsMap().get("output-2"); attrValue = attr.getValues().get(0); - assertEquals(attrValue, "test"); + assertEquals("test", attrValue); } catch (IllegalArgumentException e) { fail("Failed to replace the output default value on output-1"); } catch (OnapCommandException e) { diff --git a/framework/src/test/java/org/onap/cli/fw/conf/OnapCommandConfgTest.java b/framework/src/test/java/org/onap/cli/fw/conf/OnapCommandConfgTest.java index d6ef3a34..ae620632 100644 --- a/framework/src/test/java/org/onap/cli/fw/conf/OnapCommandConfgTest.java +++ b/framework/src/test/java/org/onap/cli/fw/conf/OnapCommandConfgTest.java @@ -16,6 +16,14 @@ package org.onap.cli.fw.conf; +import org.junit.Test; + public class OnapCommandConfgTest { + @Test + public void addPropertiesTest() { + + OnapCommandConfig.getPropertyValue("cli.schema.profile.confs"); + } + } 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 5831c272..4c64ca2a 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 @@ -123,4 +123,18 @@ public class ValidateSchemaTest { assertTrue(errorList5.size() == 0); } + + @Test + public void validateAfterRemovingIfElseTest() throws OnapCommandException { + OnapCommand cmd2 = new OnapCommand() { + @Override + protected void run() throws OnapCommandException { + + } + }; + List < String > errorList2 = OnapCommandSchemaLoader.loadSchema(cmd2, + "schema-validate-basic-default-attr.yaml", true, true); + assertTrue(errorList2.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 e01c3878..b7da1c2f 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 @@ -533,4 +533,15 @@ public class OnapCommandUtilsTest { public void testMd5(){ assertNotNull(OnapCommandUtils.md5("a")); } + + @Test + public void replaceLineFromResults() { + Map<String, String> mapExample = new HashMap<String, String>(); + mapExample.put("key1", "paramA"); + mapExample.put("key2", "paramB"); + OnapCommandUtils.replaceLineFromResults("line $r{paramA} line $r{paramB}", mapExample); + assertTrue(mapExample.get("key1").equals("paramA")); + assertTrue(mapExample.get("key2").equals("paramB")); + } + } diff --git a/framework/src/test/resources/schema-validate-basic-default-attr.yaml b/framework/src/test/resources/schema-validate-basic-default-attr.yaml new file mode 100644 index 00000000..03d06281 --- /dev/null +++ b/framework/src/test/resources/schema-validate-basic-default-attr.yaml @@ -0,0 +1,91 @@ +# Copyright 2018 Huawei Technologies Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +open_cli_schema_version: 1.0 +description: Register microservice into Onap +name: schema-validate +info: + product: open-cli + service: test + type: cmd + author: Sravan Kumar sravan.kumar1@huawei.com +parameters: + - name: service-name1 + description: Oclip service name + type: string + short_option: x + long_option: service-name + is_optional: false + - name: service-version + description: Oclip service version + type: string + short_option: y + long_option: service-version + is_optional: false + - name: service-url + description: Oclip service base url + type: url1 + short_option: u + long_option: service-url + is_optional: false1 + - name: status + description: Oclip service status + type: digit + short_option: z + long_option: service-version + is_optional: true + default_value: 1 + - name: node-ip + description: Oclip service running node IP + type: string + - name: node-port + description: Oclip service running node port + type: string + - name: create-or-update + description: Oclip service create or update + type: cfbcv + default_value: true +results: + direction: portrait1 + attributes: + - name: name + description: Oclip service name + scope: short + type: string + is_default_attr: true + - name: version + description: Oclip service version + scope: short + type: string + is_default_attr: true + - name: status + description: Oclip service base url + scope: short + type: url + is_default_attr: true + - name: status + description: Oclip service status + scope: short1 + type: digit + is_default_attr: true + - name: nodes + description: Oclip service running nodes + scope: long + type: string + is_default_attr: true + - name: location + description: Oclip service location + scope: long + type: url + is_default_attr: true
\ No newline at end of file |