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.
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
26 import jalview.datamodel.DBRefEntry;
27 import jalview.datamodel.DBRefSource;
28 import jalview.datamodel.PDBEntry;
29 import jalview.datamodel.Sequence;
30 import jalview.datamodel.SequenceI;
31 import jalview.jbgui.GStructureChooser.FilterOption;
33 import java.util.Vector;
35 import org.testng.annotations.AfterMethod;
36 import org.testng.annotations.BeforeClass;
37 import org.testng.annotations.BeforeMethod;
38 import org.testng.annotations.Test;
40 public class StructureChooserTest
43 @BeforeClass(alwaysRun = true)
44 public void setUpJvOptionPane()
46 JvOptionPane.setInteractiveMode(false);
47 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
52 @BeforeMethod(alwaysRun = true)
53 public void setUp() throws Exception
55 seq = new Sequence("PDB|4kqy|4KQY|A", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1,
57 seq.createDatasetSequence();
58 for (int x = 1; x < 5; x++)
60 DBRefEntry dbRef = new DBRefEntry();
61 dbRef.setAccessionId("XYZ_" + x);
65 PDBEntry dbRef = new PDBEntry();
68 Vector<PDBEntry> pdbIds = new Vector<>();
74 @AfterMethod(alwaysRun = true)
75 public void tearDown() throws Exception
80 @Test(groups = { "Functional" })
81 public void buildQueryTest()
83 String query = StructureChooser.buildQuery(seq);
84 assertEquals("pdb_id:1tim", query);
85 System.out.println("seq >>>> " + seq);
86 seq.getAllPDBEntries().clear();
87 query = StructureChooser.buildQuery(seq);
89 "text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4 OR text:4kqy",
92 query = StructureChooser.buildQuery(seq);
93 assertEquals("text:4kqy", query);
95 DBRefEntry uniprotDBRef = new DBRefEntry();
96 uniprotDBRef.setAccessionId("P12345");
97 uniprotDBRef.setSource(DBRefSource.UNIPROT);
98 seq.addDBRef(uniprotDBRef);
100 DBRefEntry pdbDBRef = new DBRefEntry();
101 pdbDBRef.setAccessionId("1XYZ");
102 pdbDBRef.setSource(DBRefSource.PDB);
103 seq.addDBRef(pdbDBRef);
105 for (int x = 1; x < 5; x++)
107 DBRefEntry dbRef = new DBRefEntry();
108 dbRef.setAccessionId("XYZ_" + x);
111 query = StructureChooser.buildQuery(seq);
113 "uniprot_accession:P12345 OR uniprot_id:P12345 OR pdb_id:1xyz",
117 @Test(groups = { "Functional" })
118 public void populateFilterComboBoxTest() throws InterruptedException
120 SequenceI[] selectedSeqs = new SequenceI[] { seq };
121 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
122 sc.populateFilterComboBox(false, false);
123 int optionsSize = sc.getCmbFilterOption().getItemCount();
124 assertEquals(2, optionsSize); // if structures are not discovered then don't
125 // populate filter options
127 sc.populateFilterComboBox(true, false);
128 optionsSize = sc.getCmbFilterOption().getItemCount();
129 assertTrue(optionsSize > 3); // if structures are found, filter options
130 // should be populated
132 sc.populateFilterComboBox(true, true);
133 assertTrue(sc.getCmbFilterOption().getSelectedItem() != null);
134 FilterOption filterOpt = (FilterOption) sc.getCmbFilterOption()
136 assertEquals("Cached Structures", filterOpt.getName());
139 @Test(groups = { "Network" })
140 public void fetchStructuresInfoTest()
142 SequenceI[] selectedSeqs = new SequenceI[] { seq };
143 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
144 sc.fetchStructuresMetaData();
145 assertTrue(sc.getDiscoveredStructuresSet() != null);
146 assertTrue(sc.getDiscoveredStructuresSet().size() > 0);
150 @Test(groups = { "Functional" })
151 public void sanitizeSeqNameTest()
153 String name = "ab_cdEF|fwxyz012349";
154 assertEquals(name, StructureChooser.sanitizeSeqName(name));
156 // remove a [nn] substring
157 name = "abcde12[345]fg";
158 assertEquals("abcde12fg", StructureChooser.sanitizeSeqName(name));
160 // remove characters other than a-zA-Z0-9 | or _
161 name = "ab[cd],.\t£$*!- \\\"@:e";
162 assertEquals("abcde", StructureChooser.sanitizeSeqName(name));
164 name = "abcde12[345a]fg";
165 assertEquals("abcde12345afg", StructureChooser.sanitizeSeqName(name));