Fixed version of Preset class from JABA_r1 branch (see bug JWS-19)
authorpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Thu, 19 Aug 2010 10:25:41 +0000 (10:25 +0000)
committerpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Thu, 19 Aug 2010 10:25:41 +0000 (10:25 +0000)
git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@2907 e3abac25-378b-4346-85de-24260fe3988d

datamodel/compbio/metadata/Preset.java
testsrc/compbio/metadata/PresetTester.java

index 9fd17a0..be9b8f1 100644 (file)
@@ -111,7 +111,11 @@ public class Preset<T> {
            if (option != null) {\r
                // Set default value to the preset value\r
                if (containValue(optionName)) {\r
+                   // extract and set value to the parameter \r
                    option.setDefaultValue(getValue(optionName));\r
+               } else {\r
+                   // set value to the option as default, as this could be a multi-option value\r
+                   option.setDefaultValue(oname);\r
                }\r
                options.add(option);\r
            }\r
index 1665e23..0b5a0a3 100644 (file)
@@ -47,114 +47,148 @@ import compbio.runner.msa.Mafft;
 \r
 public class PresetTester {\r
 \r
-       public static final String input =  AllTestSuit.TEST_DATA_PATH\r
-                       + "MafftPresets.xml";\r
-       public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
-                       + "MafftParameters.xml";\r
-\r
-       PresetManager<Mafft> presets = null;\r
-       RunnerConfig<Mafft> rconfParams = null;\r
-\r
-       @BeforeTest(enabled = true)\r
-       public void loadPresets() {\r
-               try {\r
-                       // Load Preset definitions\r
-                       RunnerConfigMarshaller<Mafft> rconfigPresets = new RunnerConfigMarshaller<Mafft>(\r
-                                       PresetManager.class);\r
-                       File infile = new File(input);\r
-                       assertTrue(infile.exists());\r
-                       presets = rconfigPresets.read(new FileInputStream(infile),\r
-                                       PresetManager.class);\r
-                       assertNotNull(presets);\r
-                       assertFalse(presets.preset.isEmpty());\r
-\r
-                       // Load Parameters definitions\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> rconfigParams = um.unmarshal(\r
-                                       new StreamSource(input), RunnerConfig.class);\r
-                       rconfParams = rconfigParams.getValue();\r
-                       assertNotNull(rconfParams);\r
-\r
-               } catch (JAXBException e) {\r
-                       e.printStackTrace();\r
-                       fail(e.getMessage());\r
-               } catch (FileNotFoundException e) {\r
-                       e.printStackTrace();\r
-                       fail(e.getMessage());\r
-               }\r
+    public static final String input = AllTestSuit.TEST_DATA_PATH\r
+           + "MafftPresets.xml";\r
+    public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
+           + "MafftParameters.xml";\r
+\r
+    PresetManager<Mafft> presets = null;\r
+    RunnerConfig<Mafft> rconfParams = null;\r
+\r
+    @BeforeTest(enabled = true)\r
+    public void loadPresets() {\r
+       try {\r
+           // Load Preset definitions\r
+           RunnerConfigMarshaller<Mafft> rconfigPresets = new RunnerConfigMarshaller<Mafft>(\r
+                   PresetManager.class);\r
+           File infile = new File(input);\r
+           assertTrue(infile.exists());\r
+           presets = rconfigPresets.read(new FileInputStream(infile),\r
+                   PresetManager.class);\r
+           assertNotNull(presets);\r
+           assertFalse(presets.preset.isEmpty());\r
+\r
+           // Load Parameters definitions\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> rconfigParams = um.unmarshal(\r
+                   new StreamSource(input), RunnerConfig.class);\r
+           rconfParams = rconfigParams.getValue();\r
+           assertNotNull(rconfParams);\r
+\r
+       } catch (JAXBException e) {\r
+           e.printStackTrace();\r
+           fail(e.getMessage());\r
+       } catch (FileNotFoundException e) {\r
+           e.printStackTrace();\r
+           fail(e.getMessage());\r
        }\r
-\r
-       @Test\r
-       public void marshallPreset() {\r
-               try {\r
-                       RunnerConfigMarshaller<Mafft> rconfig = new RunnerConfigMarshaller<Mafft>(\r
-                                       PresetManager.class);\r
-                       PresetManager<Mafft> pman = getPresets();\r
-                       assertNotNull(pman);\r
-                       rconfig.readAndValidate(new FileInputStream(new File(input)),\r
-                                       PresetManager.class);\r
-               } catch (JAXBException e) {\r
-                       e.printStackTrace();\r
-                       fail(e.getMessage());\r
-               } catch (IOException e) {\r
-                       e.printStackTrace();\r
-                       fail(e.getMessage());\r
-               } catch (SAXException e) {\r
-                       e.printStackTrace();\r
-                       fail(e.getMessage());\r
-               }\r
+    }\r
+\r
+    @Test\r
+    public void marshallPreset() {\r
+       try {\r
+           RunnerConfigMarshaller<Mafft> rconfig = new RunnerConfigMarshaller<Mafft>(\r
+                   PresetManager.class);\r
+           PresetManager<Mafft> pman = getPresets();\r
+           assertNotNull(pman);\r
+           rconfig.readAndValidate(new FileInputStream(new File(input)),\r
+                   PresetManager.class);\r
+       } catch (JAXBException e) {\r
+           e.printStackTrace();\r
+           fail(e.getMessage());\r
+       } catch (IOException e) {\r
+           e.printStackTrace();\r
+           fail(e.getMessage());\r
+       } catch (SAXException e) {\r
+           e.printStackTrace();\r
+           fail(e.getMessage());\r
        }\r
-\r
-       @Test\r
-       public void validatePresets() {\r
-               assertNotNull(presets);\r
-               assertEquals(presets.getPresets().size(), 6);\r
-               try {\r
-                       for (Preset<Mafft> pr : presets.getPresets()) {\r
-                               List<Option<Mafft>> options;\r
-                               options = pr.getArguments(rconfParams);\r
-                               assertFalse(options.isEmpty());\r
-                               if (pr.name.equals("L-INS-i (Accuracy-oriented)")) {\r
-                                       assertEquals(options.size(), 2);\r
-                                       Option<Mafft> o = options.get(0);\r
-                                       if (o.name.equals("Pairwise alignment computation method")) {\r
-                                               List<String> onames = o.getOptionNames();\r
-                                               boolean match = false;\r
-                                               for (String oname : onames) {\r
-                                                       if (oname.equals("--localpair")) {\r
-                                                               match = true;\r
-                                                               break;\r
-                                                       }\r
-                                               }\r
-                                               assertTrue(match);\r
-                                       }\r
-                               }\r
-                               if (pr.name.equals("NW-NS-PartTree-1 (Speed oriented)")) {\r
-                                       assertEquals(options.size(), 4);\r
-                               }\r
+    }\r
+\r
+    @Test\r
+    public void validatePresets() {\r
+       assertNotNull(presets);\r
+       assertEquals(presets.getPresets().size(), 6);\r
+       try {\r
+           for (Preset<Mafft> pr : presets.getPresets()) {\r
+               List<Option<Mafft>> options;\r
+               options = pr.getArguments(rconfParams);\r
+               assertFalse(options.isEmpty());\r
+               if (pr.name.equals("L-INS-i (Accuracy-oriented)")) {\r
+                   assertEquals(options.size(), 2);\r
+                   Option<Mafft> o = options.get(0);\r
+                   if (o.name.equals("Pairwise alignment computation method")) {\r
+                       List<String> onames = o.getOptionNames();\r
+                       boolean match = false;\r
+                       for (String oname : onames) {\r
+                           if (oname.equals("--localpair")) {\r
+                               match = true;\r
+                               break;\r
+                           }\r
                        }\r
-               } catch (WrongParameterException e) {\r
-                       e.printStackTrace();\r
-                       fail(e.getMessage());\r
+                       assertTrue(match);\r
+                   }\r
+               }\r
+               if (pr.name.equals("NW-NS-PartTree-1 (Speed oriented)")) {\r
+                   assertEquals(options.size(), 4);\r
                }\r
+           }\r
+       } catch (WrongParameterException e) {\r
+           e.printStackTrace();\r
+           fail(e.getMessage());\r
        }\r
-\r
-       private static PresetManager<Mafft> getPresets() {\r
-               Preset<Mafft> preset1 = new Preset<Mafft>();\r
-               preset1.name = "L-INS-i (Accuracy-oriented)";\r
-               preset1.description = "dsfjkg fdjksghkjsgdfh jksdfg sdfgkjhsdfgk kjsdfg ";\r
-\r
-               List<String> optionNames = new ArrayList<String>();\r
-               optionNames.add("--localpair");\r
-               optionNames.add("--maxiterate 1000");\r
-               preset1.option = optionNames;\r
-               PresetManager<Mafft> prman = new PresetManager<Mafft>();\r
-               prman.preset = Collections.singletonList(preset1);\r
-               prman.runnerClassName = Mafft.class.getCanonicalName();\r
-\r
-               return prman;\r
+    }\r
+\r
+    @Test\r
+    public void testPresetWithMuptiOptions() {\r
+       assertNotNull(presets);\r
+       assertEquals(presets.getPresets().size(), 6);\r
+       try {\r
+           for (Preset<Mafft> pr : presets.getPresets()) {\r
+               List<Option<Mafft>> options;\r
+               options = pr.getArguments(rconfParams);\r
+               assertFalse(options.isEmpty());\r
+               if (pr.name.equals("E-INS-i (Accuracy-oriented)")) {\r
+                   assertEquals(options.size(), 3);\r
+                   Option<Mafft> o = options.get(0);\r
+                   if (o.name.equals("Pairwise alignment computation method")) {\r
+                       List<String> onames = o.getOptionNames();\r
+                       boolean match = false;\r
+                       for (String oname : onames) {\r
+                           if (oname.equals("--genafpair")) {\r
+                               match = true;\r
+                               break;\r
+                           }\r
+                       }\r
+                       assertTrue(match);\r
+                   }\r
+               }\r
+               if (pr.name.equals("NW-NS-PartTree-1 (Speed oriented)")) {\r
+                   assertEquals(options.size(), 4);\r
+               }\r
+           }\r
+       } catch (WrongParameterException e) {\r
+           e.printStackTrace();\r
+           fail(e.getMessage());\r
        }\r
+    }\r
+\r
+    private static PresetManager<Mafft> getPresets() {\r
+       Preset<Mafft> preset1 = new Preset<Mafft>();\r
+       preset1.name = "L-INS-i (Accuracy-oriented)";\r
+       preset1.description = "dsfjkg fdjksghkjsgdfh jksdfg sdfgkjhsdfgk kjsdfg ";\r
+\r
+       List<String> optionNames = new ArrayList<String>();\r
+       optionNames.add("--localpair");\r
+       optionNames.add("--maxiterate 1000");\r
+       preset1.option = optionNames;\r
+       PresetManager<Mafft> prman = new PresetManager<Mafft>();\r
+       prman.preset = Collections.singletonList(preset1);\r
+       prman.runnerClassName = Mafft.class.getCanonicalName();\r
+\r
+       return prman;\r
+    }\r
 }\r