99549e1bf92d74487732fe90a911e28a0d0c914c
[proteocache.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 + "MafftParameters.xml";\r
44 \r
45         RunnerConfig<Mafft> rconfig = null;\r
46 \r
47         @BeforeMethod\r
48         public void setup() {\r
49                 try {\r
50                         rconfig = new RunnerConfig<Mafft>();\r
51                         rconfig.setRunnerClassName(Mafft.class.getName());\r
52                         List<Option<Mafft>> prms = new ArrayList<Option<Mafft>>();\r
53 \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
59                 }\r
60         }\r
61 \r
62         @Test\r
63         public void testValidate() {\r
64                 try {\r
65                         rconfig.validate();\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
72                 }\r
73         }\r
74 \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
80 \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
90         }\r
91 \r
92         @Test()\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
97 \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
113         }\r
114 \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
120 \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
125                 p3.validate();\r
126         }\r
127 \r
128         @Test(expectedExceptions = WrongParameterException.class)\r
129         public void testOptionSetInvalidValue() throws WrongParameterException {\r
130 \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
134 \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
140         }\r
141 \r
142         @Test()\r
143         public void testOptionToCommand() {\r
144                 try {\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
148 \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
154                         p3.validate();\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
166                 }\r
167         }\r
168 \r
169         @Test(expectedExceptions = IllegalStateException.class)\r
170         public void testCreateNumParameterWithoutValidValue() throws MalformedURLException {\r
171                 try {\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
174                         // for\r
175                         // numeric value\r
176                         p4.setDefaultValue("5");\r
177                 } catch (WrongParameterException e) {\r
178                         e.printStackTrace();\r
179                         fail(e.getLocalizedMessage());\r
180                 }\r
181 \r
182         }\r
183 \r
184         @Test()\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
189                 vc.setMin("0");\r
190                 vc.setMax("10");\r
191                 p4.setValidValue(vc);\r
192                 try {\r
193                         p4.setDefaultValue("5");\r
194                 } catch (WrongParameterException e) {\r
195                         e.printStackTrace();\r
196                         fail(e.getLocalizedMessage());\r
197                 }\r
198         }\r
199 \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
208 \r
209                 ValueConstrain vc = new ValueConstrain();\r
210                 vc.setType(ValueConstrain.Type.Float);\r
211                 vc.setMin("-10.12");\r
212                 vc.setMax("0");\r
213                 p3.setValidValue(vc);\r
214                 // THIS IS CAUSING EXCEPTION\r
215                 p3.setDefaultValue("-11.0");\r
216         }\r
217 \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
226 \r
227                 ValueConstrain vc = new ValueConstrain();\r
228                 vc.setType(ValueConstrain.Type.Float);\r
229                 vc.setMin("-10.12");\r
230                 vc.setMax("0");\r
231                 p3.setValidValue(vc);\r
232                 // THIS IS CAUSING EXCEPTION\r
233                 p3.setDefaultValue("1");\r
234         }\r
235 \r
236         @Test()\r
237         public void testValidateBoundaryConstrainCheck() {\r
238                 try {\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
245 \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
252                         p3.validate();\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
259                 }\r
260         }\r
261 \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
267                 vc.validate();\r
268         }\r
269 }\r