Improve the UT of profile 87/12987/1
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Mon, 18 Sep 2017 06:08:10 +0000 (11:38 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Mon, 18 Sep 2017 06:08:10 +0000 (11:38 +0530)
CLI-43

Change-Id: If2f1040a93d18d8f4375c459db3e7250f4dba99f
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
framework/src/main/java/org/onap/cli/fw/error/OnapCommandLoadProfileFailed.java
framework/src/main/java/org/onap/cli/fw/error/OnapCommandPersistProfileFailed.java
framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java
framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
main/src/main/java/org/onap/cli/main/OnapCli.java
main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
main/src/test/resources/sample-test-schema.yaml

index 62fd84f..0e3846a 100644 (file)
@@ -30,4 +30,9 @@ public class OnapCommandLoadProfileFailed extends OnapCommandException {
     public OnapCommandLoadProfileFailed(String error) {
         super("0x1301", "Failed to load profile details, " + error);
     }
+
+    public OnapCommandLoadProfileFailed(Throwable error) {
+        this(error.getMessage());
+    }
+
 }
index f49e35c..4e563d5 100644 (file)
@@ -16,6 +16,8 @@
 
 package org.onap.cli.fw.error;
 
+import java.io.IOException;
+
 /**
  * Command profile persistence failed.
  *
@@ -30,4 +32,8 @@ public class OnapCommandPersistProfileFailed extends OnapCommandException {
     public OnapCommandPersistProfileFailed(String error) {
         super("0x1302", "Failed to persist profile details, " + error);
     }
+
+    public OnapCommandPersistProfileFailed(Throwable e1) {
+        this(e1.getMessage());
+    }
 }
index 6f04366..f8afd54 100644 (file)
@@ -34,8 +34,6 @@ public class OnapCommandParameterCache {
 
     private String profileName = Constants.PARAM_CACHE_FILE_NAME;
 
-    private boolean isLastPersistFailed = false;
-
     private OnapCommandParameterCache() {
 
     }
@@ -97,16 +95,16 @@ public class OnapCommandParameterCache {
         try {
             OnapCommandUtils.persistParams(params, this.profileName);
         } catch (OnapCommandPersistProfileFailed e) {
-            isLastPersistFailed = true;
+            throw new RuntimeException(e);
         }
     }
 
     private void load() {
-        List<Param> params;
+        List<Param> params= new ArrayList<>();
         try {
             params = OnapCommandUtils.loadParamFromCache(this.profileName);
         } catch (OnapCommandLoadProfileFailed e) {
-            params = new ArrayList<>();
+            throw new RuntimeException(e);
         }
 
         for (Param p : params) {
index 639e963..2404a89 100644 (file)
@@ -138,6 +138,7 @@ import org.onap.cli.fw.http.HttpResult;
 import org.onap.cli.fw.input.OnapCommandParameter;
 import org.onap.cli.fw.input.ParameterType;
 import org.onap.cli.fw.input.cache.Param;
+import org.onap.cli.fw.log.OnapCommandLogger;
 import org.onap.cli.fw.output.OnapCommandResult;
 import org.onap.cli.fw.output.OnapCommandResultAttribute;
 import org.onap.cli.fw.output.OnapCommandResultAttributeScope;
@@ -1639,7 +1640,7 @@ public class OnapCommandUtils {
                     mapper.writerWithDefaultPrettyPrinter().writeValue(file, params);
                 }
             } catch (IOException e1) {
-                throw new OnapCommandPersistProfileFailed(e1.getMessage());
+                throw new OnapCommandPersistProfileFailed(e1);
             }
         }
     }
@@ -1715,7 +1716,7 @@ public class OnapCommandUtils {
                 params.addAll(Arrays.asList(list));
             }
         } catch (IOException e) {
-            throw new OnapCommandLoadProfileFailed(e.getMessage());
+            throw new OnapCommandLoadProfileFailed(e);
         }
 
         return params;
index e33e54a..9255da2 100644 (file)
@@ -74,7 +74,7 @@ public class OnapCli {
                 throwable.printStackTrace();  // NOSONAR
             }
         } catch (OnapCommandException e) {
-            this.print(e.getCause());
+            System.out.println(e);
         }
     }
 
index 0a84d26..f052cbd 100644 (file)
@@ -128,6 +128,25 @@ public class OnapCliMainTest {
         this.handle(new String[] { "sample-test", "-h" });
     }
 
+    @Test
+    public void testVersionSampleCommandShort() {
+        this.handle(new String[] { "sample-test", "-v" });
+    }
+
+    @Test
+    public void testHandleSampleCommandSet() throws OnapCommandException {
+        OnapCommandRegistrar.getRegistrar().addParamCache("sample:string-param", "paramValue");
+        OnapCommandRegistrar.getRegistrar().addParamCache("onap-username", "paramValue");
+        OnapCommandRegistrar.getRegistrar().addParamCache("onap-password", "paramValue");
+        OnapCommandRegistrar.getRegistrar().addParamCache("host-url", "paramValue");
+        this.handle(new String[] { "sample-test", "--string-param", "test"});
+    }
+
+    @Test
+    public void testHandleSampleCommandFailure() throws OnapCommandException {
+        this.handle(new String[] { "sample-test", "--string-param"});
+    }
+
     @Test
     public void interactiveTest() {
         cli = new OnapCli(new String[] {});
index ac601c8..36edc7d 100644 (file)
@@ -19,60 +19,60 @@ parameters:
     short_option: x
     long_option: secure
     is_secured: true
-    is_optional: false
+    is_optional: true
     default_Value: pass123#
   - name: string-param
     type: string
     description: Onap string param
     long_option: string-param
     short_option: c
-    is_optional: false
+    is_optional: true
     default_Value: test
   - name: yaml-param
     type: json
     description: Onap yaml file location param
     long_option: yaml-param
     short_option: y
-    is_optional: false
+    is_optional: true
   - name: json-param
     type: json
     description: Onap json file location param
     long_option: json-param
     short_option: j
-    is_optional: false
+    is_optional: true
   - name: long-param
     type: digit
     description: Onap long param
     short_option: l
     long_option: long-opt
-    is_optional: false
+    is_optional: true
     default_value: 10
   - name: url-param
     type: url
     description: Onap url param
     short_option: r
     long_option: url
-    is_optional: false
+    is_optional: true
     default_value: http://localhost:8082/file.txt
   - name: env-param
     type: string
     description: Onap env param.
     short_option: z
     long_option: env
-    is_optional: false
+    is_optional: true
     default_value: ${ENV_VAR}
     default_value: http://localhost:8082/file.txt
   - name: positional-args
     type: string
     description: Onap positional args, if no short option and no long option given for it
-    is_optional: false
+    is_optional: true
     default_value: http://localhost:8082/file.txt
   - name: text-param
     type: text
     description: Onap text file location param
     long_option: text-param
     short_option: e
-    is_optional: false
+    is_optional: true
 results:
   direction: portrait
   attributes: