Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Included support for the promoted builds plugin and job promotions, a…
…ddressing the open issue JENKINS-21472
- Loading branch information
Stephen
committed
Oct 13, 2014
1 parent
728bc25
commit c20130b
Showing
3 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/test/java/org/jvnet/hudson/plugins/thinbackup/backup/TestBackupPromotedJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.jvnet.hudson.plugins.thinbackup.backup; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import hudson.model.ItemGroup; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Calendar; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.plugins.thinbackup.TestHelper; | ||
import org.jvnet.hudson.plugins.thinbackup.ThinBackupPeriodicWork.BackupType; | ||
import org.jvnet.hudson.plugins.thinbackup.ThinBackupPluginImpl; | ||
import org.jvnet.hudson.plugins.thinbackup.utils.Utils; | ||
|
||
public class TestBackupPromotedJob { | ||
|
||
private File backupDir; | ||
private File jenkinsHome; | ||
|
||
@Before | ||
public void setup() throws IOException, InterruptedException { | ||
File base = new File(System.getProperty("java.io.tmpdir")); | ||
backupDir = TestHelper.createBackupFolder(base); | ||
|
||
jenkinsHome = TestHelper.createBasicFolderStructure(base); | ||
File jobDir = TestHelper.createJob(jenkinsHome, TestHelper.TEST_JOB_NAME); | ||
TestHelper.addNewBuildToJob(jobDir); | ||
|
||
TestHelper.addSinglePromotionResult(jobDir); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
FileUtils.deleteDirectory(jenkinsHome); | ||
FileUtils.deleteDirectory(backupDir); | ||
FileUtils.deleteDirectory(new File(Utils.THINBACKUP_TMP_DIR)); | ||
} | ||
|
||
private ThinBackupPluginImpl createMockPlugin() { | ||
final ThinBackupPluginImpl mockPlugin = mock(ThinBackupPluginImpl.class); | ||
|
||
when(mockPlugin.getHudsonHome()).thenReturn(jenkinsHome); | ||
when(mockPlugin.getFullBackupSchedule()).thenReturn(""); | ||
when(mockPlugin.getDiffBackupSchedule()).thenReturn(""); | ||
when(mockPlugin.getExpandedBackupPath()).thenReturn(backupDir.getAbsolutePath()); | ||
when(mockPlugin.getNrMaxStoredFull()).thenReturn(-1); | ||
when(mockPlugin.isCleanupDiff()).thenReturn(false); | ||
when(mockPlugin.isMoveOldBackupsToZipFile()).thenReturn(false); | ||
when(mockPlugin.isBackupBuildResults()).thenReturn(true); | ||
when(mockPlugin.isBackupBuildArchive()).thenReturn(false); | ||
when(mockPlugin.isBackupNextBuildNumber()).thenReturn(false); | ||
when(mockPlugin.getExcludedFilesRegex()).thenReturn(""); | ||
|
||
return mockPlugin; | ||
} | ||
|
||
@Test | ||
public void testFullBuildResultsBackup() throws IOException { | ||
final Calendar cal = Calendar.getInstance(); | ||
cal.set(Calendar.MINUTE, cal.get(Calendar.MINUTE - 10)); | ||
|
||
final ThinBackupPluginImpl mockPlugin = createMockPlugin(); | ||
|
||
new HudsonBackup(mockPlugin, BackupType.FULL, cal.getTime(), mock(ItemGroup.class)).backup(); | ||
|
||
String[] list = backupDir.list(); | ||
Assert.assertEquals(1, list.length); | ||
final File backup = new File(backupDir, list[0]); | ||
list = backup.list(); | ||
Assert.assertEquals(6, list.length); | ||
|
||
File jobBackup = new File(backup, "jobs/"+TestHelper.TEST_JOB_NAME); | ||
|
||
Assert.assertTrue(new File(jobBackup, HudsonBackup.PROMOTIONS_DIR_NAME).exists()); | ||
Assert.assertTrue(new File(jobBackup, HudsonBackup.PROMOTIONS_DIR_NAME+"/promotion-x").exists()); | ||
Assert.assertTrue(new File(jobBackup, HudsonBackup.PROMOTIONS_DIR_NAME+"/promotion-x/"+HudsonBackup.BUILDS_DIR_NAME+"/"+TestHelper.CONCRET_BUILD_DIRECTORY_NAME+"/build.xml").exists()); | ||
} | ||
|
||
} |