Skip to content

Commit

Permalink
o JENKINS-11678: finished backing up the change log history plugin's …
Browse files Browse the repository at this point in the history
…files, added unit tests for that.

git-svn-id: https://svn.jenkins-ci.org/trunk/hudson/plugins/thinBackup@40139 71c3de6d-444a-0410-be80-ed276b4c234a
  • Loading branch information
msteinkogler committed Nov 22, 2011
1 parent 4fc8564 commit 58bcf08
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
Expand Up @@ -54,6 +54,7 @@ public class HudsonBackup {
public static final String XML_FILE_EXTENSION = ".xml";
public static final String ZIP_FILE_EXTENSION = ".zip";
public static final String INSTALLED_PLUGINS_XML = "installedPlugins" + XML_FILE_EXTENSION;
public static final String CHANGELOG_HISTORY_PLUGIN_DIR_NAME = "changelog-history";

private final ThinBackupPluginImpl plugin;
private final File hudsonHome;
Expand Down Expand Up @@ -221,7 +222,7 @@ private void backupBuildsFor(final File jobDirectory, final File jobBackupDirect

private void backupBuildFiles(final File srcDir, final File destDir) throws IOException {
final IOFileFilter changelogFilter = FileFilterUtils.andFileFilter(DirectoryFileFilter.DIRECTORY,
FileFilterUtils.nameFileFilter("changelog-history"));
FileFilterUtils.nameFileFilter(CHANGELOG_HISTORY_PLUGIN_DIR_NAME));
final IOFileFilter fileFilter = FileFilterUtils.andFileFilter(FileFileFilter.FILE, getFileAgeDiffFilter());

IOFileFilter filter = FileFilterUtils.orFileFilter(changelogFilter, fileFilter);
Expand Down
Expand Up @@ -62,6 +62,10 @@ public void setup() throws Exception {
builds.mkdir();
final File build = new File(builds, BACKUP_DIRECTORY_NAME);
build.mkdir();
final File changelogDir = new File(build, HudsonBackup.CHANGELOG_HISTORY_PLUGIN_DIR_NAME);
changelogDir.mkdir();
new File(changelogDir, "1.xml").createNewFile();
new File(changelogDir, "2.xml").createNewFile();

final File archiveDir = new File(build, HudsonBackup.ARCHIVE_DIR_NAME);
archiveDir.mkdir();
Expand Down
Expand Up @@ -42,7 +42,7 @@ public void testThinBackupZipper() throws Exception {
zipEntries.nextElement();
++entryCount;
}
Assert.assertEquals(19, entryCount);
Assert.assertEquals(23, entryCount);
zipFile.close();

final BackupSet backupSetFromZip = new BackupSet(zippedBackupSet);
Expand Down
Expand Up @@ -76,7 +76,13 @@ public void testBackup() throws Exception {

final File build = new File(new File(job, HudsonBackup.BUILDS_DIR_NAME), BACKUP_DIRECTORY_NAME);
list = build.list();
Assert.assertEquals(6, list.length);
Assert.assertEquals(7, list.length);

final File changelogHistory = new File(
new File(new File(job, HudsonBackup.BUILDS_DIR_NAME), BACKUP_DIRECTORY_NAME),
HudsonBackup.CHANGELOG_HISTORY_PLUGIN_DIR_NAME);
list = changelogHistory.list();
Assert.assertEquals(2, list.length);
}

@Test
Expand All @@ -101,7 +107,14 @@ public void testBackupWithExludes() throws Exception {

final File build = new File(new File(job, HudsonBackup.BUILDS_DIR_NAME), BACKUP_DIRECTORY_NAME);
list = build.list();
Assert.assertEquals(5, list.length);
Assert.assertEquals(6, list.length);

final File changelogHistory = new File(
new File(new File(job, HudsonBackup.BUILDS_DIR_NAME), BACKUP_DIRECTORY_NAME),
HudsonBackup.CHANGELOG_HISTORY_PLUGIN_DIR_NAME);
list = changelogHistory.list();
Assert.assertEquals(2, list.length);

boolean containsLogfile = false;
for (final String string : list) {
if (string.equals("logfile.log")) {
Expand Down Expand Up @@ -185,7 +198,13 @@ public void testBackupNextBuildNumber() throws Exception {

final File build = new File(new File(job, HudsonBackup.BUILDS_DIR_NAME), BACKUP_DIRECTORY_NAME);
list = build.list();
Assert.assertEquals(6, list.length);
Assert.assertEquals(7, list.length);

final File changelogHistory = new File(
new File(new File(job, HudsonBackup.BUILDS_DIR_NAME), BACKUP_DIRECTORY_NAME),
HudsonBackup.CHANGELOG_HISTORY_PLUGIN_DIR_NAME);
list = changelogHistory.list();
Assert.assertEquals(2, list.length);
}

@Test
Expand All @@ -211,7 +230,13 @@ public void testBackupArchive() throws Exception {

final File build = new File(new File(job, HudsonBackup.BUILDS_DIR_NAME), BACKUP_DIRECTORY_NAME);
arrayList = Arrays.asList(build.list());
Assert.assertEquals(7, arrayList.size());
Assert.assertEquals(8, arrayList.size());

final File changelogHistory = new File(
new File(new File(job, HudsonBackup.BUILDS_DIR_NAME), BACKUP_DIRECTORY_NAME),
HudsonBackup.CHANGELOG_HISTORY_PLUGIN_DIR_NAME);
list = changelogHistory.list();
Assert.assertEquals(2, list.length);
}

}
Expand Up @@ -216,7 +216,7 @@ public void testRestoreFromZipFileWithNextBuildNumber() throws Exception {
final FileCollector fc = new FileCollector();
final List<String> restoredFiles = fc.getFilesAsString(root);
final int nrRestored = restoredFiles.size();
Assert.assertEquals(originalFiles.size(), nrRestored + 1);// + 2 because original has more files that were not
Assert.assertEquals(originalFiles.size(), nrRestored + 1);// + 1 because original has more files that were not
// backed up on purpose (secret.key)
Assert.assertTrue(containsStringEndingWith(restoredFiles, HudsonBackup.NEXT_BUILD_NUMBER_FILE_NAME));
Assert.assertFalse(containsStringEndingWith(restoredFiles, "secret.key"));
Expand Down

0 comments on commit 58bcf08

Please sign in to comment.