*/
@LocalData
public void testOpenJUnitPublishing() throws IOException, SAXException {
List<Project> projects = this.hudson.getProjects();
// Make sure there's a project named TEST_PROJECT_WITH_HISTORY
Project proj = null;
for (Project p : projects) {
if (p.getName().equals(TEST_PROJECT_WITH_HISTORY)) proj = p;
}
assertNotNull("We should have a project named " + TEST_PROJECT_WITH_HISTORY, proj);
// Validate that there are test results where I expect them to be:
HudsonTestCase.WebClient wc = new HudsonTestCase.WebClient();
// On the project page:
HtmlPage projectPage = wc.getPage(proj);
// we should have a link that reads "Latest Test Result"
// that link should go to http://localhost:8080/job/breakable/lastBuild/testReport/
assertXPath(projectPage, "//a[@href='lastCompletedBuild/testReport/']");
assertXPathValue(projectPage, "//a[@href='lastCompletedBuild/testReport/']", "Latest Test Result");
assertXPathValueContains(projectPage, "//a[@href='lastCompletedBuild/testReport/']", "Latest Test Result");
// after "Latest Test Result" it should say "no failures"
assertXPathResultsContainText(projectPage, "//td", "(no failures)");
// there should be a test result trend graph
assertXPath(projectPage, "//img[@src='test/trend']");
// the trend graph should be served up with a good http status
Page trendGraphPage = wc.goTo(proj.getUrl() + "/test/trend", "image/png");
assertGoodStatus(trendGraphPage);
// The trend graph should be clickable and take us to a run details page
Object imageNode = projectPage.getFirstByXPath("//img[@src='test/trend']");
assertNotNull("couldn't find any matching nodes", imageNode);
assertTrue("image node should be an HtmlImage object", imageNode instanceof HtmlImage);
// TODO: Check that we can click on the graph and get to a particular run. How do I do this with HtmlUnit?
XmlPage xmlProjectPage = wc.goToXml(proj.getUrl() + "/lastBuild/testReport/api/xml");
assertXPath(xmlProjectPage, "/testResult");
assertXPath(xmlProjectPage, "/testResult/suite");
assertXPath(xmlProjectPage, "/testResult/failCount");
assertXPathValue(xmlProjectPage, "/testResult/failCount", "0");
assertXPathValue(xmlProjectPage, "/testResult/passCount", "4");
assertXPathValue(xmlProjectPage, "/testResult/skipCount", "0");
String[] packages = {"org.jvnet.hudson.examples.small.AppTest", "org.jvnet.hudson.examples.small.MiscTest", "org.jvnet.hudson.examples.small.deep.DeepTest"};
for (String packageName : packages) {
assertXPath(xmlProjectPage, "/testResult/suite/case/className[text()='" + packageName + "']");
}
// Go to a page that we know has a failure
HtmlPage buildPage = wc.getPage(proj.getBuildByNumber(3));
assertGoodStatus(buildPage);
// We expect to see one failure, for com.yahoo.breakable.misc.UglyTest.becomeUglier
// which should link to http://localhost:8080/job/wonky/3/testReport/org.jvnet.hudson.examples.small/MiscTest/testEleanor/
assertXPathResultsContainText(buildPage, "//a", "org.jvnet.hudson.examples.small.MiscTest.testEleanor");
HtmlAnchor failingTestLink = buildPage.getFirstAnchorByText("org.jvnet.hudson.examples.small.MiscTest.testEleanor");
assertNotNull(failingTestLink);
Page failingTestPage = failingTestLink.click();
assertGoodStatus(failingTestPage);
// Go to the xml page for a build we know has failures
XmlPage xmlBuildPage = wc.goToXml(proj.getBuildByNumber(3).getUrl() + "/api/xml");
assertXPathValue(xmlBuildPage, "//failCount", "2");
assertXPathValue(xmlBuildPage, "//skipCount", "0");
assertXPathValue(xmlBuildPage, "//totalCount", "4");
assertXPathValue(xmlBuildPage, "//result", "FAILURE");
// Check overall test result counts
XmlPage xmlTestReportPage = wc.goToXml(proj.getBuildByNumber(3).getUrl() + "/testReport/api/xml");
assertXPathValue(xmlTestReportPage, "/testResult/failCount", "2");
assertXPathValue(xmlTestReportPage, "/testResult/passCount", "2");
assertXPathValue(xmlTestReportPage, "/testResult/skipCount", "0");
// Make sure the right tests passed and failed
assertXPathValue(xmlTestReportPage, "/testResult/suite/case[className/text()='org.jvnet.hudson.examples.small.AppTest']/status", "PASSED");
assertXPathValue(xmlTestReportPage, "/testResult/suite/case[name/text()='testEleanor']/status", "FAILED");
// TODO: implement more of these tests
// On the lastBuild/testReport page:
// Breadcrumbs should read #6 > Test Result where Test Result is a link to this page
// inside of div id="main-panel" we should find the text "0 failures (-1)"
// we should have a blue bar which is blue all the way across: div style="width: 100%; height: 1em; background-color: rgb(114, 159, 207);
// we should find the words "7 tests (?0)"
// we should find the words "All Tests"
// we should find a table
// Inside that table, there should be the following rows:
// org.jvnet.hudson.examples.small 0ms 0 -1 0 3
// org.jvnet.hudson.examples.small.deep 4ms 0 0 0 1
Run theRun = proj.getBuildByNumber(7);
assertTestResultsAsExpected(wc, theRun, "/testReport",
"org.jvnet.hudson.examples.small", "0 ms", "SUCCESS",
/* total tests expected, diff */ 3, 0,
/* fail count expected, diff */ 0, -1,
/* skip count expected, diff */ 0, 0);