summaryrefslogtreecommitdiffstats
path: root/framework/src
diff options
context:
space:
mode:
authorSravanKumarGunda <sravan.kumar1@huawei.com>2020-07-14 14:55:47 +0530
committerSravanKumarGunda <sravan.kumar1@huawei.com>2020-07-14 19:22:59 +0530
commit9a08d687e48312beef47bce357d374ede2ce0dc7 (patch)
tree3717d377dd4ea90f4e88c28d52bb3c0d5d28f34c /framework/src
parent5f23e02caa5ab128a4c01866dec91eaea8dc7cee (diff)
Code Improvements
Signed-off-by: SravanKumarGunda <sravan.kumar1@huawei.com> Issue-ID: CLI-270 Change-Id: I3de621dab68f153c16a36102239b095c60abf9ab
Diffstat (limited to 'framework/src')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java5
-rw-r--r--framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java1
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java4
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java10
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java6
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommandTest.java4
-rw-r--r--framework/src/test/java/org/onap/cli/fw/info/OnapCommandInfoTest.java6
-rw-r--r--framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java11
-rw-r--r--framework/src/test/java/org/onap/cli/fw/input/ParameterTypeTest.java3
-rw-r--r--framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultAttributeTest.java3
-rw-r--r--framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java12
-rw-r--r--framework/src/test/java/org/onap/cli/fw/output/PrintDirectionTest.java3
-rw-r--r--framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java2
-rw-r--r--framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java2
-rw-r--r--framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java3
-rw-r--r--framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java6
17 files changed, 38 insertions, 45 deletions
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 7a125ce5..09050c6c 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
@@ -71,10 +71,7 @@ public class OnapCommandPrint {
* @return list
*/
public List<String> getColumn(String header) {
- if (this.data.get(header) == null) {
- this.data.put(header, new ArrayList<String>());
- }
- return this.data.get(header);
+ return this.data.computeIfAbsent(header, k -> new ArrayList<String>());
}
public boolean isPrintTitle() {
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 04a81aa7..7de56025 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
@@ -511,7 +511,7 @@ public class OnapCommandSchemaLoader {
* @throws OnapCommandInvalidSchema
* exception
*/
- public static Map<String, Object> loadSchema(InputStream stream, String schemaName) throws OnapCommandInvalidSchema {
+ public static Map<String, Object> loadSchema(InputStream stream, String schemaName) throws OnapCommandInvalidSchema { //NOSONAR
return OnapCommandDiscoveryUtils.loadYaml(stream);
}
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 15996a8f..7352eced 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
@@ -17,7 +17,6 @@
package org.onap.cli.fw.store;
import java.io.File;
-import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
index 677c45ea..39645120 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
@@ -19,7 +19,6 @@ package org.onap.cli.fw.store;
import static org.onap.cli.fw.conf.OnapCommandConstants.DATA_PATH_PROFILE_JSON;
import java.io.File;
-import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
@@ -147,8 +146,7 @@ public class OnapCommandProfileStore {
}
private void load(String profileName, boolean include) throws OnapCommandException {
- List<OnapCommandParamEntity> params= new ArrayList<>();
- params = this.loadParamFromCache(profileName);
+ List<OnapCommandParamEntity> params = this.loadParamFromCache(profileName);
for (OnapCommandParamEntity p : params) {
if (include) {
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 b2999077..b866db09 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
@@ -113,7 +113,7 @@ public class OnapCommandDiscoveryUtils {
* exception
*/
public static List<OnapCommandSchemaInfo> discoverOrLoadSchemas(boolean forceRefresh) throws OnapCommandException {
- List<OnapCommandSchemaInfo> schemas = new ArrayList<>();
+ List<OnapCommandSchemaInfo> schemas = new ArrayList<>(); //NOSONAR
if (forceRefresh || Boolean.parseBoolean(OnapCommandConfig.getPropertyValue(OnapCommandConstants.DISCOVER_ALWAYS))
|| !OnapCommandDiscoveryUtils.isAlreadyDiscovered()) {
schemas = OnapCommandDiscoveryUtils.discoverSchemas();
@@ -219,13 +219,7 @@ public class OnapCommandDiscoveryUtils {
* exception
*/
public static Map<String, Object> loadSchema(Resource resource) throws OnapCommandInvalidSchema {
- Map<String, Object> values = null;
- try {
- values = loadYaml(resource.getInputStream());
- } catch (Exception e) {
- throw new OnapCommandInvalidSchema(resource.getFilename(), e);
- }
- return values;
+ return loadYaml(resource);
}
/**
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 60bf2d2b..58fe7df6 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
@@ -328,11 +328,11 @@ public class OnapCommandUtils {
|| OnapCommandParameterType.JSON.equals(param.getParameterType())
|| OnapCommandParameterType.YAML.equals(param.getParameterType())) {
// ignore the front and back double quotes in json body
- String va_ = params.get(paramName).getValue().toString();
+ String value = params.get(paramName).getValue().toString();
if (idxS > 0)
- result.append(line.substring(currentIdx, idxS - 1) + va_);
+ result.append(line.substring(currentIdx, idxS - 1) + value);
else
- result.append(va_);
+ result.append(value);
currentIdx = idxE + 2;
} else if (OnapCommandParameterType.MAP.equals(param.getParameterType())) {
try {
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommandTest.java
index f094203b..5b5c6fac 100644
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommandTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommandTest.java
@@ -27,7 +27,7 @@ public class OnapSchemaValidateCommandTest {
@Ignore
@Test
- public void validateSchemaCommandTest1() throws OnapCommandException {
+ public void validateSchemaCommandTest1() throws OnapCommandException { //NOSONAR
OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("schema-validate");
cmd.getParametersMap().get("schema-location").setValue("schema-validate-pass.yaml");
cmd.getParametersMap().get("internal-schema").setValue("true");
@@ -36,7 +36,7 @@ public class OnapSchemaValidateCommandTest {
@Ignore
@Test
- public void validateSchemaCommandTest2() throws OnapCommandException {
+ public void validateSchemaCommandTest2() throws OnapCommandException { //NOSONAR
OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("schema-validate");
cmd.getParametersMap().get("schema-location").setValue(
ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-pass.yaml").getFile());
diff --git a/framework/src/test/java/org/onap/cli/fw/info/OnapCommandInfoTest.java b/framework/src/test/java/org/onap/cli/fw/info/OnapCommandInfoTest.java
index 337ee1a5..3e9cfd72 100644
--- a/framework/src/test/java/org/onap/cli/fw/info/OnapCommandInfoTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/info/OnapCommandInfoTest.java
@@ -16,7 +16,7 @@
package org.onap.cli.fw.info;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.onap.cli.fw.cmd.OnapCommandType;
@@ -31,8 +31,8 @@ public class OnapCommandInfoTest {
info.setProduct("open-cli");
info.setService("test");
- assertTrue(info.getCommandType().equals(OnapCommandType.CMD));
- assertTrue(info.getState().equals(OnapCommandState.STABLE));
+ assertEquals(OnapCommandType.CMD, info.getCommandType());
+ assertEquals(OnapCommandState.STABLE, info.getState());
}
}
diff --git a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java
index 1bf42e00..17d14235 100644
--- a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java
@@ -17,6 +17,7 @@
package org.onap.cli.fw.input;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.HashMap;
@@ -48,7 +49,7 @@ public class OnapCommandParameterTest {
&& param.isOptional() && !param.isSecured()
&& param.getParameterType().equals(OnapCommandParameterType.JSON));
- assertTrue("value".equals(param.getValue()));
+ assertEquals("value", param.getValue());
param.setParameterType(OnapCommandParameterType.ARRAY);
List<String> list = Arrays.asList("1", "2", "3");
@@ -84,7 +85,7 @@ public class OnapCommandParameterTest {
String envValue = param.getEnvVarNameFromrRawDefaultValue();
- assertTrue("DAFAULT_VALUE".equals(envValue));
+ assertEquals("DAFAULT_VALUE", envValue);
}
@Test
@@ -97,7 +98,7 @@ public class OnapCommandParameterTest {
try {
param.validate();
} catch (OnapCommandException e) {
- assertTrue("0x7003::Parameter null is mandatory".equals(e.getMessage()));
+ assertEquals("0x7003::Parameter null is mandatory", e.getMessage());
}
}
@@ -107,7 +108,7 @@ public class OnapCommandParameterTest {
param.setName("name");
param.setParameterType(OnapCommandParameterType.ARRAY);
param.setValue("value");
- assertTrue("[\"1\",\"2\",\"3\"]".equals(param.getValue()));
+ assertEquals("[\"1\",\"2\",\"3\"]", param.getValue());
}
@@ -117,7 +118,7 @@ public class OnapCommandParameterTest {
param.setName("name");
param.setParameterType(OnapCommandParameterType.MAP);
param.setValue("value");
- assertTrue("{\"One\":\"1\",\"Two\":\"2\",\"Three\":\"3\"}".equals(param.getValue()));
+ assertEquals("{\"One\":\"1\",\"Two\":\"2\",\"Three\":\"3\"}", param.getValue());
}
@Test(expected = OnapCommandInvalidParameterValue.class)
diff --git a/framework/src/test/java/org/onap/cli/fw/input/ParameterTypeTest.java b/framework/src/test/java/org/onap/cli/fw/input/ParameterTypeTest.java
index a42b9120..bfe13a0b 100644
--- a/framework/src/test/java/org/onap/cli/fw/input/ParameterTypeTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/input/ParameterTypeTest.java
@@ -18,6 +18,7 @@ package org.onap.cli.fw.input;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandInvalidParameterType;
@@ -44,7 +45,7 @@ public class ParameterTypeTest {
try {
OnapCommandParameterType.get("name");
} catch (OnapCommandInvalidParameterType e) {
- assertTrue("0x7001::Parameter type name is invalid".equals(e.getMessage()));
+ assertEquals("0x7001::Parameter type name is invalid", e.getMessage());
}
}
diff --git a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultAttributeTest.java b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultAttributeTest.java
index f2c22b21..66e151bd 100644
--- a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultAttributeTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultAttributeTest.java
@@ -18,6 +18,7 @@ package org.onap.cli.fw.output;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandInvalidResultAttributeScope;
@@ -36,7 +37,7 @@ public class OnapCommandResultAttributeTest {
try {
OnapCommandResultAttributeScope.get("name");
} catch (OnapCommandInvalidResultAttributeScope e) {
- assertTrue("0x8002::Result atrribute name is invalid".equals(e.getMessage()));
+ assertEquals("0x8002::Result atrribute name is invalid", e.getMessage());
}
}
diff --git a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java
index d5d04888..83a46088 100644
--- a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java
@@ -35,7 +35,7 @@ public class OnapCommandResultTest {
@Test
@Ignore
- public void commandResultObjTest() throws OnapCommandException {
+ public void commandResultObjTest() throws OnapCommandException { //NOSONAR
OnapCommandResult res = new OnapCommandResult();
res.setDebugInfo("debugInfo");
res.setIncludeSeparator(true);
@@ -58,7 +58,7 @@ public class OnapCommandResultTest {
@Test
@Ignore
- public void commandResultPrintLandscapeTableTest() throws OnapCommandException {
+ public void commandResultPrintLandscapeTableTest() throws OnapCommandException { //NOSONAR
OnapCommandResult res = new OnapCommandResult();
res.setDebugInfo("debugInfo");
res.setIncludeSeparator(true);
@@ -86,7 +86,7 @@ public class OnapCommandResultTest {
@Test
@Ignore
- public void commandResultPrintLandscapeJsonTest() throws OnapCommandException {
+ public void commandResultPrintLandscapeJsonTest() throws OnapCommandException { //NOSONAR
OnapCommandResult res = new OnapCommandResult();
res.setDebugInfo("debugInfo");
res.setIncludeSeparator(true);
@@ -116,7 +116,7 @@ public class OnapCommandResultTest {
@Test
@Ignore
- public void commandResultPrintLandscapeCsvTest() throws OnapCommandException {
+ public void commandResultPrintLandscapeCsvTest() throws OnapCommandException { //NOSONAR
OnapCommandResult res = new OnapCommandResult();
res.setDebugInfo("debugInfo");
res.setIncludeSeparator(true);
@@ -150,7 +150,7 @@ public class OnapCommandResultTest {
@Test
@Ignore
- public void commandResultPrintPortraitCsvTest() throws OnapCommandException {
+ public void commandResultPrintPortraitCsvTest() throws OnapCommandException { //NOSONAR
OnapCommandResult res = new OnapCommandResult();
res.setDebugInfo("debugInfo");
res.setIncludeSeparator(true);
@@ -182,7 +182,7 @@ public class OnapCommandResultTest {
@Test
@Ignore
- public void commandResultPrintPortraitTableTest() throws OnapCommandException {
+ public void commandResultPrintPortraitTableTest() throws OnapCommandException { //NOSONAR
OnapCommandResult res = new OnapCommandResult();
res.setDebugInfo("debugInfo");
res.setIncludeSeparator(true);
diff --git a/framework/src/test/java/org/onap/cli/fw/output/PrintDirectionTest.java b/framework/src/test/java/org/onap/cli/fw/output/PrintDirectionTest.java
index ae8dd2e1..2d30de91 100644
--- a/framework/src/test/java/org/onap/cli/fw/output/PrintDirectionTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/output/PrintDirectionTest.java
@@ -18,6 +18,7 @@ package org.onap.cli.fw.output;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandInvalidPrintDirection;
@@ -36,7 +37,7 @@ public class PrintDirectionTest {
try {
OnapCommandPrintDirection.get("name");
} catch (OnapCommandInvalidPrintDirection e) {
- assertTrue("0x8003::Print direction name is invalid".equals(e.getMessage()));
+ assertEquals("0x8003::Print direction name is invalid", e.getMessage());
}
}
diff --git a/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java b/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java
index 850d31e7..ff728a33 100644
--- a/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/output/print/OnapCommandPrintTest.java
@@ -30,7 +30,7 @@ public class OnapCommandPrintTest {
@Test
@Ignore
- public void printCsvTest() throws OnapCommandOutputPrintingFailed {
+ public void printCsvTest() throws OnapCommandOutputPrintingFailed { //NOSONAR
OnapCommandPrint pr = new OnapCommandPrint();
pr.setDirection(OnapCommandPrintDirection.LANDSCAPE);
pr.setPrintTitle(true);
diff --git a/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java b/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java
index 2b3c62ba..3b8876cf 100644
--- a/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java
@@ -105,7 +105,7 @@ public class OnapCommandRegistrarTest {
}
@OnapCommandSchema(schema = "sample-test-schema.yaml")
-final class OnapCommandTest extends OnapCommand {
+final class OnapCommandTest extends OnapCommand { //NOSONAR
public OnapCommandTest() {
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 e951793e..6d9b2d2c 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
@@ -27,6 +27,7 @@ import org.junit.Test;
import org.onap.cli.fw.cmd.OnapCommand;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
+import static org.junit.Assert.assertEquals;
public class ValidateSchemaTest {
@@ -123,7 +124,7 @@ public class ValidateSchemaTest {
protected void run() throws OnapCommandException {}
};
List<String> errorList5 = OnapCommandSchemaLoader.loadSchema(cmd5, "schema-validate-pass.yaml", true, true);
- assertTrue(errorList5.size() == 0);
+ assertEquals(0, errorList5.size());
}
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 d7bd8051..44c18194 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
@@ -263,7 +263,7 @@ public class OnapCommandUtilsTest {
@Test
@Ignore
- public void invalidSchemaFileTest() throws OnapCommandException {
+ public void invalidSchemaFileTest() throws OnapCommandException { //NOSONAR
Map<String, ?> map = null;
try {
map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test-schema1.yaml", "1.0");
@@ -371,7 +371,7 @@ public class OnapCommandUtilsTest {
}
Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters());
- assertTrue(map.size() == 18);
+ assertEquals(18, map.size());
}
@Test
@@ -554,6 +554,6 @@ public class OnapCommandUtilsTest {
public void loadYamlTest() throws OnapCommandInvalidSchema {
File file=new File("src/test/resources/sample-test-info.yaml");
Map<String, Object> values= OnapCommandDiscoveryUtils.loadYaml(file.getAbsolutePath());
- assertEquals(values.get("name"),"sample-test-info");
+ assertEquals("sample-test-info",values.get("name"));
}
}