1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-06 21:21:08 +01:00

Create low-level inttest accounts with test run ID

This commit is contained in:
Florian Schmaus 2016-12-19 18:10:04 +01:00
parent 26b16665e5
commit 814cc1fdde
8 changed files with 31 additions and 28 deletions

View file

@ -29,6 +29,8 @@ import eu.geekplace.javapinning.java7.Java7Pinning;
public abstract class AbstractSmackLowLevelIntegrationTest extends AbstractSmackIntTest {
private final SmackIntegrationTestEnvironment environment;
/**
* The configuration
*/
@ -38,9 +40,10 @@ public abstract class AbstractSmackLowLevelIntegrationTest extends AbstractSmack
protected final DomainBareJid service;
public AbstractSmackLowLevelIntegrationTest(Configuration configuration, String testRunId) {
this.configuration = configuration;
this.testRunId = testRunId;
public AbstractSmackLowLevelIntegrationTest(SmackIntegrationTestEnvironment environment) {
this.environment = environment;
this.configuration = environment.configuration;
this.testRunId = environment.testRunId;
this.service = configuration.service;
}
@ -56,7 +59,7 @@ public abstract class AbstractSmackLowLevelIntegrationTest extends AbstractSmack
}
protected void performCheck(ConnectionCallback callback) throws Exception {
XMPPTCPConnection connection = SmackIntegrationTestFramework.getConnectedConnection(configuration);
XMPPTCPConnection connection = SmackIntegrationTestFramework.getConnectedConnection(environment, -1);
try {
callback.connectionCallback(connection);
} finally {

View file

@ -44,8 +44,9 @@ public class IntTestUtil {
private static final Logger LOGGER = Logger.getLogger(IntTestUtil.class.getName());
public static UsernameAndPassword registerAccount(XMPPTCPConnection connection, Configuration config) throws InterruptedException, XMPPException, SmackException, IOException {
return registerAccount(connection, StringUtils.insecureRandomString(12), StringUtils.insecureRandomString(12), config);
public static UsernameAndPassword registerAccount(XMPPTCPConnection connection, SmackIntegrationTestEnvironment environment, int connectionId) throws InterruptedException, XMPPException, SmackException, IOException {
String username = "sinttest-" + environment.testRunId + "-" + connectionId;
return registerAccount(connection, username, StringUtils.insecureRandomString(12), environment.configuration);
}
public static UsernameAndPassword registerAccount(XMPPTCPConnection connection, String accountUsername, String accountPassword,

View file

@ -290,7 +290,7 @@ public class SmackIntegrationTestFramework {
Constructor<? extends AbstractSmackLowLevelIntegrationTest> cons;
try {
cons = ((Class<? extends AbstractSmackLowLevelIntegrationTest>) testClass).getConstructor(
Configuration.class, String.class);
SmackIntegrationTestEnvironment.class);
}
catch (NoSuchMethodException | SecurityException e) {
LOGGER.log(Level.WARNING,
@ -300,7 +300,7 @@ public class SmackIntegrationTestFramework {
}
try {
test = cons.newInstance(config, testRunResult.testRunId);
test = cons.newInstance(environment);
}
catch (InvocationTargetException e) {
Throwable cause = e.getCause();
@ -442,7 +442,7 @@ public class SmackIntegrationTestFramework {
}
connections = new XMPPTCPConnection[numberOfConnections];
for (int i = 0; i < numberOfConnections; ++i) {
connections[i] = getConnectedConnection(config);
connections[i] = getConnectedConnection(environment, i);
}
}
catch (Exception e) {
@ -563,9 +563,10 @@ public class SmackIntegrationTestFramework {
return connection;
}
static XMPPTCPConnection getConnectedConnection(Configuration config)
static XMPPTCPConnection getConnectedConnection(SmackIntegrationTestEnvironment environment, int connectionId)
throws KeyManagementException, NoSuchAlgorithmException, InterruptedException,
SmackException, IOException, XMPPException {
Configuration config = environment.configuration;
XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
if (config.serviceTlsPin != null) {
SSLContext sc = Java7Pinning.forPin(config.serviceTlsPin);
@ -575,7 +576,7 @@ public class SmackIntegrationTestFramework {
builder.setXmppDomain(config.service);
XMPPTCPConnection connection = new XMPPTCPConnection(builder.build());
connection.connect();
UsernameAndPassword uap = IntTestUtil.registerAccount(connection, config);
UsernameAndPassword uap = IntTestUtil.registerAccount(connection, environment, connectionId);
connection.login(uap.username, uap.password);
return connection;
}