mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-06 21:21:08 +01:00
Re-activate EntityCaps integration test
This commit is contained in:
parent
1f7770b831
commit
7655ac17f2
16 changed files with 358 additions and 181 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2015 Florian Schmaus
|
||||
* Copyright 2015-2016 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -17,12 +17,58 @@
|
|||
package org.igniterealtime.smack.inttest;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.filter.StanzaFilter;
|
||||
|
||||
public abstract class AbstractSmackIntTest {
|
||||
|
||||
protected static final Logger LOGGER = Logger.getLogger(AbstractSmackIntTest.class.getName());
|
||||
|
||||
protected static final Random INSECURE_RANDOM = new Random();
|
||||
|
||||
protected final String testRunId;
|
||||
|
||||
protected final long timeout;
|
||||
|
||||
protected AbstractSmackIntTest(String testRunId, long timeout) {
|
||||
this.testRunId = testRunId;
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
protected void performActionAndWaitUntilStanzaReceived(Runnable action, XMPPConnection connection, StanzaFilter filter)
|
||||
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
PacketCollector.Configuration configuration = PacketCollector.newConfiguration().setStanzaFilter(
|
||||
filter).setSize(1);
|
||||
PacketCollector collector = connection.createPacketCollector(configuration);
|
||||
|
||||
try {
|
||||
action.run();
|
||||
collector.nextResultOrThrow(timeout);
|
||||
}
|
||||
finally {
|
||||
collector.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
protected void waitUntilTrue(Condition condition) throws TimeoutException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
final long deadline = System.currentTimeMillis() + timeout;
|
||||
do {
|
||||
if (condition.evaluate()) {
|
||||
return;
|
||||
}
|
||||
Thread.yield();
|
||||
} while (System.currentTimeMillis() <= deadline);
|
||||
throw new TimeoutException("Timeout waiting for condition to become true. Timeout was " + timeout + " ms.");
|
||||
}
|
||||
|
||||
protected interface Condition {
|
||||
boolean evaluate() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,19 +40,10 @@ public abstract class AbstractSmackIntegrationTest extends AbstractSmackIntTest
|
|||
*/
|
||||
protected final XMPPConnection connection;
|
||||
|
||||
protected final String testRunId;
|
||||
|
||||
protected final long defaultTimeout;
|
||||
|
||||
public AbstractSmackIntegrationTest(SmackIntegrationTestEnvironment environment) {
|
||||
super(environment.testRunId, environment.configuration.replyTimeout);
|
||||
this.connection = this.conOne = environment.conOne;
|
||||
this.conTwo = environment.conTwo;
|
||||
this.conThree = environment.conThree;
|
||||
if (environment.configuration.replyTimeout > 0) {
|
||||
this.defaultTimeout = environment.configuration.replyTimeout;
|
||||
} else {
|
||||
this.defaultTimeout = 2 * 60 * 1000;
|
||||
}
|
||||
this.testRunId = environment.testRunId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,14 +36,12 @@ public abstract class AbstractSmackLowLevelIntegrationTest extends AbstractSmack
|
|||
*/
|
||||
protected final Configuration configuration;
|
||||
|
||||
protected final String testRunId;
|
||||
|
||||
protected final DomainBareJid service;
|
||||
|
||||
public AbstractSmackLowLevelIntegrationTest(SmackIntegrationTestEnvironment environment) {
|
||||
super(environment.testRunId, environment.configuration.replyTimeout);
|
||||
this.environment = environment;
|
||||
this.configuration = environment.configuration;
|
||||
this.testRunId = environment.testRunId;
|
||||
this.service = configuration.service;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,11 @@ public final class Configuration {
|
|||
"'service' must be set. Either via 'properties' files or via system property 'sinttest.service'.");
|
||||
this.serviceTlsPin = serviceTlsPin;
|
||||
this.securityMode = securityMode;
|
||||
this.replyTimeout = replyTimeout;
|
||||
if (replyTimeout > 0) {
|
||||
this.replyTimeout = replyTimeout;
|
||||
} else {
|
||||
this.replyTimeout = 60000;
|
||||
}
|
||||
this.debug = debug;
|
||||
if (StringUtils.isNotEmpty(adminAccountUsername, adminAccountPassword)) {
|
||||
accountRegistration = AccountRegistration.serviceAdministration;
|
||||
|
|
|
|||
|
|
@ -95,9 +95,14 @@ public class SmackIntegrationTestFramework {
|
|||
LOGGER.info("Could not run " + testNotPossible.testMethod.getName() + " because: "
|
||||
+ testNotPossible.testNotPossibleException.getMessage());
|
||||
}
|
||||
final int successfulTests = testRunResult.successfulTests.size();
|
||||
final int availableTests = testRunResult.getNumberOfAvailableTests();
|
||||
final int possibleTests = testRunResult.getNumberOfPossibleTests();
|
||||
LOGGER.info("SmackIntegrationTestFramework[" + testRunResult.testRunId + ']' + ": Finished ["
|
||||
+ testRunResult.successfulTests.size() + '/' + testRunResult.numberOfTests + ']');
|
||||
+ successfulTests + '/' + possibleTests + "] (of " + availableTests + " available tests)");
|
||||
if (!testRunResult.failedIntegrationTests.isEmpty()) {
|
||||
final int failedTests = testRunResult.failedIntegrationTests.size();
|
||||
LOGGER.warning("The following " + failedTests + " tests failed!");
|
||||
for (FailedTest failedTest : testRunResult.failedIntegrationTests) {
|
||||
final Method method = failedTest.testMethod;
|
||||
final String className = method.getDeclaringClass().getName();
|
||||
|
|
@ -106,6 +111,8 @@ public class SmackIntegrationTestFramework {
|
|||
LOGGER.severe(className + CLASS_METHOD_SEP + methodName + " failed: " + cause);
|
||||
}
|
||||
System.exit(2);
|
||||
} else {
|
||||
LOGGER.info("All possible Smack Integration Tests completed successfully. \\o/");
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
|
@ -251,7 +258,9 @@ public class SmackIntegrationTestFramework {
|
|||
continue;
|
||||
}
|
||||
|
||||
testRunResult.numberOfTests.addAndGet(smackIntegrationTestMethods.size());
|
||||
final int detectedTestMethodsCount = smackIntegrationTestMethods.size();
|
||||
testRunResult.numberOfAvailableTests.addAndGet(detectedTestMethodsCount);
|
||||
testRunResult.numberOfPossibleTests.addAndGet(detectedTestMethodsCount);
|
||||
|
||||
AbstractSmackIntTest test;
|
||||
switch (testType) {
|
||||
|
|
@ -274,6 +283,7 @@ public class SmackIntegrationTestFramework {
|
|||
Throwable cause = e.getCause();
|
||||
if (cause instanceof TestNotPossibleException) {
|
||||
testRunResult.impossibleTestClasses.put(testClass, cause.getMessage());
|
||||
testRunResult.numberOfPossibleTests.addAndGet(-detectedTestMethodsCount);
|
||||
}
|
||||
else {
|
||||
throwFatalException(cause);
|
||||
|
|
@ -306,6 +316,7 @@ public class SmackIntegrationTestFramework {
|
|||
Throwable cause = e.getCause();
|
||||
if (cause instanceof TestNotPossibleException) {
|
||||
testRunResult.impossibleTestClasses.put(testClass, cause.getMessage());
|
||||
testRunResult.numberOfPossibleTests.addAndGet(-detectedTestMethodsCount);
|
||||
}
|
||||
else {
|
||||
throwFatalException(cause);
|
||||
|
|
@ -622,7 +633,8 @@ public class SmackIntegrationTestFramework {
|
|||
private final List<FailedTest> failedIntegrationTests = Collections.synchronizedList(new LinkedList<FailedTest>());
|
||||
private final List<TestNotPossible> impossibleTestMethods = Collections.synchronizedList(new LinkedList<TestNotPossible>());
|
||||
private final Map<Class<? extends AbstractSmackIntTest>, String> impossibleTestClasses = new HashMap<>();
|
||||
private final AtomicInteger numberOfTests = new AtomicInteger();
|
||||
private final AtomicInteger numberOfAvailableTests = new AtomicInteger();
|
||||
private final AtomicInteger numberOfPossibleTests = new AtomicInteger();
|
||||
|
||||
private TestRunResult() {
|
||||
}
|
||||
|
|
@ -631,8 +643,12 @@ public class SmackIntegrationTestFramework {
|
|||
return testRunId;
|
||||
}
|
||||
|
||||
public int getNumberOfTests() {
|
||||
return numberOfTests.get();
|
||||
public int getNumberOfAvailableTests() {
|
||||
return numberOfAvailableTests.get();
|
||||
}
|
||||
|
||||
public int getNumberOfPossibleTests() {
|
||||
return numberOfPossibleTests.get();
|
||||
}
|
||||
|
||||
public List<SuccessfulTest> getSuccessfulTests() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue