|
Author: doogie
Date: Mon Feb 22 15:41:10 2010 New Revision: 912628 URL: http://svn.apache.org/viewvc?rev=912628&view=rev Log: Tests cases for expand feature. This finally brings us back to 100% coverage on FSE. Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java Modified: 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=912628&r1=912627&r2=912628&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java Mon Feb 22 15:41:10 2010 @@ -103,29 +103,36 @@ fseTest(label, input, context, null, null, compare, isEmpty); } - private static void doFseTest(String label, String input, FlexibleStringExpander fse, Map<String, Object> context, TimeZone timeZone, Locale locale, String compare, boolean isEmpty) { + private static void doFseTest(String label, String input, FlexibleStringExpander fse, Map<String, Object> context, TimeZone timeZone, Locale locale, String compare, Object expand, boolean isEmpty) { assertEquals("isEmpty:" + label, isEmpty, fse.isEmpty()); if (input == null) { assertEquals("getOriginal():" + label, "", fse.getOriginal()); assertEquals("toString():" + label, "", fse.toString()); assertEquals("expandString(null):" + label, "", fse.expandString(null)); + assertEquals("expand(null):" + label, null, fse.expand(null)); if (timeZone == null) { assertEquals("expandString(null):" + label, "", fse.expandString(null, locale)); + assertEquals("expand(null):" + label, null, fse.expand(null, locale)); } else { assertEquals("expandString(null):" + label, "", fse.expandString(null, timeZone, locale)); + assertEquals("expand(null):" + label, null, fse.expand(null, timeZone, locale)); } } else { assertEquals("getOriginal():" + label, input, fse.getOriginal()); assertEquals("toString():" + label, input, fse.toString()); assertEquals("expandString(null):" + label, input, fse.expandString(null)); + assertEquals("expand(null):" + label, null, fse.expand(null)); if (timeZone == null) { assertEquals("expandString(null):" + label, input, fse.expandString(null, locale)); + assertEquals("expand(null):" + label, null, fse.expand(null, locale)); } else { assertEquals("expandString(null):" + label, input, fse.expandString(null, timeZone, locale)); + assertEquals("expand(null):" + label, null, fse.expand(null, timeZone, locale)); } } if (locale == null) { assertEquals(label, compare, fse.expandString(context)); + assertEquals("expand:" + label, expand, fse.expand(context)); } else { Locale defaultLocale = Locale.getDefault(); TimeZone defaultTimeZone = TimeZone.getDefault(); @@ -133,28 +140,44 @@ Locale.setDefault(locale); TimeZone.setDefault(timeZone); assertEquals(label, compare, fse.expandString(context, null, null)); + assertEquals(label, expand, fse.expand(context, null, null)); Locale.setDefault(badLocale); TimeZone.setDefault(badTimeZone); assertNotSame(label, compare, fse.expandString(context, null, null)); + if (input != null) { + assertNotSame(label, expand, fse.expand(context, null, null)); + } Map<String, Object> autoUserLogin = new HashMap<String, Object>(); autoUserLogin.put("lastLocale", locale.toString()); autoUserLogin.put("lastTimeZone", timeZone == null ? null : timeZone.getID()); context.put("autoUserLogin", autoUserLogin); assertEquals(label, compare, fse.expandString(context, null, null)); + assertEquals(label, expand, fse.expand(context, null, null)); autoUserLogin.put("lastLocale", badLocale.toString()); autoUserLogin.put("lastTimeZone", badTimeZone.getID()); assertNotSame(label, compare, fse.expandString(context, null, null)); + if (input != null) { + assertNotSame(label, expand, fse.expand(context, null, null)); + } context.remove("autoUserLogin"); context.put("locale", locale); context.put("timeZone", timeZone); assertEquals(label, compare, fse.expandString(context, null, null)); + assertEquals(label, expand, fse.expand(context, null, null)); context.put("locale", badLocale); context.put("timeZone", badTimeZone); assertNotSame(label, compare, fse.expandString(context, null, null)); + if (input != null) { + assertNotSame(label, expand, fse.expand(context, null, null)); + } context.remove("locale"); context.remove("timeZone"); assertEquals(label, compare, fse.expandString(context, timeZone, locale)); + assertEquals(label, expand, fse.expand(context, timeZone, locale)); assertNotSame(label, compare, fse.expandString(context, badTimeZone, badLocale)); + if (input != null) { + assertNotSame(label, expand, fse.expand(context, badTimeZone, badLocale)); + } } finally { Locale.setDefault(defaultLocale); TimeZone.setDefault(defaultTimeZone); @@ -163,8 +186,12 @@ } private static void fseTest(String label, String input, Map<String, Object> context, TimeZone timeZone, Locale locale, String compare, boolean isEmpty) { + fseTest(label, input, context, timeZone, locale, compare, compare, isEmpty); + } + + private static void fseTest(String label, String input, Map<String, Object> context, TimeZone timeZone, Locale locale, String compare, Object expand, boolean isEmpty) { FlexibleStringExpander fse = FlexibleStringExpander.getInstance(input); - doFseTest(label, input, fse, context, timeZone, locale, compare, isEmpty); + doFseTest(label, input, fse, context, timeZone, locale, compare, expand, isEmpty); assertEquals("static expandString:" + label, compare, FlexibleStringExpander.expandString(input, context, timeZone, locale)); if (input == null) { assertEquals("static expandString(null, null):" + label, "", FlexibleStringExpander.expandString(input, null)); @@ -175,7 +202,7 @@ } if (!fse.isEmpty()) { fse = FlexibleStringExpander.getInstance(input, false); - doFseTest(label, input, fse, context, timeZone, locale, compare, isEmpty); + doFseTest(label, input, fse, context, timeZone, locale, compare, expand, isEmpty); } } @@ -254,14 +281,15 @@ List<String> testList = new ArrayList<String>(); testList.add("World"); testMap.put("testList", testList); - fseTest("null FlexibleStringExpander, null map", null, null, "", true); - fseTest("null FlexibleStringExpander", null, testMap, "", true); - fseTest("null context", "Hello World!", null, "Hello World!", false); + fseTest("null FlexibleStringExpander, null map", null, null, null, null, "", null, true); + fseTest("null FlexibleStringExpander", null, testMap, null, null, "", null, true); + fseTest("null context", "Hello World!", null, null, null, "Hello World!", null, false); + fseTest("plain string", "Hello World!", testMap, null, null, "Hello World!", "Hello World!", false); fseTest("simple replacement", "Hello ${var}!", testMap, "Hello World!", false); - fseTest("null FlexibleStringExpander with timeZone/locale", null, testMap, timeZoneToTest, localeToTest, "", true); - fseTest("empty FlexibleStringExpander", "", testMap, "", true); + fseTest("null FlexibleStringExpander with timeZone/locale", null, testMap, timeZoneToTest, localeToTest, "", null, true); + fseTest("empty FlexibleStringExpander", "", testMap, null, null, "", null, true); fseTest("UEL integration(nested): throw Exception", "${${throwException.value}}", testMap, "", false); - fseTest("UEL integration: throw Exception", "${throwException.value}", testMap, "", false); + fseTest("UEL integration: throw Exception", "${throwException.value}", testMap, null, null, "", null, false); fseTest("hidden (runtime) nested replacement", "${nested}!", testMap, "Hello World!", false); fseTest("hidden (runtime) nested null replacement", "Hello ${${nullVar}}World!", testMap, "Hello World!", false); fseTest("hidden (runtime) nested null callreplacement", "Hello ${${groovy:" + FlexibleStringExpanderTests.class.getName() + ".StaticReturnNull()}}World!", testMap, "Hello World!", false); @@ -272,7 +300,7 @@ fseTest("UEL integration(nested): null", "${${nu${nullVar}ll}}", testMap, "", false); fseTest("UEL integration(nested): NPE", "${${nullVar.noProp}}", testMap, "", false); fseTest("UEL integration(nested): missing", "${${noL${nullVar}ist[0]}}", testMap, "", false); - fseTest("date w/ timezone", "The date is ${date}.", testMap, timeZoneToTest, localeToTest, "The date is 1970-01-14 22:56:07.890.", false); + fseTest("date w/ timezone", "The date is ${date}.", testMap, timeZoneToTest, localeToTest, "The date is 1970-01-14 22:56:07.890.", "The date is 1970-01-14 22:56:07.890.", false); fseTest("just bad", "${foobar", testMap, "${foobar", false); fseTest("constant and bad", "Hello${foobar", testMap, "Hello${foobar", false); fseTest("good and bad", "Hello ${var}${foobar", testMap, "Hello World${foobar", false); @@ -288,18 +316,23 @@ fseTest("bsh: converter exception", "${bsh:return specialNumber;}!", testMap, SpecialNumber.class.getName() + "!", false); fseTest("groovy: script", "${groovy:return \"Hello \" + var + \"!\";}", testMap, "Hello World!", false); fseTest("groovy: null", "${groovy:return null;}!", testMap, "!", false); - fseTest("groovy missing property", "${groovy: return noList[0]}", testMap, "", false); + fseTest("groovy missing property", "${groovy: return noList[0]}", testMap, null, null, "", null, false); fseTest("groovy: throw Exception", "${groovy:return throwException.value;}!", testMap, "!", false); fseTest("groovy: converter exception", "${groovy:return specialNumber;}!", testMap, SpecialNumber.class.getName() + "!", false); fseTest("UEL integration: Map", "Hello ${testMap.var}!", testMap, "Hello World!", false); fseTest("UEL integration: blank", "Hello ${testMap.blank}World!", testMap, "Hello World!", false); fseTest("UEL integration: List", "Hello ${testList[0]}!", testMap, "Hello World!", false); - fseTest("UEL integration: null", "${null}", testMap, "", false); - fseTest("UEL integration: null dereference", "${nullVar.noProp}", testMap, "", false); - fseTest("UEL integration: throw NPE", "${" + FlexibleStringExpanderTests.class.getName() + ".ThrowNPE.noProp}", testMap, "", false); - fseTest("UEL integration: missing", "${noList[0]}", testMap, "", false); + fseTest("UEL integration: null", "${null}", testMap, null, null, "", null, false); + fseTest("UEL integration: null dereference", "${nullVar.noProp}", testMap, null, null, "", null, false); + fseTest("UEL integration: throw NPE", "${" + FlexibleStringExpanderTests.class.getName() + ".ThrowNPE.noProp}", testMap, null, null, "", null, false); + fseTest("UEL integration: missing", "${noList[0]}", testMap, null, null, "", null, false); fseTest("Escaped expression", "This is an \\${escaped} expression", testMap, "This is an ${escaped} expression", false); fseTest("Escaped(bsh) expression", "This is an \\${bsh:escaped} expression", testMap, "This is an ${bsh:escaped} expression", false); fseTest("Escaped(groovy) expression", "This is an \\${groovy:escaped} expression", testMap, "This is an ${groovy:escaped} expression", false); + + fseTest("nested UEL integration(return BigDecimal)", "${a${'moun'}t}", testMap, null, null, "1,234,567.89", testMap.get("amount"), false); + fseTest("UEL integration(return BigDecimal)", "${amount}", testMap, null, null, "1,234,567.89", testMap.get("amount"), false); + fseTest("bsh: return BigDecimal", "${bsh: return amount;}", testMap, null, null, "1,234,567.89", testMap.get("amount"), false); + fseTest("groovy: return BigDecimal", "${groovy: return amount;}", testMap, null, null, "1,234,567.89", testMap.get("amount"), false); } } |
| Free forum by Nabble | Edit this page |
