84bd7148850cc31f6f68bdf69a0cf8b40dca7892
[jalview.git] / test / jalview / io / FileLoaderTest.java
1 package jalview.io;
2
3 import static org.testng.Assert.assertEquals;
4
5 import jalview.bin.Cache;
6
7 import org.junit.Assert;
8 import org.testng.annotations.Test;
9
10 public class FileLoaderTest
11 {
12
13   @Test(groups = { "Network" })
14   public void testDownloadStructuresIfInputFromURL()
15   {
16     String urlFile = "http://www.jalview.org/builds/develop/examples/3W5V.pdb";
17     FileLoader fileLoader = new FileLoader();
18     fileLoader.LoadFileWaitTillLoaded(urlFile, DataSourceType.URL,
19             FileFormat.PDB);
20     Assert.assertNotNull(fileLoader.file);
21     // The FileLoader's file is expected to be same as the original URL.
22     Assert.assertEquals(urlFile, fileLoader.file);
23     // Data source type expected to be DataSourceType.URL
24     Assert.assertEquals(DataSourceType.URL, fileLoader.protocol);
25   }
26
27   @Test(groups = "Functional")
28   public void testUpdateRecentlyOpened()
29   {
30     // ensure properties file is read-only
31     Cache.loadProperties("test/jalview/io/testProps.jvprops");
32
33     String recent = "RECENT_FILE";
34     Cache.removeProperty(recent);
35
36     String prop = FileLoader.updateRecentlyOpened("a/b/c",
37             DataSourceType.FILE);
38     assertEquals(prop, "a/b/c");
39
40     prop = FileLoader.updateRecentlyOpened("d/e/f", DataSourceType.FILE);
41     assertEquals(prop, "d/e/f\ta/b/c");
42
43     // revisiting a file moves it to the top of the list
44     prop = FileLoader.updateRecentlyOpened("a/b/c", DataSourceType.FILE);
45     assertEquals(prop, "a/b/c\td/e/f");
46     
47     // history list is limited to the most recent 11 items
48     for (int i = 0; i < 20; i++)
49     {
50       prop = FileLoader.updateRecentlyOpened(String.format("%d.fa", i),
51               DataSourceType.FILE);
52     }
53     assertEquals(prop,
54             "19.fa\t18.fa\t17.fa\t16.fa\t15.fa\t14.fa\t13.fa\t12.fa\t11.fa\t10.fa\t9.fa");
55   }
56 }