* @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() {
* @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);
}
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;
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;
}
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) {
* 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();
* 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);
}
/**
|| 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 {
@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");
@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());
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;
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());
}
}
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;
&& 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");
String envValue = param.getEnvVarNameFromrRawDefaultValue();
- assertTrue("DAFAULT_VALUE".equals(envValue));
+ assertEquals("DAFAULT_VALUE", envValue);
}
@Test
try {
param.validate();
} catch (OnapCommandException e) {
- assertTrue("0x7003::Parameter null is mandatory".equals(e.getMessage()));
+ assertEquals("0x7003::Parameter null is mandatory", e.getMessage());
}
}
param.setName("name");
param.setParameterType(OnapCommandParameterType.ARRAY);
param.setValue("value");
- assertTrue("[\"1\",\"2\",\"3\"]".equals(param.getValue()));
+ assertEquals("[\"1\",\"2\",\"3\"]", param.getValue());
}
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)
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;
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());
}
}
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;
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());
}
}
@Test
@Ignore
- public void commandResultObjTest() throws OnapCommandException {
+ public void commandResultObjTest() throws OnapCommandException { //NOSONAR
OnapCommandResult res = new OnapCommandResult();
res.setDebugInfo("debugInfo");
res.setIncludeSeparator(true);
@Test
@Ignore
- public void commandResultPrintLandscapeTableTest() throws OnapCommandException {
+ public void commandResultPrintLandscapeTableTest() throws OnapCommandException { //NOSONAR
OnapCommandResult res = new OnapCommandResult();
res.setDebugInfo("debugInfo");
res.setIncludeSeparator(true);
@Test
@Ignore
- public void commandResultPrintLandscapeJsonTest() throws OnapCommandException {
+ public void commandResultPrintLandscapeJsonTest() throws OnapCommandException { //NOSONAR
OnapCommandResult res = new OnapCommandResult();
res.setDebugInfo("debugInfo");
res.setIncludeSeparator(true);
@Test
@Ignore
- public void commandResultPrintLandscapeCsvTest() throws OnapCommandException {
+ public void commandResultPrintLandscapeCsvTest() throws OnapCommandException { //NOSONAR
OnapCommandResult res = new OnapCommandResult();
res.setDebugInfo("debugInfo");
res.setIncludeSeparator(true);
@Test
@Ignore
- public void commandResultPrintPortraitCsvTest() throws OnapCommandException {
+ public void commandResultPrintPortraitCsvTest() throws OnapCommandException { //NOSONAR
OnapCommandResult res = new OnapCommandResult();
res.setDebugInfo("debugInfo");
res.setIncludeSeparator(true);
@Test
@Ignore
- public void commandResultPrintPortraitTableTest() throws OnapCommandException {
+ public void commandResultPrintPortraitTableTest() throws OnapCommandException { //NOSONAR
OnapCommandResult res = new OnapCommandResult();
res.setDebugInfo("debugInfo");
res.setIncludeSeparator(true);
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;
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());
}
}
@Test
@Ignore
- public void printCsvTest() throws OnapCommandOutputPrintingFailed {
+ public void printCsvTest() throws OnapCommandOutputPrintingFailed { //NOSONAR
OnapCommandPrint pr = new OnapCommandPrint();
pr.setDirection(OnapCommandPrintDirection.LANDSCAPE);
pr.setPrintTitle(true);
}
@OnapCommandSchema(schema = "sample-test-schema.yaml")
-final class OnapCommandTest extends OnapCommand {
+final class OnapCommandTest extends OnapCommand { //NOSONAR
public OnapCommandTest() {
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 {
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());
}
@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");
}
Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters());
- assertTrue(map.size() == 18);
+ assertEquals(18, map.size());
}
@Test
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"));
}
}
@Override
public void run() {
// Use stderr here since the logger may have been reset by its JVM shutdown hook.
- System.err.println("*** shutting down gRPC server since JVM is shutting down");
+ System.err.println("*** shutting down gRPC server since JVM is shutting down"); //NOSONAR
OpenInterfaceGrpcServer.this.stop();
- System.err.println("*** server shut down");
+ System.err.println("*** server shut down"); //NOSONAR
}
});
}
}
protected void print(String msg) {
- System.out.println(msg);
+ System.out.println(msg); //NOSONAR
}
protected void printerr(String msg) {
- System.err.println(msg);
+ System.err.println(msg); //NOSONAR
}
private void print(Throwable throwable) {
//refer params from profile
if (this.profile != null) {
- Map<String, String> paramCache = new HashMap<>();
+ Map<String, String> paramCache = new HashMap<>(); //NOSONAR
if (this.product == null)
paramCache = OnapCommandRegistrar.getRegistrar().getParamCache();
else
package org.onap.cli.main.interactive;
-import static org.junit.Assert.assertTrue;
-
import java.util.ArrayList;
import java.util.Arrays;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
public class StringCompleterTest {
public void completeTest() {
StringCompleter com = new StringCompleter(Arrays.asList(new String[] { "test", "testing1", "testing2" }));
int result = com.complete("test", 1, new ArrayList<CharSequence>());
- assertTrue(result == 0);
+ assertEquals(0, result);
result = com.complete(null, 1, new ArrayList<CharSequence>());
- assertTrue(result == 0);
+ assertEquals(0, result);
com.add("test", "testing1", "testing2");
result = com.complete("test", 1, new ArrayList<CharSequence>());
- assertTrue(result == 0);
+ assertEquals(0, result);
result = com.complete("sfds", 1, new ArrayList<CharSequence>());
- assertTrue(result == -1);
+ assertEquals(-1, result);
result = com.complete("test", 1, new ArrayList<CharSequence>());
- assertTrue(result == 0);
+ assertEquals(0, result);
}
}
paramslist.add(param1);
OnapCliArgsParser.populateParams(paramslist,
Arrays.asList("--yaml", "name", "--yaml", "test-schema"));
- Assert.assertTrue(paramslist.iterator().next().getValue().equals("test-schema"));
+ Assert.assertEquals("test-schema", paramslist.iterator().next().getValue());
}
@Test
public void testReadYamlStringFromUrlForFile() throws OnapCommandException {
paramslist.add(param1);
OnapCliArgsParser.populateParams(paramslist,
Arrays.asList("--yaml", "main/src/test/resources/open-cli-schema/sample-test-schema.yaml", "--yaml", "test-schema"));
- Assert.assertTrue(paramslist.iterator().next().getValue().equals("test-schema"));
+ Assert.assertEquals("test-schema", paramslist.iterator().next().getValue());
}
}
\ No newline at end of file
OnapCommandParameter context = contextOpt.get();
Map<String, String> map = (Map<String, String>) context.getValue();
- mockingEnabled = map.containsKey(OnapCommandHttpConstants.VERIFY_DISABLE_MOCKING)
- && "true".equals(map.get(OnapCommandHttpConstants.VERIFY_DISABLE_MOCKING)) ? false : true;
+ mockingEnabled = !(map.containsKey(OnapCommandHttpConstants.VERIFY_DISABLE_MOCKING)
+ && "true".equals(map.get(OnapCommandHttpConstants.VERIFY_DISABLE_MOCKING)));
if (mockingEnabled) {
String mockedFile = ((Map<String, String>) context.getValue()).get(OnapCommandConstants.VERIFY_MOCO);
import org.junit.Test;
import org.onap.cli.fw.http.connect.HttpInput;
import org.onap.cli.fw.http.connect.HttpResult;
+import static org.junit.Assert.assertEquals;
public class HttpInputOutputTest {
String msg = "\nURL: uri\nMethod: method\nRequest Queries: {}\nRequest Body: body\nRequest Headers: "
+ "{}\nRequest Cookies: {}\nbinaryData=false\nContext={}";
- assertTrue(msg.equals(inp.toString()));
+ assertEquals(msg, inp.toString());
}
@Test
out.setRespCookies(new HashMap<String, String>());
out.setRespHeaders(new HashMap<String, String>());
out.setStatus(200);
- assertTrue("\nHTTP Status: 200\nResponse Body: body\nResponse Headers: {}\nResponse Cookies: {}"
- .equals(out.toString()));
+ assertEquals("\nHTTP Status: 200\nResponse Body: body\nResponse Headers: {}\nResponse Cookies: {}"
+ , out.toString());
}
}
import static org.junit.Assert.assertFalse;
import org.onap.cli.fw.http.connect.HttpInput;
import org.onap.cli.fw.http.connect.HttpInput.Part;
+import static org.junit.Assert.assertNotNull;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class OnapCommandUtilsTest {
@Test
public void oclipCommandUtilsInputStreamNotNullTest() throws OnapCommandException {
Map<String, ?> map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test1-schema-http.yaml", "1.0");
- assertTrue(map != null);
+ assertNotNull(map);
}
@Test
cmd.setName("sample-create-http");
try {
OnapCommandSchemaHttpLoader.loadHttpSchema(cmd, "sample-test-schema-http.yaml", true, true);
- assertTrue(cmd.getSuccessStatusCodes().size() == 2);
+ assertEquals(2, cmd.getSuccessStatusCodes().size());
} catch (OnapCommandParameterNameConflict | OnapCommandParameterOptionConflict
| OnapCommandInvalidParameterType | OnapCommandInvalidPrintDirection
| OnapCommandInvalidResultAttributeScope | OnapCommandSchemaNotFound | OnapCommandInvalidSchema
}
};
OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema-auth-required.yaml", true, false);
- assertTrue("sample-test".equals(cmd.getName()));
+ assertEquals("sample-test", cmd.getName());
Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters());
- assertTrue(map.size() == 9);
+ assertEquals(9, map.size());
}
@Test(expected = OnapCommandHttpHeaderNotFound.class)
writer.close();
}
- private static void writeMultilineKeyValue(PrintWriter writer, String key, String value, boolean debug) {
+ private static void writeMultilineKeyValue(PrintWriter writer, String key, String value, boolean debug) { //NOSONAR
writer.write(printTabs() + key + ":");
if (value.isEmpty()) {
return;
Date end = new Date();
System.out.println("[ Total time " + (end.getTime() - start.getTime()) + " ms ]\n");
try {
- Thread.sleep(2000);
+ Thread.sleep(2000); //NOSONAR
} catch (InterruptedException e) {
System.out.println(new Date());
}