AbstractServiceTest.java (1621B)
1 package eu.siacs.compliance.tests; 2 3 4 import eu.siacs.compliance.Result; 5 import rocks.xmpp.addr.Jid; 6 import rocks.xmpp.core.session.XmppClient; 7 import rocks.xmpp.extensions.disco.ServiceDiscoveryManager; 8 import rocks.xmpp.extensions.disco.model.items.Item; 9 import rocks.xmpp.extensions.disco.model.items.ItemNode; 10 import rocks.xmpp.util.concurrent.AsyncResult; 11 12 import java.util.ArrayList; 13 import java.util.List; 14 15 public abstract class AbstractServiceTest extends AbstractTest { 16 17 public AbstractServiceTest(XmppClient client) { 18 super(client); 19 } 20 21 @Override 22 public Result run() { 23 ServiceDiscoveryManager manager = client.getManager(ServiceDiscoveryManager.class); 24 25 //manually iterating over items. ignoring the faulty ones 26 AsyncResult<ItemNode> itemNode = manager.discoverItems(client.getDomain()); 27 try { 28 List<Jid> items = new ArrayList<>(); 29 itemNode.getResult().getItems().stream().map(Item::getJid).forEach(items::add); 30 items.add(client.getDomain()); 31 for(Jid jid : items) { 32 try { 33 for(String feature : manager.discoverInformation(jid).getResult().getFeatures()) { 34 if (getNamespace().equals(feature)) { 35 return Result.PASSED; 36 } 37 } 38 } catch (Exception e) { 39 //ignored 40 } 41 } 42 } catch (Exception e) { 43 return Result.FAILED; 44 } 45 return Result.FAILED; 46 } 47 48 public abstract String getNamespace(); 49 }