1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.fts.core; |
22 |
|
|
23 |
|
import jalview.fts.api.FTSDataColumnI; |
24 |
|
import jalview.fts.api.FTSDataColumnI.FTSDataColumnGroupI; |
25 |
|
import jalview.gui.JvOptionPane; |
26 |
|
|
27 |
|
import java.util.Collection; |
28 |
|
import java.util.HashSet; |
29 |
|
import java.util.Set; |
30 |
|
|
31 |
|
import org.testng.Assert; |
32 |
|
import org.testng.annotations.BeforeClass; |
33 |
|
import org.testng.annotations.BeforeMethod; |
34 |
|
import org.testng.annotations.Test; |
35 |
|
|
|
|
| 86% |
Uncovered Elements: 18 (129) |
Complexity: 31 |
Complexity Density: 0.28 |
|
36 |
|
public class FTSRestClientTest |
37 |
|
{ |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
39 |
1 |
@BeforeClass(alwaysRun = true)... |
40 |
|
public void setUpJvOptionPane() |
41 |
|
{ |
42 |
1 |
JvOptionPane.setInteractiveMode(false); |
43 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
44 |
|
} |
45 |
|
|
46 |
|
private FTSRestClient ftsRestClient; |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
48 |
16 |
@BeforeMethod(alwaysRun = true)... |
49 |
|
public void setup() |
50 |
|
{ |
51 |
16 |
ftsRestClient = new FTSRestClient() |
52 |
|
{ |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
16 |
@Override... |
55 |
|
public String getColumnDataConfigFileName() |
56 |
|
{ |
57 |
16 |
return "/fts/uniprot_data_columns.txt"; |
58 |
|
} |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
0 |
@Override... |
61 |
|
public FTSRestResponse executeRequest(FTSRestRequest ftsRequest) |
62 |
|
throws Exception |
63 |
|
{ |
64 |
0 |
return null; |
65 |
|
} |
66 |
|
}; |
67 |
|
} |
68 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
1PASS
|
|
69 |
1 |
@Test(groups = { "Functional" })... |
70 |
|
public void getPrimaryKeyColumIndexTest() |
71 |
|
{ |
72 |
1 |
Collection<FTSDataColumnI> wantedFields = ftsRestClient |
73 |
|
.getAllDefaultDisplayedFTSDataColumns(); |
74 |
1 |
int foundIndex = -1; |
75 |
1 |
try |
76 |
|
{ |
77 |
1 |
Assert.assertEquals(foundIndex, -1); |
78 |
1 |
foundIndex = ftsRestClient.getPrimaryKeyColumIndex(wantedFields, |
79 |
|
false); |
80 |
1 |
Assert.assertEquals(foundIndex, 0); |
81 |
1 |
foundIndex = ftsRestClient.getPrimaryKeyColumIndex(wantedFields, |
82 |
|
true); |
83 |
1 |
Assert.assertEquals(foundIndex, 1); |
84 |
|
} catch (Exception e) |
85 |
|
{ |
86 |
0 |
e.printStackTrace(); |
87 |
0 |
Assert.fail("Exception thrown while testing..."); |
88 |
|
} |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
91 |
1 |
@Test(groups = { "Functional" })... |
92 |
|
public void getAllDefaulDisplayedDataColumns() |
93 |
|
{ |
94 |
1 |
Assert.assertNotNull( |
95 |
|
ftsRestClient.getAllDefaultDisplayedFTSDataColumns()); |
96 |
1 |
Assert.assertTrue(!ftsRestClient.getAllDefaultDisplayedFTSDataColumns() |
97 |
|
.isEmpty()); |
98 |
1 |
Assert.assertEquals( |
99 |
|
ftsRestClient.getAllDefaultDisplayedFTSDataColumns().size(), 7); |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
102 |
1 |
@Test(groups = { "Functional" })... |
103 |
|
public void getDataColumnsFieldsAsCommaDelimitedString() |
104 |
|
{ |
105 |
1 |
Collection<FTSDataColumnI> wantedFields = ftsRestClient |
106 |
|
.getAllDefaultDisplayedFTSDataColumns(); |
107 |
1 |
String actual = ftsRestClient |
108 |
|
.getDataColumnsFieldsAsCommaDelimitedString(wantedFields); |
109 |
1 |
Assert.assertEquals(actual, |
110 |
|
"id,entry name,protein names,genes,organism,reviewed,length"); |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
113 |
1 |
@Test(groups = { "Functional" })... |
114 |
|
public void getAllFTSDataColumns() |
115 |
|
{ |
116 |
1 |
Collection<FTSDataColumnI> allFields = ftsRestClient |
117 |
|
.getAllFTSDataColumns(); |
118 |
1 |
Assert.assertNotNull(allFields); |
119 |
1 |
Assert.assertEquals(allFields.size(), 117); |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
122 |
1 |
@Test(groups = { "Functional" })... |
123 |
|
public void getSearchableDataColumns() |
124 |
|
{ |
125 |
1 |
Collection<FTSDataColumnI> searchalbeFields = ftsRestClient |
126 |
|
.getSearchableDataColumns(); |
127 |
1 |
Assert.assertNotNull(searchalbeFields); |
128 |
1 |
Assert.assertEquals(searchalbeFields.size(), 22); |
129 |
|
} |
130 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
131 |
1 |
@Test(groups = { "Functional" })... |
132 |
|
public void getPrimaryKeyColumn() |
133 |
|
{ |
134 |
1 |
FTSDataColumnI expectedPKColumn; |
135 |
1 |
try |
136 |
|
{ |
137 |
1 |
expectedPKColumn = ftsRestClient |
138 |
|
.getDataColumnByNameOrCode("Uniprot Id"); |
139 |
1 |
Assert.assertNotNull(ftsRestClient.getPrimaryKeyColumn()); |
140 |
1 |
Assert.assertEquals(ftsRestClient.getPrimaryKeyColumn(), |
141 |
|
expectedPKColumn); |
142 |
|
} catch (Exception e) |
143 |
|
{ |
144 |
0 |
e.printStackTrace(); |
145 |
0 |
Assert.fail("Exception thrown while testing..."); |
146 |
|
} |
147 |
|
} |
148 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
1PASS
|
|
149 |
1 |
@Test(groups = { "Functional" })... |
150 |
|
public void getDataColumnByNameOrCode() |
151 |
|
{ |
152 |
1 |
try |
153 |
|
{ |
154 |
1 |
FTSDataColumnI foundDataCol = ftsRestClient |
155 |
|
.getDataColumnByNameOrCode("genes"); |
156 |
1 |
Assert.assertNotNull(foundDataCol); |
157 |
1 |
Assert.assertEquals(foundDataCol.getName(), "Gene Names"); |
158 |
|
} catch (Exception e) |
159 |
|
{ |
160 |
0 |
e.printStackTrace(); |
161 |
0 |
Assert.fail("Exception thrown while testing..."); |
162 |
|
} |
163 |
|
} |
164 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
1PASS
|
|
165 |
1 |
@Test(groups = { "Functional" })... |
166 |
|
public void getDataColumnGroupById() |
167 |
|
{ |
168 |
1 |
FTSDataColumnGroupI foundDataColGroup; |
169 |
1 |
try |
170 |
|
{ |
171 |
1 |
foundDataColGroup = ftsRestClient.getDataColumnGroupById("g3"); |
172 |
1 |
Assert.assertNotNull(foundDataColGroup); |
173 |
1 |
Assert.assertEquals(foundDataColGroup.getName(), "Names & Taxonomy"); |
174 |
|
} catch (Exception e) |
175 |
|
{ |
176 |
0 |
e.printStackTrace(); |
177 |
|
} |
178 |
|
} |
179 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
180 |
1 |
@Test(groups = { "Functional" })... |
181 |
|
public void getDefaultResponsePageSize() |
182 |
|
{ |
183 |
1 |
int defaultResSize = ftsRestClient.getDefaultResponsePageSize(); |
184 |
1 |
Assert.assertEquals(defaultResSize, 500); |
185 |
|
} |
186 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
187 |
1 |
@Test(groups = { "Functional" })... |
188 |
|
public void getColumnMinWidthTest() |
189 |
|
{ |
190 |
1 |
try |
191 |
|
{ |
192 |
1 |
FTSDataColumnI foundDataCol = ftsRestClient |
193 |
|
.getDataColumnByNameOrCode("Protein names"); |
194 |
1 |
Assert.assertNotNull(foundDataCol); |
195 |
1 |
int actualColMinWidth = foundDataCol.getMinWidth(); |
196 |
1 |
Assert.assertEquals(actualColMinWidth, 300); |
197 |
|
} catch (Exception e) |
198 |
|
{ |
199 |
0 |
e.printStackTrace(); |
200 |
0 |
Assert.fail("Exception thrown while testing..."); |
201 |
|
} |
202 |
|
} |
203 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
204 |
1 |
@Test(groups = { "Functional" })... |
205 |
|
public void getColumnMaxWidthTest() |
206 |
|
{ |
207 |
1 |
try |
208 |
|
{ |
209 |
1 |
FTSDataColumnI foundDataCol = ftsRestClient |
210 |
|
.getDataColumnByNameOrCode("Protein names"); |
211 |
1 |
Assert.assertNotNull(foundDataCol); |
212 |
1 |
int actualColMinWidth = foundDataCol.getMaxWidth(); |
213 |
1 |
Assert.assertEquals(actualColMinWidth, 1500); |
214 |
|
} catch (Exception e) |
215 |
|
{ |
216 |
0 |
e.printStackTrace(); |
217 |
0 |
Assert.fail("Exception thrown while testing..."); |
218 |
|
} |
219 |
|
} |
220 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
221 |
1 |
@Test(groups = { "Functional" })... |
222 |
|
public void getColumnPreferredWidthTest() |
223 |
|
{ |
224 |
1 |
try |
225 |
|
{ |
226 |
1 |
FTSDataColumnI foundDataCol = ftsRestClient |
227 |
|
.getDataColumnByNameOrCode("Protein names"); |
228 |
1 |
Assert.assertNotNull(foundDataCol); |
229 |
1 |
int actualColMinWidth = foundDataCol.getPreferredWidth(); |
230 |
1 |
Assert.assertEquals(actualColMinWidth, 500); |
231 |
|
} catch (Exception e) |
232 |
|
{ |
233 |
0 |
e.printStackTrace(); |
234 |
0 |
Assert.fail("Exception thrown while testing..."); |
235 |
|
} |
236 |
|
} |
237 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
1PASS
|
|
238 |
1 |
@Test(groups = { "Functional" })... |
239 |
|
public void getColumnClassTest() |
240 |
|
{ |
241 |
1 |
try |
242 |
|
{ |
243 |
1 |
FTSDataColumnI foundDataCol = ftsRestClient |
244 |
|
.getDataColumnByNameOrCode("Protein names"); |
245 |
1 |
Assert.assertNotNull(foundDataCol); |
246 |
1 |
Assert.assertEquals(foundDataCol.getDataType().getDataTypeClass(), |
247 |
|
String.class); |
248 |
1 |
foundDataCol = ftsRestClient.getDataColumnByNameOrCode("length"); |
249 |
1 |
Assert.assertNotNull(foundDataCol); |
250 |
1 |
Assert.assertEquals(foundDataCol.getDataType().getDataTypeClass(), |
251 |
|
Integer.class); |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
} catch (Exception e) |
256 |
|
{ |
257 |
0 |
e.printStackTrace(); |
258 |
0 |
Assert.fail("Exception thrown while testing..."); |
259 |
|
} |
260 |
|
} |
261 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
262 |
1 |
@Test(groups = { "Functional" })... |
263 |
|
public void coverageForEqualsAndHashFunction() |
264 |
|
{ |
265 |
1 |
Set<FTSDataColumnI> uniqueSet = new HashSet<FTSDataColumnI>(); |
266 |
1 |
Collection<FTSDataColumnI> searchableCols = ftsRestClient |
267 |
|
.getSearchableDataColumns(); |
268 |
1 |
for (FTSDataColumnI foundCol : searchableCols) |
269 |
|
{ |
270 |
22 |
System.out.println(foundCol.toString()); |
271 |
22 |
uniqueSet.add(foundCol); |
272 |
22 |
uniqueSet.add(foundCol); |
273 |
|
} |
274 |
1 |
Assert.assertTrue(!uniqueSet.isEmpty()); |
275 |
1 |
Assert.assertEquals(uniqueSet.size(), 22); |
276 |
|
} |
277 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 2 |
Complexity Density: 0.18 |
1PASS
|
|
278 |
1 |
@Test(groups = { "Functional" })... |
279 |
|
public void coverageForMiscellaneousBranches() |
280 |
|
{ |
281 |
1 |
String actual = ftsRestClient.getPrimaryKeyColumn().toString(); |
282 |
1 |
Assert.assertEquals(actual, "Uniprot Id"); |
283 |
|
|
284 |
1 |
String actualGroupStr; |
285 |
1 |
try |
286 |
|
{ |
287 |
1 |
actualGroupStr = ftsRestClient.getDataColumnGroupById("g4") |
288 |
|
.toString(); |
289 |
1 |
Assert.assertEquals(actualGroupStr, "Procedures & Softwares"); |
290 |
1 |
actualGroupStr = ftsRestClient |
291 |
|
.getDataColumnGroupById("unavailable group").toString(); |
292 |
|
} catch (Exception e) |
293 |
|
{ |
294 |
1 |
Assert.assertTrue(true); |
295 |
|
} |
296 |
|
|
297 |
1 |
String actualResourseFile = ftsRestClient |
298 |
|
.getResourceFile("/fts/uniprot_data_columns.txt"); |
299 |
1 |
Assert.assertNotNull(actualResourseFile); |
300 |
1 |
Assert.assertTrue(actualResourseFile.length() > 31); |
301 |
|
} |
302 |
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 3 |
Complexity Density: 0.25 |
1PASS
|
|
303 |
1 |
@Test(groups = { "Functional" }, expectedExceptions = Exception.class)... |
304 |
|
public void coverageForExceptionBranches() throws Exception |
305 |
|
{ |
306 |
1 |
try |
307 |
|
{ |
308 |
1 |
ftsRestClient.getDataColumnByNameOrCode("unavailable column"); |
309 |
|
} catch (Exception e) |
310 |
|
{ |
311 |
1 |
System.out.println(e.getMessage()); |
312 |
1 |
String expectedMessage = "Couldn't find data column with name : unavailable column"; |
313 |
1 |
Assert.assertEquals(e.getMessage(), expectedMessage); |
314 |
|
} |
315 |
1 |
try |
316 |
|
{ |
317 |
1 |
ftsRestClient.getDataColumnGroupById("unavailable column group Id"); |
318 |
|
} catch (Exception e) |
319 |
|
{ |
320 |
1 |
System.out.println(e.getMessage()); |
321 |
1 |
String expectedMessage = "Couldn't find data column group with id : unavailable column group Id"; |
322 |
1 |
Assert.assertEquals(e.getMessage(), expectedMessage); |
323 |
|
} |
324 |
|
|
325 |
1 |
ftsRestClient.getDataColumnByNameOrCode("unavailable column"); |
326 |
|
|
327 |
0 |
ftsRestClient.getResourceFile("unavailable resource file"); |
328 |
|
|
329 |
|
} |
330 |
|
|
331 |
|
} |