This is an automated email from the ASF dual-hosted git repository. yasserzamani pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/struts.git
commit 704e41c6e802972def971c1223a3aa522e525bdb Author: Yasser Zamani <yasserzam...@apache.org> AuthorDate: Sun Jun 2 17:22:28 2019 +0430 test false for logMissingProperties (WW-4999) (cherry picked from commit a50af87) --- .../xwork2/ognl/OgnlValueStackTest.java | 61 +++++++++++++++++++--- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java index 5fa8aa8..0d3952f 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java @@ -246,9 +246,18 @@ public class OgnlValueStackTest extends XWorkTestCase { } } + /** + * monitors the resolution of WW-4999 + * @since 2.5.21 + */ public void testLogMissingProperties() { + testLogMissingProperties(true); + testLogMissingProperties(false); + } + + private void testLogMissingProperties(boolean logMissingProperties) { OgnlValueStack vs = createValueStack(); - vs.setLogMissingProperties("true"); + vs.setLogMissingProperties("" + logMissingProperties); Dog dog = new Dog(); vs.push(dog); @@ -263,19 +272,27 @@ public class OgnlValueStackTest extends XWorkTestCase { vs.findValue("missingProp2", false); vs.findValue("missingProp3", Integer.class, false); - assertEquals(3, testAppender.logEvents.size()); - assertEquals("Error setting value [missingProp1Value] with expression [missingProp1]", - testAppender.logEvents.get(0).getMessage().getFormattedMessage()); - assertEquals("Could not find property [missingProp2]!", - testAppender.logEvents.get(1).getMessage().getFormattedMessage()); - assertEquals("Could not find property [missingProp3]!", - testAppender.logEvents.get(2).getMessage().getFormattedMessage()); + if (logMissingProperties) { + assertEquals(3, testAppender.logEvents.size()); + assertEquals("Error setting value [missingProp1Value] with expression [missingProp1]", + testAppender.logEvents.get(0).getMessage().getFormattedMessage()); + assertEquals("Could not find property [missingProp2]!", + testAppender.logEvents.get(1).getMessage().getFormattedMessage()); + assertEquals("Could not find property [missingProp3]!", + testAppender.logEvents.get(2).getMessage().getFormattedMessage()); + } else { + assertEquals(0, testAppender.logEvents.size()); + } } finally { testAppender.stop(); logger.removeAppender(testAppender); } } + /** + * tests the correctness of distinguishing between user exception and NoSuchMethodException + * @since 2.5.21 + */ public void testNotLogUserExceptionsAsMissingProperties() { OgnlValueStack vs = createValueStack(); vs.setLogMissingProperties("true"); @@ -299,6 +316,18 @@ public class OgnlValueStackTest extends XWorkTestCase { vs.findValue("getBite()", false); vs.findValue("getBite()", void.class, false); + vs.setLogMissingProperties("false"); + + vs.setValue("exception", "exceptionValue", false); + vs.findValue("exception", false); + vs.findValue("exception", String.class, false); + vs.findValue("getException()", false); + vs.findValue("getException()", String.class, false); + vs.findValue("bite", false); + vs.findValue("bite", void.class, false); + vs.findValue("getBite()", false); + vs.findValue("getBite()", void.class, false); + assertEquals(0, testAppender.logEvents.size()); } finally { testAppender.stop(); @@ -975,7 +1004,23 @@ public class OgnlValueStackTest extends XWorkTestCase { assertEquals(12, vs.findValue("age", Integer.class, true)); assertEquals(12, vs.findValue("getAge()", true)); assertEquals(12, vs.findValue("getAge()", Integer.class, true)); + } + + /** + * Fails on 2.5.20 and earlier - tested on 2.5 (5/5/2016) and failed + * @since 2.5.21 + */ + public void testNotSkipUserReturnedNullValues() { + OgnlValueStack vs = createValueStack(); + + Dog dog = new Dog(); + dog.setName("Rover"); + vs.push(dog); + + Cat cat = new Cat(); + vs.push(cat); + // should not skip returned null values from cat.name assertNull(vs.findValue("name", true)); assertNull(vs.findValue("name", String.class, true)); assertNull(vs.findValue("getName()", true));