3bf2368577d54a4be3d61cef9c4ee31566b013fd
[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", "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
83 \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
96                 }\r
97         }\r
98 \r
99         @Test()\r
100         public void testParameterToCommand() throws WrongParameterException {\r
101                 try {\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
105 \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
124                 }\r
125         }\r
126 \r
127         @Test(expectedExceptions = ValidationException.class)\r
128         public void testOptionNoDefaultValidate() throws ValidationException {\r
129                 try {\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
133 \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
138                         p3.validate();\r
139                 } catch (MalformedURLException e) {\r
140                         e.printStackTrace();\r
141                         fail(e.getMessage());\r
142                 }\r
143         }\r
144 \r
145         @Test(expectedExceptions = WrongParameterException.class)\r
146         public void testOptionSetInvalidValue() throws WrongParameterException {\r
147                 try {\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
151 \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
160                 }\r
161         }\r
162 \r
163         @Test()\r
164         public void testOptionToCommand() {\r
165                 try {\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
169 \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
175                         p3.validate();\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
190                 }\r
191         }\r
192 \r
193         @Test(expectedExceptions = IllegalStateException.class)\r
194         public void testCreateNumParameterWithoutValidValue() throws MalformedURLException {\r
195                 try {\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
198                         // for\r
199                         // numeric value\r
200                         p4.setDefaultValue("5");\r
201                 } catch (WrongParameterException e) {\r
202                         e.printStackTrace();\r
203                         fail(e.getLocalizedMessage());\r
204                 }\r
205 \r
206         }\r
207 \r
208         @Test()\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
213                 vc.setMin("0");\r
214                 vc.setMax("10");\r
215                 p4.setValidValue(vc);\r
216                 try {\r
217                         p4.setDefaultValue("5");\r
218                 } catch (WrongParameterException e) {\r
219                         e.printStackTrace();\r
220                         fail(e.getLocalizedMessage());\r
221                 }\r
222         }\r
223 \r
224         @Test(expectedExceptions = WrongParameterException.class)\r
225         public void testValidateLowerBoundaryConstrainCheck()\r
226                         throws WrongParameterException {\r
227                 try {\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
234 \r
235                         ValueConstrain vc = new ValueConstrain();\r
236                         vc.setType(ValueConstrain.Type.Float);\r
237                         vc.setMin("-10.12");\r
238                         vc.setMax("0");\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
245                 }\r
246         }\r
247 \r
248         @Test(expectedExceptions = WrongParameterException.class)\r
249         public void testValidateUpperBoundaryConstrainCheck()\r
250                         throws WrongParameterException {\r
251                 try {\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
258 \r
259                         ValueConstrain vc = new ValueConstrain();\r
260                         vc.setType(ValueConstrain.Type.Float);\r
261                         vc.setMin("-10.12");\r
262                         vc.setMax("0");\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
269                 }\r
270         }\r
271 \r
272         @Test()\r
273         public void testValidateBoundaryConstrainCheck() {\r
274                 try {\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
281 \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
288                         p3.validate();\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
298                 }\r
299         }\r
300 \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
306                 vc.validate();\r
307         }\r
308 }\r