From a404c8b827214ae8a4a431d3c9ec74da8fbd654e Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Fri, 24 Mar 2017 02:29:31 +0100 Subject: Refactored SelfTestCLI. The SelfTestCLI and its submodules have been modified to use lazy initialization to get the PKIClient object. --- .../src/com/netscape/cmstools/selftests/SelfTestCLI.java | 9 ++++++--- .../src/com/netscape/cmstools/selftests/SelfTestFindCLI.java | 4 +++- .../src/com/netscape/cmstools/selftests/SelfTestRunCLI.java | 6 ++++-- .../src/com/netscape/cmstools/selftests/SelfTestShowCLI.java | 4 +++- 4 files changed, 16 insertions(+), 7 deletions(-) (limited to 'base/java-tools') diff --git a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestCLI.java b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestCLI.java index 2e64e0576..1e674267d 100644 --- a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestCLI.java @@ -22,6 +22,7 @@ import java.io.IOException; import org.jboss.resteasy.plugins.providers.atom.Link; +import com.netscape.certsrv.client.PKIClient; import com.netscape.certsrv.selftests.SelfTestClient; import com.netscape.certsrv.selftests.SelfTestData; import com.netscape.cmstools.cli.CLI; @@ -40,12 +41,14 @@ public class SelfTestCLI extends CLI { addModule(new SelfTestShowCLI(this)); } - public void execute(String[] args) throws Exception { + public SelfTestClient getSelfTestClient() throws Exception { - client = parent.getClient(); + if (selfTestClient != null) return selfTestClient; + + PKIClient client = getClient(); selfTestClient = (SelfTestClient)parent.getClient("selftest"); - super.execute(args); + return selfTestClient; } public static void printSelfTestData(SelfTestData selfTestData) throws IOException { diff --git a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestFindCLI.java b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestFindCLI.java index e98ab21d6..3b480533c 100644 --- a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestFindCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestFindCLI.java @@ -24,6 +24,7 @@ import java.util.Collection; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; +import com.netscape.certsrv.selftests.SelfTestClient; import com.netscape.certsrv.selftests.SelfTestCollection; import com.netscape.certsrv.selftests.SelfTestData; import com.netscape.cmstools.cli.CLI; @@ -75,7 +76,8 @@ public class SelfTestFindCLI extends CLI { s = cmd.getOptionValue("size"); Integer size = s == null ? null : Integer.valueOf(s); - SelfTestCollection result = selfTestCLI.selfTestClient.findSelfTests(filter, start, size); + SelfTestClient selfTestClient = selfTestCLI.getSelfTestClient(); + SelfTestCollection result = selfTestClient.findSelfTests(filter, start, size); MainCLI.printMessage(result.getTotal() + " entries matched"); if (result.getTotal() == 0) return; 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 59f8a71a8..924455efd 100644 --- a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestRunCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestRunCLI.java @@ -23,6 +23,7 @@ import java.util.Arrays; import org.apache.commons.cli.CommandLine; import org.apache.commons.lang.StringUtils; +import com.netscape.certsrv.selftests.SelfTestClient; import com.netscape.certsrv.selftests.SelfTestResult; import com.netscape.certsrv.selftests.SelfTestResults; import com.netscape.cmstools.cli.CLI; @@ -68,17 +69,18 @@ public class SelfTestRunCLI extends CLI { String[] cmdArgs = cmd.getArgs(); + SelfTestClient selfTestClient = selfTestCLI.getSelfTestClient(); SelfTestResults results; if (cmdArgs.length == 0) { - results = selfTestCLI.selfTestClient.runSelfTests(); + results = selfTestClient.runSelfTests(); } else { results = new SelfTestResults(); for (String selfTestID : cmdArgs) { - SelfTestResult result = selfTestCLI.selfTestClient.runSelfTest(selfTestID); + SelfTestResult result = selfTestClient.runSelfTest(selfTestID); results.addEntry(result);; } } diff --git a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestShowCLI.java b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestShowCLI.java index cce4fb587..b8ff12aa3 100644 --- a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestShowCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestShowCLI.java @@ -25,6 +25,7 @@ import java.util.Arrays; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; +import com.netscape.certsrv.selftests.SelfTestClient; import com.netscape.certsrv.selftests.SelfTestData; import com.netscape.cmstools.cli.CLI; import com.netscape.cmstools.cli.MainCLI; @@ -71,7 +72,8 @@ public class SelfTestShowCLI extends CLI { String selfTestID = args[0]; String output = cmd.getOptionValue("output"); - SelfTestData selfTestInfo = selfTestCLI.selfTestClient.getSelfTest(selfTestID); + SelfTestClient selfTestClient = selfTestCLI.getSelfTestClient(); + SelfTestData selfTestInfo = selfTestClient.getSelfTest(selfTestID); if (output == null) { MainCLI.printMessage("SelfTest \"" + selfTestID + "\""); -- cgit