Head title change
[jabaws.git] / testsrc / compbio / metadata / RunnerConfigTester.java
1 /* Copyright (c) 2009 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0     \r
4  * \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
7  * \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
11  * \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
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 package compbio.metadata;\r
19 \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
24 \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
31 \r
32 import javax.xml.bind.JAXBException;\r
33 import javax.xml.bind.ValidationException;\r
34 \r
35 import org.testng.annotations.BeforeMethod;\r
36 import org.testng.annotations.Test;\r
37 \r
38 import compbio.engine.conf.RunnerConfigMarshaller;\r
39 import compbio.runner.msa.Mafft;\r
40 \r
41 public class RunnerConfigTester {\r
42 \r
43         public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
44                         + "MafftParameters.xml";\r
45 \r
46         RunnerConfig<Mafft> rconfig = null;\r
47 \r
48         @BeforeMethod\r
49         public void setup() {\r
50                 try {\r
51                         rconfig = new RunnerConfig<Mafft>();\r
52                         rconfig.setRunnerClassName(Mafft.class.getName());\r
53                         List<Option<Mafft>> prms = new ArrayList<Option<Mafft>>();\r
54 \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
61                 }\r
62         }\r
63 \r
64         @Test\r
65         public void testValidate() {\r
66                 try {\r
67                         rconfig.validate();\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
74                 }\r
75         }\r
76 \r
77         @Test(expectedExceptions = WrongParameterException.class)\r
78         public void testCreateParameter() throws WrongParameterException {\r
79                 try {\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
85                                         "Index.html"));\r
86 \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
99                 }\r
100         }\r
101 \r
102         @Test()\r
103         public void testParameterToCommand() throws WrongParameterException {\r
104                 try {\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
110                                         "Index.html"));\r
111 \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
127 \r
128                 } catch (MalformedURLException e) {\r
129                         e.printStackTrace();\r
130                         fail(e.getMessage());\r
131                 }\r
132         }\r
133 \r
134         @Test(expectedExceptions = ValidationException.class)\r
135         public void testOptionNoDefaultValidate() throws ValidationException {\r
136                 try {\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
142                                         "Index.html"));\r
143 \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
149                         p3.validate();\r
150 \r
151                 } catch (MalformedURLException e) {\r
152                         e.printStackTrace();\r
153                         fail(e.getMessage());\r
154                 }\r
155         }\r
156 \r
157         @Test(expectedExceptions = WrongParameterException.class)\r
158         public void testOptionSetInvalidValue() throws WrongParameterException {\r
159                 try {\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
165                                         "Index.html"));\r
166 \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
173 \r
174                 } catch (MalformedURLException e) {\r
175                         e.printStackTrace();\r
176                         fail(e.getMessage());\r
177                 }\r
178         }\r
179 \r
180         @Test()\r
181         public void testOptionToCommand() {\r
182                 try {\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
188                                         "Index.html"));\r
189 \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
196                         p3.validate();\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
211                 }\r
212         }\r
213 \r
214         @Test(expectedExceptions = IllegalStateException.class)\r
215         public void testCreateNumParameterWithoutValidValue() {\r
216                 try {\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
220                         // for\r
221                         // numeric value\r
222                         p4.setDefaultValue("5");\r
223                 } catch (WrongParameterException e) {\r
224                         e.printStackTrace();\r
225                         fail(e.getLocalizedMessage());\r
226                 }\r
227 \r
228         }\r
229 \r
230         @Test()\r
231         public void testCreateParameterWithValidValueConstrain() {\r
232 \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
237                 vc.setMin("0");\r
238                 vc.setMax("10");\r
239                 p4.setValidValue(vc);\r
240                 try {\r
241                         p4.setDefaultValue("5");\r
242                 } catch (WrongParameterException e) {\r
243                         e.printStackTrace();\r
244                         fail(e.getLocalizedMessage());\r
245                 }\r
246         }\r
247 \r
248         @Test(expectedExceptions = WrongParameterException.class)\r
249         public void testValidateLowerBoundaryConstrainCheck()\r
250                         throws WrongParameterException {\r
251                 try {\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
257                                         "Index.html"));\r
258                         // This attribute is required by strict schema\r
259                         p3.setOptionName("--AAMATRIX");\r
260                         p3.setRequired(true);\r
261 \r
262                         ValueConstrain vc = new ValueConstrain();\r
263                         vc.setType(ValueConstrain.Type.Float);\r
264                         vc.setMin("-10.12");\r
265                         vc.setMax("0");\r
266                         p3.setValidValue(vc);\r
267                         // THIS IS CAUSING EXCEPTION\r
268                         p3.setDefaultValue("-11.0");\r
269 \r
270                 } catch (MalformedURLException e) {\r
271                         e.printStackTrace();\r
272                         fail(e.getMessage());\r
273                 }\r
274         }\r
275 \r
276         @Test(expectedExceptions = WrongParameterException.class)\r
277         public void testValidateUpperBoundaryConstrainCheck()\r
278                         throws WrongParameterException {\r
279                 try {\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
285                                         "Index.html"));\r
286                         // This attribute is required by strict schema\r
287                         p3.setOptionName("--AAMATRIX");\r
288                         p3.setRequired(true);\r
289 \r
290                         ValueConstrain vc = new ValueConstrain();\r
291                         vc.setType(ValueConstrain.Type.Float);\r
292                         vc.setMin("-10.12");\r
293                         vc.setMax("0");\r
294                         p3.setValidValue(vc);\r
295                         // THIS IS CAUSING EXCEPTION\r
296                         p3.setDefaultValue("1");\r
297 \r
298                 } catch (MalformedURLException e) {\r
299                         e.printStackTrace();\r
300                         fail(e.getMessage());\r
301                 }\r
302         }\r
303 \r
304         @Test()\r
305         public void testValidateBoundaryConstrainCheck() {\r
306                 try {\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
312                                         "Index.html"));\r
313                         // This attribute is required by strict schema\r
314                         p3.setOptionName("--AAMATRIX");\r
315                         p3.setRequired(true);\r
316 \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
323                         p3.validate();\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
333                 }\r
334         }\r
335 \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
341                 vc.validate();\r
342         }\r
343 }\r