+
+ @Test(groups = { "Functional" })
+ public void getDataColumnsFieldsAsCommaDelimitedString()
+ {
+ // to change when resources.tdbeacons_data_columns.txt is changed
+ Collection<FTSDataColumnI> wantedFields = ftsRestClient
+ .getAllDefaultDisplayedFTSDataColumns();
+ String actual = ftsRestClient
+ .getDataColumnsFieldsAsCommaDelimitedString(wantedFields);
+ Assert.assertEquals(actual,
+ "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");
+ }
+
+ @Test(groups = { "Functional" })
+ public void getAllFTSDataColumns()
+ {
+ Collection<FTSDataColumnI> allFields = ftsRestClient
+ .getAllFTSDataColumns();
+ Assert.assertNotNull(allFields);
+ // System.out.println(allFields.size());
+ Assert.assertEquals(allFields.size(), 20);
+ }
+
+ @Test(groups = { "Functional" })
+ public void getSearchableDataColumns()
+ {
+ // to change when resources.tdbeacons_data_columns.txt is changed
+ Collection<FTSDataColumnI> searchableFields = ftsRestClient
+ .getSearchableDataColumns();
+ Assert.assertNotNull(searchableFields);
+ // System.out.println(searchableFields.size());
+ Assert.assertEquals(searchableFields.size(), 1); // only 1: uniprot
+ // accession
+ }
+
+ @Test(groups = { "Functional" })
+ public void getPrimaryKeyColumn()
+ {
+ // to change when resources.tdbeacons_data_columns.txt is changed
+ FTSDataColumnI expectedPKColumn;
+ try
+ {
+ expectedPKColumn = ftsRestClient.getDataColumnByNameOrCode("Url");
+ Assert.assertNotNull(ftsRestClient.getPrimaryKeyColumn());
+ Assert.assertEquals(ftsRestClient.getPrimaryKeyColumn(),
+ expectedPKColumn);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ Assert.fail("Exception thrown while testing...");
+ }
+ }
+
+ @Test(groups = { "Functional" })
+ public void getDataColumnByNameOrCode()
+ {
+ try
+ {
+ FTSDataColumnI foundDataCol = ftsRestClient
+ .getDataColumnByNameOrCode("uniprot_accession");
+ Assert.assertNotNull(foundDataCol);
+ Assert.assertEquals(foundDataCol.getName(), "UniProt Accession");
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ Assert.fail("Exception thrown while testing...");
+ }
+ }
+
+ @Test(groups = { "Functional" })
+ public void getDataColumnGroupById()
+ {
+ FTSDataColumnGroupI foundDataColGroup;
+ try
+ {
+ foundDataColGroup = ftsRestClient.getDataColumnGroupById("g2");
+ Assert.assertNotNull(foundDataColGroup);
+ Assert.assertEquals(foundDataColGroup.getName(), "Quality");
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ @Test(groups = { "Functional" })
+ public void getDefaultResponsePageSize()
+ {
+ int defaultResSize = ftsRestClient.getDefaultResponsePageSize();
+ Assert.assertEquals(defaultResSize, 100); // why 100 or 500 ? pdb is 100,
+ // uniprot 500
+ }
+
+ @Test(groups = { "Functional" })
+ public void getColumnMinWidthTest()
+ {
+ try
+ {
+ FTSDataColumnI foundDataCol = ftsRestClient
+ .getDataColumnByNameOrCode("uniprot_accession");
+ Assert.assertNotNull(foundDataCol);
+ int actualColMinWidth = foundDataCol.getMinWidth();
+ Assert.assertEquals(actualColMinWidth, 50);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ Assert.fail("Exception thrown while testing...");
+ }
+ }
+ // could add test for MaxWidth & PreferedWith
+
+ @Test(groups = { "Functional" })
+ public void getColumnClassTest()
+ {
+ try
+ {
+ FTSDataColumnI foundDataCol = ftsRestClient
+ .getDataColumnByNameOrCode("uniprot_accession");
+ Assert.assertNotNull(foundDataCol);
+ Assert.assertEquals(foundDataCol.getDataType().getDataTypeClass(),
+ String.class);
+ foundDataCol = ftsRestClient.getDataColumnByNameOrCode("id");
+ Assert.assertNotNull(foundDataCol);
+ Assert.assertEquals(foundDataCol.getDataType().getDataTypeClass(),
+ String.class);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ Assert.fail("Exception thrown while testing...");
+ }
+ }
+
+ @Test(groups = { "Functional" })
+ public void coverageForEqualsAndHashFunction()
+ {
+ Set<FTSDataColumnI> uniqueSet = new HashSet<FTSDataColumnI>();
+ Collection<FTSDataColumnI> searchableCols = ftsRestClient
+ .getSearchableDataColumns();
+ System.out.println(searchableCols);
+ for (FTSDataColumnI foundCol : searchableCols)
+ {
+ System.out.println(foundCol.toString());
+ uniqueSet.add(foundCol);
+ uniqueSet.add(foundCol);
+ }
+ Assert.assertTrue(!uniqueSet.isEmpty());
+ // Assert.assertEquals(uniqueSet.size(), 22); -> 1 or 2 currently for 3DB
+ }
+
+ @Test(groups = { "Functional" })
+ public void getTDBIdColumIndexTest()
+ {
+ List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
+ try
+ {
+ wantedFields.add(TDBeaconsFTSRestClient.getInstance()
+ .getDataColumnByNameOrCode("Model id"));
+ wantedFields.add(TDBeaconsFTSRestClient.getInstance()
+ .getDataColumnByNameOrCode("uniprot_accession"));
+ wantedFields.add(TDBeaconsFTSRestClient.getInstance()
+ .getDataColumnByNameOrCode("Title"));
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ try
+ {
+ assertEquals(4, TDBeaconsFTSRestClient.getInstance()
+ .getPrimaryKeyColumIndex(wantedFields, true));
+ // assertEquals(3, TDBeaconsFTSRestClient.getInstance()
+ // .getPrimaryKeyColumIndex(wantedFields, true));
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private static String[][] mocks = { { "P38398.json", null },
+ { "P01308.json", null },
+ { "P0DTD1.json", null }
+
+ // , { "P0DTD3.json", "{}" } actually results in 404, but {} is in body
+ };
+
+ private static void setMockData()
+ {
+ try
+ {
+ mocks[0][1] = PDBFTSRestClientTest.readJsonStringFromFile(
+ "test/jalview/fts/threedbeacons/p38398_tdb_fts_query_resp.txt");
+
+ mocks[1][1] = PDBFTSRestClientTest.readJsonStringFromFile(
+ "test/jalview/fts/threedbeacons/p01308_tdb_fts_query_resp.txt");
+
+ mocks[2][1] = PDBFTSRestClientTest.readJsonStringFromFile(
+ "test/jalview/fts/threedbeacons/p0dtd1_tdb_fts_query_resp.txt");
+
+ } catch (IOException e)
+ {
+ Assert.fail("Couldn't read mock response data", e);
+ }
+ }
+
+ public static void setMock()
+ {
+ setMockData();
+ FTSRestClient.createMockFTSRestClient(
+ (FTSRestClient) TDBeaconsFTSRestClient.getInstance(), mocks);
+ }
+
+ private static String dev_url = "https://wwwdev.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons/api/uniprot/summary/";
+
+ private static String prod_url = "https://www.ebi.ac.uk/pdbe/pdbe-kb/3dbeacons/api/uniprot/summary/";
+
+ /**
+ * check that the mock request and response are the same as the response from
+ * a live 3D-beacons endpoint
+ *
+ * Note - servers often have rapidly changing ids / URIs so this might fail,
+ * but the overall structure will remain.
+ *
+ * @throws Exception
+ */
+ @Test(groups = { "Network", "Integration" })
+ public void verifyMockTDBRequest() throws Exception
+ {
+ setMockData();
+ for (String[] otherMock : mocks)
+ {
+ verifyMockTDBRequest(otherMock[0], otherMock[1]);
+ }
+ }
+
+ private void verifyMockTDBRequest(String mockRequest,
+ String _mockResponse) throws Exception