Skip to content

Commit a8a377b

Browse files
committed
test: Add tests for McpServerObjectMapperAutoConfiguration
Signed-off-by: guanxu <1510424541@qq.com>
1 parent e464266 commit a8a377b

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2025-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ai.mcp.server.common.autoconfigure;
18+
19+
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.boot.autoconfigure.AutoConfigurations;
23+
import org.springframework.boot.context.annotation.UserConfigurations;
24+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
25+
import org.springframework.context.annotation.Bean;
26+
import org.springframework.context.annotation.Configuration;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
/**
31+
* Integration tests for {@link McpServerObjectMapperAutoConfiguration}
32+
*
33+
* @author guan xu
34+
*/
35+
public class McpServerObjectMapperAutoConfigurationIT {
36+
37+
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
38+
.withConfiguration(AutoConfigurations.of(McpServerObjectMapperAutoConfiguration.class));
39+
40+
@Test
41+
void defaultMcpServerObjectMapper() {
42+
this.contextRunner.run(context -> {
43+
assertThat(context).hasSingleBean(ObjectMapper.class);
44+
assertThat(context).hasBean("mcpServerObjectMapper");
45+
});
46+
}
47+
48+
@Test
49+
void customizeMcpServerObjectMapper() {
50+
this.contextRunner.withConfiguration(UserConfigurations.of(TestConfig.class)).run(context -> {
51+
assertThat(context).hasSingleBean(ObjectMapper.class);
52+
assertThat(context).hasBean("mcpServerObjectMapper");
53+
});
54+
}
55+
56+
@Configuration
57+
static class TestConfig {
58+
59+
@Bean(name = "mcpServerObjectMapper")
60+
ObjectMapper mcpServerObjectMapper() {
61+
return new ObjectMapper();
62+
}
63+
64+
}
65+
66+
}

0 commit comments

Comments
 (0)