Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 16:11:35 GMT
  2. Package jalview.ws.jws2

File ParameterUtilsTest.java

 

Code metrics

12
54
6
1
190
136
13
0.24
9
6
2.17

Classes

Class Line # Actions
ParameterUtilsTest 54 54 13
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.ws.jws2;
22   
23    import java.util.Locale;
24    import static org.testng.AssertJUnit.assertEquals;
25    import static org.testng.AssertJUnit.assertFalse;
26    import static org.testng.AssertJUnit.assertTrue;
27   
28    import jalview.bin.Cache;
29    import jalview.bin.Console;
30    import jalview.gui.JvOptionPane;
31    import jalview.ws.api.ServiceWithParameters;
32    import jalview.ws.api.UIinfo;
33    import jalview.ws.jabaws.JalviewJabawsTestUtils;
34    import jalview.ws.jws2.jabaws2.Jws2Instance;
35   
36    import java.util.ArrayList;
37    import java.util.Iterator;
38    import java.util.List;
39   
40    import org.testng.annotations.BeforeClass;
41    import org.testng.annotations.Test;
42   
43    import compbio.metadata.Option;
44    import compbio.metadata.Parameter;
45    import compbio.metadata.Preset;
46    import compbio.metadata.PresetManager;
47    import compbio.metadata.WrongParameterException;
48   
49    /*
50    * All methods in this class are set to the Network group because setUpBeforeClass will fail
51    * if there is no network.
52    */
53    @Test(singleThreaded = true)
 
54    public class ParameterUtilsTest
55    {
56   
 
57  0 toggle @BeforeClass(alwaysRun = true)
58    public void setUpJvOptionPane()
59    {
60  0 JvOptionPane.setInteractiveMode(false);
61  0 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
62    }
63   
64    /*
65    * To limit tests to specify services, add them to this list; leave list empty
66    * to test all
67    */
68    private static List<String> serviceTests = new ArrayList<>();
69   
70    private static Jws2Discoverer disc = null;
71   
 
72  0 toggle @BeforeClass(alwaysRun = true)
73    public static void setUpBeforeClass() throws Exception
74    {
75  0 serviceTests.add("AAConWS".toLowerCase(Locale.ROOT));
76  0 Cache.loadProperties("test/jalview/io/testProps.jvprops");
77  0 Console.initLogger();
78  0 disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
79    }
80   
 
81  0 toggle @Test(groups = { "Network" })
82    public void testWriteParameterSet() throws WrongParameterException
83    {
84  0 for (ServiceWithParameters _service : disc.getServices())
85    {
86  0 if (isForTesting(_service))
87    {
88  0 Jws2Instance service = (Jws2Instance) _service;
89   
90  0 List<Preset> prl = null;
91  0 PresetManager prman = service.getPresets();
92  0 if (prman == null)
93    {
94  0 continue;
95    }
96  0 prl = prman.getPresets();
97  0 if (prl == null)
98    {
99  0 continue;
100    }
101  0 for (Preset pr : prl)
102    {
103  0 List<String> writeparam = null;
104  0 List<String> readparam = null;
105  0 writeparam = ParameterUtils.writeParameterSet(
106    pr.getArguments(service.getRunnerConfig()), " ");
107  0 List<Option> pset = ParameterUtils.processParameters(writeparam,
108    service.getRunnerConfig(), " ");
109  0 readparam = ParameterUtils.writeParameterSet(pset, " ");
110  0 Iterator<String> o = pr.getOptions().iterator();
111  0 Iterator<String> s = writeparam.iterator();
112  0 Iterator<String> t = readparam.iterator();
113  0 boolean failed = false;
114  0 while (s.hasNext() && t.hasNext())
115    {
116  0 String on = o.next();
117  0 String sn = s.next();
118  0 String st = t.next();
119  0 final String errorMsg = "Original was " + on + " Phase 1 wrote "
120    + sn + "\tPhase 2 wrote " + st;
121  0 assertEquals(errorMsg, sn, st);
122  0 assertEquals(errorMsg, sn, on);
123    }
124    }
125    }
126    }
127    }
128   
129    /**
130    * Returns true if the service is in the list of the ones we chose to test,
131    * _or_ the list is empty (test all)
132    *
133    * @param service
134    * @return
135    */
 
136  0 toggle public boolean isForTesting(UIinfo service)
137    {
138  0 return serviceTests.size() == 0 || serviceTests
139    .contains(service.getServiceType().toLowerCase(Locale.ROOT));
140    }
141   
 
142  0 toggle @Test(groups = { "Network" })
143    public void testCopyOption()
144    {
145  0 for (ServiceWithParameters _service : disc.getServices())
146    {
147  0 if (isForTesting(_service))
148    {
149  0 Jws2Instance service = (Jws2Instance) _service;
150  0 List<Option<?>> options = service.getRunnerConfig().getOptions();
151  0 for (Option<?> o : options)
152    {
153  0 System.out.println("Testing copyOption for option " + o.getName()
154    + " of " + service.getActionText());
155  0 Option<?> cpy = ParameterUtils.copyOption(o);
156  0 assertTrue(cpy.equals(o));
157  0 assertEquals(cpy.getName(), o.getName());
158  0 assertFalse(cpy == o);
159    // todo more assertions?
160    }
161    }
162    }
163    }
164   
165    /**
166    */
 
167  0 toggle @Test(groups = { "Network" })
168    public void testCopyParameter()
169    {
170  0 for (ServiceWithParameters _service : disc.getServices())
171    {
172  0 if (isForTesting(_service))
173    {
174  0 Jws2Instance service = (Jws2Instance) _service;
175  0 List<Parameter> parameters = service.getRunnerConfig()
176    .getParameters();
177  0 for (Parameter o : parameters)
178    {
179  0 System.out.println("Testing copyParameter for parameter "
180    + o.getName() + " of " + service.getActionText());
181  0 Parameter cpy = ParameterUtils.copyParameter(o);
182  0 assertTrue(cpy.equals(o));
183  0 assertFalse(cpy == o);
184  0 assertEquals(cpy.getName(), o.getName());
185    // todo more assertions?
186    }
187    }
188    }
189    }
190    }