1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 20:42:06 +01:00

IntegrationTest: Implement custom host configuration

Added the following possible connection configuration options:

* adminAccountHostname: hostname for the admin account
* adminAccountPort: port for the admin account
* accountOneHostname: hostname for the first test account
* accountTwoPort: port for the first test account

Similar options exist for connection two and three of course.
These configuration options may come in handy when dealing with
an XMPP server that is clustered among different machines.
This commit is contained in:
Paul Schaub 2019-09-28 01:12:37 +02:00
parent f0300dc906
commit 92e8f81b3c
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 123 additions and 10 deletions

View file

@ -76,18 +76,34 @@ public final class Configuration {
public final String adminAccountPassword; public final String adminAccountPassword;
public final String adminAccountHostname;
public final int adminAccountPort;
public final String accountOneUsername; public final String accountOneUsername;
public final String accountOnePassword; public final String accountOnePassword;
public final String accountOneHostname;
public final int accountOnePort;
public final String accountTwoUsername; public final String accountTwoUsername;
public final String accountTwoPassword; public final String accountTwoPassword;
public final String accountTwoHostname;
public final int accountTwoPort;
public final String accountThreeUsername; public final String accountThreeUsername;
public final String accountThreePassword; public final String accountThreePassword;
public final String accountThreeHostname;
public final int accountThreePort;
public final Debugger debugger; public final Debugger debugger;
public final Set<String> enabledTests; public final Set<String> enabledTests;
@ -98,10 +114,13 @@ public final class Configuration {
public final ConnectionConfigurationBuilderApplier configurationApplier; public final ConnectionConfigurationBuilderApplier configurationApplier;
private Configuration(DomainBareJid service, String serviceTlsPin, SecurityMode securityMode, int replyTimeout, private Configuration(DomainBareJid service, String serviceTlsPin, SecurityMode securityMode,
Debugger debugger, String accountOneUsername, String accountOnePassword, String accountTwoUsername, int replyTimeout, Debugger debugger,
String accountTwoPassword, String accountThreeUsername, String accountThreePassword, Set<String> enabledTests, Set<String> disabledTests, String accountOneUsername, String accountOnePassword, String accountOneHostname, int accountOnePort,
Set<String> testPackages, String adminAccountUsername, String adminAccountPassword) String accountTwoUsername, String accountTwoPassword, String accountTwoHostname, int accountTwoPort,
String accountThreeUsername, String accountThreePassword, String accountThreeHostname, int accountThreePort,
Set<String> enabledTests, Set<String> disabledTests, Set<String> testPackages,
String adminAccountUsername, String adminAccountPassword, String adminAccountHostname, int adminAccountPort)
throws KeyManagementException, NoSuchAlgorithmException { throws KeyManagementException, NoSuchAlgorithmException {
this.service = Objects.requireNonNull(service, this.service = Objects.requireNonNull(service,
"'service' must be set. Either via 'properties' files or via system property 'sinttest.service'."); "'service' must be set. Either via 'properties' files or via system property 'sinttest.service'.");
@ -131,6 +150,8 @@ public final class Configuration {
this.adminAccountUsername = adminAccountUsername; this.adminAccountUsername = adminAccountUsername;
this.adminAccountPassword = adminAccountPassword; this.adminAccountPassword = adminAccountPassword;
this.adminAccountHostname = adminAccountHostname;
this.adminAccountPort = adminAccountPort;
boolean accountOnePasswordSet = StringUtils.isNotEmpty(accountOnePassword); boolean accountOnePasswordSet = StringUtils.isNotEmpty(accountOnePassword);
if (accountOnePasswordSet != StringUtils.isNotEmpty(accountTwoPassword) || if (accountOnePasswordSet != StringUtils.isNotEmpty(accountTwoPassword) ||
@ -141,10 +162,19 @@ public final class Configuration {
this.accountOneUsername = accountOneUsername; this.accountOneUsername = accountOneUsername;
this.accountOnePassword = accountOnePassword; this.accountOnePassword = accountOnePassword;
this.accountOneHostname = accountOneHostname;
this.accountOnePort = accountOnePort;
this.accountTwoUsername = accountTwoUsername; this.accountTwoUsername = accountTwoUsername;
this.accountTwoPassword = accountTwoPassword; this.accountTwoPassword = accountTwoPassword;
this.accountTwoHostname = accountTwoHostname;
this.accountTwoPort = accountTwoPort;
this.accountThreeUsername = accountThreeUsername; this.accountThreeUsername = accountThreeUsername;
this.accountThreePassword = accountThreePassword; this.accountThreePassword = accountThreePassword;
this.accountThreeHostname = accountThreeHostname;
this.accountThreePort = accountThreePort;
this.enabledTests = enabledTests; this.enabledTests = enabledTests;
this.disabledTests = disabledTests; this.disabledTests = disabledTests;
this.testPackages = testPackages; this.testPackages = testPackages;
@ -192,17 +222,33 @@ public final class Configuration {
private String adminAccountPassword; private String adminAccountPassword;
private String adminAccountHostname;
private int adminAccountPort;
private String accountOneUsername; private String accountOneUsername;
private String accountOnePassword; private String accountOnePassword;
private String accountOneHostname;
private int accountOnePort;
private String accountTwoUsername; private String accountTwoUsername;
private String accountTwoPassword; private String accountTwoPassword;
public String accountThreeUsername; private String accountTwoHostname;
public String accountThreePassword; private int accountTwoPort;
private String accountThreeUsername;
private String accountThreePassword;
private String accountThreeHostname;
private int accountThreePort;
private Debugger debugger = Debugger.none; private Debugger debugger = Debugger.none;
@ -256,6 +302,12 @@ public final class Configuration {
return this; return this;
} }
public Builder setAdminHostnameAndPort(String adminAccountHostname, int adminAccountPort) {
this.adminAccountHostname = adminAccountHostname;
this.adminAccountPort = adminAccountPort;
return this;
}
public Builder setUsernamesAndPassword(String accountOneUsername, String accountOnePassword, public Builder setUsernamesAndPassword(String accountOneUsername, String accountOnePassword,
String accountTwoUsername, String accountTwoPassword, String accountThreeUsername, String accountThreePassword) { String accountTwoUsername, String accountTwoPassword, String accountThreeUsername, String accountThreePassword) {
this.accountOneUsername = StringUtils.requireNotNullNorEmpty(accountOneUsername, "accountOneUsername must not be null nor empty"); this.accountOneUsername = StringUtils.requireNotNullNorEmpty(accountOneUsername, "accountOneUsername must not be null nor empty");
@ -267,6 +319,18 @@ public final class Configuration {
return this; return this;
} }
public Builder setUserHostnamesAndPorts(String accountOneHostname, int accountOnePort,
String accountTwoHostname, int accountTwoPort,
String accountThreeHostname, int accountThreePort) {
this.accountOneHostname = accountOneHostname;
this.accountOnePort = accountOnePort;
this.accountTwoHostname = accountTwoHostname;
this.accountTwoPort = accountTwoPort;
this.accountThreeHostname = accountThreeHostname;
this.accountThreePort = accountThreePort;
return this;
}
public Builder setServiceTlsPin(String tlsPin) { public Builder setServiceTlsPin(String tlsPin) {
this.serviceTlsPin = tlsPin; this.serviceTlsPin = tlsPin;
return this; return this;
@ -351,9 +415,12 @@ public final class Configuration {
} }
public Configuration build() throws KeyManagementException, NoSuchAlgorithmException { public Configuration build() throws KeyManagementException, NoSuchAlgorithmException {
return new Configuration(service, serviceTlsPin, securityMode, replyTimeout, debugger, accountOneUsername, return new Configuration(service, serviceTlsPin, securityMode, replyTimeout, debugger,
accountOnePassword, accountTwoUsername, accountTwoPassword, accountThreeUsername, accountThreePassword, enabledTests, disabledTests, accountOneUsername, accountOnePassword, accountOneHostname, accountOnePort,
testPackages, adminAccountUsername, adminAccountPassword); accountTwoUsername, accountTwoPassword, accountTwoHostname, accountTwoPort,
accountThreeUsername, accountThreePassword, accountThreeHostname, accountThreePort,
enabledTests, disabledTests, testPackages,
adminAccountUsername, adminAccountPassword, adminAccountHostname, adminAccountPort);
} }
} }
@ -394,6 +461,12 @@ public final class Configuration {
builder.setAdminAccountUsernameAndPassword(adminAccountUsername, adminAccountPassword); builder.setAdminAccountUsernameAndPassword(adminAccountUsername, adminAccountPassword);
} }
String adminAccountHostname = properties.getProperty("adminAccountHostname");
int adminAccountPort = getIntProperty(properties, "adminAccountPort", 0);
if (StringUtils.isNotEmpty(adminAccountHostname)) {
builder.setAdminHostnameAndPort(adminAccountHostname, adminAccountPort);
}
String accountOneUsername = properties.getProperty("accountOneUsername"); String accountOneUsername = properties.getProperty("accountOneUsername");
String accountOnePassword = properties.getProperty("accountOnePassword"); String accountOnePassword = properties.getProperty("accountOnePassword");
String accountTwoUsername = properties.getProperty("accountTwoUsername"); String accountTwoUsername = properties.getProperty("accountTwoUsername");
@ -406,6 +479,19 @@ public final class Configuration {
accountTwoPassword, accountThreeUsername, accountThreePassword); accountTwoPassword, accountThreeUsername, accountThreePassword);
} }
String accountOneHostname = properties.getProperty("accountOneHostname");
int accountOnePort = getIntProperty(properties, "accountOnePort", 0);
String accountTwoHostname = properties.getProperty("accountTwoHostname");
int accountTwoPort = getIntProperty(properties, "accountTwoPort", 0);
String accountThreeHostname = properties.getProperty("accountThreeHostname");
int accountThreePort = getIntProperty(properties, "accountThreePort", 0);
if (accountOneHostname != null || accountTwoHostname != null || accountThreeHostname != null) {
builder.setUserHostnamesAndPorts(
accountOneHostname, accountOnePort,
accountTwoHostname, accountTwoPort,
accountThreeHostname, accountThreePort);
}
String debugString = properties.getProperty("debug"); String debugString = properties.getProperty("debug");
if (debugString != null) { if (debugString != null) {
LOGGER.warning("Usage of depreacted 'debug' option detected, please use 'debugger' instead"); LOGGER.warning("Usage of depreacted 'debug' option detected, please use 'debugger' instead");
@ -456,4 +542,9 @@ public final class Configuration {
} }
return string; return string;
} }
private static int getIntProperty(Properties properties, String propertyName, int defaultValue) {
String s = properties.getProperty(propertyName, Integer.toString(defaultValue));
return Integer.parseInt(s);
}
} }

View file

@ -133,7 +133,15 @@ public class XmppConnectionManager<DC extends AbstractXMPPConnection> {
switch (sinttestConfiguration.accountRegistration) { switch (sinttestConfiguration.accountRegistration) {
case serviceAdministration: case serviceAdministration:
case inBandRegistration: case inBandRegistration:
accountRegistrationConnection = defaultConnectionDescriptor.construct(sinttestConfiguration); accountRegistrationConnection = defaultConnectionDescriptor.construct(sinttestConfiguration,
builder -> {
if (sinttestConfiguration.adminAccountHostname != null) {
builder.setHost(sinttestConfiguration.adminAccountHostname);
}
if (sinttestConfiguration.adminAccountPort != 0) {
builder.setPort(sinttestConfiguration.adminAccountPort);
}
});
accountRegistrationConnection.connect(); accountRegistrationConnection.connect();
accountRegistrationConnection.login(sinttestConfiguration.adminAccountUsername, accountRegistrationConnection.login(sinttestConfiguration.adminAccountUsername,
sinttestConfiguration.adminAccountPassword); sinttestConfiguration.adminAccountPassword);
@ -255,20 +263,28 @@ public class XmppConnectionManager<DC extends AbstractXMPPConnection> {
String middlefix; String middlefix;
String accountUsername; String accountUsername;
String accountPassword; String accountPassword;
String accountHostname;
int accountPort;
switch (accountNum) { switch (accountNum) {
case One: case One:
accountUsername = sinttestConfiguration.accountOneUsername; accountUsername = sinttestConfiguration.accountOneUsername;
accountPassword = sinttestConfiguration.accountOnePassword; accountPassword = sinttestConfiguration.accountOnePassword;
accountHostname = sinttestConfiguration.accountOneHostname;
accountPort = sinttestConfiguration.accountOnePort;
middlefix = "one"; middlefix = "one";
break; break;
case Two: case Two:
accountUsername = sinttestConfiguration.accountTwoUsername; accountUsername = sinttestConfiguration.accountTwoUsername;
accountPassword = sinttestConfiguration.accountTwoPassword; accountPassword = sinttestConfiguration.accountTwoPassword;
accountHostname = sinttestConfiguration.accountTwoHostname;
accountPort = sinttestConfiguration.accountTwoPort;
middlefix = "two"; middlefix = "two";
break; break;
case Three: case Three:
accountUsername = sinttestConfiguration.accountThreeUsername; accountUsername = sinttestConfiguration.accountThreeUsername;
accountPassword = sinttestConfiguration.accountThreePassword; accountPassword = sinttestConfiguration.accountThreePassword;
accountHostname = sinttestConfiguration.accountThreeHostname;
accountPort = sinttestConfiguration.accountThreePort;
middlefix = "three"; middlefix = "three";
break; break;
default: default:
@ -284,6 +300,12 @@ public class XmppConnectionManager<DC extends AbstractXMPPConnection> {
} }
DC mainConnection = defaultConnectionDescriptor.construct(sinttestConfiguration, builder -> { DC mainConnection = defaultConnectionDescriptor.construct(sinttestConfiguration, builder -> {
if (accountHostname != null) {
builder.setHost(accountHostname);
}
if (accountPort != 0) {
builder.setPort(accountPort);
}
try { try {
builder.setUsernameAndPassword(finalAccountUsername, finalAccountPassword) builder.setUsernameAndPassword(finalAccountUsername, finalAccountPassword)
.setResource(middlefix + '-' + testRunId); .setResource(middlefix + '-' + testRunId);