AbstractDiscoTest.java (1283B)
1 package eu.siacs.compliance.tests; 2 3 import eu.siacs.compliance.Result; 4 import eu.siacs.utils.TestUtils; 5 import rocks.xmpp.addr.Jid; 6 import rocks.xmpp.core.XmppException; 7 import rocks.xmpp.core.session.XmppClient; 8 import rocks.xmpp.extensions.disco.ServiceDiscoveryManager; 9 import rocks.xmpp.util.concurrent.AsyncResult; 10 11 import java.util.List; 12 import java.util.Set; 13 import java.util.concurrent.TimeUnit; 14 15 public abstract class AbstractDiscoTest extends AbstractTest { 16 17 public AbstractDiscoTest(XmppClient client) { 18 super(client); 19 } 20 21 //test will succeed if any namespace matches 22 abstract List<String> getNamespaces(); 23 24 abstract boolean checkOnServer(); 25 26 @Override 27 public Result run() { 28 Jid target = checkOnServer() ? Jid.of(client.getConnectedResource().getDomain()) : client.getConnectedResource().asBareJid(); 29 final ServiceDiscoveryManager serviceDiscoveryManager = client.getManager(ServiceDiscoveryManager.class); 30 try { 31 Set<String> features = serviceDiscoveryManager.discoverInformation(target).getResult().getFeatures(); 32 return TestUtils.hasAnyone(getNamespaces(),features) ? Result.PASSED : Result.FAILED; 33 } catch (XmppException e) { 34 return Result.FAILED; 35 } 36 } 37 }