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;
28 import java.io.FileInputStream;
29 import java.io.IOException;
30 import java.io.InputStream;
32 import org.testng.AssertJUnit;
33 import org.testng.annotations.AfterClass;
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.Test;
37 import jalview.bin.Cache;
38 import jalview.gui.JvOptionPane;
44 public class FileIOTester
47 @BeforeClass(alwaysRun = true)
48 public void setUpJvOptionPane()
50 JvOptionPane.setInteractiveMode(false);
51 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
55 * @throws java.lang.Exception
57 @BeforeClass(alwaysRun = true)
58 public static void setUpBeforeClass() throws Exception
64 * @throws java.lang.Exception
66 @AfterClass(alwaysRun = true)
67 public static void tearDownAfterClass() throws Exception
71 // TODO: make a better/more comprehensive test harness for identify/io
73 final static File ALIGN_FILE = new File(
74 "test/jalview/io/test_gz_fasta.gz");
76 final static File NOTGZALIGN_FILE = new File(
77 "test/jalview/io/test_gz_fasta_notgz.gz");
79 final static File STARS_FA_FILE1 = new File(
80 "test/jalview/io/test_fasta_stars.fa");
82 final static File STARS_FA_FILE2 = new File(
83 "test/jalview/io/test_fasta_stars2.fa");
85 private void assertValidFormat(FileFormatI fmt, String src, FileParse fp)
86 throws FileFormatException
88 AssertJUnit.assertTrue("Couldn't resolve " + src + " as a valid file",
90 FileFormatI type = new IdentifyFile().identify(fp);
91 AssertJUnit.assertSame("Data from '" + src + "' Expected to be '" + fmt
92 + "' identified as '" + type + "'", type, fmt);
95 @Test(groups = { "Functional" })
96 public void testStarsInFasta1() throws IOException
99 FileParse fp = new FileParse(
100 uri = STARS_FA_FILE1.getAbsoluteFile().toString(),
101 DataSourceType.FILE);
102 assertValidFormat(FileFormat.Fasta, uri, fp);
105 @Test(groups = { "Functional" })
106 public void testStarsInFasta2() throws IOException
109 FileParse fp = new FileParse(
110 uri = STARS_FA_FILE2.getAbsoluteFile().toString(),
111 DataSourceType.FILE);
112 assertValidFormat(FileFormat.Fasta, uri, fp);
115 @Test(groups = { "Functional" })
116 public void testGzipIo() throws IOException
119 FileParse fp = new FileParse(
120 uri = ALIGN_FILE.getAbsoluteFile().toURI().toString(),
122 assertValidFormat(FileFormat.Fasta, uri, fp);
125 @Test(groups = { "Functional" })
126 public void testGziplocalFileIO() throws IOException
129 FileParse fp = new FileParse(
130 filepath = ALIGN_FILE.getAbsoluteFile().toString(),
131 DataSourceType.FILE);
132 assertValidFormat(FileFormat.Fasta, filepath, fp);
135 @Test(groups = { "Functional" })
136 public void testIsGzipInputStream() throws IOException
138 InputStream is = new FileInputStream(ALIGN_FILE);
141 * first try fails - FileInputStream does not support mark/reset
143 assertFalse(FileParse.isGzipStream(is));
146 * wrap in a BufferedInputStream and try again
148 is = new BufferedInputStream(is, 16);
149 assertTrue(FileParse.isGzipStream(is));
152 @Test(groups = { "Functional" })
153 public void testNonGzipURLIO() throws IOException
156 FileParse fp = new FileParse(
157 uri = NOTGZALIGN_FILE.getAbsoluteFile().toURI().toString(),
159 assertValidFormat(FileFormat.Fasta, uri, fp);
162 @Test(groups = { "Functional" })
163 public void testNonGziplocalFileIO() throws IOException
166 FileParse fp = new FileParse(
167 filepath = NOTGZALIGN_FILE.getAbsoluteFile().toString(),
168 DataSourceType.FILE);
169 assertValidFormat(FileFormat.Fasta, filepath, fp);