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