X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fio%2FBackupFilesTest.java;fp=test%2Fjalview%2Fio%2FBackupFilesTest.java;h=28dbf5cc1d592d06bb245b1af54b94a3183c672a;hb=304e64fb34b32659be1bbfd39fb4e15b2f79586e;hp=c84285a8637ff85b9fdbabd26f051d7d3a25957c;hpb=cfb79b69d9fa44595560659bd95d1d1cd27677ad;p=jalview.git diff --git a/test/jalview/io/BackupFilesTest.java b/test/jalview/io/BackupFilesTest.java index c84285a..28dbf5c 100644 --- a/test/jalview/io/BackupFilesTest.java +++ b/test/jalview/io/BackupFilesTest.java @@ -1,12 +1,5 @@ package jalview.io; -import jalview.bin.Cache; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.Sequence; -import jalview.datamodel.SequenceI; -import jalview.gui.AlignFrame; -import jalview.gui.JvOptionPane; - import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -24,6 +17,13 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import jalview.bin.Cache; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceI; +import jalview.gui.AlignFrame; +import jalview.gui.JvOptionPane; + public class BackupFilesTest { @BeforeClass(alwaysRun = true) @@ -43,7 +43,6 @@ public class BackupFilesTest private static String testFilename = testBasename + testExt; - private static String testFile = testDir + File.separatorChar + testFilename; @@ -88,6 +87,33 @@ public class BackupFilesTest Assert.assertTrue(backupFiles.length == 0); } + // save with no numbers in the backup file names + @Test(groups = { "Functional" }) + public void backupsEnabledSingleFileBackupTest() throws Exception + { + // Enable BackupFiles and set noMax so all backupfiles get kept + String mysuffix = "~"; + BackupFilesPresetEntry bfpe = new BackupFilesPresetEntry(mysuffix, 1, + false, true, 1, false); + setBackupFilesOptions(true, false, true, + "test/jalview/io/testProps_singlefilebackup.jvprops", bfpe); + + // init the newFile and backups (i.e. make sure newFile exists on its own + // and has no backups) + initNewFileForTesting(); + HashMap correctindexmap = new HashMap<>(); + correctindexmap.put(0, "backupfilestestTemp.fa~"); + + save(); + Assert.assertTrue(checkBackupFiles(correctindexmap, newFile, "~", 1)); + + // and a second time -- see JAL-3628 + save(); + Assert.assertTrue(checkBackupFiles(correctindexmap, newFile, "~", 1)); + + cleanupTmpFiles(newFile, "~", 1); + } + // save keeping all backup files @Test(groups = { "Functional" }) public void backupsEnabledNoRollMaxTest() throws Exception @@ -208,10 +234,16 @@ public class BackupFilesTest private void setBackupFilesOptions(boolean enabled, boolean reverse, boolean noMax) { - Cache.loadProperties("test/jalview/io/testProps.jvprops"); - BackupFilesPresetEntry bfpe = new BackupFilesPresetEntry(suffix, digits, reverse, noMax, rollMax, false); + setBackupFilesOptions(enabled, reverse, noMax, + "test/jalview/io/testProps.jvprops", bfpe); + } + + private void setBackupFilesOptions(boolean enabled, boolean reverse, + boolean noMax, String propsFile, BackupFilesPresetEntry bfpe) + { + Cache.loadProperties(propsFile); Cache.setPropertyNoSave(BackupFiles.ENABLED, Boolean.toString(enabled)); @@ -238,7 +270,7 @@ public class BackupFilesTest { if (af != null) { - af.saveAlignment(newFile, jalview.io.FileFormat.Fasta); + af.saveAlignment(newFile, jalview.io.FileFormat.Fasta); } } @@ -277,12 +309,17 @@ public class BackupFilesTest @AfterClass(alwaysRun = true) private void cleanupTmpFiles() { - File newfile = new File(newFile); + cleanupTmpFiles(newFile, suffix, digits); + } + + private void cleanupTmpFiles(String file, String mysuffix, int mydigits) + { + File newfile = new File(file); if (newfile.exists()) { newfile.delete(); } - File[] tmpFiles = getBackupFiles(newFile, suffix, digits); + File[] tmpFiles = getBackupFiles(file, mysuffix, mydigits); for (int i = 0; i < tmpFiles.length; i++) { if (actuallyDeleteTmpFiles) @@ -298,8 +335,8 @@ public class BackupFilesTest private static File[] getBackupFiles(String f, String s, int i) { - TreeMap bfTreeMap = BackupFiles.getBackupFilesAsTreeMap(f, - s, i); + TreeMap bfTreeMap = BackupFiles + .getBackupFilesAsTreeMap(f, s, i); File[] backupFiles = new File[bfTreeMap.size()]; bfTreeMap.values().toArray(backupFiles); return backupFiles; @@ -313,8 +350,14 @@ public class BackupFilesTest private static boolean checkBackupFiles(HashMap indexmap) throws IOException { - TreeMap map = BackupFiles.getBackupFilesAsTreeMap(newFile, - suffix, digits); + return checkBackupFiles(indexmap, newFile, suffix, digits); + } + + private static boolean checkBackupFiles(HashMap indexmap, + String file, String mysuffix, int mydigits) throws IOException + { + TreeMap map = BackupFiles.getBackupFilesAsTreeMap(file, + mysuffix, mydigits); Enumeration indexesenum = Collections .enumeration(indexmap.keySet()); while (indexesenum.hasMoreElements()) @@ -351,8 +394,8 @@ public class BackupFilesTest private static boolean checkBackupFiles(int[] indexes) throws IOException { - TreeMap map = BackupFiles.getBackupFilesAsTreeMap(newFile, - suffix, digits); + TreeMap map = BackupFiles + .getBackupFilesAsTreeMap(newFile, suffix, digits); for (int m = 0; m < indexes.length; m++) { int i = indexes[m]; @@ -370,7 +413,8 @@ public class BackupFilesTest { return false; } - // check the filename -- although this uses the same code to forumulate the filename so not much of a test! + // check the filename -- although this uses the same code to forumulate + // the filename so not much of a test! String filename = BackupFilenameParts.getBackupFilename(i, newBasename + testExt, suffix, digits); if (!filename.equals(f.getName())) @@ -400,10 +444,14 @@ public class BackupFilesTest return filenames; } - public static boolean sequencesEqual(SequenceI s1, SequenceI s2) { - if (s1 == null && s2 == null) { + public static boolean sequencesEqual(SequenceI s1, SequenceI s2) + { + if (s1 == null && s2 == null) + { return true; - } else if (s1 == null || s2 == null) { + } + else if (s1 == null || s2 == null) + { return false; } return (s1.getName().equals(s2.getName())