Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[integration-test] Check that connections are connected for normal integration tests #645

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.ConnectionConfiguration;
Expand All @@ -57,6 +58,7 @@
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.util.StringUtils;
Expand Down Expand Up @@ -483,7 +485,13 @@ private void runTests(Set<Class<? extends AbstractSmackIntTest>> classes)
for (Method testMethod : smackIntegrationTestMethods) {
switch (testType) {
case Normal: {
ConcreteTest.Executor concreteTestExecutor = () -> testMethod.invoke(test);
ConcreteTest.Executor concreteTestExecutor = () -> {
AbstractSmackIntegrationTest abstractTest = (AbstractSmackIntegrationTest) test;

throwIfDisconnectedConnections(abstractTest, testMethod, "Cannot execute test of");
testMethod.invoke(test);
throwIfDisconnectedConnections(abstractTest, testMethod, "There where disconnected connections after executing");
};
ConcreteTest concreteTest = new ConcreteTest(testType, testMethod, concreteTestExecutor);
concreteTests.add(concreteTest);
}
Expand Down Expand Up @@ -1111,4 +1119,12 @@ static TestMethodParameterType determineTestMethodParameterType(Method testMetho
return null;
}

private static void throwIfDisconnectedConnections(AbstractSmackIntegrationTest abstractTest, Method testMethod, String message) throws IOException {
List<XMPPConnection> disconnectedConnections = abstractTest.connections.stream().filter(c -> !c.isConnected()).collect(Collectors.toList());
if (disconnectedConnections.isEmpty()) return;

throw new IOException(message + " " + testMethod.getDeclaringClass().getSimpleName() + "."
+ testMethod.getName() + ", as not all connections are connected. Disconnected connections: "
+ disconnectedConnections);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2015-2020 Florian Schmaus
* Copyright 2015-2024 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,6 +53,11 @@ public DummySmackIntegrationTestFramework(Configuration configuration) throws Ke
@Override
protected SmackIntegrationTestEnvironment prepareEnvironment() {
DummyConnection dummyConnection = new DummyConnection();
try {
dummyConnection.connect();
} catch (SmackException | IOException | XMPPException | InterruptedException e) {
throw new AssertionError(e);
}
connectionManager.conOne = connectionManager.conTwo = connectionManager.conThree = dummyConnection;
return new SmackIntegrationTestEnvironment(dummyConnection, dummyConnection, dummyConnection,
testRunResult.getTestRunId(), config, null);
Expand Down
Loading