test and data for JAL-1447
[jalview.git] / test / jalview / io / FileIOTester.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.io;
20
21 import static org.junit.Assert.*;
22
23 import java.io.File;
24 import java.io.IOException;
25
26 import org.junit.AfterClass;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
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   // TODO: make a better/more comprehensive test harness for identify/io
53   
54   final static File ALIGN_FILE = new File("test/jalview/io/test_gz_fasta.gz");
55   final static File NOTGZALIGN_FILE = new File("test/jalview/io/test_gz_fasta_notgz.gz");
56   final static File STARS_FA_FILE1 = new File("test/jalview/io/test_fasta_stars.fa");
57   final static File STARS_FA_FILE2 = new File("test/jalview/io/test_fasta_stars2.fa");
58
59   private void assertValidFormat(String fmt, String src, FileParse fp)
60   {
61     assertTrue("Couldn't resolve "+src+" as a valid file",fp.isValid());
62     String type = new IdentifyFile().Identify(fp);
63     assertTrue("Data from '"+src+"' Expected to be '"+fmt+"' identified as '"+type+"'",type.equalsIgnoreCase(fmt));
64   }
65   @Test
66   public void testStarsInFasta1() throws IOException
67   {
68     String uri;
69     FileParse fp = new FileParse(uri=STARS_FA_FILE1.getAbsoluteFile().toString(),AppletFormatAdapter.FILE);
70     assertValidFormat("FASTA", uri, fp);
71   }
72   @Test
73   public void testStarsInFasta2() throws IOException
74   {
75     String uri;
76     FileParse fp = new FileParse(uri=STARS_FA_FILE2.getAbsoluteFile().toString(),AppletFormatAdapter.FILE);
77     assertValidFormat("FASTA", uri, fp);
78   }
79   @Test
80   public void testGzipIo() throws IOException
81   {     
82     String uri;
83     FileParse fp = new FileParse(uri=ALIGN_FILE.getAbsoluteFile().toURI().toString(),AppletFormatAdapter.URL);
84     assertValidFormat("FASTA", uri, fp);
85   }
86
87   @Test
88   public void testGziplocalFileIO() throws IOException
89   {
90     String filepath;
91     FileParse fp = new FileParse(filepath=ALIGN_FILE.getAbsoluteFile().toString(), AppletFormatAdapter.FILE);
92     assertValidFormat("FASTA",filepath, fp);
93   }
94   @Test
95   public void testNonGzipURLIO() throws IOException
96   {
97     String uri;
98     FileParse fp = new FileParse(uri=NOTGZALIGN_FILE.getAbsoluteFile().toURI().toString(),AppletFormatAdapter.URL);
99     assertValidFormat("FASTA",uri, fp);
100   }
101   @Test
102   public void testNonGziplocalFileIO() throws IOException
103   {
104     String filepath;
105     FileParse fp = new FileParse(filepath=NOTGZALIGN_FILE.getAbsoluteFile().toString(), AppletFormatAdapter.FILE);
106     assertValidFormat("FASTA",filepath, fp);
107   }
108 }