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.ws.jabaws.JalviewJabawsTestUtils;
29 import jalview.ws.jws2.jabaws2.Jws2Instance;
31 import java.util.ArrayList;
32 import java.util.Iterator;
33 import java.util.List;
35 import org.testng.annotations.BeforeClass;
36 import org.testng.annotations.Test;
38 import compbio.metadata.Option;
39 import compbio.metadata.Parameter;
40 import compbio.metadata.Preset;
41 import compbio.metadata.PresetManager;
42 import compbio.metadata.WrongParameterException;
44 public class ParameterUtilsTest
47 * To limit tests to specify services, add them to this list; leave list empty
50 private static List<String> serviceTests = new ArrayList<String>();
52 private static Jws2Discoverer disc = null;
54 @BeforeClass(alwaysRun = true)
55 public static void setUpBeforeClass() throws Exception
57 serviceTests.add("AAConWS".toLowerCase());
58 Cache.loadProperties("test/jalview/io/testProps.jvprops");
60 disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
63 @Test(groups = { "Functional" })
64 public void testWriteParameterSet() throws WrongParameterException
66 for (Jws2Instance service : disc.getServices())
68 if (isForTesting(service))
71 List<Preset> prl = null;
72 PresetManager prman = service.getPresets();
77 prl = prman.getPresets();
84 List<String> writeparam = null;
85 List<String> readparam = null;
86 writeparam = ParameterUtils.writeParameterSet(
87 pr.getArguments(service.getRunnerConfig()), " ");
88 List<Option> pset = ParameterUtils.processParameters(writeparam,
89 service.getRunnerConfig(), " ");
90 readparam = ParameterUtils.writeParameterSet(pset, " ");
91 Iterator<String> o = pr.getOptions().iterator();
92 Iterator<String> s = writeparam.iterator();
93 Iterator<String> t = readparam.iterator();
94 boolean failed = false;
95 while (s.hasNext() && t.hasNext())
100 final String errorMsg = "Original was " + on
101 + " Phase 1 wrote " + sn + "\tPhase 2 wrote " + st;
102 assertEquals(errorMsg, sn, st);
103 assertEquals(errorMsg, sn, on);
111 * Returns true if the service is in the list of the ones we chose to test,
112 * _or_ the list is empty (test all)
117 public boolean isForTesting(Jws2Instance service)
119 return serviceTests.size() == 0
120 || serviceTests.contains(service.serviceType.toLowerCase());
123 @Test(groups = { "Functional" })
124 public void testCopyOption()
126 for (Jws2Instance service : disc.getServices())
128 if (isForTesting(service))
130 List<Option<?>> options = service.getRunnerConfig().getOptions();
131 for (Option<?> o : options)
133 System.out.println("Testing copyOption for option " + o.getName()
134 + " of " + service.getActionText());
135 Option<?> cpy = ParameterUtils.copyOption(o);
136 assertTrue(cpy.equals(o));
137 assertEquals(cpy.getName(), o.getName());
138 assertFalse(cpy == o);
139 // todo more assertions?
147 @Test(groups = { "Functional" })
148 public void testCopyParameter()
150 for (Jws2Instance service : disc.getServices())
152 if (isForTesting(service))
154 List<Parameter> parameters = service.getRunnerConfig()
156 for (Parameter o : parameters)
158 System.out.println("Testing copyParameter for parameter "
159 + o.getName() + " of " + service.getActionText());
160 Parameter cpy = ParameterUtils.copyParameter(o);
161 assertTrue(cpy.equals(o));
162 assertFalse(cpy == o);
163 assertEquals(cpy.getName(), o.getName());
164 // todo more assertions?