Skip to content

Commit

Permalink
test false for logMissingProperties (WW-4999)
Browse files Browse the repository at this point in the history
(cherry picked from commit a50af87)
  • Loading branch information
yasserzamani committed Jun 3, 2019
1 parent eca9c34 commit 704e41c
Showing 1 changed file with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,18 @@ public void testFailOnMissingProperty() {
}
}

/**
* 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);
Expand All @@ -263,19 +272,27 @@ public void testLogMissingProperties() {
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");
Expand All @@ -299,6 +316,18 @@ public void testNotLogUserExceptionsAsMissingProperties() {
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();
Expand Down Expand Up @@ -975,7 +1004,23 @@ public void testNotThrowExceptionOnTopMissingProperty() {
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));
Expand Down

0 comments on commit 704e41c

Please sign in to comment.