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