+++ /dev/null
-/* 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
-\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.assertNotNull;\r
-import static org.testng.AssertJUnit.assertTrue;\r
-import static org.testng.AssertJUnit.fail;\r
-\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileNotFoundException;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-import java.net.MalformedURLException;\r
-import java.net.URL;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import javax.xml.bind.JAXBContext;\r
-import javax.xml.bind.JAXBElement;\r
-import javax.xml.bind.JAXBException;\r
-import javax.xml.bind.Unmarshaller;\r
-import javax.xml.transform.stream.StreamSource;\r
-\r
-import org.testng.annotations.BeforeMethod;\r
-import org.testng.annotations.Test;\r
-import org.xml.sax.SAXException;\r
-\r
-import compbio.engine.conf.RunnerConfigMarshaller;\r
-import compbio.runner.msa.Mafft;\r
-\r
-public class OptionMarshallerTester {\r
-\r
- public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE + "MafftParameters.xml";\r
- public static String test_schema_output = "NextGenMafftOptionsSchema.xml";\r
- public static String test_output = "MafftOptions.xml.out";\r
- public static String reWrittenInput = AllTestSuit.OUTPUT_DIR_ABSOLUTE + "rewrittenMafftParams.xml";\r
-\r
- RunnerConfig<Mafft> rconfig = null;\r
- Option<Mafft> matrixParam = null;\r
-\r
- @BeforeMethod()\r
- public void setup() {\r
- // write some parameters programmatically\r
- try {\r
- rconfig = new RunnerConfig<Mafft>();\r
- rconfig.setRunnerClassName(Mafft.class.getName());\r
- List<Option<Mafft>> prms = new ArrayList<Option<Mafft>>();\r
-\r
- Parameter<Mafft> p1 = new Parameter<Mafft>("Type", "Type of the sequence (PROTEIN or DNA)");\r
- // TODO publish help on a compbio web site\r
-\r
- p1.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");\r
- p1.addPossibleValues("PROTEIN", "DNA");\r
- p1.setOptionName("-TYPE");\r
- p1.setRequired(false);\r
-\r
- /*\r
- * -MATRIX= :Protein weight matrix=BLOSUM, PAM, GONNET, ID or\r
- * filename\r
- */\r
- Option<Mafft> p2 = new Option<Mafft>("MATRIX", "Protein weight matrix");\r
- // TODO publish help on a compbio web site\r
-\r
- p2.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html");\r
-\r
- p2.addOptionNames("-jtree");\r
- p2.addOptionNames("-jfasta");\r
- p2.setRequired(false);\r
-\r
- Parameter<Mafft> p3 = new Parameter<Mafft>("MATRIX2", "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("-MATRIX");\r
- p3.setRequired(true);\r
- p3.setDefaultValue("id");\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
-\r
- prms.add(p1);\r
- prms.add(p2);\r
- prms.add(p3);\r
- matrixParam = p2;\r
- rconfig.setOptions(prms);\r
-\r
- } catch (WrongParameterException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- }\r
- }\r
-\r
- @Test(expectedExceptions = { javax.xml.bind.MarshalException.class })\r
- public void testMarshalling() throws JAXBException {\r
-\r
- File outfile = new File(AllTestSuit.OUTPUT_DIR_ABSOLUTE, test_output);\r
- try {\r
- RunnerConfigMarshaller<Mafft> rmarsh = new RunnerConfigMarshaller<Mafft>(RunnerConfig.class);\r
-\r
- // This throws an exception\r
- // I am not sure why\r
- rmarsh.writeAndValidate(rconfig, AllTestSuit.TEST_DATA_PATH_ABSOLUTE + File.separator + "RunnerConfigSchema.xsd",\r
- new FileOutputStream(outfile));\r
-\r
- } catch (FileNotFoundException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- } catch (SAXException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- }\r
- assertTrue("Output file expected, but nothing found!", outfile.exists());\r
- // outfile.delete();\r
- }\r
-\r
- @Test()\r
- public void testUnMarshalling() {\r
- try {\r
- File input = new File(this.test_input);\r
- assertTrue(input.exists());\r
- JAXBContext ctx = JAXBContext.newInstance(RunnerConfig.class);\r
- Unmarshaller um = ctx.createUnmarshaller();\r
- JAXBElement<RunnerConfig> rconfig = um.unmarshal(new StreamSource(input), RunnerConfig.class);\r
- RunnerConfig<Mafft> runner = rconfig.getValue();\r
- assertNotNull(runner);\r
- System.out.println(runner);\r
- assertFalse(runner.options.isEmpty());\r
- assertFalse(runner.parameters.isEmpty());\r
- assertEquals(7, runner.options.size());\r
- assertEquals(8, runner.parameters.size());\r
- Option<Mafft> stypeOption = runner.getArgument("Sequence type");\r
- System.out.println(stypeOption);\r
- assertNotNull(stypeOption);\r
- assertFalse(stypeOption.isRequired);\r
- assertEquals("--auto", stypeOption.defaultValue);\r
- assertEquals(2, stypeOption.optionNames.size());\r
-\r
- assertEquals(" ", runner.getPrmSeparator());\r
- Option<Mafft> guidetrOption = runner.getArgument("Guide tree rebuild");\r
- Parameter<Mafft> guidetr = (Parameter<Mafft>) guidetrOption;\r
- ValueConstrain constraint = guidetr.getValidValue();\r
- assertEquals("Integer", constraint.type.toString());\r
- assertEquals(1, constraint.getMin());\r
- assertEquals(100, constraint.getMax());\r
-\r
- RunnerConfigMarshaller<Mafft> rmarsh = new RunnerConfigMarshaller<Mafft>(RunnerConfig.class);\r
- // Now see if we can write a valid document back discard the actual\r
- // output only validation is important here\r
- rmarsh.write(rconfig, new FileOutputStream(new File(reWrittenInput)));\r
- RunnerConfig<Mafft> rc = rmarsh.readAndValidate(new FileInputStream(new File(reWrittenInput)), RunnerConfig.class);\r
- assertEquals(runner, rc);\r
-\r
- } catch (JAXBException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- } catch (SAXException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- }\r
- }\r
-}\r