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.jabaws.JalviewJabawsTestUtils;
30 import jalview.ws.jws2.jabaws2.Jws2Instance;
32 import java.util.ArrayList;
33 import java.util.Iterator;
34 import java.util.List;
36 import org.testng.annotations.BeforeClass;
37 import org.testng.annotations.Test;
39 import compbio.metadata.Option;
40 import compbio.metadata.Parameter;
41 import compbio.metadata.Preset;
42 import compbio.metadata.PresetManager;
43 import compbio.metadata.WrongParameterException;
45 public class ParameterUtilsTest
48 @BeforeClass(alwaysRun = true)
49 public void setUpJvOptionPane()
51 JvOptionPane.setInteractiveMode(false);
52 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
56 * To limit tests to specify services, add them to this list; leave list empty
59 private static List<String> serviceTests = new ArrayList<String>();
61 private static Jws2Discoverer disc = null;
63 @BeforeClass(alwaysRun = true)
64 public static void setUpBeforeClass() throws Exception
66 serviceTests.add("AAConWS".toLowerCase());
67 Cache.loadProperties("test/jalview/io/testProps.jvprops");
69 disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
72 @Test(groups = { "Functional" })
73 public void testWriteParameterSet() throws WrongParameterException
75 for (Jws2Instance service : disc.getServices())
77 if (isForTesting(service))
80 List<Preset> prl = null;
81 PresetManager prman = service.getPresets();
86 prl = prman.getPresets();
93 List<String> writeparam = null;
94 List<String> readparam = null;
95 writeparam = ParameterUtils.writeParameterSet(
96 pr.getArguments(service.getRunnerConfig()), " ");
97 List<Option> pset = ParameterUtils.processParameters(writeparam,
98 service.getRunnerConfig(), " ");
99 readparam = ParameterUtils.writeParameterSet(pset, " ");
100 Iterator<String> o = pr.getOptions().iterator();
101 Iterator<String> s = writeparam.iterator();
102 Iterator<String> t = readparam.iterator();
103 boolean failed = false;
104 while (s.hasNext() && t.hasNext())
106 String on = o.next();
107 String sn = s.next();
108 String st = t.next();
109 final String errorMsg = "Original was " + on
110 + " Phase 1 wrote " + sn + "\tPhase 2 wrote " + st;
111 assertEquals(errorMsg, sn, st);
112 assertEquals(errorMsg, sn, on);
120 * Returns true if the service is in the list of the ones we chose to test,
121 * _or_ the list is empty (test all)
126 public boolean isForTesting(Jws2Instance service)
128 return serviceTests.size() == 0
129 || serviceTests.contains(service.serviceType.toLowerCase());
132 @Test(groups = { "Functional" })
133 public void testCopyOption()
135 for (Jws2Instance service : disc.getServices())
137 if (isForTesting(service))
139 List<Option<?>> options = service.getRunnerConfig().getOptions();
140 for (Option<?> o : options)
142 System.out.println("Testing copyOption for option " + o.getName()
143 + " of " + service.getActionText());
144 Option<?> cpy = ParameterUtils.copyOption(o);
145 assertTrue(cpy.equals(o));
146 assertEquals(cpy.getName(), o.getName());
147 assertFalse(cpy == o);
148 // todo more assertions?
156 @Test(groups = { "Functional" })
157 public void testCopyParameter()
159 for (Jws2Instance service : disc.getServices())
161 if (isForTesting(service))
163 List<Parameter> parameters = service.getRunnerConfig()
165 for (Parameter o : parameters)
167 System.out.println("Testing copyParameter for parameter "
168 + o.getName() + " of " + service.getActionText());
169 Parameter cpy = ParameterUtils.copyParameter(o);
170 assertTrue(cpy.equals(o));
171 assertFalse(cpy == o);
172 assertEquals(cpy.getName(), o.getName());
173 // todo more assertions?