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.
24 import java.io.IOException;
26 import org.testng.AssertJUnit;
27 import org.testng.annotations.AfterClass;
28 import org.testng.annotations.BeforeClass;
29 import org.testng.annotations.Test;
35 public class FileIOTester
39 * @throws java.lang.Exception
41 @BeforeClass(alwaysRun = true)
42 public static void setUpBeforeClass() throws Exception
47 * @throws java.lang.Exception
50 public static void tearDownAfterClass() throws Exception
54 // TODO: make a better/more comprehensive test harness for identify/io
56 final static File ALIGN_FILE = new File(
57 "test/jalview/io/test_gz_fasta.gz");
59 final static File NOTGZALIGN_FILE = new File(
60 "test/jalview/io/test_gz_fasta_notgz.gz");
62 final static File STARS_FA_FILE1 = new File(
63 "test/jalview/io/test_fasta_stars.fa");
65 final static File STARS_FA_FILE2 = new File(
66 "test/jalview/io/test_fasta_stars2.fa");
68 private void assertValidFormat(String fmt, String src, FileParse fp)
70 AssertJUnit.assertTrue("Couldn't resolve " + src + " as a valid file",
72 String type = new IdentifyFile().identify(fp);
73 AssertJUnit.assertTrue("Data from '" + src + "' Expected to be '" + fmt
74 + "' identified as '" + type + "'", type.equalsIgnoreCase(fmt));
77 @Test(groups = { "Functional" })
78 public void testStarsInFasta1() throws IOException
81 FileParse fp = new FileParse(uri = STARS_FA_FILE1.getAbsoluteFile()
82 .toString(), AppletFormatAdapter.FILE);
83 assertValidFormat("FASTA", uri, fp);
86 @Test(groups = { "Functional" })
87 public void testStarsInFasta2() throws IOException
90 FileParse fp = new FileParse(uri = STARS_FA_FILE2.getAbsoluteFile()
91 .toString(), AppletFormatAdapter.FILE);
92 assertValidFormat("FASTA", uri, fp);
95 @Test(groups = { "Functional" })
96 public void testGzipIo() throws IOException
99 FileParse fp = new FileParse(uri = ALIGN_FILE.getAbsoluteFile().toURI()
100 .toString(), AppletFormatAdapter.URL);
101 assertValidFormat("FASTA", uri, fp);
104 @Test(groups = { "Functional" })
105 public void testGziplocalFileIO() throws IOException
108 FileParse fp = new FileParse(filepath = ALIGN_FILE.getAbsoluteFile()
109 .toString(), AppletFormatAdapter.FILE);
110 assertValidFormat("FASTA", filepath, fp);
113 @Test(groups = { "Functional" })
114 public void testNonGzipURLIO() throws IOException
117 FileParse fp = new FileParse(uri = NOTGZALIGN_FILE.getAbsoluteFile()
118 .toURI().toString(), AppletFormatAdapter.URL);
119 assertValidFormat("FASTA", uri, fp);
122 @Test(groups = { "Functional" })
123 public void testNonGziplocalFileIO() throws IOException
126 FileParse fp = new FileParse(filepath = NOTGZALIGN_FILE
127 .getAbsoluteFile().toString(), AppletFormatAdapter.FILE);
128 assertValidFormat("FASTA", filepath, fp);