|
3 | 3 | */
|
4 | 4 | package io.modelcontextprotocol.spec;
|
5 | 5 |
|
| 6 | +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; |
| 7 | +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json; |
| 8 | +import static org.assertj.core.api.Assertions.assertThat; |
| 9 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 10 | + |
6 | 11 | import java.util.Arrays;
|
7 | 12 | import java.util.Collections;
|
8 | 13 | import java.util.HashMap;
|
9 | 14 | import java.util.List;
|
10 | 15 | import java.util.Map;
|
11 | 16 |
|
12 |
| -import com.fasterxml.jackson.core.type.TypeReference; |
| 17 | +import org.junit.jupiter.api.Test; |
| 18 | + |
13 | 19 | import com.fasterxml.jackson.databind.ObjectMapper;
|
14 | 20 | import com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
|
| 21 | + |
15 | 22 | import io.modelcontextprotocol.spec.McpSchema.TextResourceContents;
|
16 | 23 | import net.javacrumbs.jsonunit.core.Option;
|
17 |
| -import org.junit.jupiter.api.Test; |
18 |
| - |
19 |
| -import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; |
20 |
| -import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json; |
21 |
| -import static org.assertj.core.api.Assertions.assertThat; |
22 |
| -import static org.assertj.core.api.Assertions.assertThatThrownBy; |
23 | 24 |
|
24 | 25 | /**
|
25 | 26 | * @author Christian Tzolov
|
@@ -295,6 +296,59 @@ void testResource() throws Exception {
|
295 | 296 | {"uri":"resource://test","name":"Test Resource","description":"A test resource","mimeType":"text/plain","annotations":{"audience":["user","assistant"],"priority":0.8}}"""));
|
296 | 297 | }
|
297 | 298 |
|
| 299 | + @Test |
| 300 | + void testResourceBuilder() throws Exception { |
| 301 | + McpSchema.Annotations annotations = new McpSchema.Annotations( |
| 302 | + Arrays.asList(McpSchema.Role.USER, McpSchema.Role.ASSISTANT), 0.8); |
| 303 | + |
| 304 | + McpSchema.Resource resource = McpSchema.Resource.builder() |
| 305 | + .uri("resource://test") |
| 306 | + .name("Test Resource") |
| 307 | + .description("A test resource") |
| 308 | + .mimeType("text/plain") |
| 309 | + .size(256L) |
| 310 | + .annotations(annotations) |
| 311 | + .build(); |
| 312 | + |
| 313 | + String value = mapper.writeValueAsString(resource); |
| 314 | + assertThatJson(value).when(Option.IGNORING_ARRAY_ORDER) |
| 315 | + .when(Option.IGNORING_EXTRA_ARRAY_ITEMS) |
| 316 | + .isObject() |
| 317 | + .isEqualTo( |
| 318 | + json(""" |
| 319 | + {"uri":"resource://test","name":"Test Resource","description":"A test resource","mimeType":"text/plain","size":256,"annotations":{"audience":["user","assistant"],"priority":0.8}}""")); |
| 320 | + } |
| 321 | + |
| 322 | + @Test |
| 323 | + void testResourceBuilderUriRequired() { |
| 324 | + McpSchema.Annotations annotations = new McpSchema.Annotations( |
| 325 | + Arrays.asList(McpSchema.Role.USER, McpSchema.Role.ASSISTANT), 0.8); |
| 326 | + |
| 327 | + McpSchema.Resource.Builder resourceBuilder = McpSchema.Resource.builder() |
| 328 | + .name("Test Resource") |
| 329 | + .description("A test resource") |
| 330 | + .mimeType("text/plain") |
| 331 | + .size(256L) |
| 332 | + .annotations(annotations); |
| 333 | + |
| 334 | + assertThatThrownBy(resourceBuilder::build).isInstanceOf(java.lang.IllegalArgumentException.class); |
| 335 | + } |
| 336 | + |
| 337 | + @Test |
| 338 | + void testResourceBuilderNameRequired() { |
| 339 | + McpSchema.Annotations annotations = new McpSchema.Annotations( |
| 340 | + Arrays.asList(McpSchema.Role.USER, McpSchema.Role.ASSISTANT), 0.8); |
| 341 | + |
| 342 | + McpSchema.Resource.Builder resourceBuilder = McpSchema.Resource.builder() |
| 343 | + .uri("resource://test") |
| 344 | + .description("A test resource") |
| 345 | + .mimeType("text/plain") |
| 346 | + .size(256L) |
| 347 | + .annotations(annotations); |
| 348 | + |
| 349 | + assertThatThrownBy(resourceBuilder::build).isInstanceOf(java.lang.IllegalArgumentException.class); |
| 350 | + } |
| 351 | + |
298 | 352 | @Test
|
299 | 353 | void testResourceTemplate() throws Exception {
|
300 | 354 | McpSchema.Annotations annotations = new McpSchema.Annotations(Arrays.asList(McpSchema.Role.USER), 0.5);
|
|
0 commit comments