|
| 1 | +package hudson.views; |
| 2 | + |
| 3 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 4 | +import static org.hamcrest.Matchers.containsString; |
| 5 | +import static org.hamcrest.Matchers.not; |
| 6 | + |
| 7 | +import hudson.model.FreeStyleBuild; |
| 8 | +import hudson.model.FreeStyleProject; |
| 9 | +import hudson.model.ListView; |
| 10 | +import hudson.model.Result; |
| 11 | +import org.htmlunit.html.HtmlPage; |
| 12 | +import org.jvnet.hudson.test.FailureBuilder; |
| 13 | +import org.jvnet.hudson.test.JenkinsRule; |
| 14 | +import org.jvnet.hudson.test.SleepBuilder; |
| 15 | + |
| 16 | +public class LastDurationColumnTest { |
| 17 | + |
| 18 | + @org.junit.Rule |
| 19 | + public JenkinsRule j = new JenkinsRule(); |
| 20 | + |
| 21 | + @org.junit.Test |
| 22 | + public void showsDurationOfLastCompletedBuildEvenIfFailed() throws Exception { |
| 23 | + |
| 24 | + FreeStyleProject p = j.createFreeStyleProject("test-job"); |
| 25 | + |
| 26 | + p.getBuildersList().add(new SleepBuilder(700)); |
| 27 | + FreeStyleBuild oldSuccess = j.buildAndAssertSuccess(p); |
| 28 | + |
| 29 | + p.getBuildersList().clear(); |
| 30 | + p.getBuildersList().add(new FailureBuilder()); |
| 31 | + FreeStyleBuild newFailure = p.scheduleBuild2(0).get(); |
| 32 | + j.assertBuildStatus(Result.FAILURE, newFailure); |
| 33 | + |
| 34 | + String oldDuration = oldSuccess.getDurationString(); |
| 35 | + String newDuration = newFailure.getDurationString(); |
| 36 | + |
| 37 | + ListView view = new ListView("TestView", j.jenkins); |
| 38 | + view.add(p); |
| 39 | + view.getColumns().clear(); |
| 40 | + view.getColumns().add(new StatusColumn()); |
| 41 | + view.getColumns().add(new JobColumn()); |
| 42 | + view.getColumns().add(new LastDurationColumn()); |
| 43 | + j.jenkins.addView(view); |
| 44 | + |
| 45 | + HtmlPage page = j.createWebClient().getPage(view); |
| 46 | + String pageText = page.asNormalizedText(); |
| 47 | + |
| 48 | + assertThat("Page should show the duration of the latest build (failure)", pageText, containsString(newDuration)); |
| 49 | + |
| 50 | + if (!oldDuration.equals(newDuration)) { |
| 51 | + assertThat("Page should NOT show the duration of the old successful build", pageText, not(containsString(oldDuration))); |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments