From cc9e73f13addc3631f5ba2251d40cf7da78d3bc6 Mon Sep 17 00:00:00 2001 From: Sasha Sherstnev Date: Fri, 20 Sep 2013 13:48:19 +0100 Subject: [PATCH] Fix problems with tests --- .../engine/conf/RunnerConfigMarshallerTester.java | 12 +-- .../compbio/metadata/OptionMarshallerTester.java | 97 +++++++++----------- testsrc/compbio/metadata/RunnerConfigTester.java | 81 +++++----------- 3 files changed, 68 insertions(+), 122 deletions(-) diff --git a/testsrc/compbio/engine/conf/RunnerConfigMarshallerTester.java b/testsrc/compbio/engine/conf/RunnerConfigMarshallerTester.java index 9dc53c2..2263857 100644 --- a/testsrc/compbio/engine/conf/RunnerConfigMarshallerTester.java +++ b/testsrc/compbio/engine/conf/RunnerConfigMarshallerTester.java @@ -78,9 +78,7 @@ public class RunnerConfigMarshallerTester { "Type of the sequence (PROTEIN or DNA)"); // TODO publish help on a compbio web site - p1.setFurtherDetails(new URL("http", - "www.compbio.dundee.ac.uk/users/pvtroshin/ws/", - "Index.html")); + p1.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); p1.addPossibleValues("PROTEIN", "DNA"); p1.setOptionName("-TYPE"); p1.setRequired(false); @@ -93,9 +91,7 @@ public class RunnerConfigMarshallerTester { "Protein weight matrix"); // TODO publish help on a compbio web site - p2.setFurtherDetails(new URL("http", - "www.compbio.dundee.ac.uk/users/pvtroshin/ws/", - "Index.html")); + p2.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); p2.addOptionNames("-jtree"); // "-retree" p2.setRequired(false); @@ -103,9 +99,7 @@ public class RunnerConfigMarshallerTester { Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); // TODO publish help on a compbio web site - p3.setFurtherDetails(new URL("http", - "www.compbio.dundee.ac.uk/users/pvtroshin/ws/", - "Index.html")); + 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 diff --git a/testsrc/compbio/metadata/OptionMarshallerTester.java b/testsrc/compbio/metadata/OptionMarshallerTester.java index 900d6d7..a98a171 100644 --- a/testsrc/compbio/metadata/OptionMarshallerTester.java +++ b/testsrc/compbio/metadata/OptionMarshallerTester.java @@ -71,9 +71,7 @@ public class OptionMarshallerTester { "Type of the sequence (PROTEIN or DNA)"); // TODO publish help on a compbio web site - p1.setFurtherDetails(new URL("http", - "www.compbio.dundee.ac.uk/users/pvtroshin/ws/", - "Index.html")); + p1.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); p1.addPossibleValues("PROTEIN", "DNA"); p1.setOptionName("-TYPE"); p1.setRequired(false); @@ -86,9 +84,7 @@ public class OptionMarshallerTester { "Protein weight matrix"); // TODO publish help on a compbio web site - p2.setFurtherDetails(new URL("http", - "www.compbio.dundee.ac.uk/users/pvtroshin/ws/", - "Index.html")); + p2.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); p2.addOptionNames("-jtree"); p2.addOptionNames("-jfasta"); @@ -97,9 +93,7 @@ public class OptionMarshallerTester { Parameter p3 = new Parameter("MATRIX2", "Protein weight matrix"); // TODO publish help on a compbio web site - p3.setFurtherDetails(new URL("http", - "www.compbio.dundee.ac.uk/users/pvtroshin/ws/", - "Index.html")); + 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 @@ -159,56 +153,49 @@ public class OptionMarshallerTester { @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); + 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()); + e.printStackTrace(); + fail(e.getLocalizedMessage()); } catch (IOException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); + e.printStackTrace(); + fail(e.getLocalizedMessage()); } catch (SAXException e) { - e.printStackTrace(); - fail(e.getLocalizedMessage()); + e.printStackTrace(); + fail(e.getLocalizedMessage()); } } } diff --git a/testsrc/compbio/metadata/RunnerConfigTester.java b/testsrc/compbio/metadata/RunnerConfigTester.java index 087ead6..3bf2368 100644 --- a/testsrc/compbio/metadata/RunnerConfigTester.java +++ b/testsrc/compbio/metadata/RunnerConfigTester.java @@ -77,12 +77,9 @@ public class RunnerConfigTester { @Test(expectedExceptions = WrongParameterException.class) public void testCreateParameter() throws WrongParameterException { try { - Parameter p3 = new Parameter("Matrix1", - "Protein weight matrix"); + Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); // TODO publish help on a compbio web site - p3.setFurtherDetails(new URL("http", - "www.compbio.dundee.ac.uk/users/pvtroshin/ws/", - "Index.html")); + 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 @@ -102,12 +99,9 @@ public class RunnerConfigTester { @Test() public void testParameterToCommand() throws WrongParameterException { try { - Parameter p3 = new Parameter("Matrix1", - "Protein weight matrix"); + Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); // TODO publish help on a compbio web site - p3.setFurtherDetails(new URL("http", - "www.compbio.dundee.ac.uk/users/pvtroshin/ws/", - "Index.html")); + 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 @@ -124,7 +118,6 @@ public class RunnerConfigTester { com = p3.toCommand("="); assertFalse(com.endsWith("PAM")); assertFalse(com.contains("PAM")); - } catch (MalformedURLException e) { e.printStackTrace(); fail(e.getMessage()); @@ -134,20 +127,15 @@ public class RunnerConfigTester { @Test(expectedExceptions = ValidationException.class) public void testOptionNoDefaultValidate() throws ValidationException { try { - Option p3 = new Option("Matrix1", - "Protein weight matrix"); + Option p3 = new Option("Matrix1", "Protein weight matrix"); // TODO publish help on a compbio web site - p3.setFurtherDetails(new URL("http", - "www.compbio.dundee.ac.uk/users/pvtroshin/ws/", - "Index.html")); + p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", - "--ABMAT", "--BBBB"))); + 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()); @@ -157,20 +145,15 @@ public class RunnerConfigTester { @Test(expectedExceptions = WrongParameterException.class) public void testOptionSetInvalidValue() throws WrongParameterException { try { - Option p3 = new Option("Matrix1", - "Protein weight matrix"); + Option p3 = new Option("Matrix1", "Protein weight matrix"); // TODO publish help on a compbio web site - p3.setFurtherDetails(new URL("http", - "www.compbio.dundee.ac.uk/users/pvtroshin/ws/", - "Index.html")); + p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", - "--ABMAT", "--BBBB"))); + 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()); @@ -180,15 +163,11 @@ public class RunnerConfigTester { @Test() public void testOptionToCommand() { try { - Option p3 = new Option("Matrix1", - "Protein weight matrix"); + Option p3 = new Option("Matrix1", "Protein weight matrix"); // TODO publish help on a compbio web site - p3.setFurtherDetails(new URL("http", - "www.compbio.dundee.ac.uk/users/pvtroshin/ws/", - "Index.html")); + p3.setFurtherDetails("http://www.compbio.dundee.ac.uk/users/pvtroshin/ws/Index.html"); - p3.setOptionNames(new HashSet(Arrays.asList("--AAMATRIX", - "--ABMAT", "--BBBB"))); + 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 @@ -212,10 +191,9 @@ public class RunnerConfigTester { } @Test(expectedExceptions = IllegalStateException.class) - public void testCreateNumParameterWithoutValidValue() { + public void testCreateNumParameterWithoutValidValue() throws MalformedURLException { try { - Parameter p4 = new Parameter("Matrix", - "DNA weight matrix"); + Parameter p4 = new Parameter("Matrix", "DNA weight matrix"); // This is causing exception is ValidValue constrain is not defined // for // numeric value @@ -228,10 +206,8 @@ public class RunnerConfigTester { } @Test() - public void testCreateParameterWithValidValueConstrain() { - - Parameter p4 = new Parameter("Matrix", - "DNA weight matrix"); + public void testCreateParameterWithValidValueConstrain() throws MalformedURLException { + Parameter p4 = new Parameter("Matrix", "DNA weight matrix"); ValueConstrain vc = new ValueConstrain(); vc.setType(ValueConstrain.Type.Float); vc.setMin("0"); @@ -249,12 +225,9 @@ public class RunnerConfigTester { public void testValidateLowerBoundaryConstrainCheck() throws WrongParameterException { try { - Parameter p3 = new Parameter("Matrix1", - "Protein weight matrix"); + Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); // TODO publish help on a compbio web site - p3.setFurtherDetails(new URL("http", - "www.compbio.dundee.ac.uk/users/pvtroshin/ws/", - "Index.html")); + 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); @@ -266,7 +239,6 @@ public class RunnerConfigTester { p3.setValidValue(vc); // THIS IS CAUSING EXCEPTION p3.setDefaultValue("-11.0"); - } catch (MalformedURLException e) { e.printStackTrace(); fail(e.getMessage()); @@ -277,12 +249,9 @@ public class RunnerConfigTester { public void testValidateUpperBoundaryConstrainCheck() throws WrongParameterException { try { - Parameter p3 = new Parameter("Matrix1", - "Protein weight matrix"); + Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); // TODO publish help on a compbio web site - p3.setFurtherDetails(new URL("http", - "www.compbio.dundee.ac.uk/users/pvtroshin/ws/", - "Index.html")); + 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); @@ -294,7 +263,6 @@ public class RunnerConfigTester { p3.setValidValue(vc); // THIS IS CAUSING EXCEPTION p3.setDefaultValue("1"); - } catch (MalformedURLException e) { e.printStackTrace(); fail(e.getMessage()); @@ -304,12 +272,9 @@ public class RunnerConfigTester { @Test() public void testValidateBoundaryConstrainCheck() { try { - Parameter p3 = new Parameter("Matrix1", - "Protein weight matrix"); + Parameter p3 = new Parameter("Matrix1", "Protein weight matrix"); // TODO publish help on a compbio web site - p3.setFurtherDetails(new URL("http", - "www.compbio.dundee.ac.uk/users/pvtroshin/ws/", - "Index.html")); + 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); -- 1.7.10.2