2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.fts.core;
23 import jalview.fts.api.FTSDataColumnI;
24 import jalview.fts.api.FTSDataColumnI.FTSDataColumnGroupI;
25 import jalview.gui.JvOptionPane;
27 import java.util.Collection;
28 import java.util.HashSet;
31 import org.testng.Assert;
32 import org.testng.annotations.BeforeClass;
33 import org.testng.annotations.BeforeMethod;
34 import org.testng.annotations.Test;
36 public class FTSRestClientTest
39 @BeforeClass(alwaysRun = true)
40 public void setUpJvOptionPane()
42 JvOptionPane.setInteractiveMode(false);
43 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
46 private FTSRestClient ftsRestClient;
48 @BeforeMethod(alwaysRun = true)
51 ftsRestClient = new FTSRestClient()
55 public String getColumnDataConfigFileName()
57 return "/fts/uniprot_data_columns.txt";
61 public FTSRestResponse executeRequest(FTSRestRequest ftsRequest)
69 @Test(groups = { "Functional" })
70 public void getPrimaryKeyColumIndexTest()
72 Collection<FTSDataColumnI> wantedFields = ftsRestClient
73 .getAllDefaultDisplayedFTSDataColumns();
77 Assert.assertEquals(foundIndex, -1);
78 foundIndex = ftsRestClient.getPrimaryKeyColumIndex(wantedFields,
80 Assert.assertEquals(foundIndex, 0);
81 foundIndex = ftsRestClient
82 .getPrimaryKeyColumIndex(wantedFields, true);
83 Assert.assertEquals(foundIndex, 1);
87 Assert.fail("Exception thrown while testing...");
91 @Test(groups = { "Functional" })
92 public void getAllDefaulDisplayedDataColumns()
94 Assert.assertNotNull(ftsRestClient
95 .getAllDefaultDisplayedFTSDataColumns());
96 Assert.assertTrue(!ftsRestClient.getAllDefaultDisplayedFTSDataColumns()
98 Assert.assertEquals(ftsRestClient
99 .getAllDefaultDisplayedFTSDataColumns().size(), 7);
102 @Test(groups = { "Functional" })
103 public void getDataColumnsFieldsAsCommaDelimitedString()
105 Collection<FTSDataColumnI> wantedFields = ftsRestClient
106 .getAllDefaultDisplayedFTSDataColumns();
107 String actual = ftsRestClient
108 .getDataColumnsFieldsAsCommaDelimitedString(wantedFields);
109 Assert.assertEquals(actual,
110 "id,entry name,protein names,genes,organism,reviewed,length");
113 @Test(groups = { "Functional" })
114 public void getAllFTSDataColumns()
116 Collection<FTSDataColumnI> allFields = ftsRestClient
117 .getAllFTSDataColumns();
118 Assert.assertNotNull(allFields);
119 Assert.assertEquals(allFields.size(), 117);
122 @Test(groups = { "Functional" })
123 public void getSearchableDataColumns()
125 Collection<FTSDataColumnI> searchalbeFields = ftsRestClient
126 .getSearchableDataColumns();
127 Assert.assertNotNull(searchalbeFields);
128 Assert.assertEquals(searchalbeFields.size(), 22);
131 @Test(groups = { "Functional" })
132 public void getPrimaryKeyColumn()
134 FTSDataColumnI expectedPKColumn;
137 expectedPKColumn = ftsRestClient
138 .getDataColumnByNameOrCode("Uniprot Id");
139 Assert.assertNotNull(ftsRestClient.getPrimaryKeyColumn());
140 Assert.assertEquals(ftsRestClient.getPrimaryKeyColumn(),
142 } catch (Exception e)
145 Assert.fail("Exception thrown while testing...");
149 @Test(groups = { "Functional" })
150 public void getDataColumnByNameOrCode()
154 FTSDataColumnI foundDataCol = ftsRestClient
155 .getDataColumnByNameOrCode("genes");
156 Assert.assertNotNull(foundDataCol);
157 Assert.assertEquals(foundDataCol.getName(), "Gene Names");
158 } catch (Exception e)
161 Assert.fail("Exception thrown while testing...");
165 @Test(groups = { "Functional" })
166 public void getDataColumnGroupById()
168 FTSDataColumnGroupI foundDataColGroup;
171 foundDataColGroup = ftsRestClient.getDataColumnGroupById("g3");
172 Assert.assertNotNull(foundDataColGroup);
173 Assert.assertEquals(foundDataColGroup.getName(), "Names & Taxonomy");
174 } catch (Exception e)
180 @Test(groups = { "Functional" })
181 public void getDefaultResponsePageSize()
183 int defaultResSize = ftsRestClient.getDefaultResponsePageSize();
184 Assert.assertEquals(defaultResSize, 500);
187 @Test(groups = { "Functional" })
188 public void getColumnMinWidthTest()
192 FTSDataColumnI foundDataCol = ftsRestClient
193 .getDataColumnByNameOrCode("Protein names");
194 Assert.assertNotNull(foundDataCol);
195 int actualColMinWidth = foundDataCol.getMinWidth();
196 Assert.assertEquals(actualColMinWidth, 300);
197 } catch (Exception e)
200 Assert.fail("Exception thrown while testing...");
204 @Test(groups = { "Functional" })
205 public void getColumnMaxWidthTest()
209 FTSDataColumnI foundDataCol = ftsRestClient
210 .getDataColumnByNameOrCode("Protein names");
211 Assert.assertNotNull(foundDataCol);
212 int actualColMinWidth = foundDataCol.getMaxWidth();
213 Assert.assertEquals(actualColMinWidth, 1500);
214 } catch (Exception e)
217 Assert.fail("Exception thrown while testing...");
221 @Test(groups = { "Functional" })
222 public void getColumnPreferredWidthTest()
226 FTSDataColumnI foundDataCol = ftsRestClient
227 .getDataColumnByNameOrCode("Protein names");
228 Assert.assertNotNull(foundDataCol);
229 int actualColMinWidth = foundDataCol.getPreferredWidth();
230 Assert.assertEquals(actualColMinWidth, 500);
231 } catch (Exception e)
234 Assert.fail("Exception thrown while testing...");
238 @Test(groups = { "Functional" })
239 public void getColumnClassTest()
243 FTSDataColumnI foundDataCol = ftsRestClient
244 .getDataColumnByNameOrCode("Protein names");
245 Assert.assertNotNull(foundDataCol);
246 Assert.assertEquals(foundDataCol.getDataType().getDataTypeClass(),
248 foundDataCol = ftsRestClient.getDataColumnByNameOrCode("length");
249 Assert.assertNotNull(foundDataCol);
250 Assert.assertEquals(foundDataCol.getDataType().getDataTypeClass(),
252 // foundDataCol = ftsRestClient.getDataColumnByNameOrCode("length");
253 // Assert.assertNotNull(foundDataCol);
254 // Assert.assertEquals(foundDataCol.getDataColumnClass(), Double.class);
255 } catch (Exception e)
258 Assert.fail("Exception thrown while testing...");
262 @Test(groups = { "Functional" })
263 public void coverageForEqualsAndHashFunction()
265 Set<FTSDataColumnI> uniqueSet = new HashSet<FTSDataColumnI>();
266 Collection<FTSDataColumnI> searchableCols = ftsRestClient
267 .getSearchableDataColumns();
268 for (FTSDataColumnI foundCol : searchableCols)
270 System.out.println(foundCol.toString());
271 uniqueSet.add(foundCol);
272 uniqueSet.add(foundCol);
274 Assert.assertTrue(!uniqueSet.isEmpty());
275 Assert.assertEquals(uniqueSet.size(), 22);
278 @Test(groups = { "Functional" })
279 public void coverageForMiscellaneousBranches()
281 String actual = ftsRestClient.getPrimaryKeyColumn().toString();
282 Assert.assertEquals(actual, "Uniprot Id");
284 String actualGroupStr;
287 actualGroupStr = ftsRestClient.getDataColumnGroupById("g4")
289 Assert.assertEquals(actualGroupStr, "Procedures & Softwares");
290 actualGroupStr = ftsRestClient.getDataColumnGroupById(
291 "unavailable group").toString();
292 } catch (Exception e)
294 Assert.assertTrue(true);
297 String actualResourseFile = ftsRestClient
298 .getResourceFile("/fts/uniprot_data_columns.txt");
299 Assert.assertNotNull(actualResourseFile);
300 Assert.assertTrue(actualResourseFile.length() > 31);
303 @Test(groups = { "Functional" }, expectedExceptions = Exception.class)
304 public void coverageForExceptionBranches() throws Exception
308 ftsRestClient.getDataColumnByNameOrCode("unavailable column");
309 } catch (Exception e)
311 System.out.println(e.getMessage());
312 String expectedMessage = "Couldn't find data column with name : unavailable column";
313 Assert.assertEquals(e.getMessage(), expectedMessage);
317 ftsRestClient.getDataColumnGroupById("unavailable column group Id");
318 } catch (Exception e)
320 System.out.println(e.getMessage());
321 String expectedMessage = "Couldn't find data column group with id : unavailable column group Id";
322 Assert.assertEquals(e.getMessage(), expectedMessage);
325 ftsRestClient.getDataColumnByNameOrCode("unavailable column");
327 ftsRestClient.getResourceFile("unavailable resource file");