Skip to content

Commit 6a03bdb

Browse files
committed
[integration-test] Check that connections are connected for normal integration tests
1 parent 2cc77b4 commit 6a03bdb

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.util.TreeSet;
4949
import java.util.logging.Level;
5050
import java.util.logging.Logger;
51+
import java.util.stream.Collectors;
5152

5253
import org.jivesoftware.smack.AbstractXMPPConnection;
5354
import org.jivesoftware.smack.ConnectionConfiguration;
@@ -57,6 +58,7 @@
5758
import org.jivesoftware.smack.SmackException;
5859
import org.jivesoftware.smack.SmackException.NoResponseException;
5960
import org.jivesoftware.smack.SmackException.NotConnectedException;
61+
import org.jivesoftware.smack.XMPPConnection;
6062
import org.jivesoftware.smack.XMPPException;
6163
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
6264
import org.jivesoftware.smack.util.StringUtils;
@@ -483,7 +485,13 @@ private void runTests(Set<Class<? extends AbstractSmackIntTest>> classes)
483485
for (Method testMethod : smackIntegrationTestMethods) {
484486
switch (testType) {
485487
case Normal: {
486-
ConcreteTest.Executor concreteTestExecutor = () -> testMethod.invoke(test);
488+
ConcreteTest.Executor concreteTestExecutor = () -> {
489+
AbstractSmackIntegrationTest abstractTest = (AbstractSmackIntegrationTest) test;
490+
491+
throwIfDisconnectedConnections(abstractTest, testMethod, "Cannot execute test of");
492+
testMethod.invoke(test);
493+
throwIfDisconnectedConnections(abstractTest, testMethod, "There where disconnected connections after executing");
494+
};
487495
ConcreteTest concreteTest = new ConcreteTest(testType, testMethod, concreteTestExecutor);
488496
concreteTests.add(concreteTest);
489497
}
@@ -1111,4 +1119,12 @@ static TestMethodParameterType determineTestMethodParameterType(Method testMetho
11111119
return null;
11121120
}
11131121

1122+
private static void throwIfDisconnectedConnections(AbstractSmackIntegrationTest abstractTest, Method testMethod, String message) throws IOException {
1123+
List<XMPPConnection> disconnectedConnections = abstractTest.connections.stream().filter(c -> !c.isConnected()).collect(Collectors.toList());
1124+
if (disconnectedConnections.isEmpty()) return;
1125+
1126+
throw new IOException(message + " " + testMethod.getDeclaringClass().getSimpleName() + "."
1127+
+ testMethod.getName() + ", as not all connections are connected. Disconnected connections: "
1128+
+ disconnectedConnections);
1129+
}
11141130
}

0 commit comments

Comments
 (0)