summaryrefslogtreecommitdiffstats
path: root/base/java-tools/src/com/netscape
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2016-01-05 01:39:06 +0100
committerEndi S. Dewata <edewata@redhat.com>2016-01-18 16:45:32 +0100
commit02b63c6f8200042175b482b9cc00a0bc950f2f06 (patch)
tree3903613cd1989d8621dc6dafcf7e12580a6fc65a /base/java-tools/src/com/netscape
parent2c88b5d9c15487a796f65beea6c102b1ef04016f (diff)
downloadpki-02b63c6f8200042175b482b9cc00a0bc950f2f06.tar.gz
pki-02b63c6f8200042175b482b9cc00a0bc950f2f06.tar.xz
pki-02b63c6f8200042175b482b9cc00a0bc950f2f06.zip
Updated CLI to run individual selftests.
The pki selftest-run command has been modified to execute the specified selftests, or all selftests if nothing is specified. The command will also display the status of each test and the stack trace if it fails. https://fedorahosted.org/pki/ticket/1502
Diffstat (limited to 'base/java-tools/src/com/netscape')
-rw-r--r--base/java-tools/src/com/netscape/cmstools/selftests/SelfTestRunCLI.java48
1 files changed, 42 insertions, 6 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestRunCLI.java b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestRunCLI.java
index a3827178f..2e40ee4f8 100644
--- a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestRunCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestRunCLI.java
@@ -21,7 +21,10 @@ package com.netscape.cmstools.selftests;
import java.util.Arrays;
import org.apache.commons.cli.CommandLine;
+import org.apache.commons.lang.StringUtils;
+import com.netscape.certsrv.selftests.SelfTestResult;
+import com.netscape.certsrv.selftests.SelfTestResults;
import com.netscape.cmstools.cli.CLI;
import com.netscape.cmstools.cli.MainCLI;
@@ -38,7 +41,20 @@ public class SelfTestRunCLI extends CLI {
}
public void printHelp() {
- formatter.printHelp(getFullName() + " [OPTIONS...]", options);
+ formatter.printHelp(getFullName() + " [selftests...] [OPTIONS...]", options);
+ }
+
+ public static void printSelfTestResult(SelfTestResult result) {
+ System.out.println(" Selftest ID: " + result.getID());
+
+ String status = result.getStatus();
+ System.out.println(" Status: " + status);
+
+ String output = result.getOutput();
+ if (StringUtils.isNotEmpty(output)) {
+ System.out.println(" Output:");
+ System.out.println(output);
+ }
}
public void execute(String[] args) throws Exception {
@@ -62,13 +78,33 @@ public class SelfTestRunCLI extends CLI {
String[] cmdArgs = cmd.getArgs();
- if (cmdArgs.length != 0) {
- System.err.println("Error: Too many arguments specified.");
- printHelp();
- System.exit(-1);
+ SelfTestResults results;
+
+ if (cmdArgs.length == 0) {
+ results = selfTestCLI.selfTestClient.runSelfTests();
+
+ } else {
+
+ results = new SelfTestResults();
+
+ for (String selfTestID : cmdArgs) {
+ SelfTestResult result = selfTestCLI.selfTestClient.runSelfTest(selfTestID);
+ results.addEntry(result);;
+ }
}
- selfTestCLI.selfTestClient.executeSelfTests("run");
+ boolean first = true;
+
+ for (SelfTestResult result : results.getEntries()) {
+
+ if (first) {
+ first = false;
+ } else {
+ System.out.println();
+ }
+
+ printSelfTestResult(result);
+ }
MainCLI.printMessage("Selftests completed");
}