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