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;
26 import java.util.Collection;
27 import java.util.HashSet;
30 import org.testng.Assert;
31 import org.testng.annotations.BeforeMethod;
32 import org.testng.annotations.Test;
34 public class FTSRestClientTest
36 private FTSRestClient ftsRestClient;
38 @BeforeMethod(alwaysRun = true)
41 ftsRestClient = new FTSRestClient()
45 public String getColumnDataConfigFileName()
47 return "/fts/uniprot_data_columns.txt";
51 public FTSRestResponse executeRequest(FTSRestRequest ftsRequest)
59 @Test(groups = { "Functional" })
60 public void getPrimaryKeyColumIndexTest()
62 Collection<FTSDataColumnI> wantedFields = ftsRestClient
63 .getAllDefaultDisplayedFTSDataColumns();
67 Assert.assertEquals(foundIndex, -1);
68 foundIndex = ftsRestClient.getPrimaryKeyColumIndex(wantedFields,
70 Assert.assertEquals(foundIndex, 0);
71 foundIndex = ftsRestClient
72 .getPrimaryKeyColumIndex(wantedFields, true);
73 Assert.assertEquals(foundIndex, 1);
77 Assert.fail("Exception thrown while testing...");
81 @Test(groups = { "Functional" })
82 public void getAllDefaulDisplayedDataColumns()
84 Assert.assertNotNull(ftsRestClient
85 .getAllDefaultDisplayedFTSDataColumns());
86 Assert.assertTrue(!ftsRestClient.getAllDefaultDisplayedFTSDataColumns()
88 Assert.assertEquals(ftsRestClient
89 .getAllDefaultDisplayedFTSDataColumns().size(), 7);
92 @Test(groups = { "Functional" })
93 public void getDataColumnsFieldsAsCommaDelimitedString()
95 Collection<FTSDataColumnI> wantedFields = ftsRestClient
96 .getAllDefaultDisplayedFTSDataColumns();
97 String actual = ftsRestClient
98 .getDataColumnsFieldsAsCommaDelimitedString(wantedFields);
99 Assert.assertEquals(actual,
100 "id,entry name,protein names,genes,organism,reviewed,length");
103 @Test(groups = { "Functional" })
104 public void getAllFTSDataColumns()
106 Collection<FTSDataColumnI> allFields = ftsRestClient
107 .getAllFTSDataColumns();
108 Assert.assertNotNull(allFields);
109 Assert.assertEquals(allFields.size(), 117);
112 @Test(groups = { "Functional" })
113 public void getSearchableDataColumns()
115 Collection<FTSDataColumnI> searchalbeFields = ftsRestClient
116 .getSearchableDataColumns();
117 Assert.assertNotNull(searchalbeFields);
118 Assert.assertEquals(searchalbeFields.size(), 22);
121 @Test(groups = { "Functional" })
122 public void getPrimaryKeyColumn()
124 FTSDataColumnI expectedPKColumn;
127 expectedPKColumn = ftsRestClient
128 .getDataColumnByNameOrCode("Uniprot Id");
129 Assert.assertNotNull(ftsRestClient.getPrimaryKeyColumn());
130 Assert.assertEquals(ftsRestClient.getPrimaryKeyColumn(),
132 } catch (Exception e)
135 Assert.fail("Exception thrown while testing...");
139 @Test(groups = { "Functional" })
140 public void getDataColumnByNameOrCode()
144 FTSDataColumnI foundDataCol = ftsRestClient
145 .getDataColumnByNameOrCode("genes");
146 Assert.assertNotNull(foundDataCol);
147 Assert.assertEquals(foundDataCol.getName(), "Gene Names");
148 } catch (Exception e)
151 Assert.fail("Exception thrown while testing...");
155 @Test(groups = { "Functional" })
156 public void getDataColumnGroupById()
158 FTSDataColumnGroupI foundDataColGroup;
161 foundDataColGroup = ftsRestClient.getDataColumnGroupById("g3");
162 Assert.assertNotNull(foundDataColGroup);
163 Assert.assertEquals(foundDataColGroup.getName(), "Names & Taxonomy");
164 } catch (Exception e)
170 @Test(groups = { "Functional" })
171 public void getDefaultResponsePageSize()
173 int defaultResSize = ftsRestClient.getDefaultResponsePageSize();
174 Assert.assertEquals(defaultResSize, 500);
177 @Test(groups = { "Functional" })
178 public void getColumnMinWidthTest()
182 FTSDataColumnI foundDataCol = ftsRestClient
183 .getDataColumnByNameOrCode("Protein names");
184 Assert.assertNotNull(foundDataCol);
185 int actualColMinWidth = foundDataCol.getMinWidth();
186 Assert.assertEquals(actualColMinWidth, 300);
187 } catch (Exception e)
190 Assert.fail("Exception thrown while testing...");
194 @Test(groups = { "Functional" })
195 public void getColumnMaxWidthTest()
199 FTSDataColumnI foundDataCol = ftsRestClient
200 .getDataColumnByNameOrCode("Protein names");
201 Assert.assertNotNull(foundDataCol);
202 int actualColMinWidth = foundDataCol.getMaxWidth();
203 Assert.assertEquals(actualColMinWidth, 1500);
204 } catch (Exception e)
207 Assert.fail("Exception thrown while testing...");
211 @Test(groups = { "Functional" })
212 public void getColumnPreferredWidthTest()
216 FTSDataColumnI foundDataCol = ftsRestClient
217 .getDataColumnByNameOrCode("Protein names");
218 Assert.assertNotNull(foundDataCol);
219 int actualColMinWidth = foundDataCol.getPreferredWidth();
220 Assert.assertEquals(actualColMinWidth, 500);
221 } catch (Exception e)
224 Assert.fail("Exception thrown while testing...");
228 @Test(groups = { "Functional" })
229 public void getColumnClassTest()
233 FTSDataColumnI foundDataCol = ftsRestClient
234 .getDataColumnByNameOrCode("Protein names");
235 Assert.assertNotNull(foundDataCol);
236 Assert.assertEquals(foundDataCol.getDataType().getDataTypeClass(),
238 foundDataCol = ftsRestClient.getDataColumnByNameOrCode("length");
239 Assert.assertNotNull(foundDataCol);
240 Assert.assertEquals(foundDataCol.getDataType().getDataTypeClass(),
242 // foundDataCol = ftsRestClient.getDataColumnByNameOrCode("length");
243 // Assert.assertNotNull(foundDataCol);
244 // Assert.assertEquals(foundDataCol.getDataColumnClass(), Double.class);
245 } catch (Exception e)
248 Assert.fail("Exception thrown while testing...");
252 @Test(groups = { "Functional" })
253 public void coverageForEqualsAndHashFunction()
255 Set<FTSDataColumnI> uniqueSet = new HashSet<FTSDataColumnI>();
256 Collection<FTSDataColumnI> searchableCols = ftsRestClient
257 .getSearchableDataColumns();
258 for (FTSDataColumnI foundCol : searchableCols)
260 System.out.println(foundCol.toString());
261 uniqueSet.add(foundCol);
262 uniqueSet.add(foundCol);
264 Assert.assertTrue(!uniqueSet.isEmpty());
265 Assert.assertEquals(uniqueSet.size(), 22);
268 @Test(groups = { "Functional" })
269 public void coverageForMiscellaneousBranches()
271 String actual = ftsRestClient.getPrimaryKeyColumn().toString();
272 Assert.assertEquals(actual, "Uniprot Id");
274 String actualGroupStr;
277 actualGroupStr = ftsRestClient.getDataColumnGroupById("g4")
279 Assert.assertEquals(actualGroupStr, "Procedures & Softwares");
280 actualGroupStr = ftsRestClient.getDataColumnGroupById(
281 "unavailable group").toString();
282 } catch (Exception e)
284 Assert.assertTrue(true);
287 String actualResourseFile = ftsRestClient
288 .getResourceFile("/fts/uniprot_data_columns.txt");
289 Assert.assertNotNull(actualResourseFile);
290 Assert.assertTrue(actualResourseFile.length() > 31);
293 @Test(groups = { "Functional" }, expectedExceptions = Exception.class)
294 public void coverageForExceptionBranches() throws Exception
298 ftsRestClient.getDataColumnByNameOrCode("unavailable column");
299 } catch (Exception e)
301 System.out.println(e.getMessage());
302 String expectedMessage = "Couldn't find data column with name : unavailable column";
303 Assert.assertEquals(e.getMessage(), expectedMessage);
307 ftsRestClient.getDataColumnGroupById("unavailable column group Id");
308 } catch (Exception e)
310 System.out.println(e.getMessage());
311 String expectedMessage = "Couldn't find data column group with id : unavailable column group Id";
312 Assert.assertEquals(e.getMessage(), expectedMessage);
315 ftsRestClient.getDataColumnByNameOrCode("unavailable column");
317 ftsRestClient.getResourceFile("unavailable resource file");