+ private static String[][] mocks = { { "P38398.json", null },
+ { "P01308.json", null },
+ { "P0DTD1.json", null },
+ { "P27787.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");
+
+ mocks[3][1] = PDBFTSRestClientTest.readJsonStringFromFile(
+ "test/jalview/fts/threedbeacons/p27787_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
+ {
+ URL tdb_req = new URL(prod_url + mockRequest);
+ byte[] resp = tdb_req.openStream().readAllBytes();
+ String tresp = new String(resp, StandardCharsets.UTF_8);
+ // this simple test fails for responses containing multi-chain structures -
+ // since chain order in the json elements is arbitrary and varies between
+ // queries.
+ assertEquals(_mockResponse.trim(), tresp.trim());
+ }
+
+ @Test(groups = { "Functional" })
+ public void testMockTDBRequest()
+ {
+
+ setMock();
+ List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
+ try
+ {
+ wantedFields.add(TDBeaconsFTSRestClient.getInstance()
+ .getDataColumnByNameOrCode("Model Id"));
+ wantedFields.add(TDBeaconsFTSRestClient.getInstance()
+ .getDataColumnByNameOrCode("model_url"));
+ wantedFields.add(TDBeaconsFTSRestClient.getInstance()
+ .getDataColumnByNameOrCode("provider"));
+ wantedFields.add(TDBeaconsFTSRestClient.getInstance()
+ .getDataColumnByNameOrCode("model_category"));
+ wantedFields.add(TDBeaconsFTSRestClient.getInstance()
+ .getDataColumnByNameOrCode("qmean_avg_local_score"));
+ wantedFields.add(TDBeaconsFTSRestClient.getInstance()
+ .getDataColumnByNameOrCode("uniprot_start"));
+ wantedFields.add(TDBeaconsFTSRestClient.getInstance()
+ .getDataColumnByNameOrCode("uniprot_end"));
+ } catch (Exception e1)
+ {
+ e1.printStackTrace();
+ }
+ System.out.println("wantedFields >>" + wantedFields);
+
+ FTSRestRequest request = new FTSRestRequest();
+ FTSRestResponse response;
+
+ request.setResponseSize(100);
+ request.setFieldToSearchBy("");
+ request.setWantedFields(wantedFields);
+ // check 404 behaviour
+ request.setSearchTerm("P00000.json");
+
+ try
+ {
+ response = TDBeaconsFTSRestClient.getInstance()
+ .executeRequest(request);
+
+ assertNull(response);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ Assert.fail("Unexpected failure during mock 3DBeacons 404 test");
+ }
+
+ // check 200 behaviour
+ request.setSearchTerm("P38398.json");
+ System.out.println("request : " + request.getFieldToSearchBy());
+ // System.out.println(request.toString());
+
+ try
+ {
+ response = TDBeaconsFTSRestClient.getInstance()
+ .executeRequest(request);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ Assert.fail("Couldn't execute webservice call!");
+ return;
+ }
+ assertTrue(response.getSearchSummary() != null);
+ assertTrue(response.getNumberOfItemsFound() > 3); // 4 atm
+ System.out.println("Search summary : \n" + response.getSearchSummary());
+
+ // System.out.println(response.getSearchSummary().size());
+ }
+
+ @Test(groups = { "External", "Network" })