2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.ws.jws2;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertTrue;
27 import jalview.bin.Cache;
28 import jalview.gui.JvOptionPane;
29 import jalview.ws.api.UIinfo;
30 import jalview.ws.jabaws.JalviewJabawsTestUtils;
31 import jalview.ws.jws2.jabaws2.Jws2Instance;
33 import java.util.ArrayList;
34 import java.util.Iterator;
35 import java.util.List;
37 import org.testng.annotations.BeforeClass;
38 import org.testng.annotations.Test;
40 import compbio.metadata.Option;
41 import compbio.metadata.Parameter;
42 import compbio.metadata.Preset;
43 import compbio.metadata.PresetManager;
44 import compbio.metadata.WrongParameterException;
47 * All methods in this class are set to the Network group because setUpBeforeClass will fail
48 * if there is no network.
50 @Test(singleThreaded = true)
51 public class ParameterUtilsTest
54 @BeforeClass(alwaysRun = true)
55 public void setUpJvOptionPane()
57 JvOptionPane.setInteractiveMode(false);
58 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
62 * To limit tests to specify services, add them to this list; leave list empty
65 private static List<String> serviceTests = new ArrayList<>();
67 private static Jws2Discoverer disc = null;
69 @BeforeClass(alwaysRun = true)
70 public static void setUpBeforeClass() throws Exception
72 serviceTests.add("AAConWS".toLowerCase());
73 Cache.loadProperties("test/jalview/io/testProps.jvprops");
75 disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
78 @Test(groups = { "Network" })
79 public void testWriteParameterSet() throws WrongParameterException
81 for (Jws2Instance service : disc.getServices())
83 if (isForTesting(service))
86 List<Preset> prl = null;
87 PresetManager prman = service.getPresets();
92 prl = prman.getPresets();
99 List<String> writeparam = null;
100 List<String> readparam = null;
101 writeparam = ParameterUtils.writeParameterSet(
102 pr.getArguments(service.getRunnerConfig()), " ");
103 List<Option> pset = ParameterUtils.processParameters(writeparam,
104 service.getRunnerConfig(), " ");
105 readparam = ParameterUtils.writeParameterSet(pset, " ");
106 Iterator<String> o = pr.getOptions().iterator();
107 Iterator<String> s = writeparam.iterator();
108 Iterator<String> t = readparam.iterator();
109 boolean failed = false;
110 while (s.hasNext() && t.hasNext())
112 String on = o.next();
113 String sn = s.next();
114 String st = t.next();
115 final String errorMsg = "Original was " + on
116 + " Phase 1 wrote " + sn + "\tPhase 2 wrote " + st;
117 assertEquals(errorMsg, sn, st);
118 assertEquals(errorMsg, sn, on);
126 * Returns true if the service is in the list of the ones we chose to test,
127 * _or_ the list is empty (test all)
132 public boolean isForTesting(UIinfo service)
134 return serviceTests.size() == 0
135 || serviceTests.contains(service.getName().toLowerCase());
138 @Test(groups = { "Network" })
139 public void testCopyOption()
141 for (Jws2Instance service : disc.getServices())
143 if (isForTesting(service))
145 List<Option<?>> options = service.getRunnerConfig().getOptions();
146 for (Option<?> o : options)
148 System.out.println("Testing copyOption for option " + o.getName()
149 + " of " + service.getActionText());
150 Option<?> cpy = ParameterUtils.copyOption(o);
151 assertTrue(cpy.equals(o));
152 assertEquals(cpy.getName(), o.getName());
153 assertFalse(cpy == o);
154 // todo more assertions?
162 @Test(groups = { "Network" })
163 public void testCopyParameter()
165 for (Jws2Instance service : disc.getServices())
167 if (isForTesting(service))
169 List<Parameter> parameters = service.getRunnerConfig()
171 for (Parameter o : parameters)
173 System.out.println("Testing copyParameter for parameter "
174 + o.getName() + " of " + service.getActionText());
175 Parameter cpy = ParameterUtils.copyParameter(o);
176 assertTrue(cpy.equals(o));
177 assertFalse(cpy == o);
178 assertEquals(cpy.getName(), o.getName());
179 // todo more assertions?