Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / test / jalview / io / FileLoaderTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.io;
22
23 import static org.testng.Assert.assertEquals;
24
25 import jalview.bin.Cache;
26
27 import org.junit.Assert;
28 import org.testng.annotations.Test;
29
30 public class FileLoaderTest
31 {
32
33   @Test(groups = { "Network" })
34   public void testDownloadStructuresIfInputFromURL()
35   {
36     String urlFile = "http://www.jalview.org/builds/develop/examples/3W5V.pdb";
37     FileLoader fileLoader = new FileLoader();
38     fileLoader.LoadFileWaitTillLoaded(urlFile, DataSourceType.URL,
39             FileFormat.PDB);
40     Assert.assertNotNull(fileLoader.file);
41     // The FileLoader's file is expected to be same as the original URL.
42     Assert.assertEquals(urlFile, fileLoader.file);
43     // Data source type expected to be DataSourceType.URL
44     Assert.assertEquals(DataSourceType.URL, fileLoader.protocol);
45   }
46
47   @Test(groups = "Functional")
48   public void testUpdateRecentlyOpened()
49   {
50     // ensure properties file is read-only
51     Cache.loadProperties("test/jalview/io/testProps.jvprops");
52
53     String recent = "RECENT_FILE";
54     Cache.removeProperty(recent);
55
56     String prop = FileLoader.updateRecentlyOpened("a/b/c",
57             DataSourceType.FILE);
58     assertEquals(prop, "a/b/c");
59
60     prop = FileLoader.updateRecentlyOpened("d/e/f", DataSourceType.FILE);
61     assertEquals(prop, "d/e/f\ta/b/c");
62
63     // revisiting a file moves it to the top of the list
64     prop = FileLoader.updateRecentlyOpened("a/b/c", DataSourceType.FILE);
65     assertEquals(prop, "a/b/c\td/e/f");
66     
67     // history list is limited to the most recent 11 items
68     for (int i = 0; i < 20; i++)
69     {
70       prop = FileLoader.updateRecentlyOpened(String.format("%d.fa", i),
71               DataSourceType.FILE);
72     }
73     assertEquals(prop,
74             "19.fa\t18.fa\t17.fa\t16.fa\t15.fa\t14.fa\t13.fa\t12.fa\t11.fa\t10.fa\t9.fa");
75   }
76 }