Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.fts.core

File FTSRestClientTest.java

 

Code metrics

0
109
20
1
331
277
31
0.28
5.45
20
1.55

Classes

Class Line # Actions
FTSRestClientTest 36 109 31
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.fts.core;
22   
23    import jalview.fts.api.FTSDataColumnI;
24    import jalview.fts.api.FTSDataColumnI.FTSDataColumnGroupI;
25    import jalview.gui.JvOptionPane;
26   
27    import java.util.Collection;
28    import java.util.HashSet;
29    import java.util.Set;
30   
31    import org.testng.Assert;
32    import org.testng.annotations.BeforeClass;
33    import org.testng.annotations.BeforeMethod;
34    import org.testng.annotations.Test;
35   
 
36    public class FTSRestClientTest
37    {
38   
 
39  0 toggle @BeforeClass(alwaysRun = true)
40    public void setUpJvOptionPane()
41    {
42  0 JvOptionPane.setInteractiveMode(false);
43  0 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
44    }
45   
46    private FTSRestClient ftsRestClient;
47   
 
48  0 toggle @BeforeMethod(alwaysRun = true)
49    public void setup()
50    {
51  0 ftsRestClient = new FTSRestClient()
52    {
53   
 
54  0 toggle @Override
55    public String getColumnDataConfigFileName()
56    {
57  0 return "/fts/uniprot_data_columns.txt";
58    }
59   
 
60  0 toggle @Override
61    public FTSRestResponse executeRequest(FTSRestRequest ftsRequest)
62    throws Exception
63    {
64  0 return null;
65    }
66    };
67    }
68   
 
69  0 toggle @Test(groups = { "Functional" })
70    public void getPrimaryKeyColumIndexTest()
71    {
72  0 Collection<FTSDataColumnI> wantedFields = ftsRestClient
73    .getAllDefaultDisplayedFTSDataColumns();
74  0 int foundIndex = -1;
75  0 try
76    {
77  0 Assert.assertEquals(foundIndex, -1);
78  0 foundIndex = ftsRestClient.getPrimaryKeyColumIndex(wantedFields,
79    false);
80  0 Assert.assertEquals(foundIndex, 0);
81  0 foundIndex = ftsRestClient.getPrimaryKeyColumIndex(wantedFields,
82    true);
83  0 Assert.assertEquals(foundIndex, 1);
84    } catch (Exception e)
85    {
86  0 e.printStackTrace();
87  0 Assert.fail("Exception thrown while testing...");
88    }
89    }
90   
 
91  0 toggle @Test(groups = { "Functional" })
92    public void getAllDefaulDisplayedDataColumns()
93    {
94  0 Assert.assertNotNull(
95    ftsRestClient.getAllDefaultDisplayedFTSDataColumns());
96  0 Assert.assertTrue(!ftsRestClient.getAllDefaultDisplayedFTSDataColumns()
97    .isEmpty());
98  0 Assert.assertEquals(
99    ftsRestClient.getAllDefaultDisplayedFTSDataColumns().size(), 7);
100    }
101   
 
102  0 toggle @Test(groups = { "Functional" })
103    public void getDataColumnsFieldsAsCommaDelimitedString()
104    {
105  0 Collection<FTSDataColumnI> wantedFields = ftsRestClient
106    .getAllDefaultDisplayedFTSDataColumns();
107  0 String actual = ftsRestClient
108    .getDataColumnsFieldsAsCommaDelimitedString(wantedFields);
109  0 Assert.assertEquals(actual,
110    "id,entry name,protein names,genes,organism,reviewed,length");
111    }
112   
 
113  0 toggle @Test(groups = { "Functional" })
114    public void getAllFTSDataColumns()
115    {
116  0 Collection<FTSDataColumnI> allFields = ftsRestClient
117    .getAllFTSDataColumns();
118  0 Assert.assertNotNull(allFields);
119  0 Assert.assertEquals(allFields.size(), 117);
120    }
121   
 
122  0 toggle @Test(groups = { "Functional" })
123    public void getSearchableDataColumns()
124    {
125  0 Collection<FTSDataColumnI> searchalbeFields = ftsRestClient
126    .getSearchableDataColumns();
127  0 Assert.assertNotNull(searchalbeFields);
128  0 Assert.assertEquals(searchalbeFields.size(), 22);
129    }
130   
 
131  0 toggle @Test(groups = { "Functional" })
132    public void getPrimaryKeyColumn()
133    {
134  0 FTSDataColumnI expectedPKColumn;
135  0 try
136    {
137  0 expectedPKColumn = ftsRestClient
138    .getDataColumnByNameOrCode("Uniprot Id");
139  0 Assert.assertNotNull(ftsRestClient.getPrimaryKeyColumn());
140  0 Assert.assertEquals(ftsRestClient.getPrimaryKeyColumn(),
141    expectedPKColumn);
142    } catch (Exception e)
143    {
144  0 e.printStackTrace();
145  0 Assert.fail("Exception thrown while testing...");
146    }
147    }
148   
 
149  0 toggle @Test(groups = { "Functional" })
150    public void getDataColumnByNameOrCode()
151    {
152  0 try
153    {
154  0 FTSDataColumnI foundDataCol = ftsRestClient
155    .getDataColumnByNameOrCode("genes");
156  0 Assert.assertNotNull(foundDataCol);
157  0 Assert.assertEquals(foundDataCol.getName(), "Gene Names");
158    } catch (Exception e)
159    {
160  0 e.printStackTrace();
161  0 Assert.fail("Exception thrown while testing...");
162    }
163    }
164   
 
165  0 toggle @Test(groups = { "Functional" })
166    public void getDataColumnGroupById()
167    {
168  0 FTSDataColumnGroupI foundDataColGroup;
169  0 try
170    {
171  0 foundDataColGroup = ftsRestClient.getDataColumnGroupById("g3");
172  0 Assert.assertNotNull(foundDataColGroup);
173  0 Assert.assertEquals(foundDataColGroup.getName(), "Names & Taxonomy");
174    } catch (Exception e)
175    {
176  0 e.printStackTrace();
177    }
178    }
179   
 
180  0 toggle @Test(groups = { "Functional" })
181    public void getDefaultResponsePageSize()
182    {
183  0 int defaultResSize = ftsRestClient.getDefaultResponsePageSize();
184  0 Assert.assertEquals(defaultResSize, 500);
185    }
186   
 
187  0 toggle @Test(groups = { "Functional" })
188    public void getColumnMinWidthTest()
189    {
190  0 try
191    {
192  0 FTSDataColumnI foundDataCol = ftsRestClient
193    .getDataColumnByNameOrCode("Protein names");
194  0 Assert.assertNotNull(foundDataCol);
195  0 int actualColMinWidth = foundDataCol.getMinWidth();
196  0 Assert.assertEquals(actualColMinWidth, 300);
197    } catch (Exception e)
198    {
199  0 e.printStackTrace();
200  0 Assert.fail("Exception thrown while testing...");
201    }
202    }
203   
 
204  0 toggle @Test(groups = { "Functional" })
205    public void getColumnMaxWidthTest()
206    {
207  0 try
208    {
209  0 FTSDataColumnI foundDataCol = ftsRestClient
210    .getDataColumnByNameOrCode("Protein names");
211  0 Assert.assertNotNull(foundDataCol);
212  0 int actualColMinWidth = foundDataCol.getMaxWidth();
213  0 Assert.assertEquals(actualColMinWidth, 1500);
214    } catch (Exception e)
215    {
216  0 e.printStackTrace();
217  0 Assert.fail("Exception thrown while testing...");
218    }
219    }
220   
 
221  0 toggle @Test(groups = { "Functional" })
222    public void getColumnPreferredWidthTest()
223    {
224  0 try
225    {
226  0 FTSDataColumnI foundDataCol = ftsRestClient
227    .getDataColumnByNameOrCode("Protein names");
228  0 Assert.assertNotNull(foundDataCol);
229  0 int actualColMinWidth = foundDataCol.getPreferredWidth();
230  0 Assert.assertEquals(actualColMinWidth, 500);
231    } catch (Exception e)
232    {
233  0 e.printStackTrace();
234  0 Assert.fail("Exception thrown while testing...");
235    }
236    }
237   
 
238  0 toggle @Test(groups = { "Functional" })
239    public void getColumnClassTest()
240    {
241  0 try
242    {
243  0 FTSDataColumnI foundDataCol = ftsRestClient
244    .getDataColumnByNameOrCode("Protein names");
245  0 Assert.assertNotNull(foundDataCol);
246  0 Assert.assertEquals(foundDataCol.getDataType().getDataTypeClass(),
247    String.class);
248  0 foundDataCol = ftsRestClient.getDataColumnByNameOrCode("length");
249  0 Assert.assertNotNull(foundDataCol);
250  0 Assert.assertEquals(foundDataCol.getDataType().getDataTypeClass(),
251    Integer.class);
252    // foundDataCol = ftsRestClient.getDataColumnByNameOrCode("length");
253    // Assert.assertNotNull(foundDataCol);
254    // Assert.assertEquals(foundDataCol.getDataColumnClass(), Double.class);
255    } catch (Exception e)
256    {
257  0 e.printStackTrace();
258  0 Assert.fail("Exception thrown while testing...");
259    }
260    }
261   
 
262  0 toggle @Test(groups = { "Functional" })
263    public void coverageForEqualsAndHashFunction()
264    {
265  0 Set<FTSDataColumnI> uniqueSet = new HashSet<FTSDataColumnI>();
266  0 Collection<FTSDataColumnI> searchableCols = ftsRestClient
267    .getSearchableDataColumns();
268  0 for (FTSDataColumnI foundCol : searchableCols)
269    {
270  0 System.out.println(foundCol.toString());
271  0 uniqueSet.add(foundCol);
272  0 uniqueSet.add(foundCol);
273    }
274  0 Assert.assertTrue(!uniqueSet.isEmpty());
275  0 Assert.assertEquals(uniqueSet.size(), 22);
276    }
277   
 
278  0 toggle @Test(groups = { "Functional" })
279    public void coverageForMiscellaneousBranches()
280    {
281  0 String actual = ftsRestClient.getPrimaryKeyColumn().toString();
282  0 Assert.assertEquals(actual, "Uniprot Id");
283   
284  0 String actualGroupStr;
285  0 try
286    {
287  0 actualGroupStr = ftsRestClient.getDataColumnGroupById("g4")
288    .toString();
289  0 Assert.assertEquals(actualGroupStr, "Procedures & Softwares");
290  0 actualGroupStr = ftsRestClient
291    .getDataColumnGroupById("unavailable group").toString();
292    } catch (Exception e)
293    {
294  0 Assert.assertTrue(true);
295    }
296   
297  0 String actualResourseFile = ftsRestClient
298    .getResourceFile("/fts/uniprot_data_columns.txt");
299  0 Assert.assertNotNull(actualResourseFile);
300  0 Assert.assertTrue(actualResourseFile.length() > 31);
301    }
302   
 
303  0 toggle @Test(groups = { "Functional" }, expectedExceptions = Exception.class)
304    public void coverageForExceptionBranches() throws Exception
305    {
306  0 try
307    {
308  0 ftsRestClient.getDataColumnByNameOrCode("unavailable column");
309    } catch (Exception e)
310    {
311  0 System.out.println(e.getMessage());
312  0 String expectedMessage = "Couldn't find data column with name : unavailable column";
313  0 Assert.assertEquals(e.getMessage(), expectedMessage);
314    }
315  0 try
316    {
317  0 ftsRestClient.getDataColumnGroupById("unavailable column group Id");
318    } catch (Exception e)
319    {
320  0 System.out.println(e.getMessage());
321  0 String expectedMessage = "Couldn't find data column group with id : unavailable column group Id";
322  0 Assert.assertEquals(e.getMessage(), expectedMessage);
323    }
324   
325  0 ftsRestClient.getDataColumnByNameOrCode("unavailable column");
326   
327  0 ftsRestClient.getResourceFile("unavailable resource file");
328   
329    }
330   
331    }