From: pvtroshin Date: Thu, 19 Aug 2010 10:25:41 +0000 (+0000) Subject: Fixed version of Preset class from JABA_r1 branch (see bug JWS-19) X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=589af47c756cfdfb8651f71ba1071c8b240129ff;p=jabaws.git Fixed version of Preset class from JABA_r1 branch (see bug JWS-19) git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@2907 e3abac25-378b-4346-85de-24260fe3988d --- diff --git a/datamodel/compbio/metadata/Preset.java b/datamodel/compbio/metadata/Preset.java index 9fd17a0..be9b8f1 100644 --- a/datamodel/compbio/metadata/Preset.java +++ b/datamodel/compbio/metadata/Preset.java @@ -111,7 +111,11 @@ public class Preset { if (option != null) { // Set default value to the preset value if (containValue(optionName)) { + // extract and set value to the parameter option.setDefaultValue(getValue(optionName)); + } else { + // set value to the option as default, as this could be a multi-option value + option.setDefaultValue(oname); } options.add(option); } diff --git a/testsrc/compbio/metadata/PresetTester.java b/testsrc/compbio/metadata/PresetTester.java index 1665e23..0b5a0a3 100644 --- a/testsrc/compbio/metadata/PresetTester.java +++ b/testsrc/compbio/metadata/PresetTester.java @@ -47,114 +47,148 @@ import compbio.runner.msa.Mafft; public class PresetTester { - public static final String input = AllTestSuit.TEST_DATA_PATH - + "MafftPresets.xml"; - public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE - + "MafftParameters.xml"; - - PresetManager presets = null; - RunnerConfig rconfParams = null; - - @BeforeTest(enabled = true) - public void loadPresets() { - try { - // Load Preset definitions - RunnerConfigMarshaller rconfigPresets = new RunnerConfigMarshaller( - PresetManager.class); - File infile = new File(input); - assertTrue(infile.exists()); - presets = rconfigPresets.read(new FileInputStream(infile), - PresetManager.class); - assertNotNull(presets); - assertFalse(presets.preset.isEmpty()); - - // Load Parameters definitions - File input = new File(this.test_input); - assertTrue(input.exists()); - JAXBContext ctx = JAXBContext.newInstance(RunnerConfig.class); - Unmarshaller um = ctx.createUnmarshaller(); - JAXBElement rconfigParams = um.unmarshal( - new StreamSource(input), RunnerConfig.class); - rconfParams = rconfigParams.getValue(); - assertNotNull(rconfParams); - - } catch (JAXBException e) { - e.printStackTrace(); - fail(e.getMessage()); - } catch (FileNotFoundException e) { - e.printStackTrace(); - fail(e.getMessage()); - } + public static final String input = AllTestSuit.TEST_DATA_PATH + + "MafftPresets.xml"; + public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE + + "MafftParameters.xml"; + + PresetManager presets = null; + RunnerConfig rconfParams = null; + + @BeforeTest(enabled = true) + public void loadPresets() { + try { + // Load Preset definitions + RunnerConfigMarshaller rconfigPresets = new RunnerConfigMarshaller( + PresetManager.class); + File infile = new File(input); + assertTrue(infile.exists()); + presets = rconfigPresets.read(new FileInputStream(infile), + PresetManager.class); + assertNotNull(presets); + assertFalse(presets.preset.isEmpty()); + + // Load Parameters definitions + File input = new File(this.test_input); + assertTrue(input.exists()); + JAXBContext ctx = JAXBContext.newInstance(RunnerConfig.class); + Unmarshaller um = ctx.createUnmarshaller(); + JAXBElement rconfigParams = um.unmarshal( + new StreamSource(input), RunnerConfig.class); + rconfParams = rconfigParams.getValue(); + assertNotNull(rconfParams); + + } catch (JAXBException e) { + e.printStackTrace(); + fail(e.getMessage()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail(e.getMessage()); } - - @Test - public void marshallPreset() { - try { - RunnerConfigMarshaller rconfig = new RunnerConfigMarshaller( - PresetManager.class); - PresetManager pman = getPresets(); - assertNotNull(pman); - rconfig.readAndValidate(new FileInputStream(new File(input)), - PresetManager.class); - } catch (JAXBException e) { - e.printStackTrace(); - fail(e.getMessage()); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } catch (SAXException e) { - e.printStackTrace(); - fail(e.getMessage()); - } + } + + @Test + public void marshallPreset() { + try { + RunnerConfigMarshaller rconfig = new RunnerConfigMarshaller( + PresetManager.class); + PresetManager pman = getPresets(); + assertNotNull(pman); + rconfig.readAndValidate(new FileInputStream(new File(input)), + PresetManager.class); + } catch (JAXBException e) { + e.printStackTrace(); + fail(e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } catch (SAXException e) { + e.printStackTrace(); + fail(e.getMessage()); } - - @Test - public void validatePresets() { - assertNotNull(presets); - assertEquals(presets.getPresets().size(), 6); - try { - for (Preset pr : presets.getPresets()) { - List> options; - options = pr.getArguments(rconfParams); - assertFalse(options.isEmpty()); - if (pr.name.equals("L-INS-i (Accuracy-oriented)")) { - assertEquals(options.size(), 2); - Option o = options.get(0); - if (o.name.equals("Pairwise alignment computation method")) { - List onames = o.getOptionNames(); - boolean match = false; - for (String oname : onames) { - if (oname.equals("--localpair")) { - match = true; - break; - } - } - assertTrue(match); - } - } - if (pr.name.equals("NW-NS-PartTree-1 (Speed oriented)")) { - assertEquals(options.size(), 4); - } + } + + @Test + public void validatePresets() { + assertNotNull(presets); + assertEquals(presets.getPresets().size(), 6); + try { + for (Preset pr : presets.getPresets()) { + List> options; + options = pr.getArguments(rconfParams); + assertFalse(options.isEmpty()); + if (pr.name.equals("L-INS-i (Accuracy-oriented)")) { + assertEquals(options.size(), 2); + Option o = options.get(0); + if (o.name.equals("Pairwise alignment computation method")) { + List onames = o.getOptionNames(); + boolean match = false; + for (String oname : onames) { + if (oname.equals("--localpair")) { + match = true; + break; + } } - } catch (WrongParameterException e) { - e.printStackTrace(); - fail(e.getMessage()); + assertTrue(match); + } + } + if (pr.name.equals("NW-NS-PartTree-1 (Speed oriented)")) { + assertEquals(options.size(), 4); } + } + } catch (WrongParameterException e) { + e.printStackTrace(); + fail(e.getMessage()); } - - private static PresetManager getPresets() { - Preset preset1 = new Preset(); - preset1.name = "L-INS-i (Accuracy-oriented)"; - preset1.description = "dsfjkg fdjksghkjsgdfh jksdfg sdfgkjhsdfgk kjsdfg "; - - List optionNames = new ArrayList(); - optionNames.add("--localpair"); - optionNames.add("--maxiterate 1000"); - preset1.option = optionNames; - PresetManager prman = new PresetManager(); - prman.preset = Collections.singletonList(preset1); - prman.runnerClassName = Mafft.class.getCanonicalName(); - - return prman; + } + + @Test + public void testPresetWithMuptiOptions() { + assertNotNull(presets); + assertEquals(presets.getPresets().size(), 6); + try { + for (Preset pr : presets.getPresets()) { + List> options; + options = pr.getArguments(rconfParams); + assertFalse(options.isEmpty()); + if (pr.name.equals("E-INS-i (Accuracy-oriented)")) { + assertEquals(options.size(), 3); + Option o = options.get(0); + if (o.name.equals("Pairwise alignment computation method")) { + List onames = o.getOptionNames(); + boolean match = false; + for (String oname : onames) { + if (oname.equals("--genafpair")) { + match = true; + break; + } + } + assertTrue(match); + } + } + if (pr.name.equals("NW-NS-PartTree-1 (Speed oriented)")) { + assertEquals(options.size(), 4); + } + } + } catch (WrongParameterException e) { + e.printStackTrace(); + fail(e.getMessage()); } + } + + private static PresetManager getPresets() { + Preset preset1 = new Preset(); + preset1.name = "L-INS-i (Accuracy-oriented)"; + preset1.description = "dsfjkg fdjksghkjsgdfh jksdfg sdfgkjhsdfgk kjsdfg "; + + List optionNames = new ArrayList(); + optionNames.add("--localpair"); + optionNames.add("--maxiterate 1000"); + preset1.option = optionNames; + PresetManager prman = new PresetManager(); + prman.preset = Collections.singletonList(preset1); + prman.runnerClassName = Mafft.class.getCanonicalName(); + + return prman; + } }