use of org.testng.xml.XmlSuite in project druid by druid-io.
the class TestNG method createCommandLineSuitesForClasses.
private List<XmlSuite> createCommandLineSuitesForClasses(Class[] classes) {
//
// See if any of the classes has an xmlSuite or xmlTest attribute.
// If it does, create the appropriate XmlSuite, otherwise, create
// the default one
//
XmlClass[] xmlClasses = Utils.classesToXmlClasses(classes);
Map<String, XmlSuite> suites = Maps.newHashMap();
IAnnotationFinder finder = m_configuration.getAnnotationFinder();
for (int i = 0; i < classes.length; i++) {
Class c = classes[i];
ITestAnnotation test = finder.findAnnotation(c, ITestAnnotation.class);
String suiteName = getDefaultSuiteName();
String testName = getDefaultTestName();
boolean isJUnit = false;
if (test != null) {
suiteName = defaultIfStringEmpty(test.getSuiteName(), suiteName);
testName = defaultIfStringEmpty(test.getTestName(), testName);
} else {
if (m_isMixed && JUnitTestFinder.isJUnitTest(c)) {
isJUnit = true;
testName = c.getName();
}
}
XmlSuite xmlSuite = suites.get(suiteName);
if (xmlSuite == null) {
xmlSuite = new XmlSuite();
xmlSuite.setName(suiteName);
suites.put(suiteName, xmlSuite);
}
if (m_dataProviderThreadCount != null) {
xmlSuite.setDataProviderThreadCount(m_dataProviderThreadCount);
}
XmlTest xmlTest = null;
for (XmlTest xt : xmlSuite.getTests()) {
if (xt.getName().equals(testName)) {
xmlTest = xt;
break;
}
}
if (xmlTest == null) {
xmlTest = new XmlTest(xmlSuite);
xmlTest.setName(testName);
xmlTest.setJUnit(isJUnit);
}
xmlTest.getXmlClasses().add(xmlClasses[i]);
}
return new ArrayList<XmlSuite>(suites.values());
}
use of org.testng.xml.XmlSuite in project druid by druid-io.
the class RemoteTestNG method run.
@Override
public void run() {
IMessageSender sender = m_serPort != null ? new SerializedMessageSender(m_host, m_serPort, m_ack) : new StringMessageSender(m_host, m_port);
final MessageHub msh = new MessageHub(sender);
msh.setDebug(isDebug());
try {
msh.connect();
// We couldn't do this until now in debug mode since the .xml file didn't exist yet.
// Now that we have connected with the Eclipse client, we know that it created the .xml
// file so we can proceed with the initialization
initializeSuitesAndJarFile();
List<XmlSuite> suites = Lists.newArrayList();
calculateAllSuites(m_suites, suites);
// + " and:" + suites.get(0).getChildSuites().size());
if (suites.size() > 0) {
int testCount = 0;
for (int i = 0; i < suites.size(); i++) {
testCount += (suites.get(i)).getTests().size();
}
GenericMessage gm = new GenericMessage(MessageHelper.GENERIC_SUITE_COUNT);
gm.setSuiteCount(suites.size());
gm.setTestCount(testCount);
msh.sendMessage(gm);
addListener(new RemoteSuiteListener(msh));
setTestRunnerFactory(new DelegatingTestRunnerFactory(buildTestRunnerFactory(), msh));
// System.out.println("RemoteTestNG starting");
super.run();
} else {
System.err.println("No test suite found. Nothing to run");
}
} catch (Throwable cause) {
cause.printStackTrace(System.err);
} finally {
// System.out.println("RemoteTestNG finishing: " + (getEnd() - getStart()) + " ms");
msh.shutDown();
if (!m_debug && !m_dontExit) {
System.exit(0);
}
}
}
use of org.testng.xml.XmlSuite in project druid by druid-io.
the class TestNG method createCommandLineSuitesForMethods.
/**
* @param commandLineMethods a string with the form "com.example.Foo.f1,com.example.Bar.f2"
*
* @return a list of XmlSuite objects that represent the list of classes and methods passed
* in parameter.
*/
private List<XmlSuite> createCommandLineSuitesForMethods(List<String> commandLineMethods) {
//
// Create the <classes> tag
//
Set<Class> classes = Sets.newHashSet();
for (String m : commandLineMethods) {
Class c = ClassHelper.forName(splitMethod(m)[0]);
if (c != null) {
classes.add(c);
}
}
List<XmlSuite> result = createCommandLineSuitesForClasses(classes.toArray(new Class[0]));
//
// Add the method tags
//
List<XmlClass> xmlClasses = Lists.newArrayList();
for (XmlSuite s : result) {
for (XmlTest t : s.getTests()) {
xmlClasses.addAll(t.getClasses());
}
}
for (XmlClass xc : xmlClasses) {
for (String m : commandLineMethods) {
String[] split = splitMethod(m);
String className = split[0];
if (xc.getName().equals(className)) {
XmlInclude includedMethod = new XmlInclude(split[1]);
xc.getIncludedMethods().add(includedMethod);
}
}
}
return result;
}
use of org.testng.xml.XmlSuite in project druid by druid-io.
the class TestNG method extractTestNames.
/**
* If the XmlSuite contains at least one test named as testNames, return
* an XmlSuite that's made only of these tests, otherwise, return the
* original suite.
*/
private static XmlSuite extractTestNames(XmlSuite s, List<String> testNames) {
List<XmlTest> tests = Lists.newArrayList();
for (XmlTest xt : s.getTests()) {
for (String tn : testNames) {
if (xt.getName().equals(tn)) {
tests.add(xt);
}
}
}
if (tests.size() == 0) {
return s;
} else {
XmlSuite result = (XmlSuite) s.clone();
result.getTests().clear();
result.getTests().addAll(tests);
return result;
}
}
use of org.testng.xml.XmlSuite in project druid by druid-io.
the class TestNG method initializeCommandLineSuitesGroups.
private void initializeCommandLineSuitesGroups() {
// If groups were specified on the command line, they should override groups
// specified in the XML file
boolean hasIncludedGroups = null != m_includedGroups && m_includedGroups.length > 0;
boolean hasExcludedGroups = null != m_excludedGroups && m_excludedGroups.length > 0;
List<XmlSuite> suites = m_cmdlineSuites != null ? m_cmdlineSuites : m_suites;
if (hasIncludedGroups || hasExcludedGroups) {
for (XmlSuite s : suites) {
//set on each test, instead of just the first one of the suite
for (XmlTest t : s.getTests()) {
if (hasIncludedGroups) {
t.setIncludedGroups(Arrays.asList(m_includedGroups));
}
if (hasExcludedGroups) {
t.setExcludedGroups(Arrays.asList(m_excludedGroups));
}
}
}
}
}
Aggregations