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",
\r
81 "Protein weight matrix");
\r
82 // TODO publish help on a compbio web site
\r
83 p3.setFurtherDetails(new URL("http",
\r
84 "www.compbio.dundee.ac.uk/users/pvtroshin/ws/",
\r
87 p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID");
\r
88 // This attribute is required by strict schema
\r
89 p3.setOptionName("--AAMATRIX");
\r
90 p3.setRequired(true);
\r
91 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
92 // IN WITHIN POSSIBLE VALUES
\r
93 p3.setDefaultValue("pam22");
\r
94 String com = p3.toCommand(" ");
\r
95 System.out.println("AAAAAAAAAAAAAA!" + com);
\r
96 } catch (MalformedURLException e) {
\r
97 e.printStackTrace();
\r
98 fail(e.getMessage());
\r
103 public void testParameterToCommand() throws WrongParameterException {
\r
105 Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1",
\r
106 "Protein weight matrix");
\r
107 // TODO publish help on a compbio web site
\r
108 p3.setFurtherDetails(new URL("http",
\r
109 "www.compbio.dundee.ac.uk/users/pvtroshin/ws/",
\r
112 p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID");
\r
113 // This attribute is required by strict schema
\r
114 p3.setOptionName("--AAMATRIX");
\r
115 p3.setRequired(true);
\r
116 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
117 // IN WITHIN POSSIBLE VALUES
\r
118 p3.setDefaultValue("PAM");
\r
119 String com = p3.toCommand("=");
\r
120 assertTrue(com.startsWith("--AAMATRIX"));
\r
121 assertTrue(com.endsWith("PAM"));
\r
122 assertTrue(com.contains("="));
\r
123 p3.setDefaultValue("ID");
\r
124 com = p3.toCommand("=");
\r
125 assertFalse(com.endsWith("PAM"));
\r
126 assertFalse(com.contains("PAM"));
\r
128 } catch (MalformedURLException e) {
\r
129 e.printStackTrace();
\r
130 fail(e.getMessage());
\r
134 @Test(expectedExceptions = ValidationException.class)
\r
135 public void testOptionNoDefaultValidate() throws ValidationException {
\r
137 Option<Mafft> p3 = new Option<Mafft>("Matrix1",
\r
138 "Protein weight matrix");
\r
139 // TODO publish help on a compbio web site
\r
140 p3.setFurtherDetails(new URL("http",
\r
141 "www.compbio.dundee.ac.uk/users/pvtroshin/ws/",
\r
144 p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX",
\r
145 "--ABMAT", "--BBBB")));
\r
146 p3.setRequired(true);
\r
147 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
148 // IN WITHIN POSSIBLE VALUES
\r
151 } catch (MalformedURLException e) {
\r
152 e.printStackTrace();
\r
153 fail(e.getMessage());
\r
157 @Test(expectedExceptions = WrongParameterException.class)
\r
158 public void testOptionSetInvalidValue() throws WrongParameterException {
\r
160 Option<Mafft> p3 = new Option<Mafft>("Matrix1",
\r
161 "Protein weight matrix");
\r
162 // TODO publish help on a compbio web site
\r
163 p3.setFurtherDetails(new URL("http",
\r
164 "www.compbio.dundee.ac.uk/users/pvtroshin/ws/",
\r
167 p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX",
\r
168 "--ABMAT", "--BBBB")));
\r
169 p3.setRequired(true);
\r
170 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
171 // IN WITHIN POSSIBLE VALUES
\r
172 p3.setDefaultValue("AAA");
\r
174 } catch (MalformedURLException e) {
\r
175 e.printStackTrace();
\r
176 fail(e.getMessage());
\r
181 public void testOptionToCommand() {
\r
183 Option<Mafft> p3 = new Option<Mafft>("Matrix1",
\r
184 "Protein weight matrix");
\r
185 // TODO publish help on a compbio web site
\r
186 p3.setFurtherDetails(new URL("http",
\r
187 "www.compbio.dundee.ac.uk/users/pvtroshin/ws/",
\r
190 p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX",
\r
191 "--ABMAT", "--BBBB")));
\r
192 p3.setRequired(true);
\r
193 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
194 // IN WITHIN POSSIBLE VALUES
\r
195 p3.setDefaultValue("--BBBB");
\r
197 String com = p3.toCommand("=");
\r
198 assertEquals("--BBBB", com);
\r
199 p3.setDefaultValue("--ABMAT");
\r
200 com = p3.toCommand("=");
\r
201 assertEquals("--ABMAT", com);
\r
202 } catch (MalformedURLException e) {
\r
203 e.printStackTrace();
\r
204 fail(e.getMessage());
\r
205 } catch (ValidationException e) {
\r
206 e.printStackTrace();
\r
207 fail(e.getMessage());
\r
208 } catch (WrongParameterException e) {
\r
209 e.printStackTrace();
\r
210 fail(e.getMessage());
\r
214 @Test(expectedExceptions = IllegalStateException.class)
\r
215 public void testCreateNumParameterWithoutValidValue() {
\r
217 Parameter<Mafft> p4 = new Parameter<Mafft>("Matrix",
\r
218 "DNA weight matrix");
\r
219 // This is causing exception is ValidValue constrain is not defined
\r
222 p4.setDefaultValue("5");
\r
223 } catch (WrongParameterException e) {
\r
224 e.printStackTrace();
\r
225 fail(e.getLocalizedMessage());
\r
231 public void testCreateParameterWithValidValueConstrain() {
\r
233 Parameter<Mafft> p4 = new Parameter<Mafft>("Matrix",
\r
234 "DNA weight matrix");
\r
235 ValueConstrain vc = new ValueConstrain();
\r
236 vc.setType(ValueConstrain.Type.Float);
\r
239 p4.setValidValue(vc);
\r
241 p4.setDefaultValue("5");
\r
242 } catch (WrongParameterException e) {
\r
243 e.printStackTrace();
\r
244 fail(e.getLocalizedMessage());
\r
248 @Test(expectedExceptions = WrongParameterException.class)
\r
249 public void testValidateLowerBoundaryConstrainCheck()
\r
250 throws WrongParameterException {
\r
252 Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1",
\r
253 "Protein weight matrix");
\r
254 // TODO publish help on a compbio web site
\r
255 p3.setFurtherDetails(new URL("http",
\r
256 "www.compbio.dundee.ac.uk/users/pvtroshin/ws/",
\r
258 // This attribute is required by strict schema
\r
259 p3.setOptionName("--AAMATRIX");
\r
260 p3.setRequired(true);
\r
262 ValueConstrain vc = new ValueConstrain();
\r
263 vc.setType(ValueConstrain.Type.Float);
\r
264 vc.setMin("-10.12");
\r
266 p3.setValidValue(vc);
\r
267 // THIS IS CAUSING EXCEPTION
\r
268 p3.setDefaultValue("-11.0");
\r
270 } catch (MalformedURLException e) {
\r
271 e.printStackTrace();
\r
272 fail(e.getMessage());
\r
276 @Test(expectedExceptions = WrongParameterException.class)
\r
277 public void testValidateUpperBoundaryConstrainCheck()
\r
278 throws WrongParameterException {
\r
280 Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1",
\r
281 "Protein weight matrix");
\r
282 // TODO publish help on a compbio web site
\r
283 p3.setFurtherDetails(new URL("http",
\r
284 "www.compbio.dundee.ac.uk/users/pvtroshin/ws/",
\r
286 // This attribute is required by strict schema
\r
287 p3.setOptionName("--AAMATRIX");
\r
288 p3.setRequired(true);
\r
290 ValueConstrain vc = new ValueConstrain();
\r
291 vc.setType(ValueConstrain.Type.Float);
\r
292 vc.setMin("-10.12");
\r
294 p3.setValidValue(vc);
\r
295 // THIS IS CAUSING EXCEPTION
\r
296 p3.setDefaultValue("1");
\r
298 } catch (MalformedURLException e) {
\r
299 e.printStackTrace();
\r
300 fail(e.getMessage());
\r
305 public void testValidateBoundaryConstrainCheck() {
\r
307 Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1",
\r
308 "Protein weight matrix");
\r
309 // TODO publish help on a compbio web site
\r
310 p3.setFurtherDetails(new URL("http",
\r
311 "www.compbio.dundee.ac.uk/users/pvtroshin/ws/",
\r
313 // This attribute is required by strict schema
\r
314 p3.setOptionName("--AAMATRIX");
\r
315 p3.setRequired(true);
\r
317 ValueConstrain vc = new ValueConstrain();
\r
318 vc.setType(ValueConstrain.Type.Float);
\r
319 vc.setMin("-10.12");
\r
320 p3.setValidValue(vc);
\r
321 // Max value boundary is not defined so 1 is valid
\r
322 p3.setDefaultValue("1");
\r
324 } catch (MalformedURLException e) {
\r
325 e.printStackTrace();
\r
326 fail(e.getMessage());
\r
327 } catch (WrongParameterException e) {
\r
328 e.printStackTrace();
\r
329 fail(e.getMessage());
\r
330 } catch (ValidationException e) {
\r
331 e.printStackTrace();
\r
332 fail(e.getMessage());
\r
336 @Test(expectedExceptions = ValidationException.class)
\r
337 public void testValidateValueConstrain() throws ValidationException {
\r
338 ValueConstrain vc = new ValueConstrain();
\r
339 vc.setType(ValueConstrain.Type.Float);
\r
340 // NO BOUNDARIES DEFINED
\r