JAL-1759 merge from develop
[jalview.git] / test / jalview / io / FileIOTester.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 java.io.File;
24 import java.io.IOException;
25
26 import org.testng.AssertJUnit;
27 import org.testng.annotations.AfterClass;
28 import org.testng.annotations.BeforeClass;
29 import org.testng.annotations.Test;
30
31 /**
32  * @author jimp
33  * 
34  */
35 public class FileIOTester
36 {
37
38   /**
39    * @throws java.lang.Exception
40    */
41   @BeforeClass
42   public static void setUpBeforeClass() throws Exception
43   {
44   }
45
46   /**
47    * @throws java.lang.Exception
48    */
49   @AfterClass
50   public static void tearDownAfterClass() throws Exception
51   {
52   }
53
54   // TODO: make a better/more comprehensive test harness for identify/io
55
56   final static File ALIGN_FILE = new File(
57           "test/jalview/io/test_gz_fasta.gz");
58
59   final static File NOTGZALIGN_FILE = new File(
60           "test/jalview/io/test_gz_fasta_notgz.gz");
61
62   final static File STARS_FA_FILE1 = new File(
63           "test/jalview/io/test_fasta_stars.fa");
64
65   final static File STARS_FA_FILE2 = new File(
66           "test/jalview/io/test_fasta_stars2.fa");
67
68   private void assertValidFormat(String fmt, String src, FileParse fp)
69   {
70     AssertJUnit.assertTrue("Couldn't resolve " + src + " as a valid file", fp.isValid());
71     String type = new IdentifyFile().Identify(fp);
72     AssertJUnit.assertTrue("Data from '" + src + "' Expected to be '" + fmt
73             + "' identified as '" + type + "'", type.equalsIgnoreCase(fmt));
74   }
75
76   @Test(groups ={ "Functional" })
77   public void testStarsInFasta1() throws IOException
78   {
79     String uri;
80     FileParse fp = new FileParse(uri = STARS_FA_FILE1.getAbsoluteFile()
81             .toString(), AppletFormatAdapter.FILE);
82     assertValidFormat("FASTA", uri, fp);
83   }
84
85   @Test(groups ={ "Functional" })
86   public void testStarsInFasta2() throws IOException
87   {
88     String uri;
89     FileParse fp = new FileParse(uri = STARS_FA_FILE2.getAbsoluteFile()
90             .toString(), AppletFormatAdapter.FILE);
91     assertValidFormat("FASTA", uri, fp);
92   }
93
94   @Test(groups ={ "Functional" })
95   public void testGzipIo() throws IOException
96   {
97     String uri;
98     FileParse fp = new FileParse(uri = ALIGN_FILE.getAbsoluteFile().toURI()
99             .toString(), AppletFormatAdapter.URL);
100     assertValidFormat("FASTA", uri, fp);
101   }
102
103   @Test(groups ={ "Functional" })
104   public void testGziplocalFileIO() throws IOException
105   {
106     String filepath;
107     FileParse fp = new FileParse(filepath = ALIGN_FILE.getAbsoluteFile()
108             .toString(), AppletFormatAdapter.FILE);
109     assertValidFormat("FASTA", filepath, fp);
110   }
111
112   @Test(groups ={ "Functional" })
113   public void testNonGzipURLIO() throws IOException
114   {
115     String uri;
116     FileParse fp = new FileParse(uri = NOTGZALIGN_FILE.getAbsoluteFile()
117             .toURI().toString(), AppletFormatAdapter.URL);
118     assertValidFormat("FASTA", uri, fp);
119   }
120
121   @Test(groups ={ "Functional" })
122   public void testNonGziplocalFileIO() throws IOException
123   {
124     String filepath;
125     FileParse fp = new FileParse(filepath = NOTGZALIGN_FILE
126             .getAbsoluteFile().toString(), AppletFormatAdapter.FILE);
127     assertValidFormat("FASTA", filepath, fp);
128   }
129 }