xmpp-compliance-tester

XMPP Compliance Tester, forked from github.com/iNPUTmice/ComplianceTester
git clone https://git.in0rdr.ch/xmpp-compliance-tester.git
Log | Files | Refs | Pull requests |Archive | README | LICENSE

commit 959b72ad103c5ad4b4ba24cc65dc4731fcfe05fd
parent 10f4472f138d3852fe171112ba570efc12d7de56
Author: Daniel Gultsch <daniel@gultsch.de>
Date:   Wed, 23 Aug 2017 17:58:38 +0200

fixed disco features checker for multiple namespaces

Diffstat:
Msrc/main/java/eu/siacs/compliance/tests/AbstractDiscoTest.java | 19++++++++++---------
Msrc/main/java/eu/siacs/compliance/tests/MAM.java | 5++++-
Msrc/main/java/eu/siacs/compliance/tests/MamMuc.java | 5+++--
Asrc/main/java/eu/siacs/utils/TestUtils.java | 16++++++++++++++++
4 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/src/main/java/eu/siacs/compliance/tests/AbstractDiscoTest.java b/src/main/java/eu/siacs/compliance/tests/AbstractDiscoTest.java @@ -1,11 +1,15 @@ package eu.siacs.compliance.tests; import eu.siacs.compliance.Result; +import eu.siacs.utils.TestUtils; import rocks.xmpp.addr.Jid; +import rocks.xmpp.core.XmppException; import rocks.xmpp.core.session.XmppClient; +import rocks.xmpp.extensions.disco.ServiceDiscoveryManager; import rocks.xmpp.util.concurrent.AsyncResult; import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; public abstract class AbstractDiscoTest extends AbstractTest { @@ -22,15 +26,12 @@ public abstract class AbstractDiscoTest extends AbstractTest { @Override public Result run() { Jid target = checkOnServer() ? Jid.of(client.getConnectedResource().getDomain()) : client.getConnectedResource().asBareJid(); - for(String namespace : getNamespaces()) { - AsyncResult<Boolean> result = client.isSupported(namespace, target); - try { - Boolean hasCarbons = result.getResult(10, TimeUnit.SECONDS); - return hasCarbons ? Result.PASSED : Result.FAILED; - } catch (Exception e) { - //ignore and go to next namespace - } + final ServiceDiscoveryManager serviceDiscoveryManager = client.getManager(ServiceDiscoveryManager.class); + try { + Set<String> features = serviceDiscoveryManager.discoverInformation(target).getResult().getFeatures(); + return TestUtils.hasAnyone(getNamespaces(),features) ? Result.PASSED : Result.FAILED; + } catch (XmppException e) { + return Result.FAILED; } - return Result.FAILED; } } diff --git a/src/main/java/eu/siacs/compliance/tests/MAM.java b/src/main/java/eu/siacs/compliance/tests/MAM.java @@ -3,17 +3,20 @@ package eu.siacs.compliance.tests; import rocks.xmpp.core.session.XmppClient; import java.util.Arrays; +import java.util.Collection; import java.util.List; public class MAM extends AbstractDiscoTest { + public static final List<String> NAMESPACES = Arrays.asList("urn:xmpp:mam:0","urn:xmpp:mam:1","urn:xmpp:mam:2"); + public MAM(XmppClient client) { super(client); } @Override List<String> getNamespaces() { - return Arrays.asList("urn:xmpp:mam:0","urn:xmpp:mam:1","urn:xmpp:mam:2"); + return NAMESPACES; } @Override diff --git a/src/main/java/eu/siacs/compliance/tests/MamMuc.java b/src/main/java/eu/siacs/compliance/tests/MamMuc.java @@ -1,6 +1,7 @@ package eu.siacs.compliance.tests; import eu.siacs.compliance.Result; +import eu.siacs.utils.TestUtils; import rocks.xmpp.core.XmppException; import rocks.xmpp.core.session.XmppClient; import rocks.xmpp.extensions.disco.ServiceDiscoveryManager; @@ -29,8 +30,8 @@ public class MamMuc extends AbstractTest { ChatService chatService = chatServices.get(0); ChatRoom room = chatService.createRoom(UUID.randomUUID().toString()); room.enter("test"); - final Set<String> f = serviceDiscoveryManager.discoverInformation(room.getAddress()).getResult().getFeatures(); - final boolean mam = f.contains("urn:xmpp:mam:0") || f.contains("urn:xmpp:mam:1") || f.contains("urn:xmpp:mam:2"); + final Set<String> features = serviceDiscoveryManager.discoverInformation(room.getAddress()).getResult().getFeatures(); + final boolean mam = TestUtils.hasAnyone(MAM.NAMESPACES,features); room.destroy().getResult(); return mam ? Result.PASSED : Result.FAILED; } catch (XmppException e) { diff --git a/src/main/java/eu/siacs/utils/TestUtils.java b/src/main/java/eu/siacs/utils/TestUtils.java @@ -0,0 +1,16 @@ +package eu.siacs.utils; + +import java.util.List; +import java.util.Set; + +public class TestUtils { + + public static boolean hasAnyone(List<String> needles, Set<String> haystack) { + for(String needle : needles) { + if (haystack.contains(needle)) { + return true; + } + } + return false; + } +}