Add validation for all commands 17/9317/1
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Wed, 30 Aug 2017 06:58:29 +0000 (12:28 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Wed, 30 Aug 2017 06:59:17 +0000 (12:29 +0530)
Add new project to validate the commands
and optionally add required test cases

CLI-35
Change-Id: I8bd437c77421a590b0e60e4aec12cc99997451a1
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaRefreshCommand.java
framework/src/main/java/org/onap/cli/fw/cmd/OnapSchemaValidateCommand.java
main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
pom.xml
validation/pom.xml
validation/src/test/java/org/onap/cli/validation/OnapCliMainTest.java [new file with mode: 0644]

index ca875b3..56f04e1 100644 (file)
@@ -52,6 +52,8 @@ public class OnapCommandRegistrar {
 
     private Set<String> availableProductVersions = new HashSet<>();
 
+    private String enabledProductVersion = OnapCommandConfg.getEnabledProductVersion();
+
     private static OnapCommandRegistrar registrar = null;
 
     /**
@@ -105,7 +107,7 @@ public class OnapCommandRegistrar {
      * @return set
      */
     public Set<String> listCommandsForEnabledProductVersion() {
-        String version = OnapCommandConfg.getEnabledProductVersion();
+        String version = this.getEnabledProductVersion();
 
         Set<String> cmds = new HashSet<>();
         if (!this.availableProductVersions.contains(version)) {
@@ -120,30 +122,27 @@ public class OnapCommandRegistrar {
         return cmds;
     }
 
+    public Set<String> getAvailableProductVersions() {
+        return this.availableProductVersions;
+    }
+
+    public void setEnabledProductVersion(String version) {
+        this.enabledProductVersion = version;
+    }
+
+    public String getEnabledProductVersion() {
+        return this.enabledProductVersion;
+    }
+
     /**
-     * Returns map of command to schema.
+     * Returns command details.
      *
      * @return map
      * @throws OnapCommandException
      *             exception
      */
-    public Map<String, String> getAllCommandToSchemaMap() throws OnapCommandException {
-        Map<String, String> map = new HashMap<>();
-        List<ExternalSchema> schemas = OnapCommandUtils.findAllExternalSchemas();
-        if (schemas != null) {
-            for (ExternalSchema schema : schemas) {
-                map.put(schema.getCmdName() + ":" + schema.getCmdVersion(), schema.getSchemaName());
-            }
-        }
-        if (this.registry != null) {
-            for (String cmd : this.registry.keySet()) {
-                if (!map.containsKey(cmd) && registry.get(cmd) != null) {
-                    map.put(cmd, this.getSchemaFileName(registry.get(cmd)));
-                }
-            }
-        }
-
-        return map;
+    public List<ExternalSchema> listCommandInfo() throws OnapCommandException {
+        return OnapCommandUtils.findAllExternalSchemas();
     }
 
     /**
@@ -156,7 +155,7 @@ public class OnapCommandRegistrar {
      *             Exception
      */
     public OnapCommand get(String cmdName) throws OnapCommandException {
-        return this.get(cmdName, OnapCommandConfg.getEnabledProductVersion());
+        return this.get(cmdName, this.getEnabledProductVersion());
     }
 
     private OnapCommand get(String cmdName, String version) throws OnapCommandException {
index 7a156ca..823f0d7 100644 (file)
@@ -30,7 +30,7 @@ import java.util.List;
  * Refresh external schema.
  *
  */
-@OnapCommandSchema(name = "schema-refresh", version="cli-1.0", schema = "schema-refresh.yaml")
+@OnapCommandSchema(name = "schema-refresh", version = "cli-1.0", schema = "schema-refresh.yaml")
 public class OnapSchemaRefreshCommand extends OnapCommand {
 
     @Override
index 3119f9c..4028cc9 100644 (file)
@@ -29,7 +29,7 @@ import java.util.Map;
 /**
  * Validate schema command.
  */
-@OnapCommandSchema(name = "schema-validate", version="cli-1.0", schema = "schema-validate.yaml")
+@OnapCommandSchema(name = "schema-validate", version = "cli-1.0", schema = "schema-validate.yaml")
 public class OnapSchemaValidateCommand extends OnapCommand {
 
     @Override
index 7827885..ff4b436 100644 (file)
@@ -124,27 +124,6 @@ public class OnapCliMainTest {
         this.handle(new String[] { "sample-test", "-h" });
     }
 
-    @Test
-    public void validateCommands() throws IOException, OnapCommandException {
-        Map<String, String> cmdSchemaMap = OnapCommandRegistrar.getRegistrar().getAllCommandToSchemaMap();
-        for (String cmdName : cmdSchemaMap.keySet()) {
-            System.out.println(
-                    "************************* '" + cmdSchemaMap.get(cmdName) + "' *******************************");
-            this.handle(new String[] { "schema-validate", "-l", cmdSchemaMap.get(cmdName), "-i"});
-        }
-    }
-
-    @Test
-    public void commandHelpTest() throws OnapCommandException {
-        Set<String> cmds = OnapCommandRegistrar.getRegistrar().listCommands();
-
-        for (String cmdName : cmds) {
-            System.out.println("************************* '" + cmdName + "' *******************************");
-            this.handle(new String[] { cmdName, "-h" });
-        }
-
-    }
-
     @Test
     public void interactiveTest() {
         cli = new OnapCli(new String[] { "-i" });
diff --git a/pom.xml b/pom.xml
index 46a4bf0..63e48d7 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -40,6 +40,7 @@
         <module>plugins</module>
         <module>main</module>
         <module>deployment</module>
+        <module>validation</module>
     </modules>
 
     <distributionManagement>
index adeb49b..dc42e2f 100644 (file)
             <version>4.11</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.onap.cli</groupId>
+            <artifactId>cli-main</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.cli</groupId>
+            <artifactId>cli-plugins-msb</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.cli</groupId>
+            <artifactId>cli-plugins-sdc</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.cli</groupId>
+            <artifactId>cli-plugins-aai</artifactId>
+            <version>${project.version}</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> -->
 </project>
diff --git a/validation/src/test/java/org/onap/cli/validation/OnapCliMainTest.java b/validation/src/test/java/org/onap/cli/validation/OnapCliMainTest.java
new file mode 100644 (file)
index 0000000..f89e265
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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.validation;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Set;
+
+import org.aspectj.lang.annotation.After;
+import org.junit.Test;
+import org.onap.cli.fw.OnapCommandRegistrar;
+import org.onap.cli.fw.error.OnapCommandException;
+import org.onap.cli.fw.utils.ExternalSchema;
+import org.onap.cli.fw.utils.OnapCommandUtils;
+import org.onap.cli.main.OnapCli;
+
+public class OnapCliMainTest {
+
+    OnapCli cli = null;
+
+    /**
+     * Clean up.
+     */
+    @After(value = "")
+    public void cleanup() {
+        if (this.cli != null) {
+            if (cli.getExitCode() != 0) {
+                // Fail test case
+            }
+        }
+    }
+
+    private void handle(String[] args) {
+        cli = new OnapCli(args);
+        cli.handle();
+    }
+
+    @Test
+    public void validateCommands() throws IOException, OnapCommandException {
+        OnapCommandRegistrar.getRegistrar().setEnabledProductVersion("cli-1.0");
+        for (ExternalSchema sch : OnapCommandRegistrar.getRegistrar().listCommandInfo()) {
+            System.out.println(
+                    "************************* validate '" + sch.getCmdName() + "' *******************************");
+            this.handle(new String[] { "schema-validate", "-l", sch.getSchemaName(), "-i"});
+        }
+    }
+
+    @Test
+    public void commandHelpTest() throws OnapCommandException {
+        for (String version: OnapCommandRegistrar.getRegistrar().getAvailableProductVersions()) {
+            OnapCommandRegistrar.getRegistrar().setEnabledProductVersion(version);
+            for (ExternalSchema sch : OnapCommandRegistrar.getRegistrar().listCommandInfo()) {
+                if (sch.getCmdVersion().equals(version)) {
+                    System.out.println(
+                            "************************* help '" + sch.getCmdName() + "' *******************************");
+                    this.handle(new String[] { sch.getCmdName(), "-h"});
+                }
+            }
+        }
+    }
+
+ }