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.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
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;
36 import java.util.Collection;
37 import java.util.Vector;
39 import org.testng.annotations.AfterMethod;
40 import org.testng.annotations.BeforeClass;
41 import org.testng.annotations.BeforeMethod;
42 import org.testng.annotations.Test;
44 import junit.extensions.PA;
46 public class StructureChooserTest
49 @BeforeClass(alwaysRun = true)
50 public void setUpJvOptionPane()
52 JvOptionPane.setInteractiveMode(false);
53 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
58 @BeforeMethod(alwaysRun = true)
59 public void setUp() throws Exception
61 seq = new Sequence("PDB|4kqy|4KQY|A", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1,
63 seq.createDatasetSequence();
64 for (int x = 1; x < 5; x++)
66 DBRefEntry dbRef = new DBRefEntry();
67 dbRef.setAccessionId("XYZ_" + x);
71 PDBEntry dbRef = new PDBEntry();
74 Vector<PDBEntry> pdbIds = new Vector<>();
80 @AfterMethod(alwaysRun = true)
81 public void tearDown() throws Exception
86 @SuppressWarnings("deprecation")
87 @Test(groups = { "Functional" })
88 public void buildQueryTest()
90 System.out.println("seq >>>> " + seq);
91 StructureChooserQuerySource scquery = StructureChooserQuerySource.getPDBfts();
92 String query = scquery.buildQuery(seq);
93 assertEquals("pdb_id:1tim", query);
94 seq.getAllPDBEntries().clear();
95 query = scquery.buildQuery(seq);
97 "text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4 OR text:4kqy",
100 query = scquery.buildQuery(seq);
101 System.out.println(query);
102 assertEquals("text:4kqy", query);
104 DBRefEntry uniprotDBRef = new DBRefEntry();
105 uniprotDBRef.setAccessionId("P12345");
106 uniprotDBRef.setSource(DBRefSource.UNIPROT);
107 seq.addDBRef(uniprotDBRef);
109 DBRefEntry pdbDBRef = new DBRefEntry();
110 pdbDBRef.setAccessionId("1XYZ");
111 pdbDBRef.setSource(DBRefSource.PDB);
112 seq.addDBRef(pdbDBRef);
114 for (int x = 1; x < 5; x++)
116 DBRefEntry dbRef = new DBRefEntry();
117 dbRef.setAccessionId("XYZ_" + x);
120 System.out.println("");
121 System.out.println(seq.getDBRefs());
122 System.out.println(query);
123 query = scquery.buildQuery(seq);
125 "uniprot_accession:P12345 OR uniprot_id:P12345 OR pdb_id:1xyz",
129 @Test(groups = { "Functional" })
130 public void populateFilterComboBoxTest() throws InterruptedException
132 SequenceI[] selectedSeqs = new SequenceI[] { seq };
133 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
134 sc.populateFilterComboBox(false, false);
135 int optionsSize = sc.getCmbFilterOption().getItemCount();
136 assertEquals(2, optionsSize); // if structures are not discovered then don't
137 // populate filter options
139 sc.populateFilterComboBox(true, false);
140 optionsSize = sc.getCmbFilterOption().getItemCount();
141 assertTrue(optionsSize > 3); // if structures are found, filter options
142 // should be populated
144 sc.populateFilterComboBox(true, true);
145 assertTrue(sc.getCmbFilterOption().getSelectedItem() != null);
146 FilterOption filterOpt = (FilterOption) sc.getCmbFilterOption()
148 assertEquals("Cached Structures", filterOpt.getName());
151 @Test(groups = { "Network" })
152 public void fetchStructuresInfoTest()
154 SequenceI[] selectedSeqs = new SequenceI[] { seq };
155 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
156 sc.fetchStructuresMetaData();
157 Collection<FTSData> ss = (Collection<FTSData>) PA.getValue(sc,
158 "discoveredStructuresSet");
160 assertTrue(ss.size() > 0);
164 @Test(groups = { "Functional" })
165 public void sanitizeSeqNameTest()
167 String name = "ab_cdEF|fwxyz012349";
168 assertEquals(name, StructureChooserQuerySource.sanitizeSeqName(name));
170 // remove a [nn] substring
171 name = "abcde12[345]fg";
172 assertEquals("abcde12fg", StructureChooserQuerySource.sanitizeSeqName(name));
174 // remove characters other than a-zA-Z0-9 | or _
175 name = "ab[cd],.\t£$*!- \\\"@:e";
176 assertEquals("abcde", StructureChooserQuerySource.sanitizeSeqName(name));
178 name = "abcde12[345a]fg";
179 assertEquals("abcde12345afg", StructureChooserQuerySource.sanitizeSeqName(name));