2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
23 import static org.testng.Assert.assertFalse;
24 import static org.testng.Assert.assertTrue;
26 import java.io.BufferedInputStream;
27 import java.io.ByteArrayInputStream;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.io.StringBufferInputStream;
34 import org.testng.AssertJUnit;
35 import org.testng.annotations.AfterClass;
36 import org.testng.annotations.BeforeClass;
37 import org.testng.annotations.Test;
39 import jalview.bin.Console;
40 import jalview.gui.JvOptionPane;
46 public class FileIOTester
49 @BeforeClass(alwaysRun = true)
50 public void setUpJvOptionPane()
52 JvOptionPane.setInteractiveMode(false);
53 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
57 * @throws java.lang.Exception
59 @BeforeClass(alwaysRun = true)
60 public static void setUpBeforeClass() throws Exception
66 * @throws java.lang.Exception
68 @AfterClass(alwaysRun = true)
69 public static void tearDownAfterClass() throws Exception
73 // TODO: make a better/more comprehensive test harness for identify/io
75 final static File ALIGN_FILE = new File(
76 "test/jalview/io/test_gz_fasta.gz");
78 final static File NOTGZALIGN_FILE = new File(
79 "test/jalview/io/test_gz_fasta_notgz.gz");
81 final static File STARS_FA_FILE1 = new File(
82 "test/jalview/io/test_fasta_stars.fa");
84 final static File STARS_FA_FILE2 = new File(
85 "test/jalview/io/test_fasta_stars2.fa");
87 private void assertValidFormat(FileFormatI fmt, String src, FileParse fp)
88 throws FileFormatException
90 AssertJUnit.assertTrue("Couldn't resolve " + src + " as a valid file",
92 FileFormatI type = new IdentifyFile().identify(fp);
93 AssertJUnit.assertSame("Data from '" + src + "' Expected to be '" + fmt
94 + "' identified as '" + type + "'", type, fmt);
97 @Test(groups = { "Functional" })
98 public void testStarsInFasta1() throws IOException
101 FileParse fp = new FileParse(
102 uri = STARS_FA_FILE1.getAbsoluteFile().toString(),
103 DataSourceType.FILE);
104 assertValidFormat(FileFormat.Fasta, uri, fp);
107 @Test(groups = { "Functional" })
108 public void testStarsInFasta2() throws IOException
111 FileParse fp = new FileParse(
112 uri = STARS_FA_FILE2.getAbsoluteFile().toString(),
113 DataSourceType.FILE);
114 assertValidFormat(FileFormat.Fasta, uri, fp);
117 @Test(groups = { "Functional" })
118 public void testGzipIo() throws IOException
121 FileParse fp = new FileParse(
122 uri = ALIGN_FILE.getAbsoluteFile().toURI().toString(),
124 assertValidFormat(FileFormat.Fasta, uri, fp);
127 @Test(groups = { "Functional" })
128 public void testGziplocalFileIO() throws IOException
131 FileParse fp = new FileParse(
132 filepath = ALIGN_FILE.getAbsoluteFile().toString(),
133 DataSourceType.FILE);
134 assertValidFormat(FileFormat.Fasta, filepath, fp);
137 @Test(groups = { "Functional" })
138 public void testIsGzipInputStream() throws IOException
140 InputStream is = new FileInputStream(ALIGN_FILE);
143 * first try fails - FileInputStream does not support mark/reset
145 assertFalse(FileParse.isGzipStream(is));
148 * wrap in a BufferedInputStream and try again
150 is = new BufferedInputStream(is, 16);
151 assertTrue(FileParse.isGzipStream(is));
154 * check recognition of non-gzipped input
156 assertFalse(FileParse.isGzipStream(new BufferedInputStream(
157 new ByteArrayInputStream("NOT A GZIP".getBytes()))));
160 @Test(groups = { "Functional" })
161 public void testNonGzipURLIO() throws IOException
164 FileParse fp = new FileParse(
165 uri = NOTGZALIGN_FILE.getAbsoluteFile().toURI().toString(),
167 assertValidFormat(FileFormat.Fasta, uri, fp);
170 @Test(groups = { "Functional" })
171 public void testNonGziplocalFileIO() throws IOException
174 FileParse fp = new FileParse(
175 filepath = NOTGZALIGN_FILE.getAbsoluteFile().toString(),
176 DataSourceType.FILE);
177 assertValidFormat(FileFormat.Fasta, filepath, fp);