}
// get the tests to run
JunitSuiteWrapper jsWrapper = new JunitSuiteWrapper(component, suiteName, testCase);
if (jsWrapper.getAllTestList().size() == 0) {
throw new ContainerException("No tests found (" + component + " / " + suiteName + " / " + testCase + ")");
}
boolean failedRun = false;
for (ModelTestSuite modelSuite: jsWrapper.getModelTestSuites()) {
Delegator testDelegator = modelSuite.getDelegator();
TestSuite suite = modelSuite.makeTestSuite();
JUnitTest test = new JUnitTest();
test.setName(suite.getName());
// create the XML logger
JunitXmlListener xml;
try {
xml = new JunitXmlListener(new FileOutputStream(logDir + suite.getName() + ".xml"));
} catch (FileNotFoundException e) {
throw new ContainerException(e);
}
// per-suite results
TestResult results = new TestResult();
results.addListener(new JunitListener());
results.addListener(xml);
// add the suite to the xml listener
xml.startTestSuite(test);
// run the tests
suite.run(results);
test.setCounts(results.runCount(), results.failureCount(), results.errorCount());
// rollback all entity operations performed by the delegator
testDelegator.rollback();
xml.endTestSuite(test);
if (!results.wasSuccessful()) {
failedRun = true;
}
// display the results
Debug.logInfo("[JUNIT] Results for test suite: " + suite.getName(), module);
Debug.logInfo("[JUNIT] Pass: " + results.wasSuccessful() + " | # Tests: " + results.runCount() + " | # Failed: " +
results.failureCount() + " # Errors: " + results.errorCount(), module);
if (Debug.importantOn()) {
Debug.logInfo("[JUNIT] ----------------------------- ERRORS ----------------------------- [JUNIT]", module);
Enumeration<?> err = results.errors();
if (!err.hasMoreElements()) {
Debug.logInfo("None", module);
} else {
while (err.hasMoreElements()) {
Object error = err.nextElement();
Debug.logInfo("--> " + error, module);
if (error instanceof TestFailure) {
Debug.logInfo(((TestFailure) error).trace(), module);
}
}
}
Debug.logInfo("[JUNIT] ------------------------------------------------------------------ [JUNIT]", module);
Debug.logInfo("[JUNIT] ---------------------------- FAILURES ---------------------------- [JUNIT]", module);
Enumeration<?> fail = results.failures();
if (!fail.hasMoreElements()) {
Debug.logInfo("None", module);
} else {
while (fail.hasMoreElements()) {
Object failure = fail.nextElement();
Debug.logInfo("--> " + failure, module);
if (failure instanceof TestFailure) {
Debug.logInfo(((TestFailure) failure).trace(), module);
}
}
}
Debug.logInfo("[JUNIT] ------------------------------------------------------------------ [JUNIT]", module);
}
}
if (failedRun) {
throw new ContainerException("Test run was unsuccessful");
}
return true;
}