1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
18 package compbio.metadata;
\r
20 import static org.testng.AssertJUnit.assertEquals;
\r
21 import static org.testng.AssertJUnit.assertFalse;
\r
22 import static org.testng.AssertJUnit.assertTrue;
\r
23 import static org.testng.AssertJUnit.fail;
\r
25 import java.net.MalformedURLException;
\r
26 import java.net.URL;
\r
27 import java.util.ArrayList;
\r
28 import java.util.Arrays;
\r
29 import java.util.HashSet;
\r
30 import java.util.List;
\r
32 import javax.xml.bind.JAXBException;
\r
33 import javax.xml.bind.ValidationException;
\r
35 import org.testng.annotations.BeforeMethod;
\r
36 import org.testng.annotations.Test;
\r
38 import compbio.engine.conf.RunnerConfigMarshaller;
\r
39 import compbio.runner.msa.Mafft;
\r
41 public class RunnerConfigTester {
\r
43 public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE
\r
44 + "MafftParameters.xml";
\r
46 RunnerConfig<Mafft> rconfig = null;
\r
49 public void setup() {
\r
51 rconfig = new RunnerConfig<Mafft>();
\r
52 rconfig.setRunnerClassName(Mafft.class.getName());
\r
53 List<Option<Mafft>> prms = new ArrayList<Option<Mafft>>();
\r
55 RunnerConfigMarshaller<Mafft> pmarshaller = new RunnerConfigMarshaller<Mafft>(
\r
56 RunnerConfig.class, Parameter.class, Option.class,
\r
57 ValueConstrain.class);
\r
58 } catch (JAXBException e) {
\r
59 e.printStackTrace();
\r
60 fail(e.getLocalizedMessage());
\r
65 public void testValidate() {
\r
68 } catch (ValidationException e) {
\r
69 e.printStackTrace();
\r
70 fail(e.getLocalizedMessage());
\r
71 } catch (IllegalStateException e) {
\r
72 e.printStackTrace();
\r
73 fail(e.getLocalizedMessage());
\r
77 @Test(expectedExceptions = WrongParameterException.class)
\r
78 public void testCreateParameter() throws WrongParameterException {
\r
80 Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");
\r
81 // TODO publish help on a compbio web site
\r
82 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
84 p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID");
\r
85 // This attribute is required by strict schema
\r
86 p3.setOptionName("--AAMATRIX");
\r
87 p3.setRequired(true);
\r
88 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
89 // IN WITHIN POSSIBLE VALUES
\r
90 p3.setDefaultValue("pam22");
\r
91 String com = p3.toCommand(" ");
\r
92 System.out.println("AAAAAAAAAAAAAA!" + com);
\r
93 } catch (MalformedURLException e) {
\r
94 e.printStackTrace();
\r
95 fail(e.getMessage());
\r
100 public void testParameterToCommand() throws WrongParameterException {
\r
102 Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");
\r
103 // TODO publish help on a compbio web site
\r
104 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
106 p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID");
\r
107 // This attribute is required by strict schema
\r
108 p3.setOptionName("--AAMATRIX");
\r
109 p3.setRequired(true);
\r
110 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
111 // IN WITHIN POSSIBLE VALUES
\r
112 p3.setDefaultValue("PAM");
\r
113 String com = p3.toCommand("=");
\r
114 assertTrue(com.startsWith("--AAMATRIX"));
\r
115 assertTrue(com.endsWith("PAM"));
\r
116 assertTrue(com.contains("="));
\r
117 p3.setDefaultValue("ID");
\r
118 com = p3.toCommand("=");
\r
119 assertFalse(com.endsWith("PAM"));
\r
120 assertFalse(com.contains("PAM"));
\r
121 } catch (MalformedURLException e) {
\r
122 e.printStackTrace();
\r
123 fail(e.getMessage());
\r
127 @Test(expectedExceptions = ValidationException.class)
\r
128 public void testOptionNoDefaultValidate() throws ValidationException {
\r
130 Option<Mafft> p3 = new Option<Mafft>("Matrix1", "Protein weight matrix");
\r
131 // TODO publish help on a compbio web site
\r
132 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
134 p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", "--ABMAT", "--BBBB")));
\r
135 p3.setRequired(true);
\r
136 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
137 // IN WITHIN POSSIBLE VALUES
\r
139 } catch (MalformedURLException e) {
\r
140 e.printStackTrace();
\r
141 fail(e.getMessage());
\r
145 @Test(expectedExceptions = WrongParameterException.class)
\r
146 public void testOptionSetInvalidValue() throws WrongParameterException {
\r
148 Option<Mafft> p3 = new Option<Mafft>("Matrix1", "Protein weight matrix");
\r
149 // TODO publish help on a compbio web site
\r
150 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
152 p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", "--ABMAT", "--BBBB")));
\r
153 p3.setRequired(true);
\r
154 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
155 // IN WITHIN POSSIBLE VALUES
\r
156 p3.setDefaultValue("AAA");
\r
157 } catch (MalformedURLException e) {
\r
158 e.printStackTrace();
\r
159 fail(e.getMessage());
\r
164 public void testOptionToCommand() {
\r
166 Option<Mafft> p3 = new Option<Mafft>("Matrix1", "Protein weight matrix");
\r
167 // TODO publish help on a compbio web site
\r
168 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
170 p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", "--ABMAT", "--BBBB")));
\r
171 p3.setRequired(true);
\r
172 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
173 // IN WITHIN POSSIBLE VALUES
\r
174 p3.setDefaultValue("--BBBB");
\r
176 String com = p3.toCommand("=");
\r
177 assertEquals("--BBBB", com);
\r
178 p3.setDefaultValue("--ABMAT");
\r
179 com = p3.toCommand("=");
\r
180 assertEquals("--ABMAT", com);
\r
181 } catch (MalformedURLException e) {
\r
182 e.printStackTrace();
\r
183 fail(e.getMessage());
\r
184 } catch (ValidationException e) {
\r
185 e.printStackTrace();
\r
186 fail(e.getMessage());
\r
187 } catch (WrongParameterException e) {
\r
188 e.printStackTrace();
\r
189 fail(e.getMessage());
\r
193 @Test(expectedExceptions = IllegalStateException.class)
\r
194 public void testCreateNumParameterWithoutValidValue() throws MalformedURLException {
\r
196 Parameter<Mafft> p4 = new Parameter<Mafft>("Matrix", "DNA weight matrix");
\r
197 // This is causing exception is ValidValue constrain is not defined
\r
200 p4.setDefaultValue("5");
\r
201 } catch (WrongParameterException e) {
\r
202 e.printStackTrace();
\r
203 fail(e.getLocalizedMessage());
\r
209 public void testCreateParameterWithValidValueConstrain() throws MalformedURLException {
\r
210 Parameter<Mafft> p4 = new Parameter<Mafft>("Matrix", "DNA weight matrix");
\r
211 ValueConstrain vc = new ValueConstrain();
\r
212 vc.setType(ValueConstrain.Type.Float);
\r
215 p4.setValidValue(vc);
\r
217 p4.setDefaultValue("5");
\r
218 } catch (WrongParameterException e) {
\r
219 e.printStackTrace();
\r
220 fail(e.getLocalizedMessage());
\r
224 @Test(expectedExceptions = WrongParameterException.class)
\r
225 public void testValidateLowerBoundaryConstrainCheck()
\r
226 throws WrongParameterException {
\r
228 Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");
\r
229 // TODO publish help on a compbio web site
\r
230 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
231 // This attribute is required by strict schema
\r
232 p3.setOptionName("--AAMATRIX");
\r
233 p3.setRequired(true);
\r
235 ValueConstrain vc = new ValueConstrain();
\r
236 vc.setType(ValueConstrain.Type.Float);
\r
237 vc.setMin("-10.12");
\r
239 p3.setValidValue(vc);
\r
240 // THIS IS CAUSING EXCEPTION
\r
241 p3.setDefaultValue("-11.0");
\r
242 } catch (MalformedURLException e) {
\r
243 e.printStackTrace();
\r
244 fail(e.getMessage());
\r
248 @Test(expectedExceptions = WrongParameterException.class)
\r
249 public void testValidateUpperBoundaryConstrainCheck()
\r
250 throws WrongParameterException {
\r
252 Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");
\r
253 // TODO publish help on a compbio web site
\r
254 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
255 // This attribute is required by strict schema
\r
256 p3.setOptionName("--AAMATRIX");
\r
257 p3.setRequired(true);
\r
259 ValueConstrain vc = new ValueConstrain();
\r
260 vc.setType(ValueConstrain.Type.Float);
\r
261 vc.setMin("-10.12");
\r
263 p3.setValidValue(vc);
\r
264 // THIS IS CAUSING EXCEPTION
\r
265 p3.setDefaultValue("1");
\r
266 } catch (MalformedURLException e) {
\r
267 e.printStackTrace();
\r
268 fail(e.getMessage());
\r
273 public void testValidateBoundaryConstrainCheck() {
\r
275 Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");
\r
276 // TODO publish help on a compbio web site
\r
277 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
278 // This attribute is required by strict schema
\r
279 p3.setOptionName("--AAMATRIX");
\r
280 p3.setRequired(true);
\r
282 ValueConstrain vc = new ValueConstrain();
\r
283 vc.setType(ValueConstrain.Type.Float);
\r
284 vc.setMin("-10.12");
\r
285 p3.setValidValue(vc);
\r
286 // Max value boundary is not defined so 1 is valid
\r
287 p3.setDefaultValue("1");
\r
289 } catch (MalformedURLException e) {
\r
290 e.printStackTrace();
\r
291 fail(e.getMessage());
\r
292 } catch (WrongParameterException e) {
\r
293 e.printStackTrace();
\r
294 fail(e.getMessage());
\r
295 } catch (ValidationException e) {
\r
296 e.printStackTrace();
\r
297 fail(e.getMessage());
\r
301 @Test(expectedExceptions = ValidationException.class)
\r
302 public void testValidateValueConstrain() throws ValidationException {
\r
303 ValueConstrain vc = new ValueConstrain();
\r
304 vc.setType(ValueConstrain.Type.Float);
\r
305 // NO BOUNDARIES DEFINED
\r