Clover icon

Coverage Report

  1. Project Clover database Tue Mar 10 2026 14:58:44 GMT
  2. Package jalview.fts.threedbeacons

File TDBeaconsFTSRestClientTest.java

 

Code metrics

0
157
24
1
504
404
38
0.24
6.54
24
1.58

Classes

Class Line # Actions
TDBeaconsFTSRestClientTest 57 157 38
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.fts.threedbeacons;
22   
23    import static org.testng.Assert.assertNull;
24    import static org.testng.AssertJUnit.assertEquals;
25    import static org.testng.AssertJUnit.assertTrue;
26   
27    import java.io.IOException;
28    import java.net.URL;
29    import java.nio.charset.StandardCharsets;
30    import java.util.ArrayList;
31    import java.util.Collection;
32    import java.util.HashSet;
33    import java.util.List;
34    import java.util.Set;
35   
36    import org.testng.Assert;
37    import org.testng.annotations.AfterMethod;
38    import org.testng.annotations.BeforeClass;
39    import org.testng.annotations.BeforeMethod;
40    import org.testng.annotations.Test;
41   
42    import jalview.datamodel.Sequence;
43    import jalview.fts.api.FTSData;
44    import jalview.fts.api.FTSDataColumnI;
45    import jalview.fts.api.FTSDataColumnI.FTSDataColumnGroupI;
46    import jalview.fts.core.FTSRestClient;
47    import jalview.fts.core.FTSRestRequest;
48    import jalview.fts.core.FTSRestResponse;
49    import jalview.fts.service.pdb.PDBFTSRestClientTest;
50    import jalview.fts.service.threedbeacons.TDB_FTSData;
51    import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient;
52    import jalview.gui.JvOptionPane;
53    import jalview.gui.structurechooser.PDBStructureChooserQuerySource;
54    import jalview.gui.structurechooser.TDBResultAnalyser;
55    import jalview.gui.structurechooser.ThreeDBStructureChooserQuerySource;
56   
 
57    public class TDBeaconsFTSRestClientTest
58    {
 
59  0 toggle @BeforeClass(alwaysRun = true)
60    public void setUpJvOptionPane()
61    {
62  0 JvOptionPane.setInteractiveMode(false);
63  0 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
64    }
65   
66    private FTSRestClient ftsRestClient;
67   
 
68  0 toggle @BeforeMethod(alwaysRun = true)
69    public void setUp() throws Exception
70    {
71  0 ftsRestClient = new FTSRestClient()
72    {
73   
 
74  0 toggle @Override
75    public String getColumnDataConfigFileName()
76    {
77  0 return "/fts/tdbeacons_data_columns.txt";
78    }
79   
 
80  0 toggle @Override
81    public FTSRestResponse executeRequest(FTSRestRequest ftsRequest)
82    throws Exception
83    {
84  0 return null;
85    }
86    };
87    }
88   
 
89  0 toggle @AfterMethod(alwaysRun = true)
90    public void tearDown() throws Exception
91    {
92    }
93   
 
94  0 toggle @Test
95    public void getAllDefaulDisplayedDataColumns()
96    {
97    // to change when resources.tdbeacons_data_columns.txt is changed
98  0 Assert.assertNotNull(
99    ftsRestClient.getAllDefaultDisplayedFTSDataColumns());
100  0 System.out
101    .println(ftsRestClient.getAllDefaultDisplayedFTSDataColumns());
102  0 Assert.assertTrue(!ftsRestClient.getAllDefaultDisplayedFTSDataColumns()
103    .isEmpty());
104  0 Assert.assertEquals(
105    ftsRestClient.getAllDefaultDisplayedFTSDataColumns().size(),
106    15);
107    }
108   
 
109  0 toggle @Test(groups = { "Functional" })
110    public void getPrimaryKeyColumIndexTest()
111    {
112  0 Collection<FTSDataColumnI> wantedFields = ftsRestClient
113    .getAllDefaultDisplayedFTSDataColumns();
114  0 int foundIndex = -1;
115  0 try
116    {
117  0 Assert.assertEquals(foundIndex, -1);
118  0 foundIndex = ftsRestClient.getPrimaryKeyColumIndex(wantedFields,
119    false);
120  0 Assert.assertEquals(foundIndex, 12);
121  0 foundIndex = ftsRestClient.getPrimaryKeyColumIndex(wantedFields,
122    true);
123    // 1+primary key index
124  0 Assert.assertEquals(foundIndex, 13);
125    } catch (Exception e)
126    {
127  0 e.printStackTrace();
128  0 Assert.fail("Exception thrown while testing...");
129    }
130    }
131   
 
132  0 toggle @Test(groups = { "Functional" })
133    public void getDataColumnsFieldsAsCommaDelimitedString()
134    {
135    // to change when resources.tdbeacons_data_columns.txt is changed
136  0 Collection<FTSDataColumnI> wantedFields = ftsRestClient
137    .getAllDefaultDisplayedFTSDataColumns();
138  0 String actual = ftsRestClient
139    .getDataColumnsFieldsAsCommaDelimitedString(wantedFields);
140  0 Assert.assertEquals(actual,
141    "uniprot_start,uniprot_end,provider,model_identifier,model_category,model_title,resolution,confidence_avg_local_score,confidence_type,confidence_version,coverage,created,model_url,model_format,model_page_url");
142    }
143   
 
144  0 toggle @Test(groups = { "Functional" })
145    public void getAllFTSDataColumns()
146    {
147  0 Collection<FTSDataColumnI> allFields = ftsRestClient
148    .getAllFTSDataColumns();
149  0 Assert.assertNotNull(allFields);
150    // System.out.println(allFields.size());
151  0 Assert.assertEquals(allFields.size(), 20);
152    }
153   
 
154  0 toggle @Test(groups = { "Functional" })
155    public void getSearchableDataColumns()
156    {
157    // to change when resources.tdbeacons_data_columns.txt is changed
158  0 Collection<FTSDataColumnI> searchableFields = ftsRestClient
159    .getSearchableDataColumns();
160  0 Assert.assertNotNull(searchableFields);
161    // System.out.println(searchableFields.size());
162  0 Assert.assertEquals(searchableFields.size(), 1); // only 1: uniprot
163    // accession
164    }
165   
 
166  0 toggle @Test(groups = { "Functional" })
167    public void getPrimaryKeyColumn()
168    {
169    // to change when resources.tdbeacons_data_columns.txt is changed
170  0 FTSDataColumnI expectedPKColumn;
171  0 try
172    {
173  0 expectedPKColumn = ftsRestClient.getDataColumnByNameOrCode("Url");
174  0 Assert.assertNotNull(ftsRestClient.getPrimaryKeyColumn());
175  0 Assert.assertEquals(ftsRestClient.getPrimaryKeyColumn(),
176    expectedPKColumn);
177    } catch (Exception e)
178    {
179  0 e.printStackTrace();
180  0 Assert.fail("Exception thrown while testing...");
181    }
182    }
183   
 
184  0 toggle @Test(groups = { "Functional" })
185    public void getDataColumnByNameOrCode()
186    {
187  0 try
188    {
189  0 FTSDataColumnI foundDataCol = ftsRestClient
190    .getDataColumnByNameOrCode("uniprot_accession");
191  0 Assert.assertNotNull(foundDataCol);
192  0 Assert.assertEquals(foundDataCol.getName(), "UniProt Accession");
193    } catch (Exception e)
194    {
195  0 e.printStackTrace();
196  0 Assert.fail("Exception thrown while testing...");
197    }
198    }
199   
 
200  0 toggle @Test(groups = { "Functional" })
201    public void getDataColumnGroupById()
202    {
203  0 FTSDataColumnGroupI foundDataColGroup;
204  0 try
205    {
206  0 foundDataColGroup = ftsRestClient.getDataColumnGroupById("g2");
207  0 Assert.assertNotNull(foundDataColGroup);
208  0 Assert.assertEquals(foundDataColGroup.getName(), "Quality");
209    } catch (Exception e)
210    {
211  0 e.printStackTrace();
212    }
213    }
214   
 
215  0 toggle @Test(groups = { "Functional" })
216    public void getDefaultResponsePageSize()
217    {
218  0 int defaultResSize = ftsRestClient.getDefaultResponsePageSize();
219  0 Assert.assertEquals(defaultResSize, 100); // why 100 or 500 ? pdb is 100,
220    // uniprot 500
221    }
222   
 
223  0 toggle @Test(groups = { "Functional" })
224    public void getColumnMinWidthTest()
225    {
226  0 try
227    {
228  0 FTSDataColumnI foundDataCol = ftsRestClient
229    .getDataColumnByNameOrCode("uniprot_accession");
230  0 Assert.assertNotNull(foundDataCol);
231  0 int actualColMinWidth = foundDataCol.getMinWidth();
232  0 Assert.assertEquals(actualColMinWidth, 50);
233    } catch (Exception e)
234    {
235  0 e.printStackTrace();
236  0 Assert.fail("Exception thrown while testing...");
237    }
238    }
239    // could add test for MaxWidth & PreferedWith
240   
 
241  0 toggle @Test(groups = { "Functional" })
242    public void getColumnClassTest()
243    {
244  0 try
245    {
246  0 FTSDataColumnI foundDataCol = ftsRestClient
247    .getDataColumnByNameOrCode("uniprot_accession");
248  0 Assert.assertNotNull(foundDataCol);
249  0 Assert.assertEquals(foundDataCol.getDataType().getDataTypeClass(),
250    String.class);
251  0 foundDataCol = ftsRestClient.getDataColumnByNameOrCode("id");
252  0 Assert.assertNotNull(foundDataCol);
253  0 Assert.assertEquals(foundDataCol.getDataType().getDataTypeClass(),
254    String.class);
255    } catch (Exception e)
256    {
257  0 e.printStackTrace();
258  0 Assert.fail("Exception thrown while testing...");
259    }
260    }
261   
 
262  0 toggle @Test(groups = { "Functional" })
263    public void coverageForEqualsAndHashFunction()
264    {
265  0 Set<FTSDataColumnI> uniqueSet = new HashSet<FTSDataColumnI>();
266  0 Collection<FTSDataColumnI> searchableCols = ftsRestClient
267    .getSearchableDataColumns();
268  0 System.out.println(searchableCols);
269  0 for (FTSDataColumnI foundCol : searchableCols)
270    {
271  0 System.out.println(foundCol.toString());
272  0 uniqueSet.add(foundCol);
273  0 uniqueSet.add(foundCol);
274    }
275  0 Assert.assertTrue(!uniqueSet.isEmpty());
276    // Assert.assertEquals(uniqueSet.size(), 22); -> 1 or 2 currently for 3DB
277    }
278   
 
279  0 toggle @Test(groups = { "Functional" })
280    public void getTDBIdColumIndexTest()
281    {
282  0 List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
283  0 try
284    {
285  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
286    .getDataColumnByNameOrCode("Model id"));
287  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
288    .getDataColumnByNameOrCode("uniprot_accession"));
289  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
290    .getDataColumnByNameOrCode("Title"));
291    } catch (Exception e)
292    {
293  0 e.printStackTrace();
294    }
295  0 try
296    {
297  0 assertEquals(4, TDBeaconsFTSRestClient.getInstance()
298    .getPrimaryKeyColumIndex(wantedFields, true));
299    // assertEquals(3, TDBeaconsFTSRestClient.getInstance()
300    // .getPrimaryKeyColumIndex(wantedFields, true));
301    } catch (Exception e)
302    {
303  0 e.printStackTrace();
304    }
305    }
306   
307    private static String[][] mocks = { { "P38398.json", null },
308    { "P01308.json", null },
309    { "P0DTD1.json", null },
310    { "P27787.json", null },
311    { "Q99814.json", null }
312   
313    // , { "P0DTD3.json", "{}" } actually results in 404, but {} is in body
314    };
315   
 
316  0 toggle private static void setMockData()
317    {
318  0 try
319    {
320  0 mocks[0][1] = PDBFTSRestClientTest.readJsonStringFromFile(
321    "test/jalview/fts/threedbeacons/p38398_tdb_fts_query_resp.txt");
322   
323  0 mocks[1][1] = PDBFTSRestClientTest.readJsonStringFromFile(
324    "test/jalview/fts/threedbeacons/p01308_tdb_fts_query_resp.txt");
325   
326  0 mocks[2][1] = PDBFTSRestClientTest.readJsonStringFromFile(
327    "test/jalview/fts/threedbeacons/p0dtd1_tdb_fts_query_resp.txt");
328   
329  0 mocks[3][1] = PDBFTSRestClientTest.readJsonStringFromFile(
330    "test/jalview/fts/threedbeacons/p27787_tdb_fts_query_resp.txt");
331  0 mocks[4][1] = PDBFTSRestClientTest.readJsonStringFromFile(
332    "test/jalview/fts/threedbeacons/q99814_tdb_fts_query_resp.txt");
333   
334    } catch (IOException e)
335    {
336  0 Assert.fail("Couldn't read mock response data", e);
337    }
338    }
339   
 
340  0 toggle public static void setMock()
341    {
342  0 setMockData();
343  0 FTSRestClient.createMockFTSRestClient(
344    (FTSRestClient) TDBeaconsFTSRestClient.getInstance(), mocks);
345    }
346   
347    private static String dev_url = "https://wwwdev.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons/api/uniprot/summary/";
348   
349    private static String prod_url = "https://www.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons/api/uniprot/summary/";
350   
351    /**
352    * check that the mock request and response are the same as the response from
353    * a live 3D-beacons endpoint
354    *
355    * Note - servers often have rapidly changing ids / URIs so this might fail,
356    * but the overall structure will remain.
357    *
358    * @throws Exception
359    */
 
360  0 toggle @Test(groups = { "Network", "Integration" })
361    public void verifyMockTDBRequest() throws Exception
362    {
363  0 setMockData();
364  0 for (String[] otherMock : mocks)
365    {
366  0 verifyMockTDBRequest(otherMock[0], otherMock[1]);
367    }
368    }
369   
 
370  0 toggle private void verifyMockTDBRequest(String mockRequest,
371    String _mockResponse) throws Exception
372    {
373  0 URL tdb_req = new URL(prod_url + mockRequest);
374  0 byte[] resp = tdb_req.openStream().readAllBytes();
375  0 String tresp = new String(resp, StandardCharsets.UTF_8);
376    // this simple test fails for responses containing multi-chain structures -
377    // since chain order in the json elements is arbitrary and varies between
378    // queries.
379  0 assertEquals(_mockResponse.trim(), tresp.trim());
380    }
381   
 
382  0 toggle @Test(groups = { "Functional" })
383    public void testMockTDBRequest()
384    {
385   
386  0 setMock();
387  0 List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
388  0 try
389    {
390  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
391    .getDataColumnByNameOrCode("Model Id"));
392  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
393    .getDataColumnByNameOrCode("model_url"));
394  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
395    .getDataColumnByNameOrCode("provider"));
396  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
397    .getDataColumnByNameOrCode("model_category"));
398  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
399    .getDataColumnByNameOrCode("qmean_avg_local_score"));
400  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
401    .getDataColumnByNameOrCode("uniprot_start"));
402  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
403    .getDataColumnByNameOrCode("uniprot_end"));
404    } catch (Exception e1)
405    {
406  0 e1.printStackTrace();
407    }
408  0 System.out.println("wantedFields >>" + wantedFields);
409   
410  0 FTSRestRequest request = new FTSRestRequest();
411  0 FTSRestResponse response;
412   
413  0 request.setResponseSize(100);
414  0 request.setFieldToSearchBy("");
415  0 request.setWantedFields(wantedFields);
416    // check 404 behaviour
417  0 request.setSearchTerm("P00000.json");
418   
419  0 try
420    {
421  0 response = TDBeaconsFTSRestClient.getInstance()
422    .executeRequest(request);
423   
424  0 assertNull(response);
425    } catch (Exception e)
426    {
427  0 e.printStackTrace();
428  0 Assert.fail("Unexpected failure during mock 3DBeacons 404 test");
429    }
430   
431    // check 200 behaviour
432  0 request.setSearchTerm("P38398.json");
433  0 System.out.println("request : " + request.getFieldToSearchBy());
434    // System.out.println(request.toString());
435   
436  0 try
437    {
438  0 response = TDBeaconsFTSRestClient.getInstance()
439    .executeRequest(request);
440    } catch (Exception e)
441    {
442  0 e.printStackTrace();
443  0 Assert.fail("Couldn't execute webservice call!");
444  0 return;
445    }
446  0 assertTrue(response.getSearchSummary() != null);
447  0 assertTrue(response.getNumberOfItemsFound() > 3); // 4 atm
448  0 System.out.println("Search summary : \n" + response.getSearchSummary());
449   
450    // System.out.println(response.getSearchSummary().size());
451    }
452   
 
453  0 toggle @Test(groups = { "External", "Network" })
454    public void executeRequestTest()
455    {
456  0 List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
457  0 try
458    {
459  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
460    .getDataColumnByNameOrCode("Model Id"));
461  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
462    .getDataColumnByNameOrCode("model_url"));
463  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
464    .getDataColumnByNameOrCode("provider"));
465  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
466    .getDataColumnByNameOrCode("model_category"));
467  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
468    .getDataColumnByNameOrCode("confidence_avg_local_score"));
469  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
470    .getDataColumnByNameOrCode("uniprot_start"));
471  0 wantedFields.add(TDBeaconsFTSRestClient.getInstance()
472    .getDataColumnByNameOrCode("uniprot_end"));
473    } catch (Exception e1)
474    {
475  0 e1.printStackTrace();
476    }
477  0 System.out.println("wantedFields >>" + wantedFields);
478   
479  0 FTSRestRequest request = new FTSRestRequest();
480  0 request.setResponseSize(100);
481  0 request.setFieldToSearchBy("");
482  0 request.setSearchTerm("P01318.json");
483  0 request.setWantedFields(wantedFields);
484  0 System.out.println("request : " + request.getFieldToSearchBy());
485    // System.out.println(request.toString());
486   
487  0 FTSRestResponse response;
488  0 try
489    {
490  0 response = TDBeaconsFTSRestClient.getInstance()
491    .executeRequest(request);
492    } catch (Exception e)
493    {
494  0 e.printStackTrace();
495  0 Assert.fail("Couldn't execute webservice call!");
496  0 return;
497    }
498  0 assertTrue(response.getSearchSummary() != null);
499  0 assertTrue(response.getNumberOfItemsFound() > 3); // 4 atm
500  0 System.out.println("Search summary : \n" + response.getSearchSummary());
501    // System.out.println(response.getSearchSummary().size());
502    }
503   
504    }