Created 3Dbeacons data_columns.txt Test passed for data columns
[jalview.git] / test / jalview / fts / threedbeacons / TDBeaconsFTSRestClientTest.java
1 package jalview.fts.threedbeacons;
2
3 import static org.testng.AssertJUnit.assertTrue;
4
5 import java.util.ArrayList;
6 import java.util.Collection;
7 import java.util.List;
8
9 import org.testng.Assert;
10 import org.testng.annotations.AfterMethod;
11 import org.testng.annotations.BeforeClass;
12 import org.testng.annotations.BeforeMethod;
13 import org.testng.annotations.Test;
14
15 import jalview.fts.api.FTSDataColumnI;
16 import jalview.fts.core.FTSRestClient;
17 import jalview.fts.core.FTSRestRequest;
18 import jalview.fts.core.FTSRestResponse;
19 import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient;
20 import jalview.gui.JvOptionPane;
21
22 public class TDBeaconsFTSRestClientTest
23 {
24   @BeforeClass(alwaysRun = true)
25   public void setUpJvOptionPane()
26   {
27     JvOptionPane.setInteractiveMode(false);
28     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
29   }
30   
31   private FTSRestClient ftsRestClient;
32
33   @BeforeMethod(alwaysRun = true)
34   public void setUp() throws Exception
35   {
36     ftsRestClient = new FTSRestClient()
37     {
38
39       @Override
40       public String getColumnDataConfigFileName()
41       {
42         return "/fts/tdbeacons_data_columns.txt";
43       }
44
45       @Override
46       public FTSRestResponse executeRequest(FTSRestRequest ftsRequest)
47               throws Exception
48       {
49         return null;
50       }
51     };
52   }
53
54   @AfterMethod(alwaysRun = true)
55   public void tearDown() throws Exception
56   {
57   }
58   
59   @Test
60   public void getAllDefaulDisplayedDataColumns()
61   {
62     Assert.assertNotNull(ftsRestClient
63             .getAllDefaultDisplayedFTSDataColumns());
64     System.out.println(ftsRestClient.getAllDefaultDisplayedFTSDataColumns());
65     Assert.assertTrue(!ftsRestClient.getAllDefaultDisplayedFTSDataColumns()
66             .isEmpty());
67     Assert.assertEquals(ftsRestClient
68             .getAllDefaultDisplayedFTSDataColumns().size(), 3);
69   }
70   
71   @Test(groups = { "Functional" })
72   public void getPrimaryKeyColumIndexTest()
73   {
74     Collection<FTSDataColumnI> wantedFields = ftsRestClient
75             .getAllDefaultDisplayedFTSDataColumns();
76     int foundIndex = -1;
77     try
78     {
79       Assert.assertEquals(foundIndex, -1);
80       foundIndex = ftsRestClient.getPrimaryKeyColumIndex(wantedFields,
81               false);
82       Assert.assertEquals(foundIndex, 0);
83       foundIndex = ftsRestClient
84               .getPrimaryKeyColumIndex(wantedFields, true);
85       Assert.assertEquals(foundIndex, 1);
86     } catch (Exception e)
87     {
88       e.printStackTrace();
89       Assert.fail("Exception thrown while testing...");
90     }
91   }
92   
93   @Test(groups = { "External", "Network" })  
94   public void executeRequestTest()
95   {
96     List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
97     try
98     {
99       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
100               .getDataColumnByNameOrCode("model_category"));
101       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
102               .getDataColumnByNameOrCode("provider"));
103       wantedFields.add(TDBeaconsFTSRestClient.getInstance()
104               .getDataColumnByNameOrCode("created"));
105     } catch (Exception e1)
106     {
107       e1.printStackTrace();
108     }
109     System.out.println("wantedFields >>" + wantedFields);
110
111     FTSRestRequest request = new FTSRestRequest();
112     //request.setAllowEmptySeq(false);
113     //request.setResponseSize(100);
114     request.setSearchTerm("01308.json");
115     request.setWantedFields(wantedFields);
116     System.out.println("request : " + request.getFieldToSearchBy());
117     System.out.println(request.toString());
118
119     FTSRestResponse response;
120     try
121     {
122       response = TDBeaconsFTSRestClient.getInstance().executeRequest(request);
123     } catch (Exception e)
124     {
125       e.printStackTrace();
126       Assert.fail("Couldn't execute webservice call!");
127       return;
128     }
129     //assertTrue(response.getNumberOfItemsFound() > 99);
130     assertTrue(response.getSearchSummary() != null);
131     assertTrue(response.getSearchSummary().size() > 99);
132   }
133 }