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