diff --git a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/Configuration.java b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/Configuration.java index 0df16141cf..3ab8f9e15c 100644 --- a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/Configuration.java +++ b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/Configuration.java @@ -36,6 +36,7 @@ import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode; import org.jivesoftware.smack.debugger.ConsoleDebugger; +import org.jivesoftware.smack.debugger.SmackDebuggerFactory; import org.jivesoftware.smack.util.CollectionUtil; import org.jivesoftware.smack.util.Function; import org.jivesoftware.smack.util.Objects; @@ -61,12 +62,6 @@ public enum AccountRegistration { serviceAdministration, } - public enum Debugger { - none, - console, - enhanced, - } - public enum DnsResolver { minidns, javax, @@ -101,7 +96,7 @@ public enum DnsResolver { public final String accountThreePassword; - public final Debugger debugger; + public final SmackDebuggerFactory debuggerFactory; public final Set enabledTests; @@ -148,7 +143,7 @@ private Configuration(Configuration.Builder builder) throws KeyManagementExcepti } else { replyTimeout = 47000; } - debugger = builder.debugger; + debuggerFactory = builder.debuggerFactory; if (StringUtils.isNotEmpty(builder.adminAccountUsername, builder.adminAccountPassword)) { accountRegistration = AccountRegistration.serviceAdministration; } @@ -193,16 +188,8 @@ else if (StringUtils.isNotEmpty(builder.accountOneUsername, builder.accountOnePa b.setSecurityMode(securityMode); b.setXmppDomain(service); - switch (debugger) { - case enhanced: - b.setDebuggerFactory(EnhancedDebugger.Factory.INSTANCE); - break; - case console: - b.setDebuggerFactory(ConsoleDebugger.Factory.INSTANCE); - break; - case none: - // Nothing to do :). - break; + if (debuggerFactory != null) { + b.setDebuggerFactory(debuggerFactory); } }; @@ -246,7 +233,7 @@ public static final class Builder { public String accountThreePassword; - private Debugger debugger = Debugger.none; + private SmackDebuggerFactory debuggerFactory; private Set enabledTests; @@ -352,18 +339,23 @@ public Builder setDebugger(String debuggerString) { case "false": // For backwards compatibility settings with previous boolean setting. LOGGER.warning("Debug string \"" + debuggerString + "\" is deprecated, please use \"none\" instead"); case "none": - debugger = Debugger.none; + debuggerFactory = null; break; case "true": // For backwards compatibility settings with previous boolean setting. LOGGER.warning("Debug string \"" + debuggerString + "\" is deprecated, please use \"console\" instead"); case "console": - debugger = Debugger.console; + debuggerFactory = ConsoleDebugger.Factory.INSTANCE; break; case "enhanced": - debugger = Debugger.enhanced; + debuggerFactory = EnhancedDebugger.Factory.INSTANCE; break; default: - throw new IllegalArgumentException("Unrecognized debugger string: " + debuggerString); + try { + final Class aClass = Class.forName(debuggerString).asSubclass(SmackDebuggerFactory.class); + debuggerFactory = aClass.getConstructor().newInstance(); + } catch (Exception e) { + throw new IllegalArgumentException("Unable to construct debugger from value: " + debuggerString, e); + } } return this; } diff --git a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java index 8be908fb00..aedd552211 100644 --- a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java +++ b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java @@ -64,6 +64,7 @@ import org.jivesoftware.smack.util.dns.javax.JavaxResolver; import org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver; +import org.jivesoftware.smackx.debugger.EnhancedDebugger; import org.jivesoftware.smackx.debugger.EnhancedDebuggerWindow; import org.jivesoftware.smackx.iqregister.AccountManager; @@ -138,12 +139,8 @@ public static void main(String[] args) throws IOException, KeyManagementExceptio exitStatus = 0; } - switch (config.debugger) { - case enhanced: + if (config.debuggerFactory instanceof EnhancedDebugger) { EnhancedDebuggerWindow.getInstance().waitUntilClosed(); - break; - default: - break; } System.exit(exitStatus); @@ -175,7 +172,7 @@ public synchronized TestRunResult run() this.connectionManager = new XmppConnectionManager(this); LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + ']' + ": Starting\nSmack version: " + Smack.getVersion()); - if (config.debugger != Configuration.Debugger.none) { + if (config.debuggerFactory != null) { // JUL Debugger will not print any information until configured to print log messages of // level FINE // TODO configure JUL for log? diff --git a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/package-info.java b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/package-info.java index 2caf8d7928..46bea2cd0c 100644 --- a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/package-info.java +++ b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/package-info.java @@ -125,7 +125,7 @@ * * * debugger - * ‘console’ for console debugger, ‘enhanced’ for the enhanced debugger + * ‘console’ for console debugger, ‘enhanced’ for the enhanced debugger, or the name of a class that implements SmackDebuggerFactory for a custom debugger * * * enabledTests @@ -284,6 +284,18 @@ * Debug Window launching when your tests launch, and you'll get a stanza-by-stanza account of what happened on each * connection, hopefully enough to diagnose what went wrong. *

+ *

+ * Lastly, you can provide a custom debugger, by providing the fully qualified name of a class that implements + * {@link org.jivesoftware.smack.debugger.SmackDebuggerFactory}. The provided factory must declare a public constructor + * that takes no arguments. + *

+ *

+ * Example: + *

+ * + *
{@code
+ * $ gradle integrationTest -Dsinttest.service=my.xmppservice.org -Dsinttest.debugger="org.example.MyDebugger$Factory"
+ * }
*

Debugging in the IDE

*

* If the output isn't enough, you may need to debug and inspect running code within the IDE. Depending on the IDE, in @@ -302,7 +314,7 @@ *

* *
{@code
- * $ gradle integrationTest -Dsinttest.service=my.xmppserivce.org -Dsinttest.testPackages=org.mypackage,org.otherpackage
+ * $ gradle integrationTest -Dsinttest.service=my.xmppservice.org -Dsinttest.testPackages=org.mypackage,org.otherpackage
  * }
*/ package org.igniterealtime.smack.inttest;