Author: chatellier Date: 2009-03-11 14:20:09 +0000 (Wed, 11 Mar 2009) New Revision: 1939 Added: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/EvaluateHelperTest.java Log: Add test on EvaluateHelper Added: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/EvaluateHelperTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/EvaluateHelperTest.java (rev 0) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/EvaluateHelperTest.java 2009-03-11 14:20:09 UTC (rev 1939) @@ -0,0 +1,115 @@ +/* *##% + * Copyright (C) 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 + * 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 java.util.HashMap; +import java.util.Map; + +import junit.framework.Assert; + +import org.junit.BeforeClass; +import org.junit.Test; + +import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.equation.EmigrationEquation; +import fr.ifremer.isisfish.equation.PopulationGrowth; +import fr.ifremer.isisfish.equation.PopulationGrowthReverse; + +/** + * Test class for {@link EvaluatorHelper}. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class EvaluateHelperTest { + + @BeforeClass + public static void init() throws Exception { + TestUtils.init(); + } + + /** + * Test #normalizeClassName(). + */ + @Test + public void testNormalizeClassName() { + Assert.assertEquals("Test", EvaluatorHelper.normalizeClassName("Test")); + Assert.assertEquals("Te_t", EvaluatorHelper.normalizeClassName("Te/t")); + Assert.assertEquals("org_test_Test", EvaluatorHelper + .normalizeClassName("org.test.Test")); + } + + /** + * Test #check(). + */ + @Test + public void testCheck() { + String equationContent = "return 12.0;"; + + int result = EvaluatorHelper.check(EmigrationEquation.class, + equationContent, null); + Assert.assertEquals(0, result); + } + + /** + * Test #evaluate(). + */ + @Test + public void testEvaluate() { + String equationContent = "return age * 2.0;"; + + Map<String, Object> args = new HashMap<String, Object>(); + args.put("context", null); + args.put("age", 2.0); + args.put("group", null); + Object result = EvaluatorHelper.evaluate("org.codelutin.equation", + "TestEvaluate", PopulationGrowth.class, equationContent, args); + + Assert.assertNotNull(result); + Assert.assertEquals("4.0", result.toString()); + } + + /** + * Test #evaluate() but twice to check that previous + * class don't stay in class loader. + */ + @Test + public void testDoubleContentEvaluate() { + + Map<String, Object> args = new HashMap<String, Object>(); + args.put("context", null); + args.put("length", 2.0); + args.put("group", null); + + String equationContent = "return length * 2.0;"; + Object result = EvaluatorHelper.evaluate("org.codelutin.equation", + "TestDoubleContentEvaluate", PopulationGrowthReverse.class, equationContent, args); + Assert.assertNotNull(result); + Assert.assertEquals("4.0", result.toString()); + + equationContent = "return length * 3.0;"; + result = EvaluatorHelper.evaluate("org.codelutin.equation", + "TestDoubleContentEvaluate", PopulationGrowthReverse.class, equationContent, args); + Assert.assertNotNull(result); + Assert.assertEquals("6.0", result.toString()); + } +} Property changes on: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/util/EvaluateHelperTest.java ___________________________________________________________________ Name: svn:keywords + Revision Date Author