also testing the removal of build if LogRotator is configured to discard

old builds and not only artifacts (Not needed for the issue, but an
extra test is not a luxury )
This commit is contained in:
redlab committed 2013-04-18 08:58:30 +02:00
1 parent 2a0bd7eebd
commit ca7f4e682c
1 file changed
+14 -9
@@ -12,15 +12,10 @@ import hudson.tasks.Maven.MavenInstallation;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.PrefixFileFilter;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceWithChangesSCM;
import org.jvnet.hudson.test.HudsonTestCase;
@@ -31,7 +26,6 @@ import org.jvnet.hudson.test.HudsonTestCase;
* for jars in archive for build one and build two, expecting no jars in build 1
* and expecting jars in build 2
*
* @author redlab
*
*/
public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase {
@@ -55,7 +49,7 @@ public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase {
super.setUp();
configureDefaultMaven("apache-maven-2.2.1", MavenInstallation.MAVEN_21);
m = createMavenProject();
m.setBuildDiscarder(new LogRotator("-1", "-1", "-1", "1"));
m.setBuildDiscarder(new LogRotator("-1", "2", "-1", "1"));
m.getReporters().add(new TestReporter());
m.getReporters().add(new MavenFingerprinter());
m.setScm(new ExtractResourceWithChangesSCM(getClass().getResource(
@@ -66,15 +60,14 @@ public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase {
m.setIncrementalBuild(false);
buildAndAssertSuccess(m);
FilePath workspace = m.getWorkspace();
URI uri = workspace.toURI();
FilePath parent = workspace.getParent().getParent();
jobs = new FilePath(parent, "jobs");
}
@SuppressWarnings("unchecked")
public void testArtifactsAreDeletedInBuildOneWhenBuildDiscarderRun()
throws Exception {
File directory = new File(new FilePath(jobs, "test0/builds/1").toURI());
System.out.println(directory);
Collection<File> files = FileUtils.listFiles(directory,
new String[] { "jar" }, true);
Assert.assertTrue(
@@ -85,4 +78,16 @@ public class MavenMultiModuleLogRotatorCleanArtifacts extends HudsonTestCase {
Assert.assertFalse("No jars in last build ALERT!", files2.isEmpty());
}
/**
* Performs a third build and expecting build one to be deleted
* @throws Exception
*/
@SuppressWarnings("unchecked")
public void testArtifactsOldBuildsDeletedWhenBuildDiscarderRun()
throws Exception {
buildAndAssertSuccess(m);
File directory = new File(new FilePath(jobs, "test0/builds/1").toURI());
Assert.assertFalse("oops the build should have been deleted", directory.exists());
}
}