1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io; |
22 |
|
|
23 |
|
import static org.testng.AssertJUnit.assertFalse; |
24 |
|
import static org.testng.AssertJUnit.assertSame; |
25 |
|
import static org.testng.AssertJUnit.assertTrue; |
26 |
|
|
27 |
|
import java.io.FileNotFoundException; |
28 |
|
|
29 |
|
import org.testng.Assert; |
30 |
|
import org.testng.annotations.BeforeClass; |
31 |
|
import org.testng.annotations.DataProvider; |
32 |
|
import org.testng.annotations.Test; |
33 |
|
|
34 |
|
import jalview.gui.JvOptionPane; |
35 |
|
|
|
|
| 0% |
Uncovered Elements: 42 (42) |
Complexity: 9 |
Complexity Density: 0.27 |
|
36 |
|
public class IdentifyFileTest |
37 |
|
{ |
38 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
39 |
0 |
@BeforeClass(alwaysRun = true)... |
40 |
|
public void setUpJvOptionPane() |
41 |
|
{ |
42 |
0 |
JvOptionPane.setInteractiveMode(false); |
43 |
0 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
44 |
|
} |
45 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
4-
|
|
46 |
0 |
@Test(groups = { "Functional" }, dataProvider = "identifyFiles")... |
47 |
|
public void testIdentify(String data, FileFormatI expectedFileType) |
48 |
|
throws FileFormatException, FileNotFoundException |
49 |
|
{ |
50 |
0 |
DataSourceType protocol = DataSourceType.FILE; |
51 |
0 |
IdentifyFile ider = new IdentifyFile(); |
52 |
0 |
FileFormatI actualFiletype = ider.identify(data, protocol); |
53 |
0 |
Assert.assertSame(actualFiletype, expectedFileType, |
54 |
|
"File identification Failed!"); |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@throws |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
4-
|
|
62 |
0 |
@Test(groups = "Functional")... |
63 |
|
public void testIdentify_featureFile() |
64 |
|
throws FileFormatException, FileNotFoundException |
65 |
|
{ |
66 |
0 |
IdentifyFile ider = new IdentifyFile(); |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
0 |
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 |
0 |
assertSame(FileFormat.Features, |
74 |
|
ider.identify(data, DataSourceType.PASTE)); |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
0 |
data = "METAL\tcc9900\n" + "GFF\n" |
80 |
|
+ "FER_CAPAA\tuniprot\tMETAL\t44\t45\t4.0\t.\t.\n"; |
81 |
0 |
assertSame(FileFormat.Features, |
82 |
|
ider.identify(data, DataSourceType.PASTE)); |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
0 |
data = "kD < 3\tred\n" + "Low kD\tFER_CAPAA\t-1\t39\t39\tkD < 3\n"; |
88 |
0 |
assertSame(FileFormat.Features, |
89 |
|
ider.identify(data, DataSourceType.PASTE)); |
90 |
|
} |
91 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
0 |
@DataProvider(name = "identifyFiles")... |
93 |
|
public Object[][] IdentifyFileDP() |
94 |
|
{ |
95 |
0 |
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", |
115 |
|
FileFormat.Fasta }, |
116 |
|
{ "resources/scoreModel/pam250.scm", FileFormat.ScoreMatrix }, |
117 |
|
{ "resources/scoreModel/blosum80.scm", FileFormat.ScoreMatrix } |
118 |
|
|
119 |
|
|
120 |
|
}; |
121 |
|
} |
122 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
4-
|
|
123 |
0 |
@Test(groups = "Functional")... |
124 |
|
public void testLooksLikeFeatureData() |
125 |
|
{ |
126 |
0 |
IdentifyFile id = new IdentifyFile(); |
127 |
0 |
assertFalse(id.looksLikeFeatureData(null)); |
128 |
0 |
assertFalse(id.looksLikeFeatureData("")); |
129 |
|
|
130 |
0 |
assertFalse(id.looksLikeFeatureData("1 \t 2 \t 3 \t 4 \t 5")); |
131 |
|
|
132 |
0 |
assertTrue( |
133 |
|
id.looksLikeFeatureData("Seq1\tlocal\tHelix\t2456\t2462\tss")); |
134 |
|
|
135 |
0 |
assertTrue(id.looksLikeFeatureData("Helix\tSeq1\t-1\t2456\t2462\tss")); |
136 |
|
|
137 |
0 |
assertFalse(id.looksLikeFeatureData("Helix\tSeq1\t-1\t.\t2462\tss")); |
138 |
|
|
139 |
0 |
assertFalse(id.looksLikeFeatureData("Helix\tSeq1\t-1\t2456\t.\tss")); |
140 |
|
} |
141 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.3 |
4-
|
|
142 |
0 |
@Test(groups = "Network", dataProvider = "urlTargetsAndExceptions")... |
143 |
|
public void testExceptions(String url, |
144 |
|
Class<? extends Exception> expectedExceptionClass, |
145 |
|
FileFormatI expectedFormat) |
146 |
|
{ |
147 |
0 |
Class<? extends Exception> actualExceptionClass = null; |
148 |
0 |
FileFormatI actualFormat = null; |
149 |
0 |
try |
150 |
|
{ |
151 |
0 |
actualFormat = new IdentifyFile().identify(url, DataSourceType.URL); |
152 |
|
} catch (FileFormatException | FileNotFoundException e) |
153 |
|
{ |
154 |
0 |
Assert.assertNull(expectedFormat, |
155 |
|
"Exception occurred when expecting an identifiable format."); |
156 |
0 |
Assert.assertNotNull(expectedExceptionClass, |
157 |
|
"An unexpected exception occurred: '" + e.getMessage() + "'"); |
158 |
0 |
Assert.assertEquals(e.getClass(), expectedExceptionClass, |
159 |
|
"Got the wrong kind of exception."); |
160 |
0 |
actualExceptionClass = e.getClass(); |
161 |
|
} |
162 |
|
|
163 |
0 |
if (expectedExceptionClass != null) |
164 |
|
{ |
165 |
0 |
Assert.assertEquals(actualExceptionClass, expectedExceptionClass, |
166 |
|
"Expected an exception but got the wrong one."); |
167 |
|
} |
168 |
|
|
169 |
|
} |
170 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
171 |
0 |
@DataProvider(name = "urlTargetsAndExceptions")... |
172 |
|
public Object[][] urlTargetsAndExceptions() |
173 |
|
{ |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
0 |
return new Object[][] { |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
{ "https://www.jalview.org/schools/Jalview_Schools_Workbook_200.jpg", |
190 |
|
FileFormatException.class, null }, |
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
}; |
195 |
|
} |
196 |
|
|
197 |
|
} |