mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 10:49:41 +02:00
Rework Smack debugger.
Also fixes SMACK-728.
This commit is contained in:
parent
104146c5ed
commit
b8ee8d808f
24 changed files with 328 additions and 390 deletions
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
|
@ -41,12 +42,20 @@ import org.jxmpp.stringprep.XmppStringprepException;
|
|||
|
||||
public final class Configuration {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(Configuration.class.getName());
|
||||
|
||||
public enum AccountRegistration {
|
||||
disabled,
|
||||
inBandRegistration,
|
||||
serviceAdministration,
|
||||
}
|
||||
|
||||
public enum Debugger {
|
||||
none,
|
||||
console,
|
||||
enhanced,
|
||||
}
|
||||
|
||||
public final DomainBareJid service;
|
||||
|
||||
public final String serviceTlsPin;
|
||||
|
@ -75,7 +84,7 @@ public final class Configuration {
|
|||
|
||||
public final String accountThreePassword;
|
||||
|
||||
public final boolean debug;
|
||||
public final Debugger debugger;
|
||||
|
||||
public final Set<String> enabledTests;
|
||||
|
||||
|
@ -84,7 +93,7 @@ public final class Configuration {
|
|||
public final Set<String> testPackages;
|
||||
|
||||
private Configuration(DomainBareJid service, String serviceTlsPin, SecurityMode securityMode, int replyTimeout,
|
||||
boolean debug, String accountOneUsername, String accountOnePassword, String accountTwoUsername,
|
||||
Debugger debugger, String accountOneUsername, String accountOnePassword, String accountTwoUsername,
|
||||
String accountTwoPassword, String accountThreeUsername, String accountThreePassword, Set<String> enabledTests, Set<String> disabledTests,
|
||||
Set<String> testPackages, String adminAccountUsername, String adminAccountPassword)
|
||||
throws KeyManagementException, NoSuchAlgorithmException {
|
||||
|
@ -102,7 +111,7 @@ public final class Configuration {
|
|||
} else {
|
||||
this.replyTimeout = 60000;
|
||||
}
|
||||
this.debug = debug;
|
||||
this.debugger = debugger;
|
||||
if (StringUtils.isNotEmpty(adminAccountUsername, adminAccountPassword)) {
|
||||
accountRegistration = AccountRegistration.serviceAdministration;
|
||||
}
|
||||
|
@ -162,7 +171,7 @@ public final class Configuration {
|
|||
|
||||
public String accountThreePassword;
|
||||
|
||||
private boolean debug;
|
||||
private Debugger debugger = Debugger.none;
|
||||
|
||||
private Set<String> enabledTests;
|
||||
|
||||
|
@ -247,9 +256,27 @@ public final class Configuration {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setDebug(String debugString) {
|
||||
if (debugString != null) {
|
||||
debug = Boolean.valueOf(debugString);
|
||||
@SuppressWarnings("fallthrough")
|
||||
public Builder setDebugger(String debuggerString) {
|
||||
if (debuggerString == null) {
|
||||
return this;
|
||||
}
|
||||
switch (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;
|
||||
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;
|
||||
break;
|
||||
case "enhanced":
|
||||
debugger = Debugger.enhanced;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unrecognized debugger string: " + debuggerString);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -291,7 +318,7 @@ public final class Configuration {
|
|||
}
|
||||
|
||||
public Configuration build() throws KeyManagementException, NoSuchAlgorithmException {
|
||||
return new Configuration(service, serviceTlsPin, securityMode, replyTimeout, debug, accountOneUsername,
|
||||
return new Configuration(service, serviceTlsPin, securityMode, replyTimeout, debugger, accountOneUsername,
|
||||
accountOnePassword, accountTwoUsername, accountTwoPassword, accountThreeUsername, accountThreePassword, enabledTests, disabledTests,
|
||||
testPackages, adminAccountUsername, adminAccountPassword);
|
||||
}
|
||||
|
@ -346,7 +373,12 @@ public final class Configuration {
|
|||
accountTwoPassword, accountThreeUsername, accountThreePassword);
|
||||
}
|
||||
|
||||
builder.setDebug(properties.getProperty("debug"));
|
||||
String debugString = properties.getProperty("debug");
|
||||
if (debugString != null) {
|
||||
LOGGER.warning("Usage of depreacted 'debug' option detected, please use 'debugger' instead");
|
||||
builder.setDebugger(debugString);
|
||||
}
|
||||
builder.setDebugger(properties.getProperty("debugger"));
|
||||
builder.setEnabledTests(properties.getProperty("enabledTests"));
|
||||
builder.setDisabledTests(properties.getProperty("disabledTests"));
|
||||
|
||||
|
|
|
@ -48,11 +48,14 @@ import org.jivesoftware.smack.SmackConfiguration;
|
|||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.debugger.ConsoleDebugger;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration.Builder;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
import org.jivesoftware.smackx.debugger.EnhancedDebugger;
|
||||
import org.jivesoftware.smackx.debugger.EnhancedDebuggerWindow;
|
||||
import org.jivesoftware.smackx.iqregister.AccountManager;
|
||||
|
||||
import org.igniterealtime.smack.inttest.IntTestUtil.UsernameAndPassword;
|
||||
|
@ -98,6 +101,8 @@ public class SmackIntegrationTestFramework {
|
|||
final int possibleTests = testRunResult.getNumberOfPossibleTests();
|
||||
LOGGER.info("SmackIntegrationTestFramework[" + testRunResult.testRunId + ']' + ": Finished ["
|
||||
+ successfulTests + '/' + possibleTests + "] (of " + availableTests + " available tests)");
|
||||
|
||||
int exitStatus;
|
||||
if (!testRunResult.failedIntegrationTests.isEmpty()) {
|
||||
final int failedTests = testRunResult.failedIntegrationTests.size();
|
||||
LOGGER.warning("The following " + failedTests + " tests failed!");
|
||||
|
@ -108,11 +113,21 @@ public class SmackIntegrationTestFramework {
|
|||
final Throwable cause = failedTest.failureReason;
|
||||
LOGGER.severe(className + CLASS_METHOD_SEP + methodName + " failed: " + cause);
|
||||
}
|
||||
System.exit(2);
|
||||
exitStatus = 2;
|
||||
} else {
|
||||
LOGGER.info("All possible Smack Integration Tests completed successfully. \\o/");
|
||||
exitStatus = 0;
|
||||
}
|
||||
System.exit(0);
|
||||
|
||||
switch (config.debugger) {
|
||||
case enhanced:
|
||||
EnhancedDebuggerWindow.getInstance().waitUntilClosed();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
System.exit(exitStatus);
|
||||
}
|
||||
|
||||
public SmackIntegrationTestFramework(Configuration configuration) {
|
||||
|
@ -123,7 +138,7 @@ public class SmackIntegrationTestFramework {
|
|||
IOException, XMPPException, InterruptedException {
|
||||
testRunResult = new TestRunResult();
|
||||
LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + ']' + ": Starting");
|
||||
if (config.debug) {
|
||||
if (config.debugger != Configuration.Debugger.none) {
|
||||
// JUL Debugger will not print any information until configured to print log messages of
|
||||
// level FINE
|
||||
// TODO configure JUL for log?
|
||||
|
@ -583,6 +598,19 @@ public class SmackIntegrationTestFramework {
|
|||
}
|
||||
builder.setSecurityMode(config.securityMode);
|
||||
builder.setXmppDomain(config.service);
|
||||
|
||||
switch (config.debugger) {
|
||||
case enhanced:
|
||||
builder.setDebuggerFactory(EnhancedDebugger.Factory.INSTANCE);
|
||||
break;
|
||||
case console:
|
||||
builder.setDebuggerFactory(ConsoleDebugger.Factory.INSTANCE);
|
||||
break;
|
||||
case none:
|
||||
// Nothing to do :).
|
||||
break;
|
||||
}
|
||||
|
||||
XMPPTCPConnection connection = new XMPPTCPConnection(builder.build());
|
||||
connection.connect();
|
||||
UsernameAndPassword uap = IntTestUtil.registerAccount(connection, environment, connectionId);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue