package jalview.ws.gui;
import java.awt.BorderLayout;
+import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.JPanel;
import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
-import compbio.metadata.Option;
-import compbio.metadata.Parameter;
import compbio.metadata.Preset;
import compbio.metadata.PresetManager;
{
Cache.initLogger();
disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
-
}
+ /**
+ * This test marked Ignore as it appears to need user action to complete
+ * rather than hang
+ */
@Test
+ @Ignore
public void testJws2Gui()
{
- Jws2Instance lastserv = null;
Iterator<String> presetEnum = presetTests.iterator();
for (Jws2Instance service : disc.getServices())
{
- lastserv = service;
if (serviceTests.size() == 0
|| serviceTests.contains(service.serviceType.toLowerCase()))
{
- if (lastserv != null)
+ List<Preset> prl = null;
+ Preset pr = null;
+ if (presetEnum.hasNext())
{
- List<Preset> prl = null;
- Preset pr = null;
- if (presetEnum.hasNext())
+ PresetManager prman = service.getPresets();
+ if (prman != null)
{
- PresetManager prman = lastserv.getPresets();
- if (prman != null)
+ pr = prman.getPresetByName(presetEnum.next());
+ if (pr == null)
{
- pr = prman.getPresetByName(presetEnum.next());
- if (pr == null)
- {
- // just grab the last preset.
- prl = prman.getPresets();
- }
+ // just grab the last preset.
+ prl = prman.getPresets();
}
}
- else
+ }
+ else
+ {
+ PresetManager prman = service.getPresets();
+ if (prman != null)
{
- PresetManager prman = lastserv.getPresets();
- if (prman != null)
- {
- prl = prman.getPresets();
- }
+ prl = prman.getPresets();
}
- Iterator<Preset> en = (prl == null) ? null : prl.iterator();
- while (en != null && en.hasNext())
+ }
+ Iterator<Preset> en = (prl == null) ? null : prl.iterator();
+ while (en != null && en.hasNext())
+ {
+ if (en != null)
{
- if (en != null)
- {
- if (!en.hasNext())
- {
- en = prl.iterator();
- }
- pr = en.next();
- }
+ if (!en.hasNext())
{
- System.out.println("Testing opts dupes for "
- + lastserv.getUri() + " : "
- + lastserv.getActionText() + ":" + pr.getName());
- List<Option> rg = lastserv.getRunnerConfig().getOptions();
- for (Option o : rg)
- {
- try
- {
- Option cpy = jalview.ws.jws2.ParameterUtils.copyOption(o);
- } catch (Exception e)
- {
- System.err.println("Failed to copy " + o.getName());
- e.printStackTrace();
- } catch (Error e)
- {
- System.err.println("Failed to copy " + o.getName());
- e.printStackTrace();
- }
- }
+ en = prl.iterator();
}
+ pr = en.next();
+ }
+ WsJobParameters pgui = new WsJobParameters(service,
+ new JabaPreset(service, pr));
+ JFrame jf = new JFrame(MessageManager.formatMessage(
+ "label.ws_parameters_for", new String[]
+ { service.getActionText() }));
+ jf.setSize(700, 800);
+ JPanel cont = new JPanel(new BorderLayout());
+ pgui.validate();
+ cont.setPreferredSize(pgui.getPreferredSize());
+ cont.add(pgui, BorderLayout.CENTER);
+ jf.setLayout(new BorderLayout());
+ jf.add(cont, BorderLayout.CENTER);
+ jf.validate();
+
+ final Thread thr = Thread.currentThread();
+
+ /*
+ * This seems to need a user to manually inspect / test / close the
+ * GUI for each service tested. Not standalone JUnit.
+ */
+ jf.addWindowListener(new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent e)
{
- System.out.println("Testing param dupes:");
- List<Parameter> rg = lastserv.getRunnerConfig()
- .getParameters();
- for (Parameter o : rg)
- {
- try
- {
- Parameter cpy = jalview.ws.jws2.ParameterUtils
- .copyParameter(o);
- } catch (Exception e)
- {
- System.err.println("Failed to copy " + o.getName());
- e.printStackTrace();
- } catch (Error e)
- {
- System.err.println("Failed to copy " + o.getName());
- e.printStackTrace();
- }
- }
+ thr.interrupt();
}
+ });
+ jf.setVisible(true);
+ boolean inter = false;
+ while (!inter)
+ {
+ try
{
- System.out.println("Testing param write:");
- List<String> writeparam = null, readparam = null;
- try
- {
- writeparam = jalview.ws.jws2.ParameterUtils
- .writeParameterSet(
- pr.getArguments(lastserv.getRunnerConfig()),
- " ");
- System.out.println("Testing param read :");
- List<Option> pset = jalview.ws.jws2.ParameterUtils
- .processParameters(writeparam,
- lastserv.getRunnerConfig(), " ");
- readparam = jalview.ws.jws2.ParameterUtils
- .writeParameterSet(pset, " ");
- Iterator<String> o = pr.getOptions().iterator(), s = writeparam
- .iterator(), t = readparam.iterator();
- boolean failed = false;
- while (s.hasNext() && t.hasNext())
- {
- String on = o.next(), sn = s.next(), st = t.next();
- if (!sn.equals(st))
- {
- System.out.println("Original was " + on
- + " Phase 1 wrote " + sn + "\tPhase 2 wrote "
- + st);
- failed = true;
- }
- }
- if (failed)
- {
- System.out.println("Original parameters:\n"
- + pr.getOptions());
- System.out.println("Wrote parameters in first set:\n"
- + writeparam);
- System.out.println("Wrote parameters in second set:\n"
- + readparam);
-
- }
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- WsJobParameters pgui = new WsJobParameters(lastserv,
- new JabaPreset(lastserv, pr));
- JFrame jf = new JFrame(MessageManager.formatMessage("label.ws_parameters_for", new String[]{lastserv.getActionText()}));
- JPanel cont = new JPanel(new BorderLayout());
- pgui.validate();
- cont.setPreferredSize(pgui.getPreferredSize());
- cont.add(pgui, BorderLayout.CENTER);
- jf.setLayout(new BorderLayout());
- jf.add(cont, BorderLayout.CENTER);
- jf.validate();
- final Thread thr = Thread.currentThread();
- jf.addWindowListener(new WindowListener()
- {
-
- public void windowActivated(WindowEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void windowClosed(WindowEvent e)
- {
- }
-
- public void windowClosing(WindowEvent e)
- {
- thr.interrupt();
-
- }
-
- public void windowDeactivated(WindowEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void windowDeiconified(WindowEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void windowIconified(WindowEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void windowOpened(WindowEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- });
- jf.setVisible(true);
- boolean inter = false;
- while (!inter)
+ Thread.sleep(10 * 1000);
+ } catch (InterruptedException e)
{
- try
- {
- Thread.sleep(10000);
- } catch (Exception e)
- {
- inter = true;
- }
- ;
+ inter = true;
}
- jf.dispose();
}
+ jf.dispose();
}
}
}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.ws.jws2;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import compbio.metadata.Option;
+import compbio.metadata.Parameter;
+import compbio.metadata.Preset;
+import compbio.metadata.PresetManager;
+import compbio.metadata.WrongParameterException;
+
+import jalview.bin.Cache;
+import jalview.ws.jabaws.JalviewJabawsTestUtils;
+import jalview.ws.jws2.jabaws2.Jws2Instance;
+
+public class ParameterUtilsTest
+{
+ /*
+ * To limit tests to specify services, add them to this list; leave list empty
+ * to test all
+ */
+ private static List<String> serviceTests = new ArrayList<String>();
+
+ private static Jws2Discoverer disc = null;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception
+ {
+ serviceTests.add("AAConWS".toLowerCase());
+ Cache.initLogger();
+ disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
+ }
+
+ @Test
+ public void testWriteParameterSet() throws WrongParameterException
+ {
+ for (Jws2Instance service : disc.getServices())
+ {
+ if (isForTesting(service))
+ {
+
+ List<Preset> prl = null;
+ PresetManager prman = service.getPresets();
+ if (prman == null)
+ {
+ continue;
+ }
+ prl = prman.getPresets();
+ if (prl == null)
+ {
+ continue;
+ }
+ for (Preset pr : prl)
+ {
+ List<String> writeparam = null;
+ List<String> readparam = null;
+ writeparam = ParameterUtils.writeParameterSet(
+ pr.getArguments(service.getRunnerConfig()), " ");
+ List<Option> pset = ParameterUtils.processParameters(writeparam,
+ service.getRunnerConfig(), " ");
+ readparam = ParameterUtils.writeParameterSet(pset, " ");
+ Iterator<String> o = pr.getOptions().iterator();
+ Iterator<String> s = writeparam.iterator();
+ Iterator<String> t = readparam.iterator();
+ boolean failed = false;
+ while (s.hasNext() && t.hasNext())
+ {
+ String on = o.next();
+ String sn = s.next();
+ String st = t.next();
+ final String errorMsg = "Original was " + on + " Phase 1 wrote " + sn
+ + "\tPhase 2 wrote " + st;
+ assertEquals(errorMsg, sn, st);
+ assertEquals(errorMsg, sn, on);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns true if the service is in the list of the ones we chose to test,
+ * _or_ the list is empty (test all)
+ *
+ * @param service
+ * @return
+ */
+ public boolean isForTesting(Jws2Instance service)
+ {
+ return serviceTests.size() == 0
+ || serviceTests.contains(service.serviceType.toLowerCase());
+ }
+
+ @Test
+ public void testCopyOption()
+ {
+ for (Jws2Instance service : disc.getServices())
+ {
+ if (isForTesting(service))
+ {
+ List<Option<?>> options = service.getRunnerConfig().getOptions();
+ for (Option<?> o : options)
+ {
+ System.out.println("Testing copyOption for option " + o.getName()
+ + " of " + service.getActionText());
+ Option<?> cpy = ParameterUtils.copyOption(o);
+ assertTrue(cpy.equals(o));
+ assertEquals(cpy.getName(), o.getName());
+ assertFalse(cpy == o);
+ // todo more assertions?
+ }
+ }
+ }
+ }
+
+ /**
+ */
+ @Test
+ public void testCopyParameter()
+ {
+ for (Jws2Instance service : disc.getServices())
+ {
+ if (isForTesting(service))
+ {
+ List<Parameter> parameters = service.getRunnerConfig()
+ .getParameters();
+ for (Parameter o : parameters)
+ {
+ System.out.println("Testing copyParameter for parameter "
+ + o.getName() + " of " + service.getActionText());
+ Parameter cpy = ParameterUtils.copyParameter(o);
+ assertTrue(cpy.equals(o));
+ assertFalse(cpy == o);
+ assertEquals(cpy.getName(), o.getName());
+ // todo more assertions?
+ }
+ }
+ }
+ }
+}