Fixes SONAR critical bugs 17/12717/1
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Fri, 15 Sep 2017 12:40:17 +0000 (18:10 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Fri, 15 Sep 2017 12:48:38 +0000 (18:18 +0530)
CLI-43

Change-Id: I8a901da62617589ec17b125b788104d201afafef
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java
framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterCacheTest.java [new file with mode: 0644]
framework/src/test/java/org/onap/cli/fw/input/ParameterTypeTest.java
main/src/main/java/org/onap/cli/main/OnapCli.java
main/src/test/java/org/onap/cli/main/OnapCliMainTest.java

index 9b824d3..4cde508 100644 (file)
@@ -1637,7 +1637,7 @@ public class OnapCommandUtils {
                     mapper.writerWithDefaultPrettyPrinter().writeValue(file, params);
                 }
             } catch (IOException e1) {
-                // Never occur  //  NOSONAR
+                // pass // NOSONAR
             }
         }
     }
@@ -1713,7 +1713,7 @@ public class OnapCommandUtils {
                 params.addAll(Arrays.asList(list));
             }
         } catch (IOException e) {
-            // Never occur  //  NOSONAR
+            // pass // NOSONAR
         }
 
         return params;
index 840a75d..ecbbf97 100644 (file)
@@ -139,6 +139,19 @@ public class OnapCommandRegistrarTest {
     public void listTest() {
         registerar.listCommands();
     }
+
+    @Test
+    public void testParamCache() throws OnapCommandException {
+        OnapCommandRegistrar.getRegistrar().addParamCache("a", "b");
+        OnapCommandRegistrar.getRegistrar().getParamCache();
+        OnapCommandRegistrar.getRegistrar().getAvailableProductVersions();
+        OnapCommandRegistrar.getRegistrar().setDevMode(true);
+        OnapCommandRegistrar.getRegistrar().isDevMode();
+        OnapCommandRegistrar.getRegistrar().isInteractiveMode();
+        OnapCommandRegistrar.getRegistrar().getEnabledProductVersion();
+        OnapCommandRegistrar.getRegistrar().setEnabledProductVersion("cli-1.0");
+
+    }
 }
 
 @OnapCommandSchema(name = OnapCommandTest.CMD_NAME, version = "cli-1.0", schema = "sample-test-schema.yaml")
diff --git a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterCacheTest.java b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterCacheTest.java
new file mode 100644 (file)
index 0000000..ea06ea1
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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.input;
+
+import org.junit.Test;
+import org.onap.cli.fw.input.cache.OnapCommandParameterCache;
+
+public class OnapCommandParameterCacheTest {
+
+    @Test
+    public void test() {
+        OnapCommandParameterCache cache = OnapCommandParameterCache.getInstance();
+
+        cache.add("1.0", "a", "b");
+        cache.remove("1.0", "a");
+        cache.setProfile("test");
+        cache.getParams("1.0");
+    }
+
+
+}
index 0a5ad00..0c48140 100644 (file)
@@ -35,6 +35,7 @@ public class ParameterTypeTest {
                     && ParameterType.BOOL.equals(ParameterType.get("bool"))
                     && ParameterType.MAP.equals(ParameterType.get("map"))
                     && ParameterType.BINARY.equals(ParameterType.get("binary"))
+                    && ParameterType.TEXT.equals(ParameterType.get("text"))
                     && ParameterType.ARRAY.equals(ParameterType.get("array")));
         } catch (OnapCommandInvalidParameterType e) {
             fail("Shouldn't have thrown this exception : " + e.getMessage());
index 36db86c..57e39f2 100644 (file)
@@ -71,10 +71,10 @@ public class OnapCli {
         System.out.println(throwable.getMessage());
         try {
             if (OnapCommandRegistrar.getRegistrar().isDevMode()) {
-                throwable.printStackTrace();
+                throwable.printStackTrace();  // NOSONAR
             }
         } catch (OnapCommandException e) {
-            //  NOSONAR
+            // pass // NOSONAR
         }
     }
 
@@ -144,7 +144,7 @@ public class OnapCli {
         }
     }
 
-    private String getDirectiveHelp() throws OnapCommandHelpFailed {
+    public static String getDirectiveHelp() throws OnapCommandHelpFailed {
         OnapCommandResult help = new OnapCommandResult();
         help.setType(ResultType.TABLE);
         help.setPrintDirection(PrintDirection.LANDSCAPE);
@@ -213,7 +213,7 @@ public class OnapCli {
                     if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_USE)) {
                         if (args.size() == 1) {
                             this.print("Please input the product version to use, supported versions: " +
-                        OnapCommandRegistrar.getRegistrar().getAvailableProductVersions());
+                                    OnapCommandRegistrar.getRegistrar().getAvailableProductVersions());
                         } else {
                             try {
                                 OnapCommandRegistrar.getRegistrar().setEnabledProductVersion(args.get(1));
index 05dd7d4..0a84d26 100644 (file)
 
 package org.onap.cli.main;
 
-import static org.junit.Assert.assertTrue;
-
-import jline.console.ConsoleReader;
-import mockit.Invocation;
-import mockit.Mock;
-import mockit.MockUp;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 import org.aspectj.lang.annotation.After;
 import org.junit.Ignore;
@@ -29,17 +30,14 @@ 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.error.OnapCommandHelpFailed;
 import org.onap.cli.main.utils.OnapCliUtils;
 
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import jline.console.ConsoleReader;
+import mockit.Invocation;
+import mockit.Mock;
+import mockit.MockUp;
+import static org.junit.Assert.fail;
 
 public class OnapCliMainTest {
 
@@ -87,6 +85,12 @@ public class OnapCliMainTest {
         this.handle(new String[] { "sample-test", "--help" });
     }
 
+    @Ignore
+    @Test
+    public void testHandleProfile() {
+        this.handle(new String[] { "-c", "test" });
+    }
+
     @Ignore
     @Test
     public void testAAICustomerList() {
@@ -144,6 +148,36 @@ public class OnapCliMainTest {
         } catch (Exception e) {
         }
 
+        mockConsole("set a=b");
+        try {
+            cli.handleInteractive();
+        } catch (Exception e) {
+        }
+
+        mockConsole("unset a");
+        try {
+            cli.handleInteractive();
+        } catch (Exception e) {
+        }
+
+        mockConsole("profile test");
+        try {
+            cli.handleInteractive();
+        } catch (Exception e) {
+        }
+
+        mockConsole("version");
+        try {
+            cli.handleInteractive();
+        } catch (Exception e) {
+        }
+
+        mockConsole("help");
+        try {
+            cli.handleInteractive();
+        } catch (Exception e) {
+        }
+
         mockConsoleReader();
         cli.handleInteractive();
 
@@ -166,7 +200,7 @@ public class OnapCliMainTest {
             public String readLine(Invocation inv) throws IOException {
                 if (isMock) {
                     isMock = false;
-                return input;
+                    return input;
                 } else {
                     return inv.proceed(input);
                 }
@@ -174,4 +208,12 @@ public class OnapCliMainTest {
         };
     }
 
+    @Test
+    public void testDirectiveHelp() {
+        try {
+            OnapCli.getDirectiveHelp();
+        } catch (OnapCommandHelpFailed e) {
+             fail("Directive help failed to run");
+        }
+    }
 }