|
43 | 43 | import com.fasterxml.jackson.core.JsonGenerator; |
44 | 44 | import com.fasterxml.jackson.databind.JsonNode; |
45 | 45 | import java.io.IOException; |
| 46 | +import java.util.Collections; |
46 | 47 | import java.util.HashMap; |
47 | 48 | import java.util.Map; |
48 | 49 | import org.junit.jupiter.api.AfterEach; |
@@ -149,6 +150,27 @@ void testWriteValidJsonStringAndValidPairToJsonTree() throws IOException { |
149 | 150 | verify(generator, times(1)).writeObject(anyString()); |
150 | 151 | } |
151 | 152 |
|
| 153 | + @Test |
| 154 | + void testWriteToJsonTreeIncludedKey() throws IOException { |
| 155 | + mdc.put( |
| 156 | + "json1", |
| 157 | + "{\n" |
| 158 | + + " \"@version\": \"1\",\n" |
| 159 | + + " \"textPayload\": \"Received response\",\n" |
| 160 | + + " \"response.payload\": {\n" |
| 161 | + + " \"name\": \"example\",\n" |
| 162 | + + " \"state\": \"ACTIVE\"\n" |
| 163 | + + " }\n" |
| 164 | + + "}"); |
| 165 | + mdc.put("example key", "example value"); |
| 166 | + provider.setIncludeMdcKeyNames(Collections.singletonList("json1")); |
| 167 | + provider.writeTo(generator, event); |
| 168 | + verify(generator, times(1)).writeFieldName("json1"); |
| 169 | + verify(generator, never()).writeFieldName("example key"); |
| 170 | + verify(generator, times(1)).writeTree(any(JsonNode.class)); |
| 171 | + verify(generator, never()).writeObject(anyString()); |
| 172 | + } |
| 173 | + |
152 | 174 | @Test |
153 | 175 | void testWriteInvalidJsonStringToString() throws IOException { |
154 | 176 | mdc.put( |
|
0 commit comments