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.PDBEntry;
28 import jalview.datamodel.Sequence;
29 import jalview.datamodel.SequenceI;
31 import java.util.Vector;
33 import org.testng.annotations.AfterMethod;
34 import org.testng.annotations.BeforeMethod;
35 import org.testng.annotations.Test;
37 public class StructureChooserTest
41 @BeforeMethod(alwaysRun = true)
42 public void setUp() throws Exception
44 seq = new Sequence("PDB|4kqy|4KQY|A", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1,
46 seq.setDatasetSequence(seq);
47 for (int x = 1; x < 5; x++)
49 DBRefEntry dbRef = new DBRefEntry();
50 dbRef.setAccessionId("XYZ_" + x);
54 PDBEntry dbRef = new PDBEntry();
57 Vector<PDBEntry> pdbIds = new Vector<PDBEntry>();
63 @AfterMethod(alwaysRun = true)
64 public void tearDown() throws Exception
69 @Test(groups = { "Functional" })
70 public void buildQueryTest()
72 String query = StructureChooser.buildQuery(seq);
73 assertEquals("pdb_id:1tim", query);
74 System.out.println("seq >>>> " + seq);
75 seq.getAllPDBEntries().clear();
76 query = StructureChooser.buildQuery(seq);
78 "text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4 OR text:4kqy",
81 query = StructureChooser.buildQuery(seq);
82 assertEquals("text:4kqy", query);
85 @Test(groups = { "Functional" })
86 public void populateFilterComboBoxTest()
88 SequenceI[] selectedSeqs = new SequenceI[] { seq };
89 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
90 sc.populateFilterComboBox();
91 int optionsSize = sc.getCmbFilterOption().getItemCount();
92 assertEquals(3, optionsSize); // if structures are not discovered then don't
93 // populate filter options
95 sc.setStructuresDiscovered(true);
96 sc.populateFilterComboBox();
100 } catch (InterruptedException e)
104 optionsSize = sc.getCmbFilterOption().getItemCount();
105 assertTrue(optionsSize > 3); // if structures are found, filter options
106 // should be populated
109 @Test(groups = { "Functional" })
110 public void fetchStructuresInfoTest()
112 SequenceI[] selectedSeqs = new SequenceI[] { seq };
113 StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
114 sc.fetchStructuresMetaData();
115 assertTrue(sc.getDiscoveredStructuresSet() != null);
116 assertTrue(sc.getDiscoveredStructuresSet().size() > 0);
120 @Test(groups = { "Functional" })
121 public void sanitizeSeqNameTest()
123 String name = "ab_cdEF|fwxyz012349";
124 assertEquals(name, StructureChooser.sanitizeSeqName(name));
126 // remove a [nn] substring
127 name = "abcde12[345]fg";
128 assertEquals("abcde12fg", StructureChooser.sanitizeSeqName(name));
130 // remove characters other than a-zA-Z0-9 | or _
131 name = "ab[cd],.\t£$*!- \\\"@:e";
132 assertEquals("abcde", StructureChooser.sanitizeSeqName(name));
134 name = "abcde12[345a]fg";
135 assertEquals("abcde12345afg", StructureChooser.sanitizeSeqName(name));