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