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

Add (partial) support for IoT XEPs

That is XEP-0323, -0324, -0325, and -0347.

SMACK-727.
This commit is contained in:
Florian Schmaus 2016-07-20 20:57:04 +02:00
parent d1fe5c2933
commit b91978dcc4
110 changed files with 5395 additions and 40 deletions

View file

@ -16,10 +16,13 @@
*/
package org.igniterealtime.smack.inttest;
import java.util.Random;
import java.util.logging.Logger;
public abstract class AbstractSmackIntTest {
protected static final Logger LOGGER = Logger.getLogger(AbstractSmackIntTest.class.getName());
protected static final Random INSECURE_RANDOM = new Random();
}

View file

@ -30,6 +30,11 @@ public abstract class AbstractSmackIntegrationTest extends AbstractSmackIntTest
*/
protected final XMPPConnection conTwo;
/**
* The third connection.
*/
protected final XMPPConnection conThree;
/**
* An alias for the first connection {@link #conOne}.
*/
@ -42,6 +47,7 @@ public abstract class AbstractSmackIntegrationTest extends AbstractSmackIntTest
public AbstractSmackIntegrationTest(SmackIntegrationTestEnvironment environment) {
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 {

View file

@ -53,6 +53,10 @@ public final class Configuration {
public final String accountTwoPassword;
public final String accountThreeUsername;
public final String accountThreePassword;
public final boolean debug;
public final Set<String> enabledTests;
@ -63,7 +67,7 @@ public final class Configuration {
private Configuration(DomainBareJid service, String serviceTlsPin, SecurityMode securityMode, int replyTimeout,
boolean debug, String accountOneUsername, String accountOnePassword, String accountTwoUsername,
String accountTwoPassword, Set<String> enabledTests, Set<String> disabledTests,
String accountTwoPassword, String accountThreeUsername, String accountThreePassword, Set<String> enabledTests, Set<String> disabledTests,
Set<String> testPackages) {
this.service = Objects.requireNonNull(service,
"'service' must be set. Either via 'properties' files or via system property 'sinttest.service'.");
@ -83,6 +87,8 @@ public final class Configuration {
this.accountOnePassword = accountOnePassword;
this.accountTwoUsername = accountTwoUsername;
this.accountTwoPassword = accountTwoPassword;
this.accountThreeUsername = accountThreeUsername;
this.accountThreePassword = accountThreePassword;
this.enabledTests = enabledTests;
this.disabledTests = disabledTests;
this.testPackages = testPackages;
@ -110,6 +116,10 @@ public final class Configuration {
private String accountTwoPassword;
public String accountThreeUsername;
public String accountThreePassword;
private boolean debug;
private Set<String> enabledTests;
@ -153,11 +163,13 @@ public final class Configuration {
}
public Builder setUsernamesAndPassword(String accountOneUsername, String accountOnePassword,
String accountTwoUsername, String accountTwoPassword) {
this.accountOneUsername = accountOneUsername;
this.accountOnePassword = accountOnePassword;
this.accountTwoUsername = accountTwoUsername;
this.accountTwoPassword = accountTwoPassword;
String accountTwoUsername, String accountTwoPassword, String accountThreeUsername, String accountThreePassword) {
this.accountOneUsername = StringUtils.requireNotNullOrEmpty(accountOneUsername, "accountOneUsername must not be null or empty");
this.accountOnePassword = StringUtils.requireNotNullOrEmpty(accountOnePassword, "accountOnePassword must not be null or empty");
this.accountTwoUsername = StringUtils.requireNotNullOrEmpty(accountTwoUsername, "accountTwoUsername must not be null or empty");
this.accountTwoPassword = StringUtils.requireNotNullOrEmpty(accountTwoPassword, "accountTwoPasswordmust not be null or empty");
this.accountThreeUsername = StringUtils.requireNotNullOrEmpty(accountThreeUsername, "accountThreeUsername must not be null or empty");
this.accountThreePassword = StringUtils.requireNotNullOrEmpty(accountThreePassword, "accountThreePassword must not be null or empty");
return this;
}
@ -213,7 +225,7 @@ public final class Configuration {
public Configuration build() {
return new Configuration(service, serviceTlsPin, securityMode, replyTimeout, debug, accountOneUsername,
accountOnePassword, accountTwoUsername, accountTwoPassword, enabledTests, disabledTests,
accountOnePassword, accountTwoUsername, accountTwoPassword, accountThreeUsername, accountThreePassword, enabledTests, disabledTests,
testPackages);
}
}
@ -252,7 +264,9 @@ public final class Configuration {
String accountOnePassword = properties.getProperty("accountOnePassword");
String accountTwoUsername = properties.getProperty("accountTwoUsername");
String accountTwoPassword = properties.getProperty("accountTwoPassword");
builder.setUsernamesAndPassword(accountOneUsername, accountOnePassword, accountTwoUsername, accountTwoPassword);
String accountThreeUsername = properties.getProperty("accountThreeUsername");
String accountThreePassword = properties.getProperty("accountThreePassword");
builder.setUsernamesAndPassword(accountOneUsername, accountOnePassword, accountTwoUsername, accountTwoPassword, accountThreeUsername, accountThreePassword);
builder.setDebug(properties.getProperty("debug"));
builder.setEnabledTests(properties.getProperty("enabledTests"));
@ -262,7 +276,7 @@ public final class Configuration {
return builder.build();
}
private static File findPropertiesFile() throws IOException {
private static File findPropertiesFile() {
List<String> possibleLocations = new LinkedList<>();
possibleLocations.add("properties");
String userHome = System.getProperty("user.home");

View file

@ -24,14 +24,17 @@ public class SmackIntegrationTestEnvironment {
public final XMPPTCPConnection conTwo;
public final XMPPTCPConnection conThree;
public final String testRunId;
public final Configuration configuration;
SmackIntegrationTestEnvironment(XMPPTCPConnection conOne, XMPPTCPConnection conTwo, String testRunId,
SmackIntegrationTestEnvironment(XMPPTCPConnection conOne, XMPPTCPConnection conTwo, XMPPTCPConnection conThree, String testRunId,
Configuration configuration) {
this.conOne = conOne;
this.conTwo = conTwo;
this.conThree = conThree;
this.testRunId = testRunId;
this.configuration = configuration;
}

View file

@ -50,7 +50,6 @@ import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
@ -166,6 +165,7 @@ public class SmackIntegrationTestFramework {
// Ensure that the accounts are deleted and disconnected before we continue
disconnectAndMaybeDelete(environment.conOne);
disconnectAndMaybeDelete(environment.conTwo);
disconnectAndMaybeDelete(environment.conThree);
}
return testRunResult;
@ -173,16 +173,16 @@ public class SmackIntegrationTestFramework {
@SuppressWarnings({"unchecked", "Finally"})
private void runTests(Set<Class<? extends AbstractSmackIntTest>> classes)
throws NoResponseException, NotConnectedException, InterruptedException {
throws NoResponseException, InterruptedException {
for (Class<? extends AbstractSmackIntTest> testClass : classes) {
final String testClassName = testClass.getName();
if (config.enabledTests != null && !config.enabledTests.contains(testClassName)) {
if (config.enabledTests != null && !isInSet(testClass, config.enabledTests)) {
LOGGER.info("Skipping test class " + testClassName + " because it is not enabled");
continue;
}
if (config.disabledTests != null && config.disabledTests.contains(testClassName)) {
if (isInSet(testClass, config.disabledTests)) {
LOGGER.info("Skipping test class " + testClassName + " because it is disalbed");
continue;
}
@ -233,9 +233,8 @@ public class SmackIntegrationTestFramework {
while (it.hasNext()) {
final Method method = it.next();
final String methodName = method.getName();
final String className = method.getDeclaringClass().getName();
if (config.enabledTests != null && !config.enabledTests.contains(methodName)
&& !config.enabledTests.contains(className)) {
if (config.enabledTests != null && !(config.enabledTests.contains(methodName)
|| isInSet(testClass, config.enabledTests))) {
LOGGER.fine("Skipping test method " + methodName + " because it is not enabled");
it.remove();
continue;
@ -472,26 +471,33 @@ public class SmackIntegrationTestFramework {
NoSuchAlgorithmException {
XMPPTCPConnection conOne = null;
XMPPTCPConnection conTwo = null;
XMPPTCPConnection conThree = null;
try {
conOne = getConnectedConnectionFor(AccountNum.One);
conTwo = getConnectedConnectionFor(AccountNum.Two);
conThree = getConnectedConnectionFor(AccountNum.Three);
}
catch (Exception e) {
// TODO Reverse the order, i.e. conThree should be disconnected first.
if (conOne != null) {
conOne.disconnect();
}
if (conTwo != null) {
conTwo.disconnect();
}
if (conThree != null) {
conThree.disconnect();
}
throw e;
}
return new SmackIntegrationTestEnvironment(conOne, conTwo, testRunResult.testRunId, config);
return new SmackIntegrationTestEnvironment(conOne, conTwo, conThree, testRunResult.testRunId, config);
}
enum AccountNum {
One,
Two,
Three,
}
private static final String USERNAME_PREFIX = "smack-inttest";
@ -513,6 +519,11 @@ public class SmackIntegrationTestFramework {
accountPassword = config.accountTwoPassword;
middlefix = "two";
break;
case Three:
accountUsername = config.accountThreeUsername;
accountPassword = config.accountThreePassword;
middlefix = "three";
break;
default:
throw new IllegalStateException();
}
@ -584,6 +595,15 @@ public class SmackIntegrationTestFramework {
return (Exception) e;
}
private static boolean isInSet(Class<?> clz, Set<String> classes) {
if (classes == null) {
return false;
}
final String className = clz.getName();
final String unqualifiedClassName = clz.getSimpleName();
return (classes.contains(className) || classes.contains(unqualifiedClassName));
}
public static final class TestRunResult {
/**