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.Assert.assertFalse; |
24 |
|
import static org.testng.Assert.assertTrue; |
25 |
|
|
26 |
|
import java.io.BufferedInputStream; |
27 |
|
import java.io.ByteArrayInputStream; |
28 |
|
import java.io.File; |
29 |
|
import java.io.FileInputStream; |
30 |
|
import java.io.IOException; |
31 |
|
import java.io.InputStream; |
32 |
|
import java.io.StringBufferInputStream; |
33 |
|
|
34 |
|
import org.testng.AssertJUnit; |
35 |
|
import org.testng.annotations.AfterClass; |
36 |
|
import org.testng.annotations.BeforeClass; |
37 |
|
import org.testng.annotations.Test; |
38 |
|
|
39 |
|
import jalview.bin.Console; |
40 |
|
import jalview.gui.JvOptionPane; |
41 |
|
|
42 |
|
|
43 |
|
@author |
44 |
|
|
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (40) |
Complexity: 11 |
Complexity Density: 0.38 |
|
46 |
|
public class FileIOTester |
47 |
|
{ |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
49 |
1 |
@BeforeClass(alwaysRun = true)... |
50 |
|
public void setUpJvOptionPane() |
51 |
|
{ |
52 |
1 |
JvOptionPane.setInteractiveMode(false); |
53 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
54 |
|
} |
55 |
|
|
56 |
|
|
57 |
|
@throws |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
1 |
@BeforeClass(alwaysRun = true)... |
60 |
|
public static void setUpBeforeClass() throws Exception |
61 |
|
{ |
62 |
1 |
Console.initLogger(); |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
|
@throws |
67 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
68 |
1 |
@AfterClass(alwaysRun = true)... |
69 |
|
public static void tearDownAfterClass() throws Exception |
70 |
|
{ |
71 |
|
} |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
final static File ALIGN_FILE = new File( |
76 |
|
"test/jalview/io/test_gz_fasta.gz"); |
77 |
|
|
78 |
|
final static File NOTGZALIGN_FILE = new File( |
79 |
|
"test/jalview/io/test_gz_fasta_notgz.gz"); |
80 |
|
|
81 |
|
final static File STARS_FA_FILE1 = new File( |
82 |
|
"test/jalview/io/test_fasta_stars.fa"); |
83 |
|
|
84 |
|
final static File STARS_FA_FILE2 = new File( |
85 |
|
"test/jalview/io/test_fasta_stars2.fa"); |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
87 |
6 |
private void assertValidFormat(FileFormatI fmt, String src, FileParse fp)... |
88 |
|
throws FileFormatException |
89 |
|
{ |
90 |
6 |
AssertJUnit.assertTrue("Couldn't resolve " + src + " as a valid file", |
91 |
|
fp.isValid()); |
92 |
6 |
FileFormatI type = new IdentifyFile().identify(fp); |
93 |
6 |
AssertJUnit.assertSame("Data from '" + src + "' Expected to be '" + fmt |
94 |
|
+ "' identified as '" + type + "'", type, fmt); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
97 |
1 |
@Test(groups = { "Functional" })... |
98 |
|
public void testStarsInFasta1() throws IOException |
99 |
|
{ |
100 |
1 |
String uri; |
101 |
1 |
FileParse fp = new FileParse( |
102 |
|
uri = STARS_FA_FILE1.getAbsoluteFile().toString(), |
103 |
|
DataSourceType.FILE); |
104 |
1 |
assertValidFormat(FileFormat.Fasta, uri, fp); |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
107 |
1 |
@Test(groups = { "Functional" })... |
108 |
|
public void testStarsInFasta2() throws IOException |
109 |
|
{ |
110 |
1 |
String uri; |
111 |
1 |
FileParse fp = new FileParse( |
112 |
|
uri = STARS_FA_FILE2.getAbsoluteFile().toString(), |
113 |
|
DataSourceType.FILE); |
114 |
1 |
assertValidFormat(FileFormat.Fasta, uri, fp); |
115 |
|
} |
116 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
117 |
1 |
@Test(groups = { "Functional" })... |
118 |
|
public void testGzipIo() throws IOException |
119 |
|
{ |
120 |
1 |
String uri; |
121 |
1 |
FileParse fp = new FileParse( |
122 |
|
uri = ALIGN_FILE.getAbsoluteFile().toURI().toString(), |
123 |
|
DataSourceType.URL); |
124 |
1 |
assertValidFormat(FileFormat.Fasta, uri, fp); |
125 |
|
} |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
127 |
1 |
@Test(groups = { "Functional" })... |
128 |
|
public void testGziplocalFileIO() throws IOException |
129 |
|
{ |
130 |
1 |
String filepath; |
131 |
1 |
FileParse fp = new FileParse( |
132 |
|
filepath = ALIGN_FILE.getAbsoluteFile().toString(), |
133 |
|
DataSourceType.FILE); |
134 |
1 |
assertValidFormat(FileFormat.Fasta, filepath, fp); |
135 |
|
} |
136 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
137 |
1 |
@Test(groups = { "Functional" })... |
138 |
|
public void testIsGzipInputStream() throws IOException |
139 |
|
{ |
140 |
1 |
InputStream is = new FileInputStream(ALIGN_FILE); |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
1 |
assertFalse(FileParse.isGzipStream(is)); |
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
1 |
is = new BufferedInputStream(is, 16); |
151 |
1 |
assertTrue(FileParse.isGzipStream(is)); |
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
1 |
assertFalse(FileParse.isGzipStream(new BufferedInputStream( |
157 |
|
new ByteArrayInputStream("NOT A GZIP".getBytes())))); |
158 |
|
} |
159 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
160 |
1 |
@Test(groups = { "Functional" })... |
161 |
|
public void testNonGzipURLIO() throws IOException |
162 |
|
{ |
163 |
1 |
String uri; |
164 |
1 |
FileParse fp = new FileParse( |
165 |
|
uri = NOTGZALIGN_FILE.getAbsoluteFile().toURI().toString(), |
166 |
|
DataSourceType.URL); |
167 |
1 |
assertValidFormat(FileFormat.Fasta, uri, fp); |
168 |
|
} |
169 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
170 |
1 |
@Test(groups = { "Functional" })... |
171 |
|
public void testNonGziplocalFileIO() throws IOException |
172 |
|
{ |
173 |
1 |
String filepath; |
174 |
1 |
FileParse fp = new FileParse( |
175 |
|
filepath = NOTGZALIGN_FILE.getAbsoluteFile().toString(), |
176 |
|
DataSourceType.FILE); |
177 |
1 |
assertValidFormat(FileFormat.Fasta, filepath, fp); |
178 |
|
} |
179 |
|
} |