Add testing dirs
[proteocache.git] / testsrc / compbio / metadata / RunnerConfigTester.java
diff --git a/testsrc/compbio/metadata/RunnerConfigTester.java b/testsrc/compbio/metadata/RunnerConfigTester.java
new file mode 100644 (file)
index 0000000..99549e1
--- /dev/null
@@ -0,0 +1,269 @@
+/* Copyright (c) 2009 Peter Troshin\r
+ *  \r
+ *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0     \r
+ * \r
+ *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
+ *  Apache License version 2 as published by the Apache Software Foundation\r
+ * \r
+ *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
+ *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
+ *  License for more details.\r
+ * \r
+ *  A copy of the license is in apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+ * \r
+ * Any republication or derived work distributed in source code form\r
+ * must include this copyright and license notice.\r
+ */\r
+package compbio.metadata;\r
+\r
+import static org.testng.AssertJUnit.assertEquals;\r
+import static org.testng.AssertJUnit.assertFalse;\r
+import static org.testng.AssertJUnit.assertTrue;\r
+import static org.testng.AssertJUnit.fail;\r
+\r
+import java.net.MalformedURLException;\r
+import java.net.URL;\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.HashSet;\r
+import java.util.List;\r
+\r
+import javax.xml.bind.JAXBException;\r
+import javax.xml.bind.ValidationException;\r
+\r
+import org.testng.annotations.BeforeMethod;\r
+import org.testng.annotations.Test;\r
+\r
+import compbio.engine.conf.RunnerConfigMarshaller;\r
+import compbio.runner.msa.Mafft;\r
+\r
+public class RunnerConfigTester {\r
+\r
+       public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE + "MafftParameters.xml";\r
+\r
+       RunnerConfig<Mafft> rconfig = null;\r
+\r
+       @BeforeMethod\r
+       public void setup() {\r
+               try {\r
+                       rconfig = new RunnerConfig<Mafft>();\r
+                       rconfig.setRunnerClassName(Mafft.class.getName());\r
+                       List<Option<Mafft>> prms = new ArrayList<Option<Mafft>>();\r
+\r
+                       RunnerConfigMarshaller<Mafft> pmarshaller = new RunnerConfigMarshaller<Mafft>(RunnerConfig.class, Parameter.class,\r
+                                       Option.class, ValueConstrain.class);\r
+               } catch (JAXBException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getLocalizedMessage());\r
+               }\r
+       }\r
+\r
+       @Test\r
+       public void testValidate() {\r
+               try {\r
+                       rconfig.validate();\r
+               } catch (ValidationException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getLocalizedMessage());\r
+               } catch (IllegalStateException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getLocalizedMessage());\r
+               }\r
+       }\r
+\r
+       @Test(expectedExceptions = WrongParameterException.class)\r
+       public void testCreateParameter() throws WrongParameterException {\r
+               Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");\r
+               // TODO publish help on a compbio web site\r
+               p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");\r
+\r
+               p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID");\r
+               // This attribute is required by strict schema\r
+               p3.setOptionName("--AAMATRIX");\r
+               p3.setRequired(true);\r
+               // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED\r
+               // IN WITHIN POSSIBLE VALUES\r
+               p3.setDefaultValue("pam22");\r
+               String com = p3.toCommand(" ");\r
+               System.out.println("AAAAAAAAAAAAAA!" + com);\r
+       }\r
+\r
+       @Test()\r
+       public void testParameterToCommand() throws WrongParameterException {\r
+               Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");\r
+               // TODO publish help on a compbio web site\r
+               p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");\r
+\r
+               p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID");\r
+               // This attribute is required by strict schema\r
+               p3.setOptionName("--AAMATRIX");\r
+               p3.setRequired(true);\r
+               // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED\r
+               // IN WITHIN POSSIBLE VALUES\r
+               p3.setDefaultValue("PAM");\r
+               String com = p3.toCommand("=");\r
+               assertTrue(com.startsWith("--AAMATRIX"));\r
+               assertTrue(com.endsWith("PAM"));\r
+               assertTrue(com.contains("="));\r
+               p3.setDefaultValue("ID");\r
+               com = p3.toCommand("=");\r
+               assertFalse(com.endsWith("PAM"));\r
+               assertFalse(com.contains("PAM"));\r
+       }\r
+\r
+       @Test(expectedExceptions = ValidationException.class)\r
+       public void testOptionNoDefaultValidate() throws ValidationException {\r
+               Option<Mafft> p3 = new Option<Mafft>("Matrix1", "Protein weight matrix");\r
+               // TODO publish help on a compbio web site\r
+               p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");\r
+\r
+               p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", "--ABMAT", "--BBBB")));\r
+               p3.setRequired(true);\r
+               // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED\r
+               // IN WITHIN POSSIBLE VALUES\r
+               p3.validate();\r
+       }\r
+\r
+       @Test(expectedExceptions = WrongParameterException.class)\r
+       public void testOptionSetInvalidValue() throws WrongParameterException {\r
+\r
+               Option<Mafft> p3 = new Option<Mafft>("Matrix1", "Protein weight matrix");\r
+               // TODO publish help on a compbio web site\r
+               p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");\r
+\r
+               p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", "--ABMAT", "--BBBB")));\r
+               p3.setRequired(true);\r
+               // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED\r
+               // IN WITHIN POSSIBLE VALUES\r
+               p3.setDefaultValue("AAA");\r
+       }\r
+\r
+       @Test()\r
+       public void testOptionToCommand() {\r
+               try {\r
+                       Option<Mafft> p3 = new Option<Mafft>("Matrix1", "Protein weight matrix");\r
+                       // TODO publish help on a compbio web site\r
+                       p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");\r
+\r
+                       p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", "--ABMAT", "--BBBB")));\r
+                       p3.setRequired(true);\r
+                       // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED\r
+                       // IN WITHIN POSSIBLE VALUES\r
+                       p3.setDefaultValue("--BBBB");\r
+                       p3.validate();\r
+                       String com = p3.toCommand("=");\r
+                       assertEquals("--BBBB", com);\r
+                       p3.setDefaultValue("--ABMAT");\r
+                       com = p3.toCommand("=");\r
+                       assertEquals("--ABMAT", com);\r
+               } catch (ValidationException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               } catch (WrongParameterException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               }\r
+       }\r
+\r
+       @Test(expectedExceptions = IllegalStateException.class)\r
+       public void testCreateNumParameterWithoutValidValue() throws MalformedURLException {\r
+               try {\r
+                       Parameter<Mafft> p4 = new Parameter<Mafft>("Matrix", "DNA weight matrix");\r
+                       // This is causing exception is ValidValue constrain is not defined\r
+                       // for\r
+                       // numeric value\r
+                       p4.setDefaultValue("5");\r
+               } catch (WrongParameterException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getLocalizedMessage());\r
+               }\r
+\r
+       }\r
+\r
+       @Test()\r
+       public void testCreateParameterWithValidValueConstrain() throws MalformedURLException {\r
+               Parameter<Mafft> p4 = new Parameter<Mafft>("Matrix", "DNA weight matrix");\r
+               ValueConstrain vc = new ValueConstrain();\r
+               vc.setType(ValueConstrain.Type.Float);\r
+               vc.setMin("0");\r
+               vc.setMax("10");\r
+               p4.setValidValue(vc);\r
+               try {\r
+                       p4.setDefaultValue("5");\r
+               } catch (WrongParameterException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getLocalizedMessage());\r
+               }\r
+       }\r
+\r
+       @Test(expectedExceptions = WrongParameterException.class)\r
+       public void testValidateLowerBoundaryConstrainCheck() throws WrongParameterException {\r
+               Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");\r
+               // TODO publish help on a compbio web site\r
+               p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");\r
+               // This attribute is required by strict schema\r
+               p3.setOptionName("--AAMATRIX");\r
+               p3.setRequired(true);\r
+\r
+               ValueConstrain vc = new ValueConstrain();\r
+               vc.setType(ValueConstrain.Type.Float);\r
+               vc.setMin("-10.12");\r
+               vc.setMax("0");\r
+               p3.setValidValue(vc);\r
+               // THIS IS CAUSING EXCEPTION\r
+               p3.setDefaultValue("-11.0");\r
+       }\r
+\r
+       @Test(expectedExceptions = WrongParameterException.class)\r
+       public void testValidateUpperBoundaryConstrainCheck() throws WrongParameterException {\r
+               Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");\r
+               // TODO publish help on a compbio web site\r
+               p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");\r
+               // This attribute is required by strict schema\r
+               p3.setOptionName("--AAMATRIX");\r
+               p3.setRequired(true);\r
+\r
+               ValueConstrain vc = new ValueConstrain();\r
+               vc.setType(ValueConstrain.Type.Float);\r
+               vc.setMin("-10.12");\r
+               vc.setMax("0");\r
+               p3.setValidValue(vc);\r
+               // THIS IS CAUSING EXCEPTION\r
+               p3.setDefaultValue("1");\r
+       }\r
+\r
+       @Test()\r
+       public void testValidateBoundaryConstrainCheck() {\r
+               try {\r
+                       Parameter<Mafft> p3 = new Parameter<Mafft>("Matrix1", "Protein weight matrix");\r
+                       // TODO publish help on a compbio web site\r
+                       p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");\r
+                       // This attribute is required by strict schema\r
+                       p3.setOptionName("--AAMATRIX");\r
+                       p3.setRequired(true);\r
+\r
+                       ValueConstrain vc = new ValueConstrain();\r
+                       vc.setType(ValueConstrain.Type.Float);\r
+                       vc.setMin("-10.12");\r
+                       p3.setValidValue(vc);\r
+                       // Max value boundary is not defined so 1 is valid\r
+                       p3.setDefaultValue("1");\r
+                       p3.validate();\r
+               } catch (WrongParameterException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               } catch (ValidationException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               }\r
+       }\r
+\r
+       @Test(expectedExceptions = ValidationException.class)\r
+       public void testValidateValueConstrain() throws ValidationException {\r
+               ValueConstrain vc = new ValueConstrain();\r
+               vc.setType(ValueConstrain.Type.Float);\r
+               // NO BOUNDARIES DEFINED\r
+               vc.validate();\r
+       }\r
+}\r