Search in sources :

Example 6 with XmlSuite

use of org.testng.xml.XmlSuite in project druid by druid-io.

the class TestNG method checkSuiteNamesInternal.

private void checkSuiteNamesInternal(List<XmlSuite> suites, Set<String> names) {
    for (XmlSuite suite : suites) {
        final String name = suite.getName();
        if (names.contains(name)) {
            throw new TestNGException("Two suites cannot have the same name: " + name);
        }
        names.add(name);
        checkSuiteNamesInternal(suite.getChildSuites(), names);
    }
}
Also used : XmlSuite(org.testng.xml.XmlSuite)

Example 7 with XmlSuite

use of org.testng.xml.XmlSuite in project druid by druid-io.

the class TestNG method checkTestNames.

/**
   * Ensure that two XmlTest within the same XmlSuite don't have the same name
   */
private void checkTestNames(List<XmlSuite> suites) {
    for (XmlSuite suite : suites) {
        Set<String> testNames = Sets.newHashSet();
        for (XmlTest test : suite.getTests()) {
            if (testNames.contains(test.getName())) {
                throw new TestNGException("Two tests in the same suite " + "cannot have the same name: " + test.getName());
            } else {
                testNames.add(test.getName());
            }
        }
        checkTestNames(suite.getChildSuites());
    }
}
Also used : XmlSuite(org.testng.xml.XmlSuite) XmlTest(org.testng.xml.XmlTest)

Example 8 with XmlSuite

use of org.testng.xml.XmlSuite in project intellij-community by JetBrains.

the class IDEARemoteTestNG method run.

public void run() {
    try {
        initializeSuitesAndJarFile();
        List<XmlSuite> suites = Lists.newArrayList();
        calculateAllSuites(m_suites, suites);
        if (suites.size() > 0) {
            for (XmlSuite suite : suites) {
                final List<XmlTest> tests = suite.getTests();
                for (XmlTest test : tests) {
                    try {
                        if (myParam != null) {
                            for (XmlClass aClass : test.getXmlClasses()) {
                                List<XmlInclude> includes = new ArrayList<XmlInclude>();
                                for (XmlInclude include : aClass.getIncludedMethods()) {
                                    includes.add(new XmlInclude(include.getName(), Collections.singletonList(Integer.parseInt(myParam)), 0));
                                }
                                aClass.setIncludedMethods(includes);
                            }
                        }
                    } catch (NumberFormatException e) {
                        System.err.println("Invocation number: expected integer but found: " + myParam);
                    }
                }
            }
            attachListeners(new IDEATestNGRemoteListener());
            super.run();
            System.exit(0);
        } else {
            System.out.println("##teamcity[enteredTheMatrix]");
            System.err.println("Nothing found to run");
        }
    } catch (Throwable cause) {
        cause.printStackTrace(System.err);
    }
}
Also used : XmlInclude(org.testng.xml.XmlInclude) XmlSuite(org.testng.xml.XmlSuite) XmlTest(org.testng.xml.XmlTest) ArrayList(java.util.ArrayList) XmlClass(org.testng.xml.XmlClass)

Example 9 with XmlSuite

use of org.testng.xml.XmlSuite in project intellij-community by JetBrains.

the class IDEARemoteTestNG method calculateAllSuites.

private static void calculateAllSuites(List<XmlSuite> suites, List<XmlSuite> outSuites) {
    for (XmlSuite s : suites) {
        outSuites.add(s);
        calculateAllSuites(s.getChildSuites(), outSuites);
    }
}
Also used : XmlSuite(org.testng.xml.XmlSuite)

Example 10 with XmlSuite

use of org.testng.xml.XmlSuite in project intellij-community by JetBrains.

the class TestNGXmlSuiteHelper method writeSuite.

public static File writeSuite(Map<String, Map<String, List<String>>> map, Map<String, String> testParams, String name, String rootPath, Logger logger) {
    File xmlFile;
    final XmlSuite xmlSuite = new XmlSuite();
    xmlSuite.setParameters(testParams);
    XmlTest xmlTest = new XmlTest(xmlSuite);
    xmlTest.setName(name);
    List<XmlClass> xmlClasses = new ArrayList<XmlClass>();
    int idx = 0;
    for (String className : map.keySet()) {
        final XmlClass xmlClass = new XmlClass(className, idx++, false);
        final Map<String, List<String>> collection = map.get(className);
        if (collection != null) {
            final ArrayList<XmlInclude> includedMethods = new ArrayList<XmlInclude>();
            int mIdx = 0;
            for (String methodName : collection.keySet()) {
                final List<Integer> includes = new ArrayList<Integer>();
                for (String include : collection.get(methodName)) {
                    try {
                        includes.add(Integer.parseInt(include));
                    } catch (NumberFormatException e) {
                        logger.log(e);
                    }
                }
                includedMethods.add(new XmlInclude(methodName, includes, mIdx++));
            }
            xmlClass.setIncludedMethods(includedMethods);
        }
        xmlClasses.add(xmlClass);
    }
    xmlTest.setXmlClasses(xmlClasses);
    xmlFile = new File(rootPath, "temp-testng-customsuite.xml");
    final String toXml = xmlSuite.toXml();
    writeToFile(logger, xmlFile, toXml);
    return xmlFile;
}
Also used : XmlSuite(org.testng.xml.XmlSuite) ArrayList(java.util.ArrayList) XmlInclude(org.testng.xml.XmlInclude) XmlTest(org.testng.xml.XmlTest) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) XmlClass(org.testng.xml.XmlClass)

Aggregations

XmlSuite (org.testng.xml.XmlSuite)22 XmlTest (org.testng.xml.XmlTest)12 XmlClass (org.testng.xml.XmlClass)8 XmlInclude (org.testng.xml.XmlInclude)5 ArrayList (java.util.ArrayList)3 File (java.io.File)2 Test (org.junit.Test)2 SuiteRunnerMap (org.testng.internal.SuiteRunnerMap)2 Parser (org.testng.xml.Parser)2 XmlMethodSelector (org.testng.xml.XmlMethodSelector)2 ParameterException (com.beust.jcommander.ParameterException)1 CantRunException (com.intellij.execution.CantRunException)1 ExecutionException (com.intellij.execution.ExecutionException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 Map (java.util.Map)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1