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;
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)
private static String testFilename = testBasename + testExt;
-
private static String testFile = testDir + File.separatorChar
+ testFilename;
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<Integer, String> 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
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.applicationProperties.setProperty(BackupFiles.ENABLED,
Boolean.toString(enabled));
{
if (af != null)
{
- af.saveAlignment(newFile, jalview.io.FileFormat.Fasta);
+ af.saveAlignment(newFile, jalview.io.FileFormat.Fasta);
}
}
@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)
private static File[] getBackupFiles(String f, String s, int i)
{
- TreeMap<Integer, File> bfTreeMap = BackupFiles.getBackupFilesAsTreeMap(f,
- s, i);
+ TreeMap<Integer, File> bfTreeMap = BackupFiles
+ .getBackupFilesAsTreeMap(f, s, i);
File[] backupFiles = new File[bfTreeMap.size()];
bfTreeMap.values().toArray(backupFiles);
return backupFiles;
private static boolean checkBackupFiles(HashMap<Integer, String> indexmap)
throws IOException
{
- TreeMap<Integer, File> map = BackupFiles.getBackupFilesAsTreeMap(newFile,
- suffix, digits);
+ return checkBackupFiles(indexmap, newFile, suffix, digits);
+ }
+
+ private static boolean checkBackupFiles(HashMap<Integer, String> indexmap,
+ String file, String mysuffix, int mydigits) throws IOException
+ {
+ TreeMap<Integer, File> map = BackupFiles.getBackupFilesAsTreeMap(file,
+ mysuffix, mydigits);
Enumeration<Integer> indexesenum = Collections
.enumeration(indexmap.keySet());
while (indexesenum.hasMoreElements())
private static boolean checkBackupFiles(int[] indexes) throws IOException
{
- TreeMap<Integer, File> map = BackupFiles.getBackupFilesAsTreeMap(newFile,
- suffix, digits);
+ TreeMap<Integer, File> map = BackupFiles
+ .getBackupFilesAsTreeMap(newFile, suffix, digits);
for (int m = 0; m < indexes.length; m++)
{
int i = indexes[m];
{
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()))
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())
--- /dev/null
+#---JalviewX Properties File---
+#Mon Dec 14 16:32:45 GMT 2020
+BACKUPFILES_CUSTOM=_BACKUPFILESTESTTMP%n\t6\tfalse\tfalse\t2\tfalse
+BACKUPFILES_ENABLED=true
+BACKUPFILES_PRESET=2
+BACKUPFILES_SAVED=~\t1\tfalse\tfalse\t1\tfalse
+ADD_SS_ANN=false
+ADD_TEMPFACT_ANN=false
+ANNOTATIONCOLOUR_MAX=ff0000
+ANNOTATIONCOLOUR_MIN=ffc800
+ANTI_ALIAS=false
+AUTHORFNAMES=Jim Procter, Mungo Carstairs, Ben Soares, Kira Mourao, Tochukwu 'Charles' Ofoegbu, Andrew Waterhouse, Jan Engelhardt, Lauren Lui, Anne Menard, Daniel Barton, Natasha Sherstnev, David Roldan-Martinez, Michele Clamp, James Cuff, Steve Searle, David Martin & Geoff Barton
+AUTHORS=J Procter, M Carstairs, B Soares, K Mourao, TC Ofoegbu, AM Waterhouse, J Engelhardt, LM Lui, A Menard, D Barton, N Sherstnev, D Roldan-Martinez, M Clamp, S Searle, G Barton
+AUTO_CALC_CONSENSUS=true
+BLC_JVSUFFIX=true
+BUILD_DATE=20\:10\:14 10 December 2020
+CLUSTAL_JVSUFFIX=true
+DAS_ACTIVE_SOURCE=uniprot\t
+DAS_LOCAL_SOURCE=
+DAS_REGISTRY_URL=http\://www.ebi.ac.uk/das-srv/registry/das/
+DEFAULT_COLOUR=None
+DEFAULT_COLOUR_NUC=None
+DEFAULT_COLOUR_PROT=None
+DEFAULT_FILE_FORMAT=FASTA
+DEFAULT_URL=EMBL-EBI Search
+EPS_RENDERING=Prompt each time
+EXPORT_EMBBED_BIOJSON=true
+FASTA_JVSUFFIX=true
+FIGURE_AUTOIDWIDTH=false
+FIGURE_FIXEDIDWIDTH=
+FIGURE_USERIDWIDTH=
+FONT_NAME=SansSerif
+FONT_SIZE=10
+FONT_STYLE=plain
+GAP_COLOUR=c0c0c0
+GAP_SYMBOL=-
+HIDDEN_COLOUR=2c2c2c
+HTML_RENDERING=Prompt each time
+ID_ITALICS=true
+INSTALLATION=Source git-commit\:225f7f621b [develop]
+JALVIEW_NEWS_RSS_LASTMODIFIED=29 Oct 2020, 21\:44\:11
+JALVIEW_RSS_WINDOW_SCREEN_HEIGHT=301
+JALVIEW_RSS_WINDOW_SCREEN_WIDTH=550
+JALVIEW_RSS_WINDOW_SCREEN_X=0
+JALVIEW_RSS_WINDOW_SCREEN_Y=0
+JAVA_CONSOLE_SCREEN_HEIGHT=250
+JAVA_CONSOLE_SCREEN_WIDTH=337
+JAVA_CONSOLE_SCREEN_X=622
+JAVA_CONSOLE_SCREEN_Y=320
+JWS2HOSTURLS=http\://www.compbio.dundee.ac.uk/jabaws
+LAST_DIRECTORY=/Volumes/Data/Users/jimp/Documents/testing/Jalview/examples
+logs.Jalview.level=DEBUG
+MAP_WITH_SIFTS=false
+MSF_JVSUFFIX=true
+NOQUESTIONNAIRES=true
+PAD_GAPS=false
+PFAM_JVSUFFIX=true
+PILEUP_JVSUFFIX=true
+PIR_JVSUFFIX=true
+PIR_MODELLER=false
+PROXY_AUTH=false
+RECENT_FILE=examples/uniref50.fa\t/Volumes/Data/Users/jimp/Documents/testing/Jalview/examples/RF00031_folded.stk\t/Volumes/Data/Users/jimp/bs_ig_mult.out
+RECENT_URL=http\://www.jalview.org/examples/exampleFile_2_7.jar
+RIGHT_ALIGN_IDS=false
+RSBS_SERVICES=|Multi-Harmony|Analysis|Sequence Harmony and Multi-Relief (Brandt et al. 2010)|hseparable,gapCharacter\='-',returns\='ANNOTATION'|?tool\=jalview|http\://zeus.few.vu.nl/programs/shmrwww/index.php?tool\=jalview&groups\=$PARTITION\:min\='2',minsize\='2',sep\=' '$&ali_file\=$ALIGNMENT\:format\='Fasta',writeasfile$
+SCALE_PROTEIN_TO_CDNA=false
+SCREENGEOMETRY_HEIGHT=1080
+SCREENGEOMETRY_WIDTH=1920
+SCREEN_HEIGHT=1018
+SCREEN_WIDTH=1920
+SCREEN_X=0
+SCREEN_Y=0
+SEQUENCE_LINKS=EMBL-EBI Search|https\://www.ebi.ac.uk/ebisearch/search.ebi?db\=allebi&query\=$SEQUENCE_ID$
+SHOW_ANNOTATIONS=true
+SHOW_AUTOCALC_ABOVE=true
+SHOW_CONSENSUS_HISTOGRAM=true
+SHOW_CONSENSUS_LOGO=false
+SHOW_CONSERVATION=true
+SHOW_DBREFS_TOOLTIP=true
+SHOW_ENFIN_SERVICES=true
+SHOW_FULLSCREEN=false
+SHOW_GROUP_CONSENSUS=false
+SHOW_GROUP_CONSERVATION=false
+SHOW_IDENTITY=true
+SHOW_JAVA_CONSOLE=false
+SHOW_JVSUFFIX=true
+SHOW_JWS2_SERVICES=true
+SHOW_NPFEATS_TOOLTIP=true
+SHOW_OCCUPANCY=true
+SHOW_OVERVIEW=false
+SHOW_OV_HIDDEN_AT_START=false
+SHOW_QUALITY=true
+SHOW_STARTUP_FILE=false
+SHOW_UNCONSERVED=false
+SHOW_WSDISCOVERY_ERRORS=true
+SORT_ALIGNMENT=No sort
+SORT_ANNOTATIONS=NONE
+SORT_BY_TREE=false
+STARTUP_FILE=http\://www.jalview.org/examples/exampleFile_2_3.jar
+STRUCT_FROM_PDB=false
+STRUCTURE_DISPLAY=JMOL
+SVG_RENDERING=Prompt each time
+USAGESTATS=false
+USE_LEGACY_GAP=false
+USE_PROXY=false
+USE_RNAVIEW=false
+VERSION=2.11.2.0-develop
+VERSION_CHECK=false
+WRAP_ALIGNMENT=false
+WSMENU_BYHOST=false
+WSMENU_BYTYPE=false
+YEAR=2018