我正在尝试为我的 spring 集成流程编写集成测试。我想使用 MockRestServiceServer 记录并将传出请求(使用 http:outbound-gateway)匹配到 Rest 服务器。但是,当我调用模拟服务器的验证方法时,它没有按预期进行验证。
我按以下方式编写测试:
RestTemplate restTemplate = new RestTemplate();
MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
mockServer.expect(requestTo("adfasfadf.com")).andExpect(method(HttpMethod.GET));
// Call spring integration flow here
mockServer.verify();
Run Code Online (Sandbox Code Playgroud)
当我检查 MockRestServiceServer 的 verify 方法时,它没有调用 RequestMatchers 的 match 方法,我认为这个逻辑有问题。我在这里错过了什么吗?
/**
* Verify that all expected requests set up via
* {@link #expect(RequestMatcher)} were indeed performed.
* @throws AssertionError when some expectations were not met
*/
public void verify() {
if (this.expectedRequests.isEmpty() || this.expectedRequests.equals(this.actualRequests)) {
return;
}
throw new AssertionError(getVerifyMessage());
}
Run Code Online (Sandbox Code Playgroud) testing spring integration-testing spring-test spring-integration
我正在为我的 Spring Boot 应用程序编写集成测试,但是当我尝试使用 @TestPropertySource 覆盖某些属性时,它正在加载上下文 xml 中定义的属性文件,但它没有覆盖注释中定义的属性。
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {DefaultApp.class, MessageITCase.Config.class})
@WebAppConfiguration
@TestPropertySource(properties = {"spring.profiles.active=hornetq", "test.url=http://www.test.com/",
"test.api.key=343krqmekrfdaskfnajk"})
public class MessageITCase {
@Value("${test.url}")
private String testUrl;
@Value("${test.api.key}")
private String testApiKey;
@Test
public void testUrl() throws Exception {
System.out.println("Loaded test url:" + testUrl);
}
@Configuration
@ImportResource("classpath:/META-INF/spring/test-context.xml")
public static class Config {
}
}
Run Code Online (Sandbox Code Playgroud)