JAL-3746 apply copyright to tests
[jalview.git] / test / jalview / fts / threedbeacons / TDBeaconsFTSRestClientTest.java
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.fts.api.FTSDataColumnI;
43 import jalview.fts.api.FTSDataColumnI.FTSDataColumnGroupI;
44 import jalview.fts.core.FTSRestClient;
45 import jalview.fts.core.FTSRestRequest;
46 import jalview.fts.core.FTSRestResponse;
47 import jalview.fts.service.pdb.PDBFTSRestClientTest;
48 import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient;
49 import jalview.gui.JvOptionPane;
50
51 public class TDBeaconsFTSRestClientTest
52 {
53   @BeforeClass(alwaysRun = true)
54   public void setUpJvOptionPane()
55   {
56     JvOptionPane.setInteractiveMode(false);
57     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
58   }
59
60   private FTSRestClient ftsRestClient;
61
62   @BeforeMethod(alwaysRun = true)
63   public void setUp() throws Exception
64   {
65     ftsRestClient = new FTSRestClient()
66     {
67
68       @Override
69       public String getColumnDataConfigFileName()
70       {
71         return "/fts/tdbeacons_data_columns.txt";
72       }
73
74       @Override
75       public FTSRestResponse executeRequest(FTSRestRequest ftsRequest)
76               throws Exception
77       {
78         return null;
79       }
80     };
81   }
82
83   @AfterMethod(alwaysRun = true)
84   public void tearDown() throws Exception
85   {
86   }
87
88   @Test
89   public void getAllDefaulDisplayedDataColumns()
90   {
91     // to change when resources.tdbeacons_data_columns.txt is changed
92     Assert.assertNotNull(
93             ftsRestClient.getAllDefaultDisplayedFTSDataColumns());
94     System.out
95             .println(ftsRestClient.getAllDefaultDisplayedFTSDataColumns());
96     Assert.assertTrue(!ftsRestClient.getAllDefaultDisplayedFTSDataColumns()
97             .isEmpty());
98     Assert.assertEquals(
99             ftsRestClient.getAllDefaultDisplayedFTSDataColumns().size(),
100             15);
101   }
102
103   @Test(groups = { "Functional" })
104   public void getPrimaryKeyColumIndexTest()
105   {
106     Collection<FTSDataColumnI> wantedFields = ftsRestClient
107             .getAllDefaultDisplayedFTSDataColumns();
108     int foundIndex = -1;
109     try
110     {
111       Assert.assertEquals(foundIndex, -1);
112       foundIndex = ftsRestClient.getPrimaryKeyColumIndex(wantedFields,
113               false);
114       Assert.assertEquals(foundIndex, 12);
115       foundIndex = ftsRestClient.getPrimaryKeyColumIndex(wantedFields,
116               true);
117       // 1+primary key index
118       Assert.assertEquals(foundIndex, 13);
119     } catch (Exception e)
120     {
121       e.printStackTrace();
122       Assert.fail("Exception thrown while testing...");
123     }
124   }
125
126   @Test(groups = { "Functional" })
127   public void getDataColumnsFieldsAsCommaDelimitedString()
128   {
129     // to change when resources.tdbeacons_data_columns.txt is changed
130     Collection<FTSDataColumnI> wantedFields = ftsRestClient
131             .getAllDefaultDisplayedFTSDataColumns();
132     String actual = ftsRestClient
133             .getDataColumnsFieldsAsCommaDelimitedString(wantedFields);
134     Assert.assertEquals(actual,
135             "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");
136   }
137
138   @Test(groups = { "Functional" })
139   public void getAllFTSDataColumns()
140   {
141     Collection<FTSDataColumnI> allFields = ftsRestClient
142             .getAllFTSDataColumns();
143     Assert.assertNotNull(allFields);
144     // System.out.println(allFields.size());
145     Assert.assertEquals(allFields.size(), 20);
146   }
147
148   @Test(groups = { "Functional" })
149   public void getSearchableDataColumns()
150   {
151     // to change when resources.tdbeacons_data_columns.txt is changed
152     Collection<FTSDataColumnI> searchableFields = ftsRestClient
153             .getSearchableDataColumns();
154     Assert.assertNotNull(searchableFields);
155     // System.out.println(searchableFields.size());
156     Assert.assertEquals(searchableFields.size(), 1); // only 1: uniprot
157                                                      // accession
158   }
159
160   @Test(groups = { "Functional" })
161   public void getPrimaryKeyColumn()
162   {
163     // to change when resources.tdbeacons_data_columns.txt is changed
164     FTSDataColumnI expectedPKColumn;
165     try
166     {
167       expectedPKColumn = ftsRestClient.getDataColumnByNameOrCode("Url");
168       Assert.assertNotNull(ftsRestClient.getPrimaryKeyColumn());
169       Assert.assertEquals(ftsRestClient.getPrimaryKeyColumn(),
170               expectedPKColumn);
171     } catch (Exception e)
172     {
173       e.printStackTrace();
174       Assert.fail("Exception thrown while testing...");
175     }
176   }
177
178   @Test(groups = { "Functional" })
179   public void getDataColumnByNameOrCode()
180   {
181     try
182     {
183       FTSDataColumnI foundDataCol = ftsRestClient
184               .getDataColumnByNameOrCode("uniprot_accession");
185       Assert.assertNotNull(foundDataCol);
186       Assert.assertEquals(foundDataCol.getName(), "UniProt Accession");
187     } catch (Exception e)
188     {
189       e.printStackTrace();
190       Assert.fail("Exception thrown while testing...");
191     }
192   }
193
194   @Test(groups = { "Functional" })
195   public void getDataColumnGroupById()
196   {
197     FTSDataColumnGroupI foundDataColGroup;
198     try
199     {
200       foundDataColGroup = ftsRestClient.getDataColumnGroupById("g2");
201       Assert.assertNotNull(foundDataColGroup);
202       Assert.assertEquals(foundDataColGroup.getName(), "Quality");
203     } catch (Exception e)
204     {
205       e.printStackTrace();
206     }
207   }
208
209   @Test(groups = { "Functional" })
210   public void getDefaultResponsePageSize()
211   {
212     int defaultResSize = ftsRestClient.getDefaultResponsePageSize();
213     Assert.assertEquals(defaultResSize, 100); // why 100 or 500 ? pdb is 100,
214                                               // uniprot 500
215   }
216
217   @Test(groups = { "Functional" })
218   public void getColumnMinWidthTest()
219   {
220     try
221     {
222       FTSDataColumnI foundDataCol = ftsRestClient
223               .getDataColumnByNameOrCode("uniprot_accession");
224       Assert.assertNotNull(foundDataCol);
225       int actualColMinWidth = foundDataCol.getMinWidth();
226       Assert.assertEquals(actualColMinWidth, 50);
227     } catch (Exception e)
228     {
229       e.printStackTrace();
230       Assert.fail("Exception thrown while testing...");
231     }
232   }
233   // could add test for MaxWidth & PreferedWith
234
235   @Test(groups = { "Functional" })
236   public void getColumnClassTest()
237   {
238     try
239     {
240       FTSDataColumnI foundDataCol = ftsRestClient
241               .getDataColumnByNameOrCode("uniprot_accession");
242       Assert.assertNotNull(foundDataCol);
243       Assert.assertEquals(foundDataCol.getDataType().getDataTypeClass(),
244               String.class);
245       foundDataCol = ftsRestClient.getDataColumnByNameOrCode("id");
246       Assert.assertNotNull(foundDataCol);
247       Assert.assertEquals(foundDataCol.getDataType().getDataTypeClass(),
248               String.class);
249     } catch (Exception e)
250     {
251       e.printStackTrace();
252       Assert.fail("Exception thrown while testing...");
253     }
254   }
255
256   @Test(groups = { "Functional" })
257   public void coverageForEqualsAndHashFunction()
258   {
259     Set<FTSDataColumnI> uniqueSet = new HashSet<FTSDataColumnI>();
260     Collection<FTSDataColumnI> searchableCols = ftsRestClient
261             .getSearchableDataColumns();
262     System.out.println(searchableCols);
263     for (FTSDataColumnI foundCol : searchableCols)
264     {
265       System.out.println(foundCol.toString());
266       uniqueSet.add(foundCol);
267       uniqueSet.add(foundCol);
268     }
269     Assert.assertTrue(!uniqueSet.isEmpty());
270     // Assert.assertEquals(uniqueSet.size(), 22); -> 1 or 2 currently for 3DB
271   }
272
273   @Test(groups = { "Functional" })
274   public void getTDBIdColumIndexTest()
275   {
276     List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
277     try
278     {
279       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
280               .getDataColumnByNameOrCode("Model id"));
281       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
282               .getDataColumnByNameOrCode("uniprot_accession"));
283       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
284               .getDataColumnByNameOrCode("Title"));
285     } catch (Exception e)
286     {
287       e.printStackTrace();
288     }
289     try
290     {
291       assertEquals(4, TDBeaconsFTSRestClient.getInstance()
292               .getPrimaryKeyColumIndex(wantedFields, true));
293       // assertEquals(3, TDBeaconsFTSRestClient.getInstance()
294       // .getPrimaryKeyColumIndex(wantedFields, true));
295     } catch (Exception e)
296     {
297       e.printStackTrace();
298     }
299   }
300
301   private static String[][] mocks = { { "P38398.json",
302       "{\"uniprot_entry\":{\"sequence_length\":1863,\"ac\":\"P38398\",\"id\":\"BRCA1_HUMAN\"},\"structures\":[{\"model_identifier\":\"4igk\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2012-12-17\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":1.75,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/4igk_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/4igk\"},{\"model_identifier\":\"1t15\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2004-04-15\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":1.85,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/1t15_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/1t15\"},{\"model_identifier\":\"4ifi\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2012-12-14\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.2,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/4ifi_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/4ifi\"},{\"model_identifier\":\"1t29\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2004-04-20\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.3,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/1t29_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/1t29\"},{\"model_identifier\":\"3pxb\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2010-12-09\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.5,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/3pxb_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/3pxb\"},{\"model_identifier\":\"4y2g\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2015-02-09\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.5,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/4y2g_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/4y2g\"},{\"model_identifier\":\"1y98\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2004-12-14\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.5,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/1y98_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/1y98\"},{\"model_identifier\":\"1jnx\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2001-07-26\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.5,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/1jnx_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/1jnx\"},{\"model_identifier\":\"3pxa\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2010-12-09\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.55,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/3pxa_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/3pxa\"},{\"model_identifier\":\"3k0h\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2009-09-24\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.7,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/3k0h_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/3k0h\"},{\"model_identifier\":\"3k0k\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2009-09-24\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.7,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/3k0k_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/3k0k\"},{\"model_identifier\":\"1n5o\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2002-11-06\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.8,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/1n5o_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/1n5o\"},{\"model_identifier\":\"3pxc\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2010-12-09\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.8,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/3pxc_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/3pxc\"},{\"model_identifier\":\"3pxd\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2010-12-09\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.8,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/3pxd_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/3pxd\"},{\"model_identifier\":\"1t2u\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2004-04-22\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.8,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/1t2u_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/1t2u\"},{\"model_identifier\":\"3k15\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2009-09-25\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.8,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/3k15_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/3k15\"},{\"model_identifier\":\"3pxe\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2010-12-09\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":2.85,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/3pxe_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/3pxe\"},{\"model_identifier\":\"3k16\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2009-09-25\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":3.0,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/3k16_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/3k16\"},{\"model_identifier\":\"4ofb\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2014-01-14\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":3.05,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/4ofb_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/4ofb\"},{\"model_identifier\":\"3coj\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2008-03-28\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":3.21,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/3coj_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/3coj\"},{\"model_identifier\":\"7lyb\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2021-03-06\",\"sequence_identity\":100.0,\"uniprot_start\":1,\"uniprot_end\":100,\"resolution\":3.28,\"coverage\":5.37,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/7lyb_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"ELECTRON MICROSCOPY\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/7lyb\"},{\"model_identifier\":\"1t2v\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2004-04-22\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":3.3,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/1t2v_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/1t2v\"},{\"model_identifier\":\"4y18\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2015-02-06\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":3.5,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/4y18_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/4y18\"},{\"model_identifier\":\"4jlu\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2013-03-13\",\"sequence_identity\":100.0,\"uniprot_start\":1649,\"uniprot_end\":1859,\"resolution\":3.5,\"coverage\":11.33,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/4jlu_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/4jlu\"},{\"model_identifier\":\"4u4a\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2014-07-23\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":3.51,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/4u4a_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/4u4a\"},{\"model_identifier\":\"2ing\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2006-10-07\",\"sequence_identity\":100.0,\"uniprot_start\":1649,\"uniprot_end\":1859,\"resolution\":3.6,\"coverage\":11.33,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/2ing_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"X-RAY DIFFRACTION\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/2ing\"},{\"model_identifier\":\"7jzv\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2020-09-02\",\"sequence_identity\":99.0,\"uniprot_start\":2,\"uniprot_end\":104,\"resolution\":3.9,\"coverage\":5.53,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/7jzv_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"ELECTRON MICROSCOPY\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/7jzv\"},{\"model_identifier\":\"6g2i\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2018-03-23\",\"sequence_identity\":100.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"resolution\":5.9,\"coverage\":11.49,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/6g2i_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"ELECTRON MICROSCOPY\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/6g2i\"},{\"model_identifier\":\"1jm7\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2001-07-17\",\"sequence_identity\":100.0,\"uniprot_start\":1,\"uniprot_end\":110,\"resolution\":null,\"coverage\":5.9,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/1jm7_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"SOLUTION NMR\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/1jm7\"},{\"model_identifier\":\"1oqa\",\"model_category\":\"EXPERIMENTALLY DETERMINED\",\"provider\":\"PDBe\",\"created\":\"2003-03-07\",\"sequence_identity\":100.0,\"uniprot_start\":1755,\"uniprot_end\":1863,\"resolution\":null,\"coverage\":5.85,\"model_url\":\"https://www.ebi.ac.uk/pdbe/static/entry/1oqa_updated.cif\",\"model_format\":\"MMCIF\",\"experimental_method\":\"SOLUTION NMR\",\"model_page_url\":\"https://www.ebi.ac.uk/pdbe/entry/pdb/1oqa\"},{\"model_identifier\":\"P38398_1646-1859:6g2i.1.K\",\"model_category\":\"TEMPLATE-BASED\",\"provider\":\"SWISS-MODEL\",\"created\":\"2021-11-05\",\"sequence_identity\":1.0,\"uniprot_start\":1646,\"uniprot_end\":1859,\"coverage\":0.115,\"confidence_version\":\"4.2.0\",\"confidence_avg_local_score\":0.776,\"model_url\":\"https://swissmodel.expasy.org/3d-beacons/uniprot/P38398.pdb?range=1646-1859&template=6g2i.1.K&provider=swissmodel\",\"model_format\":\"PDB\",\"model_page_url\":\"https://swissmodel.expasy.org/repository/uniprot/P38398?range=1646-1859&template=6g2i.1.K\",\"confidence_type\":\"QMEANDisCo\"},{\"model_identifier\":\"P38398_1-103:1jm7.1.A\",\"model_category\":\"TEMPLATE-BASED\",\"provider\":\"SWISS-MODEL\",\"created\":\"2021-11-05\",\"sequence_identity\":1.0,\"uniprot_start\":1,\"uniprot_end\":103,\"coverage\":0.055,\"confidence_version\":\"4.2.0\",\"confidence_avg_local_score\":0.655,\"model_url\":\"https://swissmodel.expasy.org/3d-beacons/uniprot/P38398.pdb?range=1-103&template=1jm7.1.A&provider=swissmodel\",\"model_format\":\"PDB\",\"model_page_url\":\"https://swissmodel.expasy.org/repository/uniprot/P38398?range=1-103&template=1jm7.1.A\",\"confidence_type\":\"QMEANDisCo\"},{\"model_identifier\":\"AF-P38398-F1\",\"model_category\":\"DEEP-LEARNING\",\"provider\":\"AlphaFold DB\",\"created\":\"2021-07-01\",\"sequence_identity\":1.0,\"uniprot_start\":1,\"uniprot_end\":1863,\"coverage\":100.0,\"model_url\":\"https://alphafold.ebi.ac.uk/files/AF-P38398-F1-model_v1.cif\",\"model_format\":\"MMCIF\",\"model_page_url\":\"https://alphafold.ebi.ac.uk/entry/P38398\"}]}" },
303       { "P01308.json", null } };
304
305   private static void setMockData()
306   {
307     try
308     {
309       mocks[1][1] = PDBFTSRestClientTest.readJsonStringFromFile(
310               "test/jalview/fts/threedbeacons/p01308_tdb_resp.txt");
311     } catch (IOException e)
312     {
313       Assert.fail("Couldn't read mock response data", e);
314     }
315   }
316
317   public static void setMock()
318   {
319     setMockData();
320     FTSRestClient.createMockFTSRestClient(
321             (FTSRestClient) TDBeaconsFTSRestClient.getInstance(), mocks);
322   }
323
324   private static String dev_url = "https://wwwdev.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons/api/uniprot/summary/";
325
326   private static String prod_url = "https://www.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons/api/uniprot/summary/";
327
328   /**
329    * check that the mock request and response are the same as the response from
330    * a live 3D-beacons endpoint
331    * 
332    * Note - servers often have rapidly changing ids / URIs so this might fail,
333    * but the overall structure will remain.
334    * 
335    * @throws Exception
336    */
337   @Test(groups = { "Network", "Integration" })
338   public void verifyMockTDBRequest() throws Exception
339   {
340     setMockData();
341     for (String[] otherMock : mocks)
342     {
343       verifyMockTDBRequest(otherMock[0], otherMock[1]);
344     }
345   }
346
347   private void verifyMockTDBRequest(String mockRequest,
348           String _mockResponse) throws Exception
349   {
350     URL tdb_req = new URL(prod_url + mockRequest);
351     byte[] resp = tdb_req.openStream().readAllBytes();
352     String tresp = new String(resp, StandardCharsets.UTF_8);
353     assertEquals(_mockResponse.trim(), tresp.trim());
354   }
355
356   @Test(groups = { "Functional" })
357   public void testMockTDBRequest()
358   {
359
360     setMock();
361     List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
362     try
363     {
364       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
365               .getDataColumnByNameOrCode("Model Id"));
366       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
367               .getDataColumnByNameOrCode("model_url"));
368       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
369               .getDataColumnByNameOrCode("provider"));
370       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
371               .getDataColumnByNameOrCode("model_category"));
372       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
373               .getDataColumnByNameOrCode("qmean_avg_local_score"));
374       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
375               .getDataColumnByNameOrCode("uniprot_start"));
376       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
377               .getDataColumnByNameOrCode("uniprot_end"));
378     } catch (Exception e1)
379     {
380       e1.printStackTrace();
381     }
382     System.out.println("wantedFields >>" + wantedFields);
383
384     FTSRestRequest request = new FTSRestRequest();
385     FTSRestResponse response;
386
387     request.setResponseSize(100);
388     request.setFieldToSearchBy("");
389     request.setWantedFields(wantedFields);
390     // check 404 behaviour
391     request.setSearchTerm("P00000.json");
392
393     try
394     {
395       response = TDBeaconsFTSRestClient.getInstance()
396               .executeRequest(request);
397
398       assertNull(response);
399     } catch (Exception e)
400     {
401       e.printStackTrace();
402       Assert.fail("Unexpected failure during mock 3DBeacons 404 test");
403     }
404
405     // check 200 behaviour
406     request.setSearchTerm("P38398.json");
407     System.out.println("request : " + request.getFieldToSearchBy());
408     // System.out.println(request.toString());
409
410     try
411     {
412       response = TDBeaconsFTSRestClient.getInstance()
413               .executeRequest(request);
414     } catch (Exception e)
415     {
416       e.printStackTrace();
417       Assert.fail("Couldn't execute webservice call!");
418       return;
419     }
420     assertTrue(response.getSearchSummary() != null);
421     assertTrue(response.getNumberOfItemsFound() > 3); // 4 atm
422     System.out.println("Search summary : \n" + response.getSearchSummary());
423
424     // System.out.println(response.getSearchSummary().size());
425   }
426
427   @Test(groups = { "External", "Network" })
428   public void executeRequestTest()
429   {
430     List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
431     try
432     {
433       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
434               .getDataColumnByNameOrCode("Model Id"));
435       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
436               .getDataColumnByNameOrCode("model_url"));
437       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
438               .getDataColumnByNameOrCode("provider"));
439       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
440               .getDataColumnByNameOrCode("model_category"));
441       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
442               .getDataColumnByNameOrCode("confidence_avg_local_score"));
443       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
444               .getDataColumnByNameOrCode("uniprot_start"));
445       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
446               .getDataColumnByNameOrCode("uniprot_end"));
447     } catch (Exception e1)
448     {
449       e1.printStackTrace();
450     }
451     System.out.println("wantedFields >>" + wantedFields);
452
453     FTSRestRequest request = new FTSRestRequest();
454     request.setResponseSize(100);
455     request.setFieldToSearchBy("");
456     request.setSearchTerm("P01318.json");
457     request.setWantedFields(wantedFields);
458     System.out.println("request : " + request.getFieldToSearchBy());
459     // System.out.println(request.toString());
460
461     FTSRestResponse response;
462     try
463     {
464       response = TDBeaconsFTSRestClient.getInstance()
465               .executeRequest(request);
466     } catch (Exception e)
467     {
468       e.printStackTrace();
469       Assert.fail("Couldn't execute webservice call!");
470       return;
471     }
472     assertTrue(response.getSearchSummary() != null);
473     assertTrue(response.getNumberOfItemsFound() > 3); // 4 atm
474     System.out.println("Search summary : \n" + response.getSearchSummary());
475     // System.out.println(response.getSearchSummary().size());
476   }
477 }