|
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.ArrayList; |
46 | 47 | import java.util.Collections; |
47 | 48 | import java.util.HashMap; |
| 49 | +import java.util.List; |
48 | 50 | import java.util.Map; |
49 | 51 | import org.junit.jupiter.api.AfterEach; |
50 | 52 | import org.junit.jupiter.api.BeforeEach; |
@@ -171,6 +173,29 @@ void testWriteToJsonTreeIncludedKey() throws IOException { |
171 | 173 | verify(generator, never()).writeObject(anyString()); |
172 | 174 | } |
173 | 175 |
|
| 176 | + @Test |
| 177 | + void testWriteToJsonTreeExcludedKey() throws IOException { |
| 178 | + mdc.put( |
| 179 | + "json1", |
| 180 | + "{\n" |
| 181 | + + " \"@version\": \"1\",\n" |
| 182 | + + " \"textPayload\": \"Received response\",\n" |
| 183 | + + " \"response.payload\": {\n" |
| 184 | + + " \"name\": \"example\",\n" |
| 185 | + + " \"state\": \"ACTIVE\"\n" |
| 186 | + + " }\n" |
| 187 | + + "}"); |
| 188 | + mdc.put("example key", "example value"); |
| 189 | + List<String> excluded = new ArrayList<>(); |
| 190 | + excluded.add("json1"); |
| 191 | + excluded.add("example key"); |
| 192 | + provider.setExcludeMdcKeyNames(excluded); |
| 193 | + provider.writeTo(generator, event); |
| 194 | + verify(generator, never()).writeFieldName(anyString()); |
| 195 | + verify(generator, never()).writeTree(any(JsonNode.class)); |
| 196 | + verify(generator, never()).writeObject(anyString()); |
| 197 | + } |
| 198 | + |
174 | 199 | @Test |
175 | 200 | void testWriteInvalidJsonStringToString() throws IOException { |
176 | 201 | mdc.put( |
|
0 commit comments