Revert "Merge branch 'bug/JAL-3807_jpred-with-slivka' into alpha/JAL-3066_Jalview_212...
[jalview.git] / test / jalview / ws / gui / Jws2ParamView.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.ws.gui;
22
23 import jalview.bin.Cache;
24 import jalview.gui.JvOptionPane;
25 import jalview.gui.WsJobParameters;
26 import jalview.util.MessageManager;
27 import jalview.ws.api.ServiceWithParameters;
28 import jalview.ws.jabaws.JalviewJabawsTestUtils;
29 import jalview.ws.jws2.JabaPreset;
30 import jalview.ws.jws2.Jws2Discoverer;
31 import jalview.ws.jws2.jabaws2.Jws2Instance;
32 import jalview.ws.params.ArgumentI;
33 import jalview.ws.params.ParamDatastoreI;
34
35 import java.awt.BorderLayout;
36 import java.awt.event.WindowAdapter;
37 import java.awt.event.WindowEvent;
38 import java.util.ArrayList;
39 import java.util.Iterator;
40 import java.util.List;
41
42 import javax.swing.JFrame;
43 import javax.swing.JPanel;
44
45 import org.testng.annotations.BeforeClass;
46 import org.testng.annotations.Test;
47
48 import compbio.metadata.Preset;
49 import compbio.metadata.PresetManager;
50
51 public class Jws2ParamView
52 {
53
54   @BeforeClass(alwaysRun = true)
55   public void setUpJvOptionPane()
56   {
57     JvOptionPane.setInteractiveMode(false);
58     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
59   }
60
61   /**
62    * which services to test
63    */
64   public static List<String> serviceTests = new ArrayList<>();
65
66   /**
67    * which presets to test for services
68    */
69   public static List<String> presetTests = new ArrayList<>();
70   static
71   {
72     serviceTests.add("AAConWS".toLowerCase());
73   }
74
75   public static Jws2Discoverer disc = null;
76
77   @BeforeClass(alwaysRun = true)
78   public static void setUpBeforeClass() throws Exception
79   {
80     Cache.loadProperties("test/jalview/io/testProps.jvprops");
81     Cache.initLogger();
82     disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
83   }
84
85   /**
86    * This test marked Interactive as it appears to need user action to complete
87    * rather than hang
88    */
89
90   @Test(groups = { "Interactive" }, enabled = true)
91   public void testJws2Gui()
92   {
93     Iterator<String> presetEnum = presetTests.iterator();
94     for (ServiceWithParameters _service : disc.getServices())
95     {
96       // This will fail for non-jabaws services
97       Jws2Instance service = (Jws2Instance) _service;
98       if (serviceTests.size() == 0
99               || serviceTests.contains(service.getName().toLowerCase()))
100       {
101         List<Preset> prl = null;
102         Preset pr = null;
103         if (presetEnum.hasNext())
104         {
105           PresetManager prman = service.getPresets();
106           if (prman != null)
107           {
108             pr = prman.getPresetByName(presetEnum.next());
109             if (pr == null)
110             {
111               // just grab the last preset.
112               prl = prman.getPresets();
113             }
114           }
115         }
116         else
117         {
118           PresetManager prman = service.getPresets();
119           if (prman != null)
120           {
121             prl = prman.getPresets();
122           }
123         }
124         Iterator<Preset> en = (prl == null) ? null : prl.iterator();
125         while (en != null && en.hasNext())
126         {
127           if (en != null)
128           {
129             if (!en.hasNext())
130             {
131               en = prl.iterator();
132             }
133             pr = en.next();
134           }
135           WsJobParameters pgui = new WsJobParameters((ParamDatastoreI) null,
136                   service, new JabaPreset(service, pr),
137                   (List<ArgumentI>) null);
138           JFrame jf = new JFrame(MessageManager
139                   .formatMessage("label.ws_parameters_for", new String[]
140                   { service.getActionText() }));
141           jf.setSize(700, 800);
142           JPanel cont = new JPanel(new BorderLayout());
143           pgui.validate();
144           cont.setPreferredSize(pgui.getPreferredSize());
145           cont.add(pgui, BorderLayout.CENTER);
146           jf.setLayout(new BorderLayout());
147           jf.add(cont, BorderLayout.CENTER);
148           jf.validate();
149
150           final Thread thr = Thread.currentThread();
151
152           /*
153            * This seems to need a user to manually inspect / test / close the
154            * GUI for each service tested. Not standalone JUnit.
155            */
156           jf.addWindowListener(new WindowAdapter()
157           {
158             @Override
159             public void windowClosing(WindowEvent e)
160             {
161               thr.interrupt();
162             }
163           });
164           jf.setVisible(true);
165           boolean inter = false;
166           while (!inter)
167           {
168             try
169             {
170               Thread.sleep(10 * 1000);
171             } catch (InterruptedException e)
172             {
173               inter = true;
174             }
175           }
176           jf.dispose();
177         }
178       }
179     }
180   }
181 }