Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.gui

File StructureChooserTest.java

 

Code metrics

4
63
7
1
175
125
9
0.14
9
7
1.29

Classes

Class Line # Actions
StructureChooserTest 46 63 9
0.905405490.5%
 

Contributing tests

This file is covered by 3 tests. .

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.gui;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertNotNull;
25    import static org.testng.AssertJUnit.assertTrue;
26   
27    import jalview.datamodel.DBRefEntry;
28    import jalview.datamodel.DBRefSource;
29    import jalview.datamodel.PDBEntry;
30    import jalview.datamodel.Sequence;
31    import jalview.datamodel.SequenceI;
32    import jalview.fts.api.FTSData;
33    import jalview.jbgui.GStructureChooser.FilterOption;
34    import jalview.ws.params.InvalidArgumentException;
35   
36    import java.util.Collection;
37    import java.util.Vector;
38   
39    import org.testng.annotations.AfterMethod;
40    import org.testng.annotations.BeforeClass;
41    import org.testng.annotations.BeforeMethod;
42    import org.testng.annotations.Test;
43   
44    import junit.extensions.PA;
45   
 
46    public class StructureChooserTest
47    {
48   
 
49  1 toggle @BeforeClass(alwaysRun = true)
50    public void setUpJvOptionPane()
51    {
52  1 JvOptionPane.setInteractiveMode(false);
53  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
54    }
55   
56    Sequence seq;
57   
 
58  3 toggle @BeforeMethod(alwaysRun = true)
59    public void setUp() throws Exception
60    {
61  3 seq = new Sequence("PDB|4kqy|4KQY|A", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1,
62    26);
63  3 seq.createDatasetSequence();
64  15 for (int x = 1; x < 5; x++)
65    {
66  12 DBRefEntry dbRef = new DBRefEntry();
67  12 dbRef.setAccessionId("XYZ_" + x);
68  12 seq.addDBRef(dbRef);
69    }
70   
71  3 PDBEntry dbRef = new PDBEntry();
72  3 dbRef.setId("1tim");
73   
74  3 Vector<PDBEntry> pdbIds = new Vector<>();
75  3 pdbIds.add(dbRef);
76   
77  3 seq.setPDBId(pdbIds);
78    }
79   
 
80  3 toggle @AfterMethod(alwaysRun = true)
81    public void tearDown() throws Exception
82    {
83  3 seq = null;
84    }
85   
 
86  1 toggle @Test(groups = { "Functional" })
87    public void buildQueryTest()
88    {
89  1 String query = StructureChooser.buildQuery(seq);
90  1 assertEquals("pdb_id:1tim", query);
91  1 System.out.println("seq >>>> " + seq);
92  1 seq.getAllPDBEntries().clear();
93  1 query = StructureChooser.buildQuery(seq);
94  1 assertEquals(
95    "text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4 OR text:4kqy",
96    query);
97  1 seq.setDBRefs(null);
98  1 query = StructureChooser.buildQuery(seq);
99  1 assertEquals("text:4kqy", query);
100   
101  1 DBRefEntry uniprotDBRef = new DBRefEntry();
102  1 uniprotDBRef.setAccessionId("P12345");
103  1 uniprotDBRef.setSource(DBRefSource.UNIPROT);
104  1 seq.addDBRef(uniprotDBRef);
105   
106  1 DBRefEntry pdbDBRef = new DBRefEntry();
107  1 pdbDBRef.setAccessionId("1XYZ");
108  1 pdbDBRef.setSource(DBRefSource.PDB);
109  1 seq.addDBRef(pdbDBRef);
110   
111  5 for (int x = 1; x < 5; x++)
112    {
113  4 DBRefEntry dbRef = new DBRefEntry();
114  4 dbRef.setAccessionId("XYZ_" + x);
115  4 seq.addDBRef(dbRef);
116    }
117  1 query = StructureChooser.buildQuery(seq);
118  1 assertEquals(
119    "uniprot_accession:P12345 OR uniprot_id:P12345 OR pdb_id:1xyz",
120    query);
121    }
122   
 
123  1 toggle @Test(groups = { "Functional" })
124    public void populateFilterComboBoxTest() throws InterruptedException
125    {
126  1 SequenceI[] selectedSeqs = new SequenceI[] { seq };
127  1 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
128  1 sc.populateFilterComboBox(false, false);
129  1 int optionsSize = sc.getCmbFilterOption().getItemCount();
130  1 assertEquals(2, optionsSize); // if structures are not discovered then don't
131    // populate filter options
132   
133  1 sc.populateFilterComboBox(true, false);
134  1 optionsSize = sc.getCmbFilterOption().getItemCount();
135  1 assertTrue(optionsSize > 3); // if structures are found, filter options
136    // should be populated
137   
138  1 sc.populateFilterComboBox(true, true);
139  1 assertTrue(sc.getCmbFilterOption().getSelectedItem() != null);
140  1 FilterOption filterOpt = (FilterOption) sc.getCmbFilterOption()
141    .getSelectedItem();
142  1 assertEquals("Cached Structures", filterOpt.getName());
143    }
144   
 
145  0 toggle @Test(groups = { "Network" })
146    public void fetchStructuresInfoTest()
147    {
148  0 SequenceI[] selectedSeqs = new SequenceI[] { seq };
149  0 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
150  0 sc.fetchStructuresMetaData();
151  0 Collection<FTSData> ss = (Collection<FTSData>) PA.getValue(sc,
152    "discoveredStructuresSet");
153  0 assertNotNull(ss);
154  0 assertTrue(ss.size() > 0);
155   
156    }
157   
 
158  1 toggle @Test(groups = { "Functional" })
159    public void sanitizeSeqNameTest()
160    {
161  1 String name = "ab_cdEF|fwxyz012349";
162  1 assertEquals(name, StructureChooser.sanitizeSeqName(name));
163   
164    // remove a [nn] substring
165  1 name = "abcde12[345]fg";
166  1 assertEquals("abcde12fg", StructureChooser.sanitizeSeqName(name));
167   
168    // remove characters other than a-zA-Z0-9 | or _
169  1 name = "ab[cd],.\t£$*!- \\\"@:e";
170  1 assertEquals("abcde", StructureChooser.sanitizeSeqName(name));
171   
172  1 name = "abcde12[345a]fg";
173  1 assertEquals("abcde12345afg", StructureChooser.sanitizeSeqName(name));
174    }
175    }