Merge branch 'alpha/JAL-3362_Jalview_212_alpha' into alpha/merge_212_JalviewJS_2112
[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.gui.JvOptionPane;
27
28 import javax.swing.JInternalFrame;
29
30 import org.testng.annotations.AfterMethod;
31 import org.testng.annotations.BeforeClass;
32 import org.testng.annotations.BeforeMethod;
33 import org.testng.annotations.Test;
34
35 import junit.extensions.PA;
36
37 public class PDBFTSPanelTest
38 {
39
40   @BeforeClass(alwaysRun = true)
41   public void setUpJvOptionPane()
42   {
43     JvOptionPane.setInteractiveMode(false);
44     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
45   }
46
47   @BeforeMethod(alwaysRun = true)
48   public void setUp() throws Exception
49   {
50   }
51
52   @AfterMethod(alwaysRun = true)
53   public void tearDown() throws Exception
54   {
55   }
56
57   @Test(groups = { "Functional" })
58   public void populateCmbSearchTargetOptionsTest()
59   {
60     PDBFTSPanel searchPanel = new PDBFTSPanel(null);
61     assertTrue(searchPanel.getCmbSearchTarget().getItemCount() > 0);
62     searchPanel.populateCmbSearchTargetOptions();
63   }
64
65   @Test(groups = { "Functional" })
66   public void testDecodeSearchTerm()
67   {
68     String expectedString = "1xyz OR text:2xyz OR text:3xyz";
69     String outcome = PDBFTSPanel.decodeSearchTerm("1xyz:A;2xyz;3xyz",
70             "text");
71     // System.out.println("1 >>>>>>>>>>> " + outcome);
72     assertEquals(expectedString, outcome);
73
74     expectedString = "1xyz";
75     outcome = PDBFTSPanel.decodeSearchTerm("1xyz", "text");
76     // System.out.println("2 >>>>>>>>>>> " + outcome);
77     assertEquals(expectedString, outcome);
78   }
79
80   @Test(groups = { "Functional" })
81   public void testgetPDBIdwithSpecifiedChain()
82   {
83
84     String expectedString = "1xyz:A";
85     String outcome = PDBFTSPanel.getPDBIdwithSpecifiedChain("1xyz",
86             "2xyz;3xyz;1xyz:A");
87     System.out.println("1 >>>>>>>>>>> " + outcome);
88     assertEquals(expectedString, outcome);
89
90     expectedString = "2xyz";
91     outcome = PDBFTSPanel.getPDBIdwithSpecifiedChain("2xyz",
92             "1xyz:A;2xyz;3xyz");
93     System.out.println("2 >>>>>>>>>>> " + outcome);
94     assertEquals(expectedString, outcome);
95
96     expectedString = "2xyz:A";
97     outcome = PDBFTSPanel.getPDBIdwithSpecifiedChain("2xyz", "2xyz:A");
98     System.out.println("3 >>>>>>>>>>> " + outcome);
99     assertEquals(expectedString, outcome);
100   }
101
102   @Test(groups = { "External" }, timeOut = 8000)
103   public void txt_search_ActionPerformedTest()
104   {
105     PDBFTSPanel searchPanel = new PDBFTSPanel(null);
106     JInternalFrame mainFrame = searchPanel.getMainFrame();
107 //    JComboBox<String> txt_search = PA.gsearchPanel.getTxtSearch();
108
109     assertTrue(mainFrame.getTitle().length() == 20);
110     assertTrue(mainFrame.getTitle()
111             .equalsIgnoreCase("PDB Sequence Fetcher"));
112     PA.invokeMethod(PA.getValue(searchPanel, "txt_search"), "setSelectedItem(java.lang.String)", "ABC");
113   //  txt_search.setSelectedItem("ABC");
114     try
115     {
116       // wait for web-service to handle response
117       Thread.sleep(3000);
118     } catch (InterruptedException e)
119     {
120       e.printStackTrace();
121     }
122     assertTrue(mainFrame.getTitle().length() > 20);
123     assertTrue(!mainFrame.getTitle().equalsIgnoreCase(
124             "PDB Sequence Fetcher"));
125   }
126
127 }