package jalview.fts.threedbeacons; import static org.testng.AssertJUnit.assertTrue; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import jalview.fts.api.FTSDataColumnI; import jalview.fts.core.FTSRestClient; import jalview.fts.core.FTSRestRequest; import jalview.fts.core.FTSRestResponse; import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient; import jalview.gui.JvOptionPane; public class TDBeaconsFTSRestClientTest { @BeforeClass(alwaysRun = true) public void setUpJvOptionPane() { JvOptionPane.setInteractiveMode(false); JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); } private FTSRestClient ftsRestClient; @BeforeMethod(alwaysRun = true) public void setUp() throws Exception { ftsRestClient = new FTSRestClient() { @Override public String getColumnDataConfigFileName() { return "/fts/tdbeacons_data_columns.txt"; } @Override public FTSRestResponse executeRequest(FTSRestRequest ftsRequest) throws Exception { return null; } }; } @AfterMethod(alwaysRun = true) public void tearDown() throws Exception { } @Test public void getAllDefaulDisplayedDataColumns() { Assert.assertNotNull(ftsRestClient .getAllDefaultDisplayedFTSDataColumns()); System.out.println(ftsRestClient.getAllDefaultDisplayedFTSDataColumns()); Assert.assertTrue(!ftsRestClient.getAllDefaultDisplayedFTSDataColumns() .isEmpty()); Assert.assertEquals(ftsRestClient .getAllDefaultDisplayedFTSDataColumns().size(), 3); } @Test(groups = { "Functional" }) public void getPrimaryKeyColumIndexTest() { Collection wantedFields = ftsRestClient .getAllDefaultDisplayedFTSDataColumns(); int foundIndex = -1; try { Assert.assertEquals(foundIndex, -1); foundIndex = ftsRestClient.getPrimaryKeyColumIndex(wantedFields, false); Assert.assertEquals(foundIndex, 0); foundIndex = ftsRestClient .getPrimaryKeyColumIndex(wantedFields, true); Assert.assertEquals(foundIndex, 1); } catch (Exception e) { e.printStackTrace(); Assert.fail("Exception thrown while testing..."); } } @Test(groups = { "External", "Network" }) public void executeRequestTest() { List wantedFields = new ArrayList(); try { wantedFields.add(TDBeaconsFTSRestClient.getInstance() .getDataColumnByNameOrCode("model_category")); wantedFields.add(TDBeaconsFTSRestClient.getInstance() .getDataColumnByNameOrCode("provider")); wantedFields.add(TDBeaconsFTSRestClient.getInstance() .getDataColumnByNameOrCode("created")); } catch (Exception e1) { e1.printStackTrace(); } System.out.println("wantedFields >>" + wantedFields); FTSRestRequest request = new FTSRestRequest(); //request.setAllowEmptySeq(false); //request.setResponseSize(100); request.setSearchTerm("01308.json"); request.setWantedFields(wantedFields); System.out.println("request : " + request.getFieldToSearchBy()); System.out.println(request.toString()); FTSRestResponse response; try { response = TDBeaconsFTSRestClient.getInstance().executeRequest(request); } catch (Exception e) { e.printStackTrace(); Assert.fail("Couldn't execute webservice call!"); return; } //assertTrue(response.getNumberOfItemsFound() > 99); assertTrue(response.getSearchSummary() != null); assertTrue(response.getSearchSummary().size() > 99); } }