1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-25 12:08:00 +01:00

sint: Allow use of custom SmackDebugger

Refactors the Smack Integration Test configuration to allow for a classname for a SmackDebugger(Factory) to be
provided.
This commit is contained in:
Guus der Kinderen 2024-03-21 16:18:14 +01:00
parent e504bc23cf
commit 92c45e0d29
3 changed files with 32 additions and 31 deletions

View file

@ -36,6 +36,7 @@ import javax.net.ssl.SSLContext;
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 final class Configuration {
serviceAdministration,
}
public enum Debugger {
none,
console,
enhanced,
}
public enum DnsResolver {
minidns,
javax,
@ -101,7 +96,7 @@ public final class Configuration {
public final String accountThreePassword;
public final Debugger debugger;
public final SmackDebuggerFactory debuggerFactory;
public final Set<String> enabledTests;
@ -148,7 +143,7 @@ public final class Configuration {
} else {
replyTimeout = 47000;
}
debugger = builder.debugger;
debuggerFactory = builder.debuggerFactory;
if (StringUtils.isNotEmpty(builder.adminAccountUsername, builder.adminAccountPassword)) {
accountRegistration = AccountRegistration.serviceAdministration;
}
@ -193,16 +188,8 @@ public final class Configuration {
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 final class Configuration {
public String accountThreePassword;
private Debugger debugger = Debugger.none;
private SmackDebuggerFactory debuggerFactory;
private Set<String> enabledTests;
@ -352,18 +339,23 @@ public final class Configuration {
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;
}

View file

@ -64,6 +64,7 @@ import org.jivesoftware.smack.util.dns.dnsjava.DNSJavaResolver;
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 class SmackIntegrationTestFramework {
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 class SmackIntegrationTestFramework {
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?

View file

@ -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>
@ -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
@ -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;