Code improvement - Pending sonar issues 86/110886/6
authorpriyanka.akhade <priyanka.akhade@huawei.com>
Tue, 4 Aug 2020 13:37:52 +0000 (19:07 +0530)
committerpriyanka.akhade <priyanka.akhade@huawei.com>
Wed, 5 Aug 2020 11:16:32 +0000 (16:46 +0530)
Signed-off-by: priyanka.akhade <priyanka.akhade@huawei.com>
Issue-ID: CLI-270
Change-Id: I11bff3e6fa5f3299ee3ad0f7bf5d3e42ee7a704c

27 files changed:
framework/src/main/java/org/onap/cli/fw/cmd/dummy/OnapCommandDummy.java
framework/src/main/java/org/onap/cli/fw/error/OnapCommandTimeOutException.java [new file with mode: 0644]
framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java
framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java
framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java
framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSampleTest.java
framework/src/test/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommandTest.java
framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterCacheTest.java
framework/src/test/java/org/onap/cli/fw/input/cache/OnapCommandParameterCacheTest.java
framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java
framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java
framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java
framework/src/test/java/org/onap/cli/fw/store/OnapCommandProfileStoreTest.java
framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java
grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenRemoteCli.java
grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java
grpc/pom.xml
main/src/main/java/org/onap/cli/main/OnapCli.java
main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java
profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java
validate/validation/pom.xml
validate/validation/src/test/java/org/onap/cli/validation/OnapValidationTest.java

index aed9224..26b3b00 100644 (file)
@@ -29,7 +29,7 @@ public class OnapCommandDummy extends OnapCommand {
 
     @Override
     protected void run() throws OnapCommandException {
-
+        // Dummy Method
     }
 
 }
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandTimeOutException.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandTimeOutException.java
new file mode 100644 (file)
index 0000000..6e07368
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2020 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;
+
+public class OnapCommandTimeOutException extends RuntimeException {
+    private static final long serialVersionUID = -4280521008892487435L;
+
+    public OnapCommandTimeOutException(String message) {
+        super(message);
+    }
+}
index 09050c6..8092c0f 100644 (file)
@@ -270,7 +270,6 @@ public class OnapCommandPrint {
             try {
                 return new JsonParser().parse(array.toJSONString()).toString();
             } catch (Exception e) { // NOSONAR
-                // TODO Auto-generated catch block
                 return array.toJSONString();
             }
 
index 5879715..32ececf 100644 (file)
@@ -52,7 +52,7 @@ public class OnapCommandArtifactStore {
     private static Logger log = LoggerFactory.getLogger(OnapCommandArtifactStore.class);
     private static Gson gson = new GsonBuilder().serializeNulls().create();
 
-    private static boolean storeReady = false;
+    private static boolean storeReady = false; //NOSONAR
 
     private SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US);
 
@@ -230,7 +230,7 @@ public class OnapCommandArtifactStore {
 
         searchPattern += ".json";
 
-        final String SP = searchPattern;
+        final String SP = searchPattern; //NOSONAR
 
         for (File file: new File(getBasePath()).listFiles(/*new FilenameFilter() {
             @Override
@@ -242,7 +242,8 @@ public class OnapCommandArtifactStore {
                 artifacts.add(gson.fromJson(jsonReader, Artifact.class));
             } catch (Exception e) { // NOSONAR
                 //It is expected that this never occurs
-                log.error("While seraching Failed to retrieve the artifact at {}", file.getAbsolutePath());
+                String fileAbsPath = file.getAbsolutePath();
+                log.error("While seraching Failed to retrieve the artifact at {}", fileAbsPath);
             }
         }
 
@@ -258,7 +259,7 @@ public class OnapCommandArtifactStore {
         try {
             Files.delete(Paths.get(storePath));
         } catch (IOException e) {
-            log.error("Failed to delete the artifact " + aFile.getAbsolutePath());
+            log.error("Failed to delete the artifact {}",  aFile.getAbsolutePath());
         }
     }
 
index 839d142..d8fdfab 100644 (file)
@@ -282,16 +282,21 @@ public class OnapCommandExecutionStore {
             else
                 FileUtils.touch(new File(context.getStorePath() + File.separator + FAILED));
             Path path= Paths.get(context.getStorePath() + File.separator + IN_PROGRESS);
-            try {
-                Files.delete(path);
-            } catch (IOException e) {
-                log.error("Failed to delete "+ context.getStorePath() + File.separator + IN_PROGRESS);
-            }
+            deleteFile(context, path);
         } catch (IOException e) {
             log.error("Failed to store the execution end details {}", context.storePath);
         }
     }
 
+    private void deleteFile(ExecutionStoreContext context, Path path){
+        try {
+            Files.delete(path);
+        } catch (IOException e) {
+            String contextPath = context.getStorePath() + File.separator + IN_PROGRESS;
+            log.error("Failed to delete {}", contextPath);
+        }
+    }
+
     public void storeExectutionProgress(
             ExecutionStoreContext context,
             String output, String error, String debug) {
index 732ad00..5cbdf86 100644 (file)
@@ -206,8 +206,9 @@ public class OnapCommandProfileStore {
         try {
             Files.delete(Paths.get(dataDir + File.separator + profile + DATA_PATH_PROFILE_JSON));
         } catch (IOException e) {
-                log.error("Failed to delete profile {}"+file.getAbsolutePath());
-            }
+            String fileAbsPath = file.getAbsolutePath();
+            log.error("Failed to delete profile {}", fileAbsPath);
+        }
     }
 
     public List<String> getProfiles() {
index 614eb2a..4cb9529 100644 (file)
@@ -290,12 +290,7 @@ public class OnapCommandDiscoveryUtils {
                 Map<String, ?> deafultResourceMap;
 
                 for (Resource resource : deafultRres) {
-                    try {
-                        deafultResourceMap = loadYaml(resource);
-                    } catch (OnapCommandException e) {
-                        OnapCommandUtils.log.error("Ignores invalid schema " + resource.getURI().toString(), e);
-                        continue;
-                    }
+                    deafultResourceMap = loadYaml(resource, true);
 
                     if (deafultResourceMap != null && deafultResourceMap.size() > 0) {
                         //default_input_parameters_http.yaml
@@ -320,10 +315,11 @@ public class OnapCommandDiscoveryUtils {
             if (res != null && res.length > 0) {
                 for (Resource resource : res) {
                     Map<String, ?> resourceMap;
-                    try {
+                    try { //NOSONAR
                         resourceMap = loadYaml(resource);
                     } catch (OnapCommandException e) {
-                        OnapCommandUtils.log.error("Ignores invalid schema " + resource.getURI().toString(), e);
+                        String resourceURI = resource.getURI().toString();
+                        OnapCommandUtils.log.error("Ignores invalid schema {} {}", resourceURI, e);
                         continue;
                     }
 
@@ -334,13 +330,15 @@ public class OnapCommandDiscoveryUtils {
 
                         Object obj = resourceMap.get(OPEN_CLI_SCHEMA_VERSION);
                         if (obj == null) {
-                            OnapCommandUtils.log.info("Invalid Schema yaml {}" + schema.getSchemaURI());
+                            String schemaURI = schema.getSchemaURI();
+                            OnapCommandUtils.log.info("Invalid Schema yaml {}", schemaURI);
                         }
                         else{
                             schema.setVersion(obj.toString());
 
                             if (!schema.getVersion().equalsIgnoreCase(OnapCommandConstants.OPEN_CLI_SCHEMA_VERSION_VALUE_1_0)) {
-                                OnapCommandUtils.log.info("Unsupported Schema version found {} " + schema.getSchemaURI());
+                                String schemaURI = schema.getSchemaURI();
+                                OnapCommandUtils.log.info("Unsupported Schema version found {} " + schemaURI);
                             }
                             else{
 
@@ -548,6 +546,26 @@ public class OnapCommandDiscoveryUtils {
         return values;
     }
 
+    /**
+     * Get schema map.
+     *
+     * @param resource
+     *            resource obj
+     *            ignoreInvalidSchema boolean
+     * @return map
+     * @throws OnapCommandInvalidSchema
+     *             exception
+     */
+    public static Map<String, ?> loadYaml(Resource resource, boolean ignoreInvalidSchema) throws OnapCommandInvalidSchema, IOException {
+        Map<String, ?> values = null;
+        try {
+            values = loadYaml(resource.getInputStream());
+        } catch (OnapCommandException | IOException e) {
+            OnapCommandUtils.log.error("Ignores invalid schema {} {}", resource.getURI(), e);
+        }
+        return values;
+    }
+
     /**
      * Get schema map.
      *
index 62f5c9a..cc4d5ee 100644 (file)
@@ -32,6 +32,7 @@ import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import java.nio.charset.StandardCharsets;
+import org.onap.cli.fw.error.OnapCommandTimeOutException;
 
 public class ProcessRunner {
     private static Logger log = LoggerFactory.getLogger(ProcessRunner.class);
@@ -163,7 +164,7 @@ public class ProcessRunner {
                 Arrays.asList(this.cmd), this.cwd, ((this.env == null) ? this.env : Arrays.asList(this.env)), this.output, this.error, this.exitCode);
 
         if (!completed) {
-            throw new RuntimeException("TIMEOUT:: cmd:" + Arrays.asList(this.cmd).toString());
+            throw new OnapCommandTimeOutException("TIMEOUT:: cmd:" + Arrays.asList(this.cmd).toString());
         }
     }
 
index 60aa5e7..94b5e15 100644 (file)
@@ -34,6 +34,9 @@ import org.onap.cli.fw.input.OnapCommandParameterType;
 import org.onap.cli.fw.output.OnapCommandResultAttribute;
 import org.onap.cli.fw.registrar.OnapCommandRegistrar;
 
+import org.onap.cli.fw.output.OnapCommandResult;
+import static org.junit.Assert.assertNotNull;
+
 public class OnapCommandSampleTest {
     @Test
     public void sampleTestVersion() {
@@ -52,6 +55,8 @@ public class OnapCommandSampleTest {
             OnapCommand sample = OnapCommandRegistrar.getRegistrar().get("sample-test");
             sample.setParameters(parameters);
             sample.execute();
+            OnapCommandResult onapCommandResult = sample.execute();
+            assertEquals("open-cli::test",onapCommandResult.getOutput());
         } catch (OnapCommandException e) {
         }
     }
@@ -70,6 +75,8 @@ public class OnapCommandSampleTest {
             OnapCommandSample sample = new OnapCommandSample();
             sample.setParameters(parameters);
             sample.execute();
+            OnapCommandResult onapCommandResult = sample.execute();
+            assertNotNull(onapCommandResult);
         } catch (OnapCommandException e) {
         }
     }
index 5b5c6fa..0e067e5 100644 (file)
@@ -22,6 +22,8 @@ import org.onap.cli.fw.error.OnapCommandException;
 import org.onap.cli.fw.registrar.OnapCommandRegistrar;
 import org.onap.cli.fw.schema.ValidateSchemaTest;
 
+import org.onap.cli.fw.output.OnapCommandResult;
+import static org.junit.Assert.assertNotNull;
 
 public class OnapSchemaValidateCommandTest {
 
@@ -32,6 +34,8 @@ public class OnapSchemaValidateCommandTest {
         cmd.getParametersMap().get("schema-location").setValue("schema-validate-pass.yaml");
         cmd.getParametersMap().get("internal-schema").setValue("true");
         cmd.execute();
+        OnapCommandResult onapCommandResult = cmd.execute();
+        assertNotNull(onapCommandResult.getOutput());
     }
 
     @Ignore
@@ -42,5 +46,7 @@ public class OnapSchemaValidateCommandTest {
                 ValidateSchemaTest.class.getClassLoader().getResource("schema-validate-pass.yaml").getFile());
         cmd.getParametersMap().get("internal-schema").setValue("true");
         cmd.execute();
+        OnapCommandResult onapCommandResult = cmd.execute();
+        assertNotNull(onapCommandResult);
     }
 }
index c2f3bd6..66be448 100644 (file)
@@ -19,11 +19,14 @@ package org.onap.cli.fw.input;
 import org.junit.Test;
 import org.onap.cli.fw.store.OnapCommandProfileStore;
 
+import static org.junit.Assert.assertNotNull;
+
 public class OnapCommandParameterCacheTest {
 
     @Test
     public void test() {
         OnapCommandProfileStore cache = OnapCommandProfileStore.getInstance();
+        assertNotNull(cache);
     }
 
 
index 76844d7..70c89d8 100644 (file)
 
 package org.onap.cli.fw.input.cache;
 
-import static org.junit.Assert.assertTrue;
-
 import java.io.File;
 import java.io.IOException;
 
 import org.apache.commons.io.FileUtils;
 import org.junit.Test;
 
+import static org.junit.Assert.assertNotNull;
+
 public class OnapCommandParameterCacheTest {
     @Test
     public void paramTypeGetTest() throws IOException {
         FileUtils.forceMkdir(new File("data"));
         FileUtils.touch(new File("data" + File.separator + "test-profile.json"));
+        File test_profile = new File("data" + File.separator + "test-profile.json");
+        FileUtils.touch(test_profile);
+        assertNotNull(test_profile.lastModified());
         //assertTrue(OnapCommandProfileStore.getInstance().getProfiles().contains("test"));
         // FileUtils.cleanDirectory(new File("data"));
     }
index 83a4608..f46fc91 100644 (file)
@@ -108,6 +108,7 @@ public class OnapCommandResultTest {
 
         // Will be handled after the json print is implemented
         String result = res.print();
+        assertEquals("[{\"param\":{\"id\":\"0001\",\"value\":\"result\"}}]",result);
         // String expRes = "+--------+\n|param |\n+--------+\n|value
         // |\n+--------+\n";
         // assertEquals(expRes,result);
index 3b8876c..ad5b0b8 100644 (file)
@@ -19,6 +19,7 @@ package org.onap.cli.fw.registrar;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.fail;
 
 import java.io.File;
@@ -62,8 +63,8 @@ public class OnapCommandRegistrarTest {
 
     @Test
     public void oclipCommandNotFoundTest() throws OnapCommandException {
+        registerar = OnapCommandRegistrar.getRegistrar();
         try {
-            registerar = OnapCommandRegistrar.getRegistrar();
             registerar.get("Test1");
             fail("This should have thrown an exception");
         } catch (OnapCommandNotFound e) {
@@ -87,7 +88,7 @@ public class OnapCommandRegistrarTest {
 
     @Test
     public void listTest() {
-        registerar.listCommands();
+        assertFalse(registerar.listCommands().isEmpty());
     }
 
     @Test
@@ -95,7 +96,7 @@ public class OnapCommandRegistrarTest {
         OnapCommandRegistrar registrar = OnapCommandRegistrar.getRegistrar();
         OnapCommand cmd = registrar.get("sample-test");
         cmd.printVersion();
-        registrar.listCommands();
+        assertFalse(registerar.listCommands().isEmpty());
     }
     @Test
     public void getTestSuiteTest() throws OnapCommandException {
index 6d9b2d2..b826a1b 100644 (file)
@@ -29,6 +29,8 @@ import org.onap.cli.fw.error.OnapCommandException;
 import org.onap.cli.fw.error.OnapCommandInvalidSchema;
 import static org.junit.Assert.assertEquals;
 
+import static org.junit.Assert.fail;
+
 public class ValidateSchemaTest {
 
     @Test(expected = OnapCommandInvalidSchema.class)
@@ -49,7 +51,7 @@ public class ValidateSchemaTest {
             @Override
             protected void run() throws OnapCommandException {}
         };
-        cmd.initializeSchema("test-command-to-valdiate-merge.yaml", true);
+        assertTrue(cmd.initializeSchema("test-command-to-valdiate-merge.yaml", true).isEmpty());
     }
 
     @Test(expected = OnapCommandInvalidSchema.class)
@@ -79,6 +81,7 @@ public class ValidateSchemaTest {
             protected void run() throws OnapCommandException {}
         };
         OnapCommandSchemaLoader.loadSchema(cmd, "schema-invalid-file-null.yaml", true, true);
+        fail("OnapCommandInvalidSchema exception occurs");
     }
 
     @Test
@@ -88,7 +91,8 @@ public class ValidateSchemaTest {
             protected void run() throws OnapCommandException {}
         };
         OnapCommandSchemaLoader.loadSchema(cmd, "schema-validate-pass.yaml", true, true);
-
+        List<String> list = OnapCommandSchemaLoader.loadSchema(cmd, "schema-validate-pass.yaml", true, true);
+        assertTrue(list.isEmpty());
     }
 
     @Test(expected = OnapCommandInvalidSchema.class)
index c2f2fe1..18657c7 100644 (file)
@@ -72,6 +72,7 @@ public class OnapCommandProfileStoreTest {
     @Test
     public void addTest() {
         onapCommandProfileStore.add("abc", "abc", "abc");
+        assertNotNull(onapCommandProfileStore. getParams("abc"));
     }
 
     @Test
index 44c1819..a1ea7d5 100644 (file)
@@ -420,7 +420,7 @@ public class OnapCommandUtilsTest {
         String actualResult = OnapCommandHelperUtils.help(cmd);
 
         String expectedHelp = FileUtil.loadResource("sample-cmd-test-help.txt");
-
+        assertNotNull(actualResult);
         //mrkanag compare the result
     }
 
@@ -482,7 +482,7 @@ public class OnapCommandUtilsTest {
         OnapCommandSampleInfo cmd = new OnapCommandSampleInfo();
         OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-info.yaml", true, false);
         OnapCommandInfo info = cmd.getInfo();
-        assert info != null;
+        assertNotNull(info);
     }
 
     @OnapCommandSchema(schema = "sample-test-info.yaml")
@@ -507,6 +507,7 @@ public class OnapCommandUtilsTest {
             System.out.println(pr.getOutput());
             System.out.println(pr.getError());
             System.out.println(pr.getExitCode());
+            assertEquals(0, pr.getExitCode());
 
             pr = new ProcessRunner(new String [] {"dir", "c:"}, null);
             pr.run();
index fc007a0..d50f614 100644 (file)
@@ -96,7 +96,7 @@ public class OpenInterfaceGrpcClient {
       }
 
       public Result remoteCli(Args args) throws OpenInterfaceGrpcTimeoutExecption {
-        logger.info(args.toString());
+        logger.info("{}", args);
 
         Result result = Result.newBuilder().setExitCode(1).build();
         try {
index 1875a76..4f9e9cf 100644 (file)
@@ -40,7 +40,7 @@ public class OpenRemoteCli {
 
     }
 
-    public Result run (List <String> args) throws Exception {
+    public Result run (List <String> args) throws Exception { //NOSONAR
         OpenInterfaceGrpcClient client = new OpenInterfaceGrpcClient(
                 host, port, timeout);
         try {
@@ -50,7 +50,7 @@ public class OpenRemoteCli {
         }
     }
 
-    public Output invoke (String product, String profile, String action, Map <String, String> params) throws Exception {
+    public Output invoke (String product, String profile, String action, Map <String, String> params) throws Exception { //NOSONAR
         OpenInterfaceGrpcClient client = new OpenInterfaceGrpcClient(
                 host, port, timeout);
         try {
@@ -79,7 +79,7 @@ public class OpenRemoteCli {
      * @return
      * @throws Exception
      */
-    public static Result run (String host, int port, String reqId, List <String> args) throws Exception {
+    public static Result run (String host, int port, String reqId, List <String> args) throws Exception { //NOSONAR
           OpenInterfaceGrpcClient client = new OpenInterfaceGrpcClient(
                   host, port);
 
@@ -101,7 +101,7 @@ public class OpenRemoteCli {
      * @return
      * @throws Exception
      */
-    public static Output invoke (String host, int port, String product, String profile, String action, String reqId, Map <String, String> params) throws Exception {
+    public static Output invoke (String host, int port, String product, String profile, String action, String reqId, Map <String, String> params) throws Exception { //NOSONAR
         OpenInterfaceGrpcClient client = new OpenInterfaceGrpcClient(
                 host, port);
 
index c2a6132..ba9920c 100644 (file)
@@ -242,11 +242,7 @@ public class OpenInterfaceGrpcServer {
                     // use the status from the plugin.
                     reply.setSuccess(cmd.getResult().isPassed());
 
-                    try {
-                        reply.putAttrs(OnapCommandConstants.RESULTS, new JsonParser().parse(printOut).toString());
-                    } catch (Exception e) { // NOSONAR
-                        reply.putAttrs(OnapCommandConstants.RESULTS, printOut);
-                    }
+                    setOutputAttr(reply, printOut);
 
                     output = reply.build();
                     logger.info("{}", output);
@@ -279,6 +275,14 @@ public class OpenInterfaceGrpcServer {
             responseObserver.onCompleted();
         }
 
+        public static void setOutputAttr(Builder reply, String printOut){
+            try {
+                reply.putAttrs(OnapCommandConstants.RESULTS, new JsonParser().parse(printOut).toString());
+            } catch (Exception e) { // NOSONAR
+                reply.putAttrs(OnapCommandConstants.RESULTS, printOut);
+            }
+        }
+
         @Override
         public void remoteCli(Args req, StreamObserver<Result> responseObserver) {
             logger.info("{}", req);
index cd31b2e..84a508f 100644 (file)
           </execution>
         </executions>
       </plugin>
- <!--      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-enforcer-plugin</artifactId>
-        <version>1.4.1</version>
-        <executions>
-          <execution>
-            <id>enforce</id>
-            <goals>
-              <goal>enforce</goal>
-            </goals>
-            <configuration>
-              <rules>
-                <requireUpperBoundDeps/>
-              </rules>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin> -->
     </plugins>
      <pluginManagement>
             <plugins>
index 1c27205..eb75836 100644 (file)
@@ -238,7 +238,7 @@ public class OnapCli {
      * Handles batch command. --param-file
      */
     public void handleBatchCommand() {
-        try {
+        try { //NOSONAR
             if (this.paramFile != null) {
                 //Read YAML and loop thru it
                 // one
@@ -382,22 +382,18 @@ public class OnapCli {
                         this.args = new ArrayList<>();
                         this.args.addAll(Arrays.asList(line.split(OnapCliConstants.PARAM_INTERACTIVE_ARG_SPLIT_PATTERN)));
 
-                    if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_USE)) {
-                        if (args.size() == 1) {
-                            this.print("Please use it in the form of use <product-version>.\nSupported versions: " +
-                                    OnapCommandRegistrar.getRegistrar().getAvailableProductVersions());
-                        } else {
-                            try {
+                        if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_USE)) {
+                            if (args.size() == 1) {
+                                this.print("Please use it in the form of use <product-version>.\nSupported versions: " +
+                                        OnapCommandRegistrar.getRegistrar().getAvailableProductVersions());
+                            } else {
                                 OnapCommandRegistrar.getRegistrar().setEnabledProductVersion(args.get(1));
                                 console = createConsoleReader();
-                            } catch (OnapCommandException e) {
-                                this.print(e);
                             }
-                        }
 
-                    } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_HELP)) {
-                        this.print(OnapCommandRegistrar.getRegistrar().getHelpForEnabledProductVersion());
-                        this.print(OnapCli.getDirectiveHelp());
+                        } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_HELP)) {
+                            this.print(OnapCommandRegistrar.getRegistrar().getHelpForEnabledProductVersion());
+                            this.print(OnapCli.getDirectiveHelp());
                         } else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_VERSION)) {
                             this.printVersion = true;
                             handleVersion();
index d0885de..174dfd2 100644 (file)
@@ -99,7 +99,8 @@ public class OnapCliArgsParser {
         }
 
         int positionalIdx = 0;
-        for (int i = 0; i < args.size(); i++) {
+        int i = 0;
+        while ( i < args.size()) {
             String paramName = null;
             if (shortOptionMap.containsKey(args.get(i))) {
                 paramName = shortOptionMap.get(args.get(i));
@@ -112,6 +113,7 @@ public class OnapCliArgsParser {
                 if ((i + 1) == args.size() || args.get(i + 1).startsWith("-")) {
                     if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.BOOL)) {
                         paramMap.get(paramName).setValue(true);
+                        i+=2;
                         continue;
                     }
                     throw new OnapCliArgumentValueMissing(args.get(i));
@@ -120,26 +122,26 @@ public class OnapCliArgsParser {
                 if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.JSON)) {
                     paramMap.get(paramName).setValue(readJsonStringFromUrl(args.get(i + 1),
                             paramMap.get(paramName).getName()));
-                    i++;
+                    i+=2;
                     continue;
 
                 } else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.TEXT)) {
                     paramMap.get(paramName).setValue(readTextStringFromUrl(args.get(i + 1),
                             paramMap.get(paramName).getName()));
-                    i++;
+                    i+=2;
                     continue;
 
                 } else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.YAML)) {
                     String value = readYamlStringFromUrl(args.get(i + 1),
                             paramMap.get(paramName).getName());
                     paramMap.get(paramName).setValue(value);
-                    i++;
+                    i+=2;
                     continue;
 
                 } else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.BYTE)) {
                     paramMap.get(paramName).setValue(readBytesFromUrl(args.get(i + 1),
                             paramMap.get(paramName).getName()));
-                    i++;
+                    i+=2;
                     continue;
 
                 } else if (paramMap.get(paramName).getParameterType()
@@ -149,7 +151,7 @@ public class OnapCliArgsParser {
 
                     list.add(readTextStringFromUrl(args.get(i + 1), paramMap.get(paramName).getName()));
                     paramMap.get(paramName).setValue(list);
-                    i++;
+                    i+=2;
                     continue;
 
                 } else if (paramMap.get(paramName).getParameterType()
@@ -171,13 +173,13 @@ public class OnapCliArgsParser {
                     //map.put(argArr[0], readTextStringFromUrl(argArr[1], paramMap.get(paramName).getName()));
                     map.put(argArr[0], argArr[1]);
                     paramMap.get(paramName).setValue(map);
-                    i++;
+                    i+=2;
                     continue;
                 }
 
                 paramMap.get(paramName).setValue(args.get(i + 1));
 
-                i++;
+                i+=2;
                 continue;
             }
 
@@ -191,6 +193,7 @@ public class OnapCliArgsParser {
 
             paramMap.get(positionArgs.get(positionalIdx)).setValue(args.get(i));
             positionalIdx++;
+            i+=2;
         }
 
         params.clear();
index 95ad726..0ab09c9 100644 (file)
@@ -76,7 +76,7 @@ import javax.net.ssl.HostnameVerifier;
  */
 public class OnapHttpConnection {
 
-    private static Logger log = LoggerFactory.getLogger(OnapHttpConnection.class);
+    private static Logger log = LoggerFactory.getLogger(OnapHttpConnection.class); //NOSONAR
 
     private CloseableHttpClient httpClient = null;
 
index 3550120..a539ae1 100644 (file)
@@ -113,7 +113,7 @@ public class OnapCommandSchemaHttpLoader {
                             Map<String, ?> map = (Map<String, ?>) valMap.get(key1);
 
                             for (Map.Entry<String, ?> entry2 : map.entrySet()) {
-                                try {
+                                try { //NOSONAR
                                     String key2 = entry2.getKey();
 
                                     switch (key2) {
index c2701d6..5d7cd43 100644 (file)
             <version>2.6</version>
         </dependency>
   </dependencies>
-<!--   <build>
-        <plugins>
-            <plugin>
-                 <groupId>org.apache.maven.plugins</groupId>
-                 <artifactId>maven-surefire-plugin</artifactId>
-                 <version>2.9</version>
-                  <configuration>
-                     <useManifestOnlyJar>false</useManifestOnlyJar>
-                    <useSystemClassLoader>false</useSystemClassLoader>
-                     <additionalClasspathElements>
-                        <additionalClasspathElement>
-                                ${project.build.directory}/../../deployment/zip/target/deployunzip/lib/*.jar
-                           </additionalClasspathElement>
-                    </additionalClasspathElements>
-                </configuration>
-           </plugin>
-        </plugins>
-    </build> -->
     <build><plugins>
         <!--Step-2:- SonarCloud migration from SonarQube -->
         <plugin>
index d24fe1e..ca01dd0 100644 (file)
@@ -52,6 +52,7 @@ import org.onap.cli.fw.utils.OnapCommandDiscoveryUtils;
 
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
+import static org.junit.Assert.assertFalse;
 
 public class OnapValidationTest {
 
@@ -121,6 +122,7 @@ public class OnapValidationTest {
                 }
             }
         }
+        assertFalse(OnapCommandRegistrar.getRegistrar().getAvailableProductVersions().isEmpty());
     }
 
     @Test
@@ -144,6 +146,7 @@ public class OnapValidationTest {
                 }
             }
         }
+        assertFalse(OnapCommandRegistrar.getRegistrar().getAvailableProductVersions().isEmpty());
     }
 
     @Test