1b00c4aff8a513de73739b832aeb6f111b424dda
[jalview.git] / test / jalview / gui / StructureChooserTest.java
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.assertTrue;
25
26 import jalview.datamodel.DBRefEntry;
27 import jalview.datamodel.PDBEntry;
28 import jalview.datamodel.Sequence;
29 import jalview.datamodel.SequenceI;
30
31 import java.util.Vector;
32
33 import org.testng.annotations.AfterMethod;
34 import org.testng.annotations.BeforeMethod;
35 import org.testng.annotations.Test;
36
37 public class StructureChooserTest
38 {
39   Sequence seq;
40
41   @BeforeMethod(alwaysRun = true)
42   public void setUp() throws Exception
43   {
44     seq = new Sequence("PDB|4kqy|4KQY|A", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1,
45             26);
46     seq.setDatasetSequence(seq);
47     for (int x = 1; x < 5; x++)
48     {
49       DBRefEntry dbRef = new DBRefEntry();
50       dbRef.setAccessionId("XYZ_" + x);
51       seq.addDBRef(dbRef);
52     }
53
54     PDBEntry dbRef = new PDBEntry();
55     dbRef.setId("1tim");
56
57     Vector<PDBEntry> pdbIds = new Vector<PDBEntry>();
58     pdbIds.add(dbRef);
59
60     seq.setPDBId(pdbIds);
61   }
62
63   @AfterMethod
64   public void tearDown() throws Exception
65   {
66     seq = null;
67   }
68
69   @Test(groups = { "Functional" })
70   public void buildQueryTest()
71   {
72     String query = StructureChooser.buildQuery(seq);
73     System.out.println(">>>>>>>>>> query : " + query);
74     assertEquals(
75             "4kqy OR text:1tim OR text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4",
76             query);
77   }
78
79   @Test(groups = { "Functional" })
80   public void populateFilterComboBoxTest()
81   {
82     SequenceI[] selectedSeqs = new SequenceI[] { seq };
83     StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
84     sc.populateFilterComboBox();
85     int optionsSize = sc.getCmbFilterOption().getItemCount();
86     assertEquals(3, optionsSize); // if structures are not discovered then don't
87                                   // populate filter options
88
89     sc.setStructuresDiscovered(true);
90     sc.populateFilterComboBox();
91     optionsSize = sc.getCmbFilterOption().getItemCount();
92     assertTrue(optionsSize > 3); // if structures are found, filter options
93                                  // should be populated
94   }
95
96   @Test(groups = { "Functional" })
97   public void fetchStructuresInfoTest()
98   {
99     SequenceI[] selectedSeqs = new SequenceI[] { seq };
100     StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
101     sc.fetchStructuresMetaData();
102     assertTrue(sc.getDiscoveredStructuresSet() != null);
103     assertTrue(sc.getDiscoveredStructuresSet().size() > 0);
104
105   }
106 }