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());
59 disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
62 @Test(groups = { "Functional" })
63 public void testWriteParameterSet() throws WrongParameterException
65 for (Jws2Instance service : disc.getServices())
67 if (isForTesting(service))
70 List<Preset> prl = null;
71 PresetManager prman = service.getPresets();
76 prl = prman.getPresets();
83 List<String> writeparam = null;
84 List<String> readparam = null;
85 writeparam = ParameterUtils.writeParameterSet(
86 pr.getArguments(service.getRunnerConfig()), " ");
87 List<Option> pset = ParameterUtils.processParameters(writeparam,
88 service.getRunnerConfig(), " ");
89 readparam = ParameterUtils.writeParameterSet(pset, " ");
90 Iterator<String> o = pr.getOptions().iterator();
91 Iterator<String> s = writeparam.iterator();
92 Iterator<String> t = readparam.iterator();
93 boolean failed = false;
94 while (s.hasNext() && t.hasNext())
99 final String errorMsg = "Original was " + on
100 + " Phase 1 wrote " + sn + "\tPhase 2 wrote " + st;
101 assertEquals(errorMsg, sn, st);
102 assertEquals(errorMsg, sn, on);
110 * Returns true if the service is in the list of the ones we chose to test,
111 * _or_ the list is empty (test all)
116 public boolean isForTesting(Jws2Instance service)
118 return serviceTests.size() == 0
119 || serviceTests.contains(service.serviceType.toLowerCase());
122 @Test(groups = { "Functional" })
123 public void testCopyOption()
125 for (Jws2Instance service : disc.getServices())
127 if (isForTesting(service))
129 List<Option<?>> options = service.getRunnerConfig().getOptions();
130 for (Option<?> o : options)
132 System.out.println("Testing copyOption for option " + o.getName()
133 + " of " + service.getActionText());
134 Option<?> cpy = ParameterUtils.copyOption(o);
135 assertTrue(cpy.equals(o));
136 assertEquals(cpy.getName(), o.getName());
137 assertFalse(cpy == o);
138 // todo more assertions?
146 @Test(groups = { "Functional" })
147 public void testCopyParameter()
149 for (Jws2Instance service : disc.getServices())
151 if (isForTesting(service))
153 List<Parameter> parameters = service.getRunnerConfig()
155 for (Parameter o : parameters)
157 System.out.println("Testing copyParameter for parameter "
158 + o.getName() + " of " + service.getActionText());
159 Parameter cpy = ParameterUtils.copyParameter(o);
160 assertTrue(cpy.equals(o));
161 assertFalse(cpy == o);
162 assertEquals(cpy.getName(), o.getName());
163 // todo more assertions?