Skip to content

Commit 93feaba

Browse files
Add test-case for unregistered custom fields
Unregistered custom fields should not be added to the `#cf` field. Only fields explicitly configured in the config files are added there.
1 parent d8f3bec commit 93feaba

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

cf-java-logging-support-log4j2/src/test/java/com/sap/hcp/cf/logging/common/TestCustomFields.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public void testLogMessageWithCustomField() throws Exception {
2929
assertThat(getCustomField(CUSTOM_FIELD_KEY), hasCustomField(CUSTOM_FIELD_KEY, SOME_VALUE, CUSTOM_FIELD_INDEX));
3030
}
3131

32+
@Test
33+
public void testCustomFieldWithoutRegistration() throws Exception {
34+
LOGGER.info(TEST_MESSAGE, customField("ungregistered", SOME_VALUE));
35+
36+
assertThat(getField("ungregistered"), is(SOME_VALUE));
37+
assertThat(getCustomField("unregistered"), is(nullValue()));
38+
}
39+
3240
@Test
3341
public void testCustomFieldAsPartOfMessage() throws Exception {
3442
String messageWithPattern = TEST_MESSAGE + " {}";

cf-java-logging-support-logback/src/test/java/com/sap/hcp/cf/logging/common/TestCustomFields.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public void testLogMessageWithCustomField() throws Exception {
2929
assertThat(getCustomField(CUSTOM_FIELD_KEY), hasCustomField(CUSTOM_FIELD_KEY, SOME_VALUE, CUSTOM_FIELD_INDEX));
3030
}
3131

32+
@Test
33+
public void testCustomFieldWithoutRegistration() throws Exception {
34+
LOGGER.info(TEST_MESSAGE, customField("ungregistered", SOME_VALUE));
35+
36+
assertThat(getField("ungregistered"), is(SOME_VALUE));
37+
assertThat(getCustomField("unregistered"), is(nullValue()));
38+
}
39+
3240
@Test
3341
public void testCustomFieldAsPartOfMessage() throws Exception {
3442
String messageWithPattern = TEST_MESSAGE + " {}";

0 commit comments

Comments
 (0)