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;
46 * All methods in this class are set to the Network group because setUpBeforeClass will fail
47 * if there is no network.
49 @Test(singleThreaded = true)
50 public class ParameterUtilsTest
53 @BeforeClass(alwaysRun = true)
54 public void setUpJvOptionPane()
56 JvOptionPane.setInteractiveMode(false);
57 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
61 * To limit tests to specify services, add them to this list; leave list empty
64 private static List<String> serviceTests = new ArrayList<String>();
66 private static Jws2Discoverer disc = null;
68 @BeforeClass(alwaysRun = true)
69 public static void setUpBeforeClass() throws Exception
71 serviceTests.add("AAConWS".toLowerCase());
72 Cache.loadProperties("test/jalview/io/testProps.jvprops");
74 disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
77 @Test(groups = { "Functional" })
78 public void testWriteParameterSet() throws WrongParameterException
80 for (Jws2Instance service : disc.getServices())
82 if (isForTesting(service))
85 List<Preset> prl = null;
86 PresetManager prman = service.getPresets();
91 prl = prman.getPresets();
98 List<String> writeparam = null;
99 List<String> readparam = null;
100 writeparam = ParameterUtils.writeParameterSet(
101 pr.getArguments(service.getRunnerConfig()), " ");
102 List<Option> pset = ParameterUtils.processParameters(writeparam,
103 service.getRunnerConfig(), " ");
104 readparam = ParameterUtils.writeParameterSet(pset, " ");
105 Iterator<String> o = pr.getOptions().iterator();
106 Iterator<String> s = writeparam.iterator();
107 Iterator<String> t = readparam.iterator();
108 boolean failed = false;
109 while (s.hasNext() && t.hasNext())
111 String on = o.next();
112 String sn = s.next();
113 String st = t.next();
114 final String errorMsg = "Original was " + on
115 + " Phase 1 wrote " + sn + "\tPhase 2 wrote " + st;
116 assertEquals(errorMsg, sn, st);
117 assertEquals(errorMsg, sn, on);
125 * Returns true if the service is in the list of the ones we chose to test,
126 * _or_ the list is empty (test all)
131 public boolean isForTesting(Jws2Instance service)
133 return serviceTests.size() == 0
134 || serviceTests.contains(service.serviceType.toLowerCase());
137 @Test(groups = { "Network" })
138 public void testCopyOption()
140 for (Jws2Instance service : disc.getServices())
142 if (isForTesting(service))
144 List<Option<?>> options = service.getRunnerConfig().getOptions();
145 for (Option<?> o : options)
147 System.out.println("Testing copyOption for option " + o.getName()
148 + " of " + service.getActionText());
149 Option<?> cpy = ParameterUtils.copyOption(o);
150 assertTrue(cpy.equals(o));
151 assertEquals(cpy.getName(), o.getName());
152 assertFalse(cpy == o);
153 // todo more assertions?
161 @Test(groups = { "Network" })
162 public void testCopyParameter()
164 for (Jws2Instance service : disc.getServices())
166 if (isForTesting(service))
168 List<Parameter> parameters = service.getRunnerConfig()
170 for (Parameter o : parameters)
172 System.out.println("Testing copyParameter for parameter "
173 + o.getName() + " of " + service.getActionText());
174 Parameter cpy = ParameterUtils.copyParameter(o);
175 assertTrue(cpy.equals(o));
176 assertFalse(cpy == o);
177 assertEquals(cpy.getName(), o.getName());
178 // todo more assertions?