JAL-2089 patch broken merge to master for Release 2.10.0b1
[jalview.git] / test / jalview / fts / service / pdb / PDBFTSPanelTest.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.fts.service.pdb;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
25
26 import javax.swing.JInternalFrame;
27 import javax.swing.JTextField;
28
29 import org.testng.annotations.AfterMethod;
30 import org.testng.annotations.BeforeMethod;
31 import org.testng.annotations.Test;
32
33 public class PDBFTSPanelTest
34 {
35
36   @BeforeMethod(alwaysRun = true)
37   public void setUp() throws Exception
38   {
39   }
40
41   @AfterMethod(alwaysRun = true)
42   public void tearDown() throws Exception
43   {
44   }
45
46   @Test(groups = { "Functional" })
47   public void populateCmbSearchTargetOptionsTest()
48   {
49     PDBFTSPanel searchPanel = new PDBFTSPanel(null);
50     assertTrue(searchPanel.getCmbSearchTarget().getItemCount() > 0);
51     searchPanel.populateCmbSearchTargetOptions();
52   }
53
54   @Test(groups = { "Functional" })
55   public void testDecodeSearchTerm()
56   {
57     String expectedString = "1xyz OR text:2xyz OR text:3xyz";
58     String outcome = PDBFTSPanel.decodeSearchTerm("1xyz:A;2xyz;3xyz",
59             "text");
60     // System.out.println("1 >>>>>>>>>>> " + outcome);
61     assertEquals(expectedString, outcome);
62
63     expectedString = "1xyz";
64     outcome = PDBFTSPanel.decodeSearchTerm("1xyz", "text");
65     // System.out.println("2 >>>>>>>>>>> " + outcome);
66     assertEquals(expectedString, outcome);
67   }
68
69   @Test(groups = { "Functional" })
70   public void testgetPDBIdwithSpecifiedChain()
71   {
72
73     String expectedString = "1xyz:A";
74     String outcome = PDBFTSPanel.getPDBIdwithSpecifiedChain("1xyz",
75             "2xyz;3xyz;1xyz:A");
76     System.out.println("1 >>>>>>>>>>> " + outcome);
77     assertEquals(expectedString, outcome);
78
79     expectedString = "2xyz";
80     outcome = PDBFTSPanel.getPDBIdwithSpecifiedChain("2xyz",
81             "1xyz:A;2xyz;3xyz");
82     System.out.println("2 >>>>>>>>>>> " + outcome);
83     assertEquals(expectedString, outcome);
84
85     expectedString = "2xyz:A";
86     outcome = PDBFTSPanel.getPDBIdwithSpecifiedChain("2xyz", "2xyz:A");
87     System.out.println("3 >>>>>>>>>>> " + outcome);
88     assertEquals(expectedString, outcome);
89   }
90
91   @Test(groups = { "External" }, timeOut = 7000)
92   public void txt_search_ActionPerformedTest()
93   {
94     PDBFTSPanel searchPanel = new PDBFTSPanel(null);
95     JInternalFrame mainFrame = searchPanel.getMainFrame();
96     JTextField txt_search = searchPanel.getTxtSearch();
97
98     assertTrue(mainFrame.getTitle().length() == 20);
99     assertTrue(mainFrame.getTitle()
100             .equalsIgnoreCase("PDB Sequence Fetcher"));
101     txt_search.setText("ABC");
102     try
103     {
104       // wait for web-service to handle response
105       Thread.sleep(3000);
106     } catch (InterruptedException e)
107     {
108       e.printStackTrace();
109     }
110     assertTrue(mainFrame.getTitle().length() > 20);
111     assertTrue(!mainFrame.getTitle().equalsIgnoreCase(
112             "PDB Sequence Fetcher"));
113   }
114
115 }