JAL-2071 architectural improvement for Plugable Free Text Search Services
[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     assertEquals("pdb_id:1tim", query);
74     System.out.println("seq >>>> " + seq);
75     seq.getAllPDBEntries().clear();
76     query = StructureChooser.buildQuery(seq);
77     assertEquals(
78             "text:XYZ_1 OR text:XYZ_2 OR text:XYZ_3 OR text:XYZ_4 OR text:4kqy",
79             query);
80     seq.setDBRefs(null);
81     query = StructureChooser.buildQuery(seq);
82     assertEquals("text:4kqy", query);
83   }
84
85   @Test(groups = { "Functional" })
86   public void populateFilterComboBoxTest()
87   {
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
94
95     sc.setStructuresDiscovered(true);
96     sc.populateFilterComboBox();
97     try
98     {
99       Thread.sleep(2000);
100     } catch (InterruptedException e)
101     {
102       e.printStackTrace();
103     }
104     optionsSize = sc.getCmbFilterOption().getItemCount();
105     assertTrue(optionsSize > 3); // if structures are found, filter options
106                                  // should be populated
107   }
108
109   @Test(groups = { "Functional" })
110   public void fetchStructuresInfoTest()
111   {
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);
117
118   }
119 }