|
17 | 17 | import org.assertj.core.api.InstanceOfAssertFactories; |
18 | 18 | import org.junit.jupiter.api.Test; |
19 | 19 | import org.junit.jupiter.params.ParameterizedTest; |
| 20 | +import org.junit.jupiter.params.provider.CsvSource; |
20 | 21 | import org.junit.jupiter.params.provider.NullSource; |
21 | 22 | import org.junit.jupiter.params.provider.ValueSource; |
22 | 23 |
|
@@ -2729,6 +2730,60 @@ void testLoggingMessageNotificationDeserializationWithMissingRequiredFields() th |
2729 | 2730 | assertThat(notification.data()).isEmpty(); |
2730 | 2731 | } |
2731 | 2732 |
|
| 2733 | + @Test |
| 2734 | + void testLoggingMessageNotificationDeserializationWithNullData() throws Exception { |
| 2735 | + McpSchema.LoggingMessageNotification notification = JSON_MAPPER.readValue(""" |
| 2736 | + {"level":"info","data":null}""", McpSchema.LoggingMessageNotification.class); |
| 2737 | + |
| 2738 | + assertThat(notification.data()).isEmpty(); |
| 2739 | + } |
| 2740 | + |
| 2741 | + @Test |
| 2742 | + void testLoggingMessageNotificationDeserializationWithStringData() throws Exception { |
| 2743 | + McpSchema.LoggingMessageNotification notification = JSON_MAPPER.readValue(""" |
| 2744 | + {"level":"warning","logger":"my-logger","data":"plain text"}""", |
| 2745 | + McpSchema.LoggingMessageNotification.class); |
| 2746 | + |
| 2747 | + assertThat(notification.level()).isEqualTo(McpSchema.LoggingLevel.WARNING); |
| 2748 | + assertThat(notification.logger()).isEqualTo("my-logger"); |
| 2749 | + assertThat(notification.data()).isEqualTo("plain text"); |
| 2750 | + } |
| 2751 | + |
| 2752 | + @Test |
| 2753 | + void testLoggingMessageNotificationDeserializationWithObjectData() throws Exception { |
| 2754 | + // FastMCP sends {"msg": ..., "extra": ...} for every ctx.log() call |
| 2755 | + McpSchema.LoggingMessageNotification notification = JSON_MAPPER.readValue(""" |
| 2756 | + { |
| 2757 | + "level": "info", |
| 2758 | + "logger": "server", |
| 2759 | + "data": { |
| 2760 | + "msg": "working", |
| 2761 | + "extra": { |
| 2762 | + "user": "bob", |
| 2763 | + "ids": [1, 2 ] |
| 2764 | + } |
| 2765 | + } |
| 2766 | + }""", McpSchema.LoggingMessageNotification.class); |
| 2767 | + |
| 2768 | + assertThat(notification.level()).isEqualTo(McpSchema.LoggingLevel.INFO); |
| 2769 | + assertThat(notification.logger()).isEqualTo("server"); |
| 2770 | + assertThat(notification.data()).isEqualTo("{msg=working, extra={user=bob, ids=[1, 2]}}"); |
| 2771 | + } |
| 2772 | + |
| 2773 | + @ParameterizedTest |
| 2774 | + @CsvSource(delimiter = '|', textBlock = """ |
| 2775 | + [1,"two",true] | [1, two, true] |
| 2776 | + 42 | 42 |
| 2777 | + 1.5 | 1.5 |
| 2778 | + true | true |
| 2779 | + """) |
| 2780 | + void testLoggingMessageNotificationDeserializationWithNonStringData(String data, String expected) throws Exception { |
| 2781 | + McpSchema.LoggingMessageNotification notification = JSON_MAPPER.readValue(""" |
| 2782 | + {"level":"debug","data":%s}""".formatted(data), McpSchema.LoggingMessageNotification.class); |
| 2783 | + |
| 2784 | + assertThat(notification.data()).isEqualTo(expected); |
| 2785 | + } |
| 2786 | + |
2732 | 2787 | // --- Icon tests (SEP-973) --- |
2733 | 2788 |
|
2734 | 2789 | @Test |
|
0 commit comments