use of org.testng.xml.Parser in project druid by druid-io.
the class TestNG method getParser.
private Parser getParser(String path) {
Parser result = new Parser(path);
initProcessor(result);
return result;
}
use of org.testng.xml.Parser in project druid by druid-io.
the class TestNG method initializeSuitesAndJarFile.
public void initializeSuitesAndJarFile() {
// so don't initialize suites twice.
if (m_isInitialized) {
return;
}
m_isInitialized = true;
if (m_suites.size() > 0) {
//to parse the suite files (<suite-file>), if any
for (XmlSuite s : m_suites) {
for (String suiteFile : s.getSuiteFiles()) {
try {
Collection<XmlSuite> childSuites = getParser(suiteFile).parse();
for (XmlSuite cSuite : childSuites) {
cSuite.setParentSuite(s);
s.getChildSuites().add(cSuite);
}
} catch (FileNotFoundException e) {
e.printStackTrace(System.out);
} catch (ParserConfigurationException e) {
e.printStackTrace(System.out);
} catch (SAXException e) {
e.printStackTrace(System.out);
} catch (IOException e) {
e.printStackTrace(System.out);
}
}
}
return;
}
//
for (String suitePath : m_stringSuites) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("suiteXmlPath: \"" + suitePath + "\"");
}
try {
Collection<XmlSuite> allSuites = getParser(suitePath).parse();
for (XmlSuite s : allSuites) {
// If test names were specified, only run these test names
if (m_testNames != null) {
m_suites.add(extractTestNames(s, m_testNames));
} else {
m_suites.add(s);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace(System.out);
} catch (IOException e) {
e.printStackTrace(System.out);
} catch (ParserConfigurationException e) {
e.printStackTrace(System.out);
} catch (SAXException e) {
e.printStackTrace(System.out);
} catch (Exception ex) {
// Probably a Yaml exception, unnest it
Throwable t = ex;
while (t.getCause() != null) {
t = t.getCause();
}
// t.printStackTrace();
if (t instanceof TestNGException) {
throw (TestNGException) t;
} else {
throw new TestNGException(t);
}
}
}
// inside that jar path
if (m_jarPath != null && m_stringSuites.size() > 0) {
StringBuilder suites = new StringBuilder();
for (String s : m_stringSuites) {
suites.append(s);
}
Utils.log("TestNG", 2, "Ignoring the XML file inside " + m_jarPath + " and using " + suites + " instead");
return;
}
if (isStringEmpty(m_jarPath)) {
return;
}
// We have a jar file and no XML file was specified: try to find an XML file inside the jar
File jarFile = new File(m_jarPath);
try {
Utils.log("TestNG", 2, "Trying to open jar file:" + jarFile);
JarFile jf = new JarFile(jarFile);
// System.out.println(" result: " + jf);
Enumeration<JarEntry> entries = jf.entries();
List<String> classes = Lists.newArrayList();
boolean foundTestngXml = false;
while (entries.hasMoreElements()) {
JarEntry je = entries.nextElement();
if (je.getName().equals(m_xmlPathInJar)) {
Parser parser = getParser(jf.getInputStream(je));
m_suites.addAll(parser.parse());
foundTestngXml = true;
break;
} else if (je.getName().endsWith(".class")) {
int n = je.getName().length() - ".class".length();
classes.add(je.getName().replace("/", ".").substring(0, n));
}
}
if (!foundTestngXml) {
Utils.log("TestNG", 1, "Couldn't find the " + m_xmlPathInJar + " in the jar file, running all the classes");
XmlSuite xmlSuite = new XmlSuite();
xmlSuite.setVerbose(0);
xmlSuite.setName("Jar suite");
XmlTest xmlTest = new XmlTest(xmlSuite);
List<XmlClass> xmlClasses = Lists.newArrayList();
for (String cls : classes) {
XmlClass xmlClass = new XmlClass(cls);
xmlClasses.add(xmlClass);
}
xmlTest.setXmlClasses(xmlClasses);
m_suites.add(xmlSuite);
}
} catch (ParserConfigurationException ex) {
ex.printStackTrace();
} catch (SAXException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
use of org.testng.xml.Parser in project druid by druid-io.
the class TestNG method getParser.
private Parser getParser(InputStream is) {
Parser result = new Parser(is);
initProcessor(result);
return result;
}
use of org.testng.xml.Parser in project intellij-community by JetBrains.
the class SearchingForTestsTask method composeTestSuiteFromXml.
private void composeTestSuiteFromXml() throws CantRunException {
final Map<String, String> buildTestParams = buildTestParameters();
try {
if (buildTestParams.isEmpty()) {
String path = new File(myData.getSuiteName()).getAbsolutePath() + "\n";
FileUtil.writeToFile(myTempFile, path.getBytes(CharsetToolkit.UTF8_CHARSET), true);
return;
}
final Parser parser = new Parser(myData.getSuiteName());
parser.setLoadClasses(false);
final Collection<XmlSuite> suites = parser.parse();
for (XmlSuite suite : suites) {
Map<String, String> params = suite.getParameters();
params.putAll(buildTestParams);
final String fileId = FileUtil.sanitizeFileName(myProject.getName() + '_' + suite.getName() + '_' + Integer.toHexString(suite.getName().hashCode()) + ".xml");
final File suiteFile = new File(PathManager.getSystemPath(), fileId);
FileWriter fileWriter = new FileWriter(suiteFile);
try {
fileWriter.write(suite.toXml());
} finally {
fileWriter.close();
}
String path = suiteFile.getAbsolutePath() + "\n";
FileUtil.writeToFile(myTempFile, path.getBytes(CharsetToolkit.UTF8_CHARSET), true);
}
} catch (Exception e) {
throw new CantRunException("Unable to parse suite: " + e.getMessage());
}
}
use of org.testng.xml.Parser in project intellij-community by JetBrains.
the class TestNGTestSuite method checkConfiguration.
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
final TestData data = myConfig.getPersistantData();
try {
final Parser parser = new Parser(data.getSuiteName());
parser.setLoadClasses(false);
synchronized (PARSE_LOCK) {
//try to parse suite.xml
parser.parse();
}
} catch (Exception e) {
throw new RuntimeConfigurationException("Unable to parse '" + data.getSuiteName() + "' specified");
}
}
Aggregations