r1907 - in isis-fish/trunk/src: main/java/fr/ifremer/isisfish/util test/java/fr/ifremer test/java/fr/ifremer/isisfish/simulator test/java/fr/ifremer/isisfish/simulator/launcher test/java/fr/ifremer/isisfish/util test/java/fr/ifremer/isisfish/vcs
Author: chatellier Date: 2009-03-04 11:18:49 +0000 (Wed, 04 Mar 2009) New Revision: 1907 Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/MatrixConverter.java Removed: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/MethodTest.java Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/ConverterUtil.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/StringConverter.java isis-fish/trunk/src/test/java/fr/ifremer/TestUtils.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationPreScriptTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/CompileHelperTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java Log: Add matrix serialization to string. Fix some tests. Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/ConverterUtil.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/ConverterUtil.java 2009-03-03 17:19:33 UTC (rev 1906) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/ConverterUtil.java 2009-03-04 11:18:49 UTC (rev 1907) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2006 + * Copyright (C) 2006 - 2009 * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or @@ -17,22 +17,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *##%*/ -/* * - * ConverterUtil.java - * - * Created: 25 sept. 06 19:37:16 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - package fr.ifremer.isisfish.util; import org.apache.commons.beanutils.BeanUtilsBean; import org.apache.commons.beanutils.ConvertUtilsBean; +import org.codelutin.math.matrix.MatrixND; import org.codelutin.topia.TopiaContext; import org.codelutin.topia.persistence.TopiaEntity; @@ -41,26 +30,30 @@ import fr.ifremer.isisfish.types.RangeOfValues; import fr.ifremer.isisfish.types.TimeUnit; - /** + * ConverterUtil. + * + * Created: 25 sept. 06 19:37:16 + * * @author poussin + * @version $Revision$ * + * Last update: $Date$ + * by : $Author$ */ - public class ConverterUtil { - static public ConvertUtilsBean getConverter(TopiaContext context) { + public static ConvertUtilsBean getConverter(TopiaContext context) { BeanUtilsBean result = BeanUtilsBean.getInstance(); ConvertUtilsBean cub = result.getConvertUtils(); - - cub.register(new TopiaEntityConverter(context), TopiaEntity.class); - - // FIXME see if register done in IsisFish.init() method permit to remove next line + // mise en place de converter de string vers des objet ... + cub.register(new TopiaEntityConverter(context), TopiaEntity.class); cub.register(new DateConverter(), Date.class); cub.register(new MonthConverter(), Month.class); cub.register(new TimeUnitConverter(), TimeUnit.class); cub.register(new RangeOfValuesConverter(), RangeOfValues.class); + cub.register(new MatrixConverter(), MatrixND.class); // ... et inversement cub.register(new StringConverter(), String.class); @@ -68,5 +61,3 @@ } } - - Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/MatrixConverter.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/MatrixConverter.java (rev 0) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/MatrixConverter.java 2009-03-04 11:18:49 UTC (rev 1907) @@ -0,0 +1,77 @@ +/* *##% Copyright (C) 2009 + * Code Lutin, Cédric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307, USA. ##% + */ + +package fr.ifremer.isisfish.util; + +import org.apache.commons.beanutils.ConversionException; +import org.apache.commons.beanutils.Converter; +import org.apache.commons.lang.StringEscapeUtils; +import org.codelutin.math.matrix.MatrixND; +import org.codelutin.math.matrix.MatrixStringEncoder; +import org.codelutin.topia.persistence.TopiaEntity; + +/** + * Classe utilisées pour convertir des matrices en string et vice-versa. + * + * @author chatellier + * @version $Revision: 1526 $ + * + * Last update: $Date: 2008-10-07 18:46:13 +0200 (mar 07 oct 2008) $ + * by : $Author: tchemit $ + */ +public class MatrixConverter extends MatrixStringEncoder implements Converter { + + protected Converter defaultStringConverter = new org.apache.commons.beanutils.converters.StringConverter(); + + /* + * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, java.lang.Object) + */ + public Object convert(Class type, Object value) { + Object result; + if (value instanceof MatrixND) { + result = value; + } else if (value instanceof String) { + String sValue = (String)value; + sValue = StringEscapeUtils.unescapeJava(sValue); + result = getMatrixFromString(sValue); + } else if (value == null) { + result = null; + } else { + throw new ConversionException("Can't convert '" + value + "' to " + type.getName()); + } + return result; + } + + /* + * @see org.codelutin.math.matrix.MatrixStringEncoder#getQualifiedName(java.lang.Object) + */ + @Override + public String getQualifiedName(Object o) { + + String qualifiedName; + + if(o instanceof TopiaEntity) { + qualifiedName = TopiaEntity.class.getName(); + } + else { + qualifiedName = o.getClass().getName(); + } + return qualifiedName; + } + +} Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/StringConverter.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/StringConverter.java 2009-03-03 17:19:33 UTC (rev 1906) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/StringConverter.java 2009-03-04 11:18:49 UTC (rev 1907) @@ -1,5 +1,5 @@ -/* - * *##% Copyright (C) 2006 Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% Copyright (C) 2006 - 2009 + * Code Lutin, Cédric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software @@ -16,21 +16,11 @@ * Place - Suite 330, Boston, MA 02111-1307, USA. ##% */ -/******************************************************************************* - * StringConverter.java - * - * Created: 12 janv. 2006 20:38:26 - * - * @author poussin - * - * @version $Revision$ - * - * Last update: $Date$ by : $Author$ - */ - package fr.ifremer.isisfish.util; import org.apache.commons.beanutils.Converter; +import org.apache.commons.lang.StringEscapeUtils; +import org.codelutin.math.matrix.MatrixND; import org.codelutin.topia.persistence.TopiaEntity; import fr.ifremer.isisfish.types.Date; @@ -38,22 +28,24 @@ import fr.ifremer.isisfish.types.TimeUnit; /** - * Classe utilise pour convertir en chaine un objet Date, Month ou TopiaEntity - * Utilisé pour la conversion et le stockage en propriete des parametres + * Classe utilisée pour convertir en chaine un objet Date, Month ou TopiaEntity. + * Utilisé pour la conversion et le stockage en propriete des parametres. + * + * Created: 12 janv. 2006 20:38:26 + * * @author poussin * + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ */ public class StringConverter implements Converter { - private Converter defaultStringConverter = - new org.apache.commons.beanutils.converters.StringConverter(); + protected Converter defaultStringConverter = new org.apache.commons.beanutils.converters.StringConverter(); - /* - * (non-Javadoc) - * - * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, - * java.lang.Object) + * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, java.lang.Object) */ public Object convert(Class type, Object o) { Object result = null; @@ -66,6 +58,10 @@ result = String.valueOf(((Month) o).getMonthNumber()); } else if (o instanceof TimeUnit) { result = String.valueOf(((TimeUnit) o).getTime()); + } else if (o instanceof MatrixND) { + MatrixConverter converter = new MatrixConverter(); + result = converter.getMatrixAsString((MatrixND)o); + result = StringEscapeUtils.escapeJava((String)result); } else { // dans tous les autres cas, on appelle le converter par defaut result = defaultStringConverter.convert(type, o); Modified: isis-fish/trunk/src/test/java/fr/ifremer/TestUtils.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/TestUtils.java 2009-03-03 17:19:33 UTC (rev 1906) +++ isis-fish/trunk/src/test/java/fr/ifremer/TestUtils.java 2009-03-04 11:18:49 UTC (rev 1907) @@ -44,6 +44,9 @@ } /** + * Toujours appeler cette method pour les test d'isis. + * (sinon,il ira ecrire dans le isis-database-3 officiel). + * * Create a temp dir and init isis with that temp dir as database. * * @throws Exception Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationPreScriptTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationPreScriptTest.java 2009-03-03 17:19:33 UTC (rev 1906) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationPreScriptTest.java 2009-03-04 11:18:49 UTC (rev 1907) @@ -73,7 +73,6 @@ * * FIXME fix this test (empty schema error) */ - at Ignore public class SimulationPreScriptTest { private static final Log log = LogFactory.getLog(SimulationPreScriptTest.class); @@ -84,12 +83,15 @@ @BeforeClass public static void init() throws Exception { - TestUtils.init(); + //TestUtils.init(); freemarkerConfiguration = TestUtils.getFreemarkerConfiguration(); } @Before - public void setUp() { + public void setUp() throws Exception { + // not do it in @BeforeClass + // test wil fail ! + TestUtils.init(); System.setProperty("hibernate.hbm2ddl.auto", "create"); } Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTest.java 2009-03-03 17:19:33 UTC (rev 1906) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTest.java 2009-03-04 11:18:49 UTC (rev 1907) @@ -25,10 +25,7 @@ import org.apache.commons.logging.LogFactory; import org.codelutin.math.matrix.MatrixFactory; import org.codelutin.math.matrix.MatrixND; -import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import fr.ifremer.TestUtils; @@ -60,21 +57,13 @@ private static final Log log = LogFactory.getLog(SimulationServiceTest.class); - @BeforeClass - public static void init() throws Exception { + @Before + public void setUp() throws Exception { + // not do it in @BeforeClass + // test wil fail ! TestUtils.init(); } - @Before - public void setUp() { - - } - - @After - public void tearDown() { - - } - /** * Build a test {@link DesignPlan}. * @@ -84,7 +73,7 @@ DesignPlan designPlan = new DesignPlan(); // factor 1 - Factor<Double> factor1 = new Factor<Double>("test double 1"); + Factor<Double> factor1 = new Factor<Double>("factor 1 (double)"); ContinuousDomain<Double> domain1 = new ContinuousDomain<Double>(); domain1.setMinBound(0.0); domain1.setMaxBound(50.0); @@ -92,7 +81,7 @@ factor1.setPath("fr.ifremer.isisfish.entities.PopulationGroup#1156461521013#0.1715620681984218#maxLength"); // factor 2 - Factor<Double> factor2 = new Factor<Double>("test double 2"); + Factor<Double> factor2 = new Factor<Double>("factor 2 (double)"); DiscreteDomain<Double> domain2 = new DiscreteDomain<Double>(); domain2.getValues().put(0.0, 12.3); domain2.getValues().put(1.0, 70.9); @@ -103,7 +92,7 @@ factor2.setPath("fr.ifremer.isisfish.entities.PopulationGroup#1156461521064#0.022976136053553198#minLength"); // factor 3 - Factor<Double> factor3 = new Factor<Double>("testint"); + Factor<Double> factor3 = new Factor<Double>("factor 3 (double)"); ContinuousDomain<Double> domain3 = new ContinuousDomain<Double>(); domain3.setMinBound(12.0); domain3.setMaxBound(99.0); @@ -135,14 +124,6 @@ matrix1.setValue(new int[] { 2, 0 }, 12); matrix1.setValue(new int[] { 2, 1 }, -1); - // factor 1 - Factor<Double> factor1 = new Factor<Double>("test double 1"); - ContinuousDomain<Double> domain1 = new ContinuousDomain<Double>(); - domain1.setMinBound(0.0); - domain1.setMaxBound(50.0); - factor1.setDomain(domain1); - factor1.setPath("fr.ifremer.isisfish.entities.Population#1156462366818#0.5536481119187864#maxLength"); - // matrix 2 MatrixND matrix2 = MatrixFactory.getInstance().create("test1", new int[] { 3, 2 }, new String[] { "col1", "col2" }); @@ -153,19 +134,15 @@ matrix2.setValue(new int[] { 2, 0 }, 12); matrix2.setValue(new int[] { 2, 1 }, -1); - // factor 2 - Factor<Double> factor2 = new Factor<Double>("test double 2"); - DiscreteDomain<Double> domain2 = new DiscreteDomain<Double>(); - domain2.getValues().put(0.0, 12.3); - domain2.getValues().put(1.0, 70.9); - domain2.getValues().put(2.0, 21.0); - domain2.getValues().put(3.0, -12.1); - domain2.getValues().put(4.0, -8.45); - factor2.setDomain(domain2); - factor2.setPath("fr.ifremer.isisfish.entities.PopulationGroup#1156461521064#0.022976136053553198#minLength"); + // factor 1 + Factor<MatrixND> factor1 = new Factor<MatrixND>("factor 1 (matrixND)"); + DiscreteDomain<MatrixND> domain1 = new DiscreteDomain<MatrixND>(); + domain1.getValues().put(0.0, matrix1); + domain1.getValues().put(1.0, matrix2); + factor1.setDomain(domain1); + factor1.setPath("fr.ifremer.isisfish.entities.StrategyMonthInfo#1156808754768#0.7282750856395208#proportionMetier"); designPlan.getFactors().add(factor1); - designPlan.getFactors().add(factor2); return designPlan; } @@ -173,7 +150,7 @@ /** * Lance une simulation avec des facteurs de sensibilité. */ - @Ignore + @Test public void testRunSensivitySimulation() { SimulationParameter params = new SimulationParameter(); @@ -222,10 +199,10 @@ /** * Lance une simulation avec des facteurs de sensibilité. * - * This test call R. + * This test use factors with matrix. */ @Test - public void testRunSensivitySimulationMorris() { + public void testRunSensivitySimulationWithMatrix() { SimulationParameter params = new SimulationParameter(); // set params region @@ -251,10 +228,9 @@ SimulatorLauncher launcher = new InProcessSimulatorLauncher(); service.addSimulationLauncher(launcher); - //SensitivityCalculator sensitivityCalculator = new SensitivityCalculatorRMorris(); SensitivityCalculator sensitivityCalculator = new SensitivityCalculatorRandomMock(); - DesignPlan designPlan = getTestDesignPlan(); + DesignPlan designPlan = getTestMatrixDesignPlan(); service.submit("sensitivity test number 1", params, launcher, 0, sensitivityCalculator, designPlan); Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java 2009-03-03 17:19:33 UTC (rev 1906) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncherTest.java 2009-03-04 11:18:49 UTC (rev 1907) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2008 Code Lutin + * Copyright (C) 2008 - 2009 Code Lutin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -54,16 +54,20 @@ final String SIMULATIONID = "testid"; final String SIMULATIONZIP = "test.zip"; final String ISISHOME = IsisFish.config.getSimulatorSshIsisHome(); - + SSHSimulatorLauncher launcher = new SSHSimulatorLauncher(); - String content = launcher.getSimulationScriptLaunchContent(SSHSimulatorLauncher.SQUB_SCRIPT_TEMPLATE, SIMULATIONID, SIMULATIONZIP); + String content = launcher.getSimulationScriptLaunchContent( + SSHSimulatorLauncher.SQUB_SCRIPT_TEMPLATE, SIMULATIONID, + SIMULATIONZIP); // simulation parameters - Assert.assertTrue("String \"" + SIMULATIONID + "\" not found in template", - content.indexOf(SIMULATIONID) > 0); - Assert.assertTrue("String \"" + SIMULATIONZIP + "\" not found in template", + Assert.assertTrue("String \"" + SIMULATIONID + + "\" not found in template", content + .indexOf(SIMULATIONID) > 0); + Assert.assertTrue("String \"" + SIMULATIONZIP + + "\" not found in template", content.indexOf(SIMULATIONZIP) > 0); - + // isis location Assert.assertTrue("String \"" + ISISHOME + "\" not found in template", content.indexOf(ISISHOME) > 0); Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/CompileHelperTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/CompileHelperTest.java 2009-03-03 17:19:33 UTC (rev 1906) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/CompileHelperTest.java 2009-03-04 11:18:49 UTC (rev 1907) @@ -1,5 +1,5 @@ /* - * *##% Copyright (C) 2006 Code Lutin, Cédric Pineau, Benjamin Poussin + * *##% Copyright (C) 2006 - 2009 Code Lutin, Cédric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software @@ -16,18 +16,6 @@ * Place - Suite 330, Boston, MA 02111-1307, USA. ##% */ -/******************************************************************************* - * ClassUtilTest.java - * - * Created: 12 janv. 2006 16:20:33 - * - * @author poussin - * - * @version $Revision$ - * - * Last update: $Date$ by : $Author$ - */ - package fr.ifremer.isisfish.util; import junit.framework.TestCase; @@ -41,10 +29,17 @@ import java.util.List; /** + * ClassUtilTest. + * + * Created: 12 janv. 2006 16:20:33 + * * @author poussin * + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ */ - public class CompileHelperTest extends TestCase { public void testCompile() throws Exception { @@ -52,12 +47,13 @@ String filename = FileUtil.basename(f, ".java"); String code = "public class " + filename + " {}"; FileUtil.writeString(f, code); - + List<File> classpath = new ArrayList<File>(); classpath.add(f.getParentFile()); - - CompileHelper.compile(classpath, Collections.singletonList(f), f.getParentFile(), null); + CompileHelper.compile(classpath, Collections.singletonList(f), f + .getParentFile(), null); + // essai de chargement de la classe URL[] cp = new URL[] { f.getParentFile().toURI().toURL() }; //URL[] cp = new URL[] { f.getParentFile().toURL() }; @@ -80,10 +76,11 @@ FileUtil.writeString(fB, codeB); File dest = new File(fB.getParentFile(), "testCompile"); - + List<File> classpath = new ArrayList<File>(); classpath.add(fB.getParentFile()); - CompileHelper.compile(classpath, Collections.singletonList(fB), dest, null); + CompileHelper.compile(classpath, Collections.singletonList(fB), dest, + null); { // essai de chargement de la classe Deleted: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/MethodTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/MethodTest.java 2009-03-03 17:19:33 UTC (rev 1906) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/MethodTest.java 2009-03-04 11:18:49 UTC (rev 1907) @@ -1,10 +0,0 @@ -package fr.ifremer.isisfish.util; - -/** - * to mark a test method (public void testXXX throws Exception()) in our TestCase - */ - at java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME) - at java.lang.annotation.Target(value = {java.lang.annotation.ElementType.METHOD}) - -public @interface MethodTest { -} Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java 2009-03-03 17:19:33 UTC (rev 1906) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/vcs/VCSSVNTest.java 2009-03-04 11:18:49 UTC (rev 1907) @@ -91,7 +91,7 @@ */ @BeforeClass public static void init() throws Exception { - IsisFish.init(); + TestUtils.init(); template = new File(TMPDIR, "testsvn-template"); remoteRepo = new File(TMPDIR, "testsvn-repo");
participants (1)
-
chatellier@users.labs.libre-entreprise.org