From b9f54dfc066b99717d901ab5239513f891a7ee43 Mon Sep 17 00:00:00 2001 From: Sasha Sherstnev Date: Mon, 14 Oct 2013 15:26:05 +0100 Subject: [PATCH] Fix problems with tests --- .../engine/conf/RunnerConfigMarshallerTester.java | 421 +++++++++----------- .../compbio/metadata/OptionMarshallerTester.java | 281 +++++++------ testsrc/compbio/metadata/RunnerConfigTester.java | 195 ++++----- 3 files changed, 411 insertions(+), 486 deletions(-) diff --git a/testsrc/compbio/engine/conf/RunnerConfigMarshallerTester.java b/testsrc/compbio/engine/conf/RunnerConfigMarshallerTester.java index 8daacff..db2ac48 100644 --- a/testsrc/compbio/engine/conf/RunnerConfigMarshallerTester.java +++ b/testsrc/compbio/engine/conf/RunnerConfigMarshallerTester.java @@ -53,236 +53,211 @@ import compbio.runner.msa.Mafft; public class RunnerConfigMarshallerTester { - public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE - + "MafftParameters.xml"; - public static String test_schema_output = "RunnerConfigSchema.xml"; - public static String test_output = AllTestSuit.OUTPUT_DIR_ABSOLUTE - + "MafftParameters.out.xml"; - - public static String invalidDoc = AllTestSuit.TEST_DATA_PATH_ABSOLUTE - + "InvalidMafftParameters.xml"; - - RunnerConfig rconfig = null; - Parameter matrixParam = null; - RunnerConfigMarshaller pmarshaller = null; - - @BeforeMethod - public void setup() { - // write some parameters programmatically - try { - rconfig = new RunnerConfig(); - rconfig.setRunnerClassName(Mafft.class.getName()); - List> prms = new ArrayList>(); - - Parameter p1 = new Parameter("Type", - "Type of the sequence (PROTEIN or DNA)"); - // TODO publish help on a compbio web site - - p1.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - p1.addPossibleValues("PROTEIN", "DNA"); - p1.setOptionName("-TYPE"); - p1.setRequired(false); - - /* - * -MATRIX= :Protein weight matrix=BLOSUM, PAM, GONNET, ID or - * filename - */ - Option p2 = new Option("MATRIX", - "Protein weight matrix"); - // TODO publish help on a compbio web site - - p2.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - - p2.addOptionNames("-jtree"); // "-retree" - p2.setRequired(false); - - Parameter p3 = new Parameter("Matrix1", - "Protein weight matrix"); - // TODO publish help on a compbio web site - p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - - p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID"); - // This attribute is required by strict schema - p3.setOptionName("--AAMATRIX"); - p3.setRequired(true); - p3.setDefaultValue("pam"); - ValueConstrain vc = new ValueConstrain(); - vc.setType(ValueConstrain.Type.Float); - vc.setMin("-10.12"); - vc.setMax("0"); - p3.setValidValue(vc); - - prms.add(p1); - prms.add(p2); - prms.add(p3); - matrixParam = p3; - rconfig.setOptions(prms); - - pmarshaller = new RunnerConfigMarshaller(RunnerConfig.class, - Parameter.class, Option.class, ValueConstrain.class); - } catch (MalformedURLException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (JAXBException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (WrongParameterException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); + public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE + "MafftParameters.xml"; + public static String test_schema_output = "RunnerConfigSchema.xml"; + public static String test_output = AllTestSuit.OUTPUT_DIR_ABSOLUTE + "MafftParameters.out.xml"; + + public static String invalidDoc = AllTestSuit.TEST_DATA_PATH_ABSOLUTE + "InvalidMafftParameters.xml"; + + RunnerConfig rconfig = null; + Parameter matrixParam = null; + RunnerConfigMarshaller pmarshaller = null; + + @BeforeMethod + public void setup() { + // write some parameters programmatically + try { + rconfig = new RunnerConfig(); + rconfig.setRunnerClassName(Mafft.class.getName()); + List> prms = new ArrayList>(); + + Parameter p1 = new Parameter("Type", "Type of the sequence (PROTEIN or DNA)"); + // TODO publish help on a compbio web site + + p1.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); + p1.addPossibleValues("PROTEIN", "DNA"); + p1.setOptionName("-TYPE"); + p1.setRequired(false); + + /* + * -MATRIX= :Protein weight matrix=BLOSUM, PAM, GONNET, ID or + * filename + */ + Option p2 = new Option("MATRIX", "Protein weight matrix"); + // TODO publish help on a compbio web site + + p2.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); + + p2.addOptionNames("-jtree"); // "-retree" + p2.setRequired(false); + + Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); + // TODO publish help on a compbio web site + p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); + + p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID"); + // This attribute is required by strict schema + p3.setOptionName("--AAMATRIX"); + p3.setRequired(true); + p3.setDefaultValue("pam"); + ValueConstrain vc = new ValueConstrain(); + vc.setType(ValueConstrain.Type.Float); + vc.setMin("-10.12"); + vc.setMax("0"); + p3.setValidValue(vc); + + prms.add(p1); + prms.add(p2); + prms.add(p3); + matrixParam = p3; + rconfig.setOptions(prms); + + pmarshaller = new RunnerConfigMarshaller(RunnerConfig.class, Parameter.class, Option.class, ValueConstrain.class); + } catch (JAXBException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (WrongParameterException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } + } - } - - @Test() - public void testMarshalling() { - - File outfile = new File(this.test_output); - try { - pmarshaller.write(rconfig, new FileOutputStream(outfile)); - } catch (FileNotFoundException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (JAXBException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); + @Test() + public void testMarshalling() { + + File outfile = new File(this.test_output); + try { + pmarshaller.write(rconfig, new FileOutputStream(outfile)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (JAXBException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } + assertTrue("Output file expected, but nothing found!", outfile.exists()); + outfile.delete(); } - assertTrue("Output file expected, but nothing found!", outfile.exists()); - outfile.delete(); - } - - @Test() - public void testUnMarshalling() { - - File outfile = new File(this.test_output); - try { - pmarshaller.write(rconfig, new FileOutputStream(outfile)); - - RunnerConfig rconfig = pmarshaller.read(new FileInputStream( - outfile), RunnerConfig.class, Parameter.class, - Option.class, ValueConstrain.class); - assertNotNull(rconfig); - assertEquals(rconfig.getParameters().size(), this.rconfig - .getParameters().size()); - assertEquals(rconfig.getRunnerClassName(), this.rconfig - .getRunnerClassName()); - assertTrue(matrixParam.equals(rconfig.getArgument("MATRIX1"))); - assertFalse(matrixParam.equals(rconfig.getArgument("Type"))); - } catch (FileNotFoundException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (JAXBException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); + + @Test() + public void testUnMarshalling() { + + File outfile = new File(this.test_output); + try { + pmarshaller.write(rconfig, new FileOutputStream(outfile)); + + RunnerConfig rconfig = pmarshaller.read(new FileInputStream(outfile), RunnerConfig.class, Parameter.class, Option.class, + ValueConstrain.class); + assertNotNull(rconfig); + assertEquals(rconfig.getParameters().size(), this.rconfig.getParameters().size()); + assertEquals(rconfig.getRunnerClassName(), this.rconfig.getRunnerClassName()); + assertTrue(matrixParam.equals(rconfig.getArgument("MATRIX1"))); + assertFalse(matrixParam.equals(rconfig.getArgument("Type"))); + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (JAXBException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } + // outfile.delete(); } - // outfile.delete(); - } - - @Test() - public void testValidation() { - try { - System.out.println("CCCC " + rconfig); - // write schema - pmarshaller.generateSchema(AllTestSuit.OUTPUT_DIR_ABSOLUTE, - test_schema_output); - - File schemafile = new File(AllTestSuit.OUTPUT_DIR_ABSOLUTE, - test_schema_output); - assertTrue(schemafile.exists()); - // document is NOT valid even against a loose schema as elements in - // java are annotated as required - Validator looseValidator = RunnerConfigMarshaller - .getValidator(schemafile.getAbsolutePath()); - - // write output xml file - File outfile = new File(this.test_output); - pmarshaller.write(rconfig, new FileOutputStream(outfile)); - - assertTrue("Invalid output is NOT expected", RunnerConfigMarshaller - .validate(looseValidator, test_output)); - - Schema strictSchema = RunnerConfigMarshaller - .getSchema(AllTestSuit.TEST_DATA_PATH_ABSOLUTE - + File.separator + "RunnerConfigSchema.xsd"); - - Validator strictVal = RunnerConfigMarshaller - .getValidator(strictSchema); - - // document is invalid against strict schema - assertFalse("Invalid output is expected", RunnerConfigMarshaller - .validate(strictVal, invalidDoc)); - - // schemafile.delete(); - // outfile.delete(); - - } catch (MalformedURLException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (JAXBException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (SAXException e) { - e.printStackTrace(); - fail(e.getMessage()); + + @Test() + public void testValidation() { + try { + System.out.println("CCCC " + rconfig); + // write schema + pmarshaller.generateSchema(AllTestSuit.OUTPUT_DIR_ABSOLUTE, test_schema_output); + + File schemafile = new File(AllTestSuit.OUTPUT_DIR_ABSOLUTE, test_schema_output); + assertTrue(schemafile.exists()); + // document is NOT valid even against a loose schema as elements in + // java are annotated as required + Validator looseValidator = RunnerConfigMarshaller.getValidator(schemafile.getAbsolutePath()); + + // write output xml file + File outfile = new File(this.test_output); + pmarshaller.write(rconfig, new FileOutputStream(outfile)); + + assertTrue("Invalid output is NOT expected", RunnerConfigMarshaller.validate(looseValidator, test_output)); + + Schema strictSchema = RunnerConfigMarshaller.getSchema(AllTestSuit.TEST_DATA_PATH_ABSOLUTE + File.separator + + "RunnerConfigSchema.xsd"); + + Validator strictVal = RunnerConfigMarshaller.getValidator(strictSchema); + + // document is invalid against strict schema + assertFalse("Invalid output is expected", RunnerConfigMarshaller.validate(strictVal, invalidDoc)); + + // schemafile.delete(); + // outfile.delete(); + + } catch (MalformedURLException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (JAXBException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (SAXException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } - } - - @Test(expectedExceptions = JAXBException.class) - public void testValidationOnMarshalling() throws SAXException, - JAXBException, MalformedURLException { - // This is not valid parameter - Parameter p = new Parameter("MATRIXXX", "Protein weight matrix"); - // This attribute is required by strict schema - // p.setOptionName("-M"); - p.setRequired(true); - rconfig.addParameter(p); - try { - - // strict schema invalidate this document and throw an exception - // just discard the output - pmarshaller.writeAndValidate(rconfig, - AllTestSuit.TEST_DATA_PATH_ABSOLUTE + File.separator - + "RunnerConfigSchema.xsd", - new ByteArrayOutputStream()); - - fail("Exception has been thrown before this place in unreachable"); - - } catch (MalformedURLException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); + @Test(expectedExceptions = JAXBException.class) + public void testValidationOnMarshalling() throws SAXException, JAXBException, MalformedURLException { + // This is not valid parameter + Parameter p = new Parameter("MATRIXXX", "Protein weight matrix"); + // This attribute is required by strict schema + // p.setOptionName("-M"); + p.setRequired(true); + rconfig.addParameter(p); + try { + + // strict schema invalidate this document and throw an exception + // just discard the output + pmarshaller.writeAndValidate(rconfig, AllTestSuit.TEST_DATA_PATH_ABSOLUTE + File.separator + "RunnerConfigSchema.xsd", + new ByteArrayOutputStream()); + + fail("Exception has been thrown before this place in unreachable"); + + } catch (MalformedURLException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } } - } - - @Test() - public void testSchemaFromCodeGeneration() { - try { - - pmarshaller.generateSchema(AllTestSuit.OUTPUT_DIR_ABSOLUTE, - test_schema_output); - } catch (JAXBException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); + + @Test() + public void testSchemaFromCodeGeneration() { + try { + + pmarshaller.generateSchema(AllTestSuit.OUTPUT_DIR_ABSOLUTE, test_schema_output); + } catch (JAXBException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } + File schemafile = new File(AllTestSuit.OUTPUT_DIR_ABSOLUTE, test_schema_output); + assertTrue("Schema file expected but not found", schemafile.exists()); + assertTrue("Schema file seems to be empty", schemafile.length() > 50); + // schemafile.delete(); } - File schemafile = new File(AllTestSuit.OUTPUT_DIR_ABSOLUTE, - test_schema_output); - assertTrue("Schema file expected but not found", schemafile.exists()); - assertTrue("Schema file seems to be empty", schemafile.length() > 50); - // schemafile.delete(); - } } diff --git a/testsrc/compbio/metadata/OptionMarshallerTester.java b/testsrc/compbio/metadata/OptionMarshallerTester.java index a98a171..b681729 100644 --- a/testsrc/compbio/metadata/OptionMarshallerTester.java +++ b/testsrc/compbio/metadata/OptionMarshallerTester.java @@ -49,153 +49,142 @@ import compbio.runner.msa.Mafft; public class OptionMarshallerTester { - public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE - + "MafftParameters.xml"; - public static String test_schema_output = "NextGenMafftOptionsSchema.xml"; - public static String test_output = "MafftOptions.xml.out"; - public static String reWrittenInput = AllTestSuit.OUTPUT_DIR_ABSOLUTE - + "rewrittenMafftParams.xml"; - - RunnerConfig rconfig = null; - Option matrixParam = null; - - @BeforeMethod() - public void setup() { - // write some parameters programmatically - try { - rconfig = new RunnerConfig(); - rconfig.setRunnerClassName(Mafft.class.getName()); - List> prms = new ArrayList>(); - - Parameter p1 = new Parameter("Type", - "Type of the sequence (PROTEIN or DNA)"); - // TODO publish help on a compbio web site - - p1.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - p1.addPossibleValues("PROTEIN", "DNA"); - p1.setOptionName("-TYPE"); - p1.setRequired(false); - - /* - * -MATRIX= :Protein weight matrix=BLOSUM, PAM, GONNET, ID or - * filename - */ - Option p2 = new Option("MATRIX", - "Protein weight matrix"); - // TODO publish help on a compbio web site - - p2.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - - p2.addOptionNames("-jtree"); - p2.addOptionNames("-jfasta"); - p2.setRequired(false); - - Parameter p3 = new Parameter("MATRIX2", - "Protein weight matrix"); - // TODO publish help on a compbio web site - p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - - p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID"); - // This attribute is required by strict schema - p3.setOptionName("-MATRIX"); - p3.setRequired(true); - p3.setDefaultValue("id"); - ValueConstrain vc = new ValueConstrain(); - vc.setType(ValueConstrain.Type.Float); - vc.setMin("-10.12"); - vc.setMax("0"); - p3.setValidValue(vc); - - prms.add(p1); - prms.add(p2); - prms.add(p3); - matrixParam = p2; - rconfig.setOptions(prms); - - } catch (MalformedURLException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (WrongParameterException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); + public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE + "MafftParameters.xml"; + public static String test_schema_output = "NextGenMafftOptionsSchema.xml"; + public static String test_output = "MafftOptions.xml.out"; + public static String reWrittenInput = AllTestSuit.OUTPUT_DIR_ABSOLUTE + "rewrittenMafftParams.xml"; + + RunnerConfig rconfig = null; + Option matrixParam = null; + + @BeforeMethod() + public void setup() { + // write some parameters programmatically + try { + rconfig = new RunnerConfig(); + rconfig.setRunnerClassName(Mafft.class.getName()); + List> prms = new ArrayList>(); + + Parameter p1 = new Parameter("Type", "Type of the sequence (PROTEIN or DNA)"); + // TODO publish help on a compbio web site + + p1.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); + p1.addPossibleValues("PROTEIN", "DNA"); + p1.setOptionName("-TYPE"); + p1.setRequired(false); + + /* + * -MATRIX= :Protein weight matrix=BLOSUM, PAM, GONNET, ID or + * filename + */ + Option p2 = new Option("MATRIX", "Protein weight matrix"); + // TODO publish help on a compbio web site + + p2.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); + + p2.addOptionNames("-jtree"); + p2.addOptionNames("-jfasta"); + p2.setRequired(false); + + Parameter p3 = new Parameter("MATRIX2", "Protein weight matrix"); + // TODO publish help on a compbio web site + p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); + + p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID"); + // This attribute is required by strict schema + p3.setOptionName("-MATRIX"); + p3.setRequired(true); + p3.setDefaultValue("id"); + ValueConstrain vc = new ValueConstrain(); + vc.setType(ValueConstrain.Type.Float); + vc.setMin("-10.12"); + vc.setMax("0"); + p3.setValidValue(vc); + + prms.add(p1); + prms.add(p2); + prms.add(p3); + matrixParam = p2; + rconfig.setOptions(prms); + + } catch (WrongParameterException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } } - } - - @Test(expectedExceptions = { javax.xml.bind.MarshalException.class }) - public void testMarshalling() throws JAXBException { - - File outfile = new File(AllTestSuit.OUTPUT_DIR_ABSOLUTE, test_output); - try { - RunnerConfigMarshaller rmarsh = new RunnerConfigMarshaller( - RunnerConfig.class); - - // This throws an exception - // I am not sure why - rmarsh.writeAndValidate(rconfig, - AllTestSuit.TEST_DATA_PATH_ABSOLUTE + File.separator - + "RunnerConfigSchema.xsd", new FileOutputStream( - outfile)); - - } catch (FileNotFoundException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (SAXException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); + + @Test(expectedExceptions = { javax.xml.bind.MarshalException.class }) + public void testMarshalling() throws JAXBException { + + File outfile = new File(AllTestSuit.OUTPUT_DIR_ABSOLUTE, test_output); + try { + RunnerConfigMarshaller rmarsh = new RunnerConfigMarshaller(RunnerConfig.class); + + // This throws an exception + // I am not sure why + rmarsh.writeAndValidate(rconfig, AllTestSuit.TEST_DATA_PATH_ABSOLUTE + File.separator + "RunnerConfigSchema.xsd", + new FileOutputStream(outfile)); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (SAXException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } + assertTrue("Output file expected, but nothing found!", outfile.exists()); + // outfile.delete(); } - assertTrue("Output file expected, but nothing found!", outfile.exists()); - // outfile.delete(); - } - - @Test() - public void testUnMarshalling() { - try { - File input = new File(this.test_input); - assertTrue(input.exists()); - JAXBContext ctx = JAXBContext.newInstance(RunnerConfig.class); - Unmarshaller um = ctx.createUnmarshaller(); - JAXBElement rconfig = um.unmarshal(new StreamSource(input), RunnerConfig.class); - RunnerConfig runner = rconfig.getValue(); - assertNotNull(runner); - System.out.println(runner); - assertFalse(runner.options.isEmpty()); - assertFalse(runner.parameters.isEmpty()); - assertEquals(7, runner.options.size()); - assertEquals(8, runner.parameters.size()); - Option stypeOption = runner.getArgument("Sequence type"); - System.out.println(stypeOption); - assertNotNull(stypeOption); - assertFalse(stypeOption.isRequired); - assertEquals("--auto", stypeOption.defaultValue); - assertEquals(2, stypeOption.optionNames.size()); - - assertEquals(" ", runner.getPrmSeparator()); - Option guidetrOption = runner.getArgument("Guide tree rebuild"); - Parameter guidetr = (Parameter) guidetrOption; - ValueConstrain constraint = guidetr.getValidValue(); - assertEquals("Integer", constraint.type.toString()); - assertEquals(1, constraint.getMin()); - assertEquals(100, constraint.getMax()); - - RunnerConfigMarshaller rmarsh = new RunnerConfigMarshaller(RunnerConfig.class); - // Now see if we can write a valid document back discard the actual - // output only validation is important here - rmarsh.write(rconfig, new FileOutputStream(new File(reWrittenInput))); - RunnerConfig rc = rmarsh.readAndValidate(new FileInputStream(new File(reWrittenInput)), RunnerConfig.class); - assertEquals(runner, rc); - - } catch (JAXBException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); - } catch (SAXException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); + + @Test() + public void testUnMarshalling() { + try { + File input = new File(this.test_input); + assertTrue(input.exists()); + JAXBContext ctx = JAXBContext.newInstance(RunnerConfig.class); + Unmarshaller um = ctx.createUnmarshaller(); + JAXBElement rconfig = um.unmarshal(new StreamSource(input), RunnerConfig.class); + RunnerConfig runner = rconfig.getValue(); + assertNotNull(runner); + System.out.println(runner); + assertFalse(runner.options.isEmpty()); + assertFalse(runner.parameters.isEmpty()); + assertEquals(7, runner.options.size()); + assertEquals(8, runner.parameters.size()); + Option stypeOption = runner.getArgument("Sequence type"); + System.out.println(stypeOption); + assertNotNull(stypeOption); + assertFalse(stypeOption.isRequired); + assertEquals("--auto", stypeOption.defaultValue); + assertEquals(2, stypeOption.optionNames.size()); + + assertEquals(" ", runner.getPrmSeparator()); + Option guidetrOption = runner.getArgument("Guide tree rebuild"); + Parameter guidetr = (Parameter) guidetrOption; + ValueConstrain constraint = guidetr.getValidValue(); + assertEquals("Integer", constraint.type.toString()); + assertEquals(1, constraint.getMin()); + assertEquals(100, constraint.getMax()); + + RunnerConfigMarshaller rmarsh = new RunnerConfigMarshaller(RunnerConfig.class); + // Now see if we can write a valid document back discard the actual + // output only validation is important here + rmarsh.write(rconfig, new FileOutputStream(new File(reWrittenInput))); + RunnerConfig rc = rmarsh.readAndValidate(new FileInputStream(new File(reWrittenInput)), RunnerConfig.class); + assertEquals(runner, rc); + + } catch (JAXBException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } catch (SAXException e) { + e.printStackTrace(); + fail(e.getLocalizedMessage()); + } } - } } diff --git a/testsrc/compbio/metadata/RunnerConfigTester.java b/testsrc/compbio/metadata/RunnerConfigTester.java index 3bf2368..99549e1 100644 --- a/testsrc/compbio/metadata/RunnerConfigTester.java +++ b/testsrc/compbio/metadata/RunnerConfigTester.java @@ -40,8 +40,7 @@ import compbio.runner.msa.Mafft; public class RunnerConfigTester { - public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE - + "MafftParameters.xml"; + public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE + "MafftParameters.xml"; RunnerConfig rconfig = null; @@ -52,9 +51,8 @@ public class RunnerConfigTester { rconfig.setRunnerClassName(Mafft.class.getName()); List> prms = new ArrayList>(); - RunnerConfigMarshaller pmarshaller = new RunnerConfigMarshaller( - RunnerConfig.class, Parameter.class, Option.class, - ValueConstrain.class); + RunnerConfigMarshaller pmarshaller = new RunnerConfigMarshaller(RunnerConfig.class, Parameter.class, + Option.class, ValueConstrain.class); } catch (JAXBException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); @@ -76,88 +74,69 @@ public class RunnerConfigTester { @Test(expectedExceptions = WrongParameterException.class) public void testCreateParameter() throws WrongParameterException { - try { - Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); - // TODO publish help on a compbio web site - p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); + Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); + // TODO publish help on a compbio web site + p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID"); - // This attribute is required by strict schema - p3.setOptionName("--AAMATRIX"); - p3.setRequired(true); - // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED - // IN WITHIN POSSIBLE VALUES - p3.setDefaultValue("pam22"); - String com = p3.toCommand(" "); - System.out.println("AAAAAAAAAAAAAA!" + com); - } catch (MalformedURLException e) { - e.printStackTrace(); - fail(e.getMessage()); - } + p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID"); + // This attribute is required by strict schema + p3.setOptionName("--AAMATRIX"); + p3.setRequired(true); + // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED + // IN WITHIN POSSIBLE VALUES + p3.setDefaultValue("pam22"); + String com = p3.toCommand(" "); + System.out.println("AAAAAAAAAAAAAA!" + com); } @Test() public void testParameterToCommand() throws WrongParameterException { - try { - Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); - // TODO publish help on a compbio web site - p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); + Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); + // TODO publish help on a compbio web site + p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID"); - // This attribute is required by strict schema - p3.setOptionName("--AAMATRIX"); - p3.setRequired(true); - // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED - // IN WITHIN POSSIBLE VALUES - p3.setDefaultValue("PAM"); - String com = p3.toCommand("="); - assertTrue(com.startsWith("--AAMATRIX")); - assertTrue(com.endsWith("PAM")); - assertTrue(com.contains("=")); - p3.setDefaultValue("ID"); - com = p3.toCommand("="); - assertFalse(com.endsWith("PAM")); - assertFalse(com.contains("PAM")); - } catch (MalformedURLException e) { - e.printStackTrace(); - fail(e.getMessage()); - } + p3.addPossibleValues("BLOSUM", "PAM", "GONNET", "ID"); + // This attribute is required by strict schema + p3.setOptionName("--AAMATRIX"); + p3.setRequired(true); + // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED + // IN WITHIN POSSIBLE VALUES + p3.setDefaultValue("PAM"); + String com = p3.toCommand("="); + assertTrue(com.startsWith("--AAMATRIX")); + assertTrue(com.endsWith("PAM")); + assertTrue(com.contains("=")); + p3.setDefaultValue("ID"); + com = p3.toCommand("="); + assertFalse(com.endsWith("PAM")); + assertFalse(com.contains("PAM")); } @Test(expectedExceptions = ValidationException.class) public void testOptionNoDefaultValidate() throws ValidationException { - try { - Option p3 = new Option("Matrix1", "Protein weight matrix"); - // TODO publish help on a compbio web site - p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); + Option p3 = new Option("Matrix1", "Protein weight matrix"); + // TODO publish help on a compbio web site + p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", "--ABMAT", "--BBBB"))); - p3.setRequired(true); - // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED - // IN WITHIN POSSIBLE VALUES - p3.validate(); - } catch (MalformedURLException e) { - e.printStackTrace(); - fail(e.getMessage()); - } + p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", "--ABMAT", "--BBBB"))); + p3.setRequired(true); + // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED + // IN WITHIN POSSIBLE VALUES + p3.validate(); } @Test(expectedExceptions = WrongParameterException.class) public void testOptionSetInvalidValue() throws WrongParameterException { - try { - Option p3 = new Option("Matrix1", "Protein weight matrix"); - // TODO publish help on a compbio web site - p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", "--ABMAT", "--BBBB"))); - p3.setRequired(true); - // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED - // IN WITHIN POSSIBLE VALUES - p3.setDefaultValue("AAA"); - } catch (MalformedURLException e) { - e.printStackTrace(); - fail(e.getMessage()); - } + Option p3 = new Option("Matrix1", "Protein weight matrix"); + // TODO publish help on a compbio web site + p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); + + p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", "--ABMAT", "--BBBB"))); + p3.setRequired(true); + // THIS LINE IS CAUSING EXCEPTION AS DEFAULT VALUE MUST BE DEFINED + // IN WITHIN POSSIBLE VALUES + p3.setDefaultValue("AAA"); } @Test() @@ -178,9 +157,6 @@ public class RunnerConfigTester { p3.setDefaultValue("--ABMAT"); com = p3.toCommand("="); assertEquals("--ABMAT", com); - } catch (MalformedURLException e) { - e.printStackTrace(); - fail(e.getMessage()); } catch (ValidationException e) { e.printStackTrace(); fail(e.getMessage()); @@ -222,51 +198,39 @@ public class RunnerConfigTester { } @Test(expectedExceptions = WrongParameterException.class) - public void testValidateLowerBoundaryConstrainCheck() - throws WrongParameterException { - try { - Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); - // TODO publish help on a compbio web site - p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - // This attribute is required by strict schema - p3.setOptionName("--AAMATRIX"); - p3.setRequired(true); + public void testValidateLowerBoundaryConstrainCheck() throws WrongParameterException { + Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); + // TODO publish help on a compbio web site + p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); + // This attribute is required by strict schema + p3.setOptionName("--AAMATRIX"); + p3.setRequired(true); - ValueConstrain vc = new ValueConstrain(); - vc.setType(ValueConstrain.Type.Float); - vc.setMin("-10.12"); - vc.setMax("0"); - p3.setValidValue(vc); - // THIS IS CAUSING EXCEPTION - p3.setDefaultValue("-11.0"); - } catch (MalformedURLException e) { - e.printStackTrace(); - fail(e.getMessage()); - } + ValueConstrain vc = new ValueConstrain(); + vc.setType(ValueConstrain.Type.Float); + vc.setMin("-10.12"); + vc.setMax("0"); + p3.setValidValue(vc); + // THIS IS CAUSING EXCEPTION + p3.setDefaultValue("-11.0"); } @Test(expectedExceptions = WrongParameterException.class) - public void testValidateUpperBoundaryConstrainCheck() - throws WrongParameterException { - try { - Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); - // TODO publish help on a compbio web site - p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - // This attribute is required by strict schema - p3.setOptionName("--AAMATRIX"); - p3.setRequired(true); + public void testValidateUpperBoundaryConstrainCheck() throws WrongParameterException { + Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); + // TODO publish help on a compbio web site + p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); + // This attribute is required by strict schema + p3.setOptionName("--AAMATRIX"); + p3.setRequired(true); - ValueConstrain vc = new ValueConstrain(); - vc.setType(ValueConstrain.Type.Float); - vc.setMin("-10.12"); - vc.setMax("0"); - p3.setValidValue(vc); - // THIS IS CAUSING EXCEPTION - p3.setDefaultValue("1"); - } catch (MalformedURLException e) { - e.printStackTrace(); - fail(e.getMessage()); - } + ValueConstrain vc = new ValueConstrain(); + vc.setType(ValueConstrain.Type.Float); + vc.setMin("-10.12"); + vc.setMax("0"); + p3.setValidValue(vc); + // THIS IS CAUSING EXCEPTION + p3.setDefaultValue("1"); } @Test() @@ -286,9 +250,6 @@ public class RunnerConfigTester { // Max value boundary is not defined so 1 is valid p3.setDefaultValue("1"); p3.validate(); - } catch (MalformedURLException e) { - e.printStackTrace(); - fail(e.getMessage()); } catch (WrongParameterException e) { e.printStackTrace(); fail(e.getMessage()); -- 1.7.10.2