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.AssertJUnit.assertFalse;
24 import static org.testng.AssertJUnit.assertSame;
25 import static org.testng.AssertJUnit.assertTrue;
27 import java.io.FileNotFoundException;
29 import org.testng.Assert;
30 import org.testng.annotations.BeforeClass;
31 import org.testng.annotations.DataProvider;
32 import org.testng.annotations.Test;
34 import jalview.gui.JvOptionPane;
36 public class IdentifyFileTest
39 @BeforeClass(alwaysRun = true)
40 public void setUpJvOptionPane()
42 JvOptionPane.setInteractiveMode(false);
43 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
46 @Test(groups = { "Functional" }, dataProvider = "identifyFiles")
47 public void testIdentify(String data, FileFormatI expectedFileType)
48 throws FileFormatException, FileNotFoundException
50 DataSourceType protocol = DataSourceType.FILE;
51 IdentifyFile ider = new IdentifyFile();
52 FileFormatI actualFiletype = ider.identify(data, protocol);
53 Assert.assertSame(actualFiletype, expectedFileType,
54 "File identification Failed!");
58 * Additional tests for Jalview features file
60 * @throws FileFormatException
62 @Test(groups = "Functional")
63 public void testIdentify_featureFile()
64 throws FileFormatException, FileNotFoundException
66 IdentifyFile ider = new IdentifyFile();
69 * Jalview format with features only, no feature colours
71 String data = "Iron-sulfur (2Fe-2S)\tFER_CAPAA\t-1\t39\t39\tMETAL\n"
72 + "Iron-phosphorus (2Fe-P)\tID_NOT_SPECIFIED\t2\t86\t87\tMETALLIC\n";
73 assertSame(FileFormat.Features,
74 ider.identify(data, DataSourceType.PASTE));
77 * Jalview feature colour followed by GFF format feature data
79 data = "METAL\tcc9900\n" + "GFF\n"
80 + "FER_CAPAA\tuniprot\tMETAL\t44\t45\t4.0\t.\t.\n";
81 assertSame(FileFormat.Features,
82 ider.identify(data, DataSourceType.PASTE));
85 * Feature with '<' in the name (JAL-2098)
87 data = "kD < 3\tred\n" + "Low kD\tFER_CAPAA\t-1\t39\t39\tkD < 3\n";
88 assertSame(FileFormat.Features,
89 ider.identify(data, DataSourceType.PASTE));
92 @DataProvider(name = "identifyFiles")
93 public Object[][] IdentifyFileDP()
95 return new Object[][] { { "examples/example.json", FileFormat.Json },
96 { "examples/plantfdx.fa", FileFormat.Fasta },
97 { "examples/dna_interleaved.phy", FileFormat.Phylip },
98 { "examples/2GIS.pdb", FileFormat.PDB },
99 { "examples/RF00031_folded.stk", FileFormat.Stockholm },
100 { "examples/testdata/test.rnaml", FileFormat.Rnaml },
101 { "examples/testdata/test.aln", FileFormat.Clustal },
102 { "examples/testdata/test.pfam", FileFormat.Pfam },
103 { "examples/testdata/test.msf", FileFormat.MSF },
104 { "examples/testdata/test.pir", FileFormat.PIR },
105 { "examples/testdata/test.html", FileFormat.Html },
106 { "examples/testdata/test.pileup", FileFormat.Pileup },
107 { "examples/testdata/test.blc", FileFormat.BLC },
108 { "test/jalview/io/J03321.embl.txt", FileFormat.Embl },
109 { "test/jalview/io/J03321.gb", FileFormat.GenBank },
110 { "examples/exampleFeatures.txt", FileFormat.Features },
111 { "examples/testdata/simpleGff3.gff", FileFormat.Features },
112 { "examples/testdata/test.jvp", FileFormat.Jalview },
113 { "examples/testdata/test.cif", FileFormat.MMCif },
114 { "examples/testdata/cullpdb_pc25_res3.0_R0.3_d150729_chains9361.fasta.15316",
116 { "resources/scoreModel/pam250.scm", FileFormat.ScoreMatrix },
117 { "resources/scoreModel/blosum80.scm", FileFormat.ScoreMatrix }
118 // { "examples/testdata/test.amsa", "AMSA" },
119 // { "examples/test.jnet", "JnetFile" },
123 @Test(groups = "Functional")
124 public void testLooksLikeFeatureData()
126 IdentifyFile id = new IdentifyFile();
127 assertFalse(id.looksLikeFeatureData(null));
128 assertFalse(id.looksLikeFeatureData(""));
130 assertFalse(id.looksLikeFeatureData("1 \t 2 \t 3 \t 4 \t 5"));
133 id.looksLikeFeatureData("Seq1\tlocal\tHelix\t2456\t2462\tss"));
135 assertTrue(id.looksLikeFeatureData("Helix\tSeq1\t-1\t2456\t2462\tss"));
136 // non-numeric start column:
137 assertFalse(id.looksLikeFeatureData("Helix\tSeq1\t-1\t.\t2462\tss"));
138 // non-numeric start column:
139 assertFalse(id.looksLikeFeatureData("Helix\tSeq1\t-1\t2456\t.\tss"));
142 @Test(groups = "Network", dataProvider = "urlTargetsAndExceptions")
143 public void testExceptions(String url,
144 Class<? extends Exception> expectedExceptionClass,
145 FileFormatI expectedFormat)
147 Class<? extends Exception> actualExceptionClass = null;
148 FileFormatI actualFormat = null;
151 actualFormat = new IdentifyFile().identify(url, DataSourceType.URL);
152 } catch (FileFormatException | FileNotFoundException e)
154 Assert.assertNull(expectedFormat,
155 "Exception occurred when expecting an identifiable format.");
156 Assert.assertNotNull(expectedExceptionClass,
157 "An unexpected exception occurred: '" + e.getMessage() + "'");
158 Assert.assertEquals(e.getClass(), expectedExceptionClass,
159 "Got the wrong kind of exception.");
160 actualExceptionClass = e.getClass();
163 if (expectedExceptionClass != null)
165 Assert.assertEquals(actualExceptionClass, expectedExceptionClass,
166 "Expected an exception but got the wrong one.");
171 @DataProvider(name = "urlTargetsAndExceptions")
172 public Object[][] urlTargetsAndExceptions()
177 String foundInFirstLine,
179 return new Object[][] {
182 { "http://jalview.org/examples/uniref50.fa", null,
184 { "https://www.jalview.org/examples/NOFILE.fa",
185 FileNotFoundException.class, null },
186 { "https://NOSERVER.jalview.org/", FileNotFoundException.class,
189 { "https://www.jalview.org/schools/Jalview_Schools_Workbook_200.jpg",
190 FileFormatException.class, null },