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 java.util.Locale;
25 import static org.testng.AssertJUnit.assertEquals;
26 import static org.testng.AssertJUnit.assertFalse;
27 import static org.testng.AssertJUnit.assertTrue;
29 import jalview.bin.Cache;
30 import jalview.bin.Console;
31 import jalview.gui.JvOptionPane;
32 import jalview.ws.jabaws.JalviewJabawsTestUtils;
33 import jalview.ws.jws2.jabaws2.Jws2Instance;
35 import java.util.ArrayList;
36 import java.util.Iterator;
37 import java.util.List;
39 import org.testng.annotations.BeforeClass;
40 import org.testng.annotations.Test;
42 import compbio.metadata.Option;
43 import compbio.metadata.Parameter;
44 import compbio.metadata.Preset;
45 import compbio.metadata.PresetManager;
46 import compbio.metadata.WrongParameterException;
49 * All methods in this class are set to the Network group because setUpBeforeClass will fail
50 * if there is no network.
52 @Test(singleThreaded = true)
53 public class ParameterUtilsTest
56 @BeforeClass(alwaysRun = true)
57 public void setUpJvOptionPane()
59 JvOptionPane.setInteractiveMode(false);
60 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
64 * To limit tests to specify services, add them to this list; leave list empty
67 private static List<String> serviceTests = new ArrayList<String>();
69 private static Jws2Discoverer disc = null;
71 @BeforeClass(alwaysRun = true)
72 public static void setUpBeforeClass() throws Exception
74 serviceTests.add("AAConWS".toLowerCase(Locale.ROOT));
75 Cache.loadProperties("test/jalview/io/testProps.jvprops");
77 disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
80 @Test(groups = { "Network" })
81 public void testWriteParameterSet() throws WrongParameterException
83 for (Jws2Instance service : disc.getServices())
85 if (isForTesting(service))
88 List<Preset> prl = null;
89 PresetManager prman = service.getPresets();
94 prl = prman.getPresets();
101 List<String> writeparam = null;
102 List<String> readparam = null;
103 writeparam = ParameterUtils.writeParameterSet(
104 pr.getArguments(service.getRunnerConfig()), " ");
105 List<Option> pset = ParameterUtils.processParameters(writeparam,
106 service.getRunnerConfig(), " ");
107 readparam = ParameterUtils.writeParameterSet(pset, " ");
108 Iterator<String> o = pr.getOptions().iterator();
109 Iterator<String> s = writeparam.iterator();
110 Iterator<String> t = readparam.iterator();
111 boolean failed = false;
112 while (s.hasNext() && t.hasNext())
114 String on = o.next();
115 String sn = s.next();
116 String st = t.next();
117 final String errorMsg = "Original was " + on + " Phase 1 wrote "
118 + sn + "\tPhase 2 wrote " + st;
119 assertEquals(errorMsg, sn, st);
120 assertEquals(errorMsg, sn, on);
128 * Returns true if the service is in the list of the ones we chose to test,
129 * _or_ the list is empty (test all)
134 public boolean isForTesting(Jws2Instance service)
136 return serviceTests.size() == 0 || serviceTests
137 .contains(service.serviceType.toLowerCase(Locale.ROOT));
140 @Test(groups = { "Network" })
141 public void testCopyOption()
143 for (Jws2Instance service : disc.getServices())
145 if (isForTesting(service))
147 List<Option<?>> options = service.getRunnerConfig().getOptions();
148 for (Option<?> o : options)
150 System.out.println("Testing copyOption for option " + o.getName()
151 + " of " + service.getActionText());
152 Option<?> cpy = ParameterUtils.copyOption(o);
153 assertTrue(cpy.equals(o));
154 assertEquals(cpy.getName(), o.getName());
155 assertFalse(cpy == o);
156 // todo more assertions?
164 @Test(groups = { "Network" })
165 public void testCopyParameter()
167 for (Jws2Instance service : disc.getServices())
169 if (isForTesting(service))
171 List<Parameter> parameters = service.getRunnerConfig()
173 for (Parameter o : parameters)
175 System.out.println("Testing copyParameter for parameter "
176 + o.getName() + " of " + service.getActionText());
177 Parameter cpy = ParameterUtils.copyParameter(o);
178 assertTrue(cpy.equals(o));
179 assertFalse(cpy == o);
180 assertEquals(cpy.getName(), o.getName());
181 // todo more assertions?