Skip to content

Commit

Permalink
sint: Allow use of custom SmackDebugger
Browse files Browse the repository at this point in the history
Refactors the Smack Integration Test configuration to allow for a classname for a SmackDebugger(Factory) to be
provided.
  • Loading branch information
guusdk committed Mar 21, 2024
1 parent e504bc2 commit 92c45e0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -61,12 +62,6 @@ public enum AccountRegistration {
serviceAdministration,
}

public enum Debugger {
none,
console,
enhanced,
}

public enum DnsResolver {
minidns,
javax,
Expand Down Expand Up @@ -101,7 +96,7 @@ public enum DnsResolver {

public final String accountThreePassword;

public final Debugger debugger;
public final SmackDebuggerFactory debuggerFactory;

public final Set<String> enabledTests;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
};

Expand Down Expand Up @@ -246,7 +233,7 @@ public static final class Builder {

public String accountThreePassword;

private Debugger debugger = Debugger.none;
private SmackDebuggerFactory debuggerFactory;

private Set<String> enabledTests;

Expand Down Expand Up @@ -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<? extends SmackDebuggerFactory> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
* </tr>
* <tr>
* <td>debugger</td>
* <td>‘console’ for console debugger, ‘enhanced’ for the enhanced debugger</td>
* <td>‘console’ for console debugger, ‘enhanced’ for the enhanced debugger, or the name of a class that implements SmackDebuggerFactory for a custom debugger</td>
* </tr>
* <tr>
* <td>enabledTests</td>
Expand Down Expand Up @@ -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.
* </p>
* <p>
* 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.
* </p>
* <p>
* Example:
* </p>
*
* <pre>{@code
* $ gradle integrationTest -Dsinttest.service=my.xmppservice.org -Dsinttest.debugger="org.example.MyDebugger$Factory"
* }</pre>
* <h3>Debugging in the IDE</h3>
* <p>
* If the output isn't enough, you may need to debug and inspect running code within the IDE. Depending on the IDE, in
Expand All @@ -302,7 +314,7 @@
* </p>
*
* <pre>{@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
* }</pre>
*/
package org.igniterealtime.smack.inttest;

0 comments on commit 92c45e0

Please sign in to comment.