* Verifies that artifacts from the last successful and stable builds of a job will be kept if requested.
*/
public class ArtifactArchiverTest extends HudsonTestCase {
public void testSuccessVsFailure() throws Exception {
FreeStyleProject project = createFreeStyleProject();
project.getPublishersList().replaceBy(Collections.singleton(new ArtifactArchiver("f", "", true)));
assertEquals("(no artifacts)", Result.FAILURE, build(project)); // #1
assertFalse(project.getBuildByNumber(1).getHasArtifacts());
project.getBuildersList().replaceBy(Collections.singleton(new CreateArtifact()));
assertEquals(Result.SUCCESS, build(project)); // #2
assertTrue(project.getBuildByNumber(2).getHasArtifacts());
project.getBuildersList().replaceBy(Arrays.asList(new CreateArtifact(), new FailureBuilder()));
assertEquals(Result.FAILURE, build(project)); // #3
assertTrue(project.getBuildByNumber(2).getHasArtifacts());
assertTrue(project.getBuildByNumber(3).getHasArtifacts());
assertEquals(Result.FAILURE, build(project)); // #4
assertTrue(project.getBuildByNumber(2).getHasArtifacts());
assertTrue(project.getBuildByNumber(3).getHasArtifacts());
assertTrue(project.getBuildByNumber(4).getHasArtifacts());
assertEquals(Result.FAILURE, build(project)); // #5
assertTrue(project.getBuildByNumber(2).getHasArtifacts());
assertFalse("no better than #4", project.getBuildByNumber(3).getHasArtifacts());
assertTrue(project.getBuildByNumber(4).getHasArtifacts());
assertTrue(project.getBuildByNumber(5).getHasArtifacts());
project.getBuildersList().replaceBy(Collections.singleton(new CreateArtifact()));
assertEquals(Result.SUCCESS, build(project)); // #6
assertTrue("#2 is still lastSuccessful until #6 is complete", project.getBuildByNumber(2).getHasArtifacts());
assertFalse(project.getBuildByNumber(3).getHasArtifacts());
assertFalse(project.getBuildByNumber(4).getHasArtifacts());
assertTrue(project.getBuildByNumber(5).getHasArtifacts());
assertTrue(project.getBuildByNumber(6).getHasArtifacts());
assertEquals(Result.SUCCESS, build(project)); // #7
assertFalse("lastSuccessful was #6 for ArtifactArchiver", project.getBuildByNumber(2).getHasArtifacts());
assertFalse(project.getBuildByNumber(3).getHasArtifacts());
assertFalse(project.getBuildByNumber(4).getHasArtifacts());
assertFalse(project.getBuildByNumber(5).getHasArtifacts());
assertTrue(project.getBuildByNumber(6).getHasArtifacts());
assertTrue(project.getBuildByNumber(7).getHasArtifacts());
}