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

AbstractTestSuite.java (2788B)


      1 package eu.siacs.compliance.suites;
      2 
      3 import eu.siacs.compliance.tests.AbstractTest;
      4 import eu.siacs.compliance.Result;
      5 import eu.siacs.compliance.TestFactory;
      6 import rocks.xmpp.addr.Jid;
      7 import rocks.xmpp.core.XmppException;
      8 import rocks.xmpp.core.session.XmppClient;
      9 import rocks.xmpp.extensions.version.SoftwareVersionManager;
     10 import rocks.xmpp.extensions.version.model.SoftwareVersion;
     11 
     12 import java.util.Collections;
     13 import java.util.HashMap;
     14 import java.util.List;
     15 
     16 public abstract class AbstractTestSuite {
     17 
     18     private final XmppClient mXmppClient;
     19     private final Jid mJid;
     20     private final String mPassword;
     21 
     22     private HashMap<Class<?extends AbstractTest>,Result> mTestResults = new HashMap<>();
     23 
     24     public AbstractTestSuite(XmppClient client, Jid jid, String password) {
     25         mXmppClient = client;
     26         mJid = jid;
     27         mPassword = password;
     28     }
     29 
     30     public void run() throws XmppException {
     31         mXmppClient.connect();
     32         mXmppClient.login(mJid.getLocal(), mPassword, "ComplianceTester");
     33         preHook();
     34         for(Class<? extends AbstractTest> test : getTests()) {
     35             run(test);
     36         }
     37         postHook();
     38         mXmppClient.close();
     39         int passed = Collections.frequency(mTestResults.values(),Result.PASSED);
     40         System.out.println("passed "+passed+"/"+mTestResults.size());
     41     }
     42 
     43     public Result result() {
     44         return Collections.frequency(mTestResults.values(),Result.FAILED) == 0 ? Result.PASSED : Result.FAILED;
     45     }
     46 
     47     private void run(Class<? extends AbstractTest> clazz) {
     48         try {
     49             AbstractTest test = TestFactory.create(clazz,mXmppClient);
     50             System.out.print("running "+test.getName()+"…");
     51             Result result = test.run();
     52             System.out.println("\t\t"+result);
     53             mTestResults.put(clazz, test.run());
     54         } catch (TestFactory.TestCreationException e) {
     55            System.err.println("failed to create test for class "+clazz.toString());
     56             mTestResults.put(clazz, Result.FAILED);
     57         }
     58     }
     59 
     60     protected void preHook() {
     61 
     62     }
     63 
     64     protected void postHook() {
     65 
     66     }
     67 
     68     protected void printServerVersion() {
     69         final SoftwareVersionManager softwareVersionManager = mXmppClient.getManager(SoftwareVersionManager.class);
     70         try {
     71             SoftwareVersion softwareVersion = softwareVersionManager.getSoftwareVersion(mXmppClient.getDomain()).getResult();
     72             System.out.println("Server is "+softwareVersion.getName()+" "+softwareVersion.getVersion());
     73         } catch (XmppException e) {
     74             //ignored
     75         }
     76     }
     77 
     78     abstract List<Class<?extends AbstractTest>> getTests();
     79 
     80     public abstract String getName();
     81     
     82     public static class TestSuiteCreationException extends Exception {
     83 
     84     }
     85 }