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