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 + "MafftParameters.xml";
\r
45 RunnerConfig<Mafft> rconfig = null;
\r
48 public void setup() {
\r
50 rconfig = new RunnerConfig<Mafft>();
\r
51 rconfig.setRunnerClassName(Mafft.class.getName());
\r
52 List<Option<Mafft>> prms = new ArrayList<Option<Mafft>>();
\r
54 RunnerConfigMarshaller<Mafft> pmarshaller = new RunnerConfigMarshaller<Mafft>(RunnerConfig.class, Parameter.class,
\r
55 Option.class, ValueConstrain.class);
\r
56 } catch (JAXBException e) {
\r
57 e.printStackTrace();
\r
58 fail(e.getLocalizedMessage());
\r
63 public void testValidate() {
\r
66 } catch (ValidationException e) {
\r
67 e.printStackTrace();
\r
68 fail(e.getLocalizedMessage());
\r
69 } catch (IllegalStateException e) {
\r
70 e.printStackTrace();
\r
71 fail(e.getLocalizedMessage());
\r
75 @Test(expectedExceptions = WrongParameterException.class)
\r
76 public void testCreateParameter() throws WrongParameterException {
\r
77 Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");
\r
78 // TODO publish help on a compbio web site
\r
79 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
81 p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID");
\r
82 // This attribute is required by strict schema
\r
83 p3.setOptionName("--AAMATRIX");
\r
84 p3.setRequired(true);
\r
85 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
86 // IN WITHIN POSSIBLE VALUES
\r
87 p3.setDefaultValue("pam22");
\r
88 String com = p3.toCommand(" ");
\r
89 System.out.println("AAAAAAAAAAAAAA!" + com);
\r
93 public void testParameterToCommand() throws WrongParameterException {
\r
94 Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");
\r
95 // TODO publish help on a compbio web site
\r
96 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
98 p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID");
\r
99 // This attribute is required by strict schema
\r
100 p3.setOptionName("--AAMATRIX");
\r
101 p3.setRequired(true);
\r
102 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
103 // IN WITHIN POSSIBLE VALUES
\r
104 p3.setDefaultValue("PAM");
\r
105 String com = p3.toCommand("=");
\r
106 assertTrue(com.startsWith("--AAMATRIX"));
\r
107 assertTrue(com.endsWith("PAM"));
\r
108 assertTrue(com.contains("="));
\r
109 p3.setDefaultValue("ID");
\r
110 com = p3.toCommand("=");
\r
111 assertFalse(com.endsWith("PAM"));
\r
112 assertFalse(com.contains("PAM"));
\r
115 @Test(expectedExceptions = ValidationException.class)
\r
116 public void testOptionNoDefaultValidate() throws ValidationException {
\r
117 Option<Mafft> p3 = new Option<Mafft>("Matrix1", "Protein weight matrix");
\r
118 // TODO publish help on a compbio web site
\r
119 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
121 p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", "--ABMAT", "--BBBB")));
\r
122 p3.setRequired(true);
\r
123 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
124 // IN WITHIN POSSIBLE VALUES
\r
128 @Test(expectedExceptions = WrongParameterException.class)
\r
129 public void testOptionSetInvalidValue() throws WrongParameterException {
\r
131 Option<Mafft> p3 = new Option<Mafft>("Matrix1", "Protein weight matrix");
\r
132 // TODO publish help on a compbio web site
\r
133 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
135 p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", "--ABMAT", "--BBBB")));
\r
136 p3.setRequired(true);
\r
137 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
138 // IN WITHIN POSSIBLE VALUES
\r
139 p3.setDefaultValue("AAA");
\r
143 public void testOptionToCommand() {
\r
145 Option<Mafft> p3 = new Option<Mafft>("Matrix1", "Protein weight matrix");
\r
146 // TODO publish help on a compbio web site
\r
147 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
149 p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", "--ABMAT", "--BBBB")));
\r
150 p3.setRequired(true);
\r
151 // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED
\r
152 // IN WITHIN POSSIBLE VALUES
\r
153 p3.setDefaultValue("--BBBB");
\r
155 String com = p3.toCommand("=");
\r
156 assertEquals("--BBBB", com);
\r
157 p3.setDefaultValue("--ABMAT");
\r
158 com = p3.toCommand("=");
\r
159 assertEquals("--ABMAT", com);
\r
160 } catch (ValidationException e) {
\r
161 e.printStackTrace();
\r
162 fail(e.getMessage());
\r
163 } catch (WrongParameterException e) {
\r
164 e.printStackTrace();
\r
165 fail(e.getMessage());
\r
169 @Test(expectedExceptions = IllegalStateException.class)
\r
170 public void testCreateNumParameterWithoutValidValue() throws MalformedURLException {
\r
172 Parameter<Mafft> p4 = new Parameter<Mafft>("Matrix", "DNA weight matrix");
\r
173 // This is causing exception is ValidValue constrain is not defined
\r
176 p4.setDefaultValue("5");
\r
177 } catch (WrongParameterException e) {
\r
178 e.printStackTrace();
\r
179 fail(e.getLocalizedMessage());
\r
185 public void testCreateParameterWithValidValueConstrain() throws MalformedURLException {
\r
186 Parameter<Mafft> p4 = new Parameter<Mafft>("Matrix", "DNA weight matrix");
\r
187 ValueConstrain vc = new ValueConstrain();
\r
188 vc.setType(ValueConstrain.Type.Float);
\r
191 p4.setValidValue(vc);
\r
193 p4.setDefaultValue("5");
\r
194 } catch (WrongParameterException e) {
\r
195 e.printStackTrace();
\r
196 fail(e.getLocalizedMessage());
\r
200 @Test(expectedExceptions = WrongParameterException.class)
\r
201 public void testValidateLowerBoundaryConstrainCheck() throws WrongParameterException {
\r
202 Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");
\r
203 // TODO publish help on a compbio web site
\r
204 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
205 // This attribute is required by strict schema
\r
206 p3.setOptionName("--AAMATRIX");
\r
207 p3.setRequired(true);
\r
209 ValueConstrain vc = new ValueConstrain();
\r
210 vc.setType(ValueConstrain.Type.Float);
\r
211 vc.setMin("-10.12");
\r
213 p3.setValidValue(vc);
\r
214 // THIS IS CAUSING EXCEPTION
\r
215 p3.setDefaultValue("-11.0");
\r
218 @Test(expectedExceptions = WrongParameterException.class)
\r
219 public void testValidateUpperBoundaryConstrainCheck() throws WrongParameterException {
\r
220 Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");
\r
221 // TODO publish help on a compbio web site
\r
222 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
223 // This attribute is required by strict schema
\r
224 p3.setOptionName("--AAMATRIX");
\r
225 p3.setRequired(true);
\r
227 ValueConstrain vc = new ValueConstrain();
\r
228 vc.setType(ValueConstrain.Type.Float);
\r
229 vc.setMin("-10.12");
\r
231 p3.setValidValue(vc);
\r
232 // THIS IS CAUSING EXCEPTION
\r
233 p3.setDefaultValue("1");
\r
237 public void testValidateBoundaryConstrainCheck() {
\r
239 Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");
\r
240 // TODO publish help on a compbio web site
\r
241 p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");
\r
242 // This attribute is required by strict schema
\r
243 p3.setOptionName("--AAMATRIX");
\r
244 p3.setRequired(true);
\r
246 ValueConstrain vc = new ValueConstrain();
\r
247 vc.setType(ValueConstrain.Type.Float);
\r
248 vc.setMin("-10.12");
\r
249 p3.setValidValue(vc);
\r
250 // Max value boundary is not defined so 1 is valid
\r
251 p3.setDefaultValue("1");
\r
253 } catch (WrongParameterException e) {
\r
254 e.printStackTrace();
\r
255 fail(e.getMessage());
\r
256 } catch (ValidationException e) {
\r
257 e.printStackTrace();
\r
258 fail(e.getMessage());
\r
262 @Test(expectedExceptions = ValidationException.class)
\r
263 public void testValidateValueConstrain() throws ValidationException {
\r
264 ValueConstrain vc = new ValueConstrain();
\r
265 vc.setType(ValueConstrain.Type.Float);
\r
266 // NO BOUNDARIES DEFINED
\r