Command profile testcase addition 21/60421/1
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Mon, 13 Aug 2018 12:47:53 +0000 (18:17 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Mon, 13 Aug 2018 12:53:40 +0000 (18:23 +0530)
Issue-ID: CLI-123

Change-Id: Icecf98da2cf85cd4a30b7109eedba57767ff3319
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
products/pom.xml
profiles/command/pom.xml
profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java
profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/ProcessRunner.java
profiles/command/src/main/java/org/onap/cli/fw/cmd/conf/OnapCommandCmdConstants.java
profiles/command/src/main/java/org/onap/cli/fw/cmd/schema/OnapCommandSchemaCmdLoader.java
profiles/command/src/test/resources/open-cli-schema/sample-test-schema-1.1.yaml [new file with mode: 0644]
profiles/command/src/test/resources/open-cli.properties [new file with mode: 0644]

index faa6d8e..e28d0bd 100644 (file)
@@ -60,7 +60,7 @@
           </activation>
           <modules>
             <module>onap-casablanca</module>
-            <module>onap-beijing</module>            
+            <module>onap-beijing</module>
           </modules>
        </profile>
        <profile>
index 4b0a07d..50d3e17 100644 (file)
@@ -54,7 +54,7 @@
             <groupId>org.onap.cli</groupId>
             <artifactId>cli-framework</artifactId>
             <version>${project.version}</version>
-        </dependency>        
+        </dependency>
   </dependencies>
    <build>
         <plugins>
index d6e0e8c..7b74e6c 100644 (file)
@@ -38,92 +38,92 @@ import org.onap.cli.fw.utils.OnapCommandUtils;
  */
 @OnapCommandSchema(type = "cmd")
 public class OpenCommandShellCmd extends OnapCommand {
-       
-       public OpenCommandShellCmd() {
+
+    public OpenCommandShellCmd() {
         super.addDefaultSchemas(OnapCommandCmdConstants.DEFAULT_PARAMETER_CMD_FILE_NAME);
     }
 
-       private Map<String, String> resultMap = new HashMap<>();
-       
-       private List<String> command;
-       
-       private Map<String, String> envs;
-
-       private String wd = null;
-       
-       private List<Integer> successStatusCodes = new ArrayList<>();
-       
-       public List<Integer> getSuccessStatusCodes() {
-               return successStatusCodes;
-       }
-
-       public void setSuccessStatusCodes(ArrayList<Integer> successStatusCodes) {
-               this.successStatusCodes = successStatusCodes;
-       }
-
-       public String getWd() {
-               return wd;
-       }
-
-       public void setWd(String wd) {
-               this.wd = wd;
-       }
-
-       public Map<String, String> getEnvs() {
-               return envs;
-       }
-
-       public void setEnvs(Map<String, String> envs) {
-               this.envs = envs;
-       }
-       
-       
-
-       public List<String> getCommand() {
-               return command;
-       }
-
-       public void setCommand(List<String> command) {
-               this.command = command;
-       }
-
-       public Map<String, String> getResultMap() {
+    private Map<String, String> resultMap = new HashMap<>();
+
+    private List<String> command;
+
+    private Map<String, String> envs;
+
+    private String wd = null;
+
+    private List<Integer> successStatusCodes = new ArrayList<>();
+
+    public List<Integer> getSuccessStatusCodes() {
+        return successStatusCodes;
+    }
+
+    public void setSuccessStatusCodes(ArrayList<Integer> successStatusCodes) {
+        this.successStatusCodes = successStatusCodes;
+    }
+
+    public String getWd() {
+        return wd;
+    }
+
+    public void setWd(String wd) {
+        this.wd = wd;
+    }
+
+    public Map<String, String> getEnvs() {
+        return envs;
+    }
+
+    public void setEnvs(Map<String, String> envs) {
+        this.envs = envs;
+    }
+
+
+
+    public List<String> getCommand() {
+        return command;
+    }
+
+    public void setCommand(List<String> command) {
+        this.command = command;
+    }
+
+    public Map<String, String> getResultMap() {
         return resultMap;
     }
-    
+
     public void setResultMap(Map<String, String> resultMap) {
         this.resultMap = resultMap;
     }
-    
+
     @Override
     protected List<String> initializeProfileSchema(Map<String, ?> schemaMap, boolean validate) throws OnapCommandException {
         return OnapCommandSchemaCmdLoader.parseCmdSchema(this, schemaMap, validate);
     }
-    
+
     @Override
     protected void run() throws OnapCommandException {
         //Read the input arguments
         Map<String, OnapCommandParameter> paramMap = this.getParametersMap();
-        
+
         //Process command
         String []cmd = this.getCommand().toArray(new String []{});
         String cwd = this.getWd();
         List <String> envs = new ArrayList<>();
-        
+
         for (String env: this.getEnvs().keySet()) {
-               envs.add(env + "=" + this.getEnvs().get(env));
+            envs.add(env + "=" + this.getEnvs().get(env));
         }
-        
+
         ProcessRunner pr = new ProcessRunner(
-                       cmd, 
-                       (envs.size() > 0) ? envs.toArray(new String []{}) : null, 
-                       cwd);
+                cmd,
+                (envs.size() > 0) ? envs.toArray(new String []{}) : null,
+                cwd);
         try {
-                       pr.run();
-               } catch (InterruptedException | IOException e) {
-                       throw new OnapCommandExecutionFailed(this.getName(), e);
-               }
-        
+            pr.run();
+        } catch (InterruptedException | IOException e) {
+            throw new OnapCommandExecutionFailed(this.getName(), e);
+        }
+
         //Populate outputs
         this.getResult().getRecordsMap().get("output").getValues().add(pr.getOutput());
         this.getResult().getRecordsMap().get("error").getValues().add(pr.getError());
index 5bd3f46..c0b93bb 100644 (file)
-/*\r
- * Copyright 2018 Huawei Technologies Co., Ltd.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.cli.fw.cmd.cmd;\r
-\r
-import java.io.BufferedReader;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.InputStreamReader;\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-public class ProcessRunner {\r
-       \r
-       private String []cmd = null;\r
-       private static String shell = System.getProperty("os.name").toLowerCase().startsWith("windows") ? "cmd.exe /c " : "sh -c ";\r
-       private String cwd = System.getProperty("user.home");\r
-       private String []env = null;\r
-       private int exitCode = -1;\r
-       private String output;\r
-       private String error;\r
-       private Map<String, Object> results;\r
-\r
-       public ProcessRunner(String []cmd, String []env, String cwd) {\r
-               this.cmd = cmd;\r
-               \r
-               if (cwd != null && !cwd.isEmpty()) {\r
-                       this.cwd = cwd;\r
-               }\r
-               \r
-               this.env = env;\r
-       }\r
-       \r
-       public ProcessRunner(String []cmd, String cwd) {\r
-               this(cmd, null, cwd);\r
-       }\r
-       \r
-       public ProcessRunner(String []cmd) {\r
-               this(cmd, null, null);\r
-       }\r
-       \r
-       public ProcessRunner(String cmd, String []env, String cwd) {\r
-               this(new String []{cmd}, env, cwd);\r
-       }\r
-       \r
-       public ProcessRunner(String cmd, String cwd) {\r
-               this(new String []{cmd}, null, cwd);\r
-       }\r
-       \r
-       public ProcessRunner(String cmd) {\r
-               this(new String []{cmd}, null, null);\r
-       }\r
-       \r
-       @SuppressWarnings("unchecked")\r
-       public void run() throws InterruptedException, IOException {\r
-               Process p = null;\r
-               if (this.cmd.length == 1) {\r
-                       p = Runtime.getRuntime().exec(this.shell + this.cmd[0], this.env, null);\r
-               } else {\r
-                       List list = new ArrayList(Arrays.asList(this.shell.split(" ")));\r
-                   list.addAll(Arrays.asList(this.cmd));\r
-                   String []cmds = Arrays.copyOf(list.toArray(), list.size(), String[].class);\r
-                       p = Runtime.getRuntime().exec(cmds, this.env, null);    \r
-               }\r
-               \r
-        this.exitCode = p.waitFor();\r
-        this.output = this.streamToString(p.getInputStream());\r
-        this.error = this.streamToString(p.getErrorStream());\r
-        p.destroy();\r
-    }\r
-\r
-       public String streamToString(InputStream stream) throws IOException {\r
-               StringBuilder sb = new StringBuilder();\r
-               BufferedReader br = null;\r
-               try {\r
-                       br = new BufferedReader(new InputStreamReader(stream));\r
-                       String line = null;\r
-                       while ((line = br.readLine()) != null) {\r
-                               sb.append(line + System.getProperty("line.separator"));\r
-                       }\r
-               } finally {\r
-                       br.close();\r
-               }\r
-               return sb.toString();\r
-       }\r
-       \r
-       public int getExitCode() {\r
-               return this.exitCode;\r
-       }\r
-       \r
-       public String getOutput() {\r
-               return this.output;\r
-       }\r
-       \r
-       public String getError() {\r
-               return this.error;\r
-       }\r
-       \r
-       public static void main(String[] args) {\r
-               try {\r
-                       ProcessRunner pr = new ProcessRunner("dir", null);\r
-                       pr.run();\r
-                       System.out.println(pr.getOutput());\r
-                       System.out.println(pr.getError());\r
-                       System.out.println(pr.getExitCode());\r
-                       \r
-                       pr = new ProcessRunner(new String [] {"dir", "c:"}, null);\r
-                       pr.run();\r
-                       System.out.println(pr.getOutput());\r
-                       System.out.println(pr.getError());\r
-                       System.out.println(pr.getExitCode());\r
-                       \r
-               } catch (InterruptedException | IOException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
-               }\r
-       }\r
+/*
+ * Copyright 2018 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.cmd.cmd;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+public class ProcessRunner {
+
+    private String []cmd = null;
+    private static String shell = System.getProperty("os.name").toLowerCase().startsWith("windows") ? "cmd.exe /c " : "sh -c ";
+    private String cwd = System.getProperty("user.home");
+    private String []env = null;
+    private int exitCode = -1;
+    private String output;
+    private String error;
+    private Map<String, Object> results;
+
+    public ProcessRunner(String []cmd, String []env, String cwd) {
+        this.cmd = cmd;
+
+        if (cwd != null && !cwd.isEmpty()) {
+            this.cwd = cwd;
+        }
+
+        this.env = env;
+    }
+
+    public ProcessRunner(String []cmd, String cwd) {
+        this(cmd, null, cwd);
+    }
+
+    public ProcessRunner(String []cmd) {
+        this(cmd, null, null);
+    }
+
+    public ProcessRunner(String cmd, String []env, String cwd) {
+        this(new String []{cmd}, env, cwd);
+    }
+
+    public ProcessRunner(String cmd, String cwd) {
+        this(new String []{cmd}, null, cwd);
+    }
+
+    public ProcessRunner(String cmd) {
+        this(new String []{cmd}, null, null);
+    }
+
+    @SuppressWarnings("unchecked")
+    public void run() throws InterruptedException, IOException {
+        Process p = null;
+        if (this.cmd.length == 1) {
+            p = Runtime.getRuntime().exec(this.shell + this.cmd[0], this.env, null);
+        } else {
+            List list = new ArrayList(Arrays.asList(this.shell.split(" ")));
+            list.addAll(Arrays.asList(this.cmd));
+            String []cmds = Arrays.copyOf(list.toArray(), list.size(), String[].class);
+            p = Runtime.getRuntime().exec(cmds, this.env, null);
+        }
+
+        this.exitCode = p.waitFor();
+        this.output = this.streamToString(p.getInputStream());
+        this.error = this.streamToString(p.getErrorStream());
+        p.destroy();
+    }
+
+    public String streamToString(InputStream stream) throws IOException {
+        StringBuilder sb = new StringBuilder();
+        BufferedReader br = null;
+        try {
+            br = new BufferedReader(new InputStreamReader(stream));
+            String line = null;
+            while ((line = br.readLine()) != null) {
+                sb.append(line + System.getProperty("line.separator"));
+            }
+        } finally {
+            br.close();
+        }
+        return sb.toString();
+    }
+
+    public int getExitCode() {
+        return this.exitCode;
+    }
+
+    public String getOutput() {
+        return this.output;
+    }
+
+    public String getError() {
+        return this.error;
+    }
+
+    public static void main(String[] args) {
+        try {
+            ProcessRunner pr = new ProcessRunner("dir", null);
+            pr.run();
+            System.out.println(pr.getOutput());
+            System.out.println(pr.getError());
+            System.out.println(pr.getExitCode());
+
+            pr = new ProcessRunner(new String [] {"dir", "c:"}, null);
+            pr.run();
+            System.out.println(pr.getOutput());
+            System.out.println(pr.getError());
+            System.out.println(pr.getExitCode());
+
+        } catch (InterruptedException | IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
 }
\ No newline at end of file
index fcd182a..e4f119e 100644 (file)
@@ -29,11 +29,11 @@ public class OnapCommandCmdConstants {
     public static final String ENVIRONMENT = "environment";
     public static final String WD = "working_directory";
     public static final String SUCCESS_EXIT_CODE = "success_code";
-    
+
     public static final String CMD_MANDATORY_SECTIONS = "cli.schema.cmd.sections.mandatory";
     public static final String CMD_SECTIONS = "cli.schema.cmd.sections";
 
-       public static final String DEFAULT_PARAMETER_CMD_FILE_NAME = "default_input_parameters_cmd.yaml";
+    public static final String DEFAULT_PARAMETER_CMD_FILE_NAME = "default_input_parameters_cmd.yaml";
     private OnapCommandCmdConstants() {
         //as per coding standard !
     }
index c3764ea..55fab73 100644 (file)
@@ -33,7 +33,7 @@ public class OnapCommandSchemaCmdLoader {
         // to follow standards !
     }
 
+
     /**
      * Load the schema.
      *
@@ -50,40 +50,40 @@ public class OnapCommandSchemaCmdLoader {
         ArrayList<String> errorList = new ArrayList<>();
         Map<String, ?> valMap = (Map<String, ?>) values.get(OnapCommandCmdConstants.CMD);
 
-               if (valMap != null) {
-                   if (validate) {
-                       OnapCommandUtils.validateTags(errorList, valMap, OnapCommandConfig.getCommaSeparatedList(OnapCommandCmdConstants.CMD_SECTIONS),
-                               OnapCommandConfig.getCommaSeparatedList(OnapCommandCmdConstants.CMD_MANDATORY_SECTIONS), OnapCommandCmdConstants.CMD);
-                   }
-                   for (Map.Entry<String, ?> entry1 : valMap.entrySet()) {
-                       String key1 = entry1.getKey();
+        if (valMap != null) {
+            if (validate) {
+                OnapCommandUtils.validateTags(errorList, valMap, OnapCommandConfig.getCommaSeparatedList(OnapCommandCmdConstants.CMD_SECTIONS),
+                        OnapCommandConfig.getCommaSeparatedList(OnapCommandCmdConstants.CMD_MANDATORY_SECTIONS), OnapCommandCmdConstants.CMD);
+            }
+            for (Map.Entry<String, ?> entry1 : valMap.entrySet()) {
+                String key1 = entry1.getKey();
+
+                switch (key1) {
+                    case OnapCommandCmdConstants.COMMAND:
+                        Object o = valMap.get(key1);
+                        if (o instanceof List) {
+                            cmd.setCommand((List<String>) o);
+                        } else {
+                            cmd.setCommand(Arrays.asList(new String [] {(String) o}));
+                        }
+                        break;
 
-                       switch (key1) {
-                           case OnapCommandCmdConstants.COMMAND:
-                               Object o = valMap.get(key1);
-                               if (o instanceof List) {
-                                       cmd.setCommand((List<String>) o);
-                               } else {
-                                       cmd.setCommand(Arrays.asList(new String [] {(String) o}));
-                               }
-                               break;
+                    case OnapCommandCmdConstants.ENVIRONMENT:
+                        Map<String, String> envMap = (Map<String, String>) valMap.get(key1);
+                        cmd.setEnvs(envMap);
 
-                           case OnapCommandCmdConstants.ENVIRONMENT:
-                               Map<String, String> envMap = (Map<String, String>) valMap.get(key1);
-                               cmd.setEnvs(envMap);
+                        break;
 
-                               break;
+                    case OnapCommandCmdConstants.WD:
+                        cmd.setWd((String)valMap.get(key1));
+                        break;
 
-                           case OnapCommandCmdConstants.WD:
-                               cmd.setWd((String)valMap.get(key1));
-                               break;
-                               
-                           case OnapCommandCmdConstants.SUCCESS_EXIT_CODE:
-                               cmd.setSuccessStatusCodes((ArrayList) valMap.get(key1));
-                               break;
-                       }
-                   }
-               }
+                    case OnapCommandCmdConstants.SUCCESS_EXIT_CODE:
+                        cmd.setSuccessStatusCodes((ArrayList) valMap.get(key1));
+                        break;
+                }
+            }
+        }
 
 
         return errorList;
diff --git a/profiles/command/src/test/resources/open-cli-schema/sample-test-schema-1.1.yaml b/profiles/command/src/test/resources/open-cli-schema/sample-test-schema-1.1.yaml
new file mode 100644 (file)
index 0000000..2bf2e85
--- /dev/null
@@ -0,0 +1,46 @@
+# Copyright 2018 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.
+
+open_cli_schema_version: 1.0
+name: sample-cmd-1
+description: Oclip sample command to following the shell command features
+info:
+  product: open-cli
+  service: test
+  type: cmd
+
+results:
+  direction: landscape
+  attributes:
+    - name: attr1
+      description: Attr1
+      scope: short
+      type: string
+    - name: attr2
+      description: Attr2
+      scope: long
+      type: string
+cmd:
+  command:
+    - d:/temp/test.bat
+  environment:
+    AA: aa
+  success_codes:
+    - 0
+  working_directory: .
+
+  result_map:
+    attr1: NA
+    attr2: NA
+  sample_output: NA
diff --git a/profiles/command/src/test/resources/open-cli.properties b/profiles/command/src/test/resources/open-cli.properties
new file mode 100644 (file)
index 0000000..8759452
--- /dev/null
@@ -0,0 +1,45 @@
+# Copyright 2018 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.
+
+cli.product_name=open-cli
+cli.version=1.0
+
+cli.discover_always=false
+
+#schema validation
+cli.schema.base.sections=open_cli_schema_version,name,description,parameters,results,info
+cli.schema.base.sections.mandatory=open_cli_schema_version
+
+cli.schema.base.info.sections=product,service,type,author,ignore
+cli.schema.base.info.sections.mandatory=product,service
+
+cli.schema.base.parameters.sections=name,description,type,short_option,long_option, is_optional,default_value,is_secured,is_include
+cli.schema.base.parameters.sections.mandatory=name,description,type
+
+cli.schema.base.results.sections=name,description,scope,type,is_secured, default_value
+cli.schema.base.results.sections.mandatory=name, description, type, scope
+
+cli.schema.boolean_values=true,false
+cli.schema.command.type=cmd,auth,catalog
+
+# moco properties
+cli.sample.gen.enable=false
+cli.sample.gen.target=.
+
+# mrkanag Move this to db, once exteranl command registration is supported in place of discovery
+cli.schema.profile.available=cmd
+
+#other properties to load (it should be hanled when plugins are made as externally register-able
+#when command plugin management support is enabled in oclip
+cli.schema.profile.confs=open-cli-cmd.properties
\ No newline at end of file