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