|
Author: doogie
Date: Sun Feb 21 01:27:32 2010 New Revision: 912272 URL: http://svn.apache.org/viewvc?rev=912272&view=rev Log: Move FlexibleStringExpander tests to a separate file. Added: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java Modified: ofbiz/trunk/framework/base/build.xml ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java ofbiz/trunk/framework/base/testdef/basetests.xml Modified: ofbiz/trunk/framework/base/build.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/build.xml?rev=912272&r1=912271&r2=912272&view=diff ============================================================================== --- ofbiz/trunk/framework/base/build.xml (original) +++ ofbiz/trunk/framework/base/build.xml Sun Feb 21 01:27:32 2010 @@ -40,6 +40,7 @@ <filelist id="test.classes" dir="${src.dir}"> <file name="org/ofbiz/base/util/test/IndentingWriterTests.java"/> <file name="org/ofbiz/base/util/test/UtilObjectTests.java"/> + <file name="org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java"/> <file name="org/ofbiz/base/util/test/TimeDurationTests.java"/> <file name="org/ofbiz/base/json/test/JSONTests.java"/> <file name="org/ofbiz/base/conversion/test/DateTimeTests.java"/> Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java?rev=912272&r1=912271&r2=912272&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/test/BaseUnitTests.java Sun Feb 21 01:27:32 2010 @@ -112,37 +112,6 @@ } } - public void testFlexibleStringExpander() { - FlexibleStringExpander fse = FlexibleStringExpander.getInstance(null); - assertTrue("null FlexibleStringExpander", fse.isEmpty()); - String compare = "Hello World!"; - fse = FlexibleStringExpander.getInstance(compare); - assertEquals("null context", compare, fse.expandString(null)); - Map<String, Object> testMap = new HashMap<String, Object>(); - testMap.put("var", "World"); - fse = FlexibleStringExpander.getInstance("Hello ${var}!"); - assertTrue("simple replacement", compare.equals(fse.expandString(testMap))); - testMap.put("nested", "Hello ${var}"); - fse = FlexibleStringExpander.getInstance("${nested}!"); - assertTrue("hidden (runtime) nested replacement", compare.equals(fse.expandString(testMap))); - fse = FlexibleStringExpander.getInstance("${'Hello ${var}'}!"); - assertTrue("visible nested replacement", compare.equals(fse.expandString(testMap))); - fse = FlexibleStringExpander.getInstance("${bsh:return \"Hello \" + var + \"!\";}"); - assertTrue("bsh: script", compare.equals(fse.expandString(testMap))); - fse = FlexibleStringExpander.getInstance("${groovy:return \"Hello \" + var + \"!\";}"); - assertTrue("groovy: script", compare.equals(fse.expandString(testMap))); - testMap.put("testMap", testMap); - fse = FlexibleStringExpander.getInstance("Hello ${testMap.var}!"); - assertTrue("UEL integration: Map", compare.equals(fse.expandString(testMap))); - List<String> testList = new ArrayList<String>(); - testList.add("World"); - testMap.put("testList", testList); - fse = FlexibleStringExpander.getInstance("Hello ${testList[0]}!"); - assertTrue("UEL integration: List", compare.equals(fse.expandString(testMap))); - fse = FlexibleStringExpander.getInstance("This is an \\${escaped} expression"); - assertTrue("Escaped expression", "This is an ${escaped} expression".equals(fse.expandString(testMap))); - } - // These tests rely upon FlexibleStringExpander, so they // should follow the FlexibleStringExpander tests. public void testFlexibleMapAccessor() { Added: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java?rev=912272&view=auto ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java (added) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java Sun Feb 21 01:27:32 2010 @@ -0,0 +1,66 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.base.util.string.test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import junit.framework.TestCase; + +import org.ofbiz.base.util.string.FlexibleStringExpander; + +public class FlexibleStringExpanderTests extends TestCase { + + public FlexibleStringExpanderTests(String name) { + super(name); + } + + public void testFlexibleStringExpander() { + FlexibleStringExpander fse = FlexibleStringExpander.getInstance(null); + assertTrue("null FlexibleStringExpander", fse.isEmpty()); + String compare = "Hello World!"; + fse = FlexibleStringExpander.getInstance(compare); + assertEquals("null context", compare, fse.expandString(null)); + Map<String, Object> testMap = new HashMap<String, Object>(); + testMap.put("var", "World"); + fse = FlexibleStringExpander.getInstance("Hello ${var}!"); + assertTrue("simple replacement", compare.equals(fse.expandString(testMap))); + testMap.put("nested", "Hello ${var}"); + fse = FlexibleStringExpander.getInstance("${nested}!"); + assertTrue("hidden (runtime) nested replacement", compare.equals(fse.expandString(testMap))); + fse = FlexibleStringExpander.getInstance("${'Hello ${var}'}!"); + assertTrue("visible nested replacement", compare.equals(fse.expandString(testMap))); + fse = FlexibleStringExpander.getInstance("${bsh:return \"Hello \" + var + \"!\";}"); + assertTrue("bsh: script", compare.equals(fse.expandString(testMap))); + fse = FlexibleStringExpander.getInstance("${groovy:return \"Hello \" + var + \"!\";}"); + assertTrue("groovy: script", compare.equals(fse.expandString(testMap))); + testMap.put("testMap", testMap); + fse = FlexibleStringExpander.getInstance("Hello ${testMap.var}!"); + assertTrue("UEL integration: Map", compare.equals(fse.expandString(testMap))); + List<String> testList = new ArrayList<String>(); + testList.add("World"); + testMap.put("testList", testList); + fse = FlexibleStringExpander.getInstance("Hello ${testList[0]}!"); + assertTrue("UEL integration: List", compare.equals(fse.expandString(testMap))); + fse = FlexibleStringExpander.getInstance("This is an \\${escaped} expression"); + assertTrue("Escaped expression", "This is an ${escaped} expression".equals(fse.expandString(testMap))); + } +} Modified: ofbiz/trunk/framework/base/testdef/basetests.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/testdef/basetests.xml?rev=912272&r1=912271&r2=912272&view=diff ============================================================================== --- ofbiz/trunk/framework/base/testdef/basetests.xml (original) +++ ofbiz/trunk/framework/base/testdef/basetests.xml Sun Feb 21 01:27:32 2010 @@ -23,6 +23,7 @@ <test-case case-name="basetests"> <junit-test-suite class-name="org.ofbiz.base.util.test.IndentingWriterTests"/> <junit-test-suite class-name="org.ofbiz.base.util.test.UtilObjectTests"/> + <junit-test-suite class-name="org.ofbiz.base.util.string.test.FlexibleStringExpanderTests"/> <junit-test-suite class-name="org.ofbiz.base.util.test.TimeDurationTests"/> <junit-test-suite class-name="org.ofbiz.base.conversion.test.DateTimeTests.java"/> <junit-test-suite class-name="org.ofbiz.base.conversion.test.MiscTests.java"/> |
| Free forum by Nabble | Edit this page |
