Spring Integration Java DSL:如何在JUnit中运行集成流程?

时间:2018-11-09 11:41:36

标签: spring-integration spring-integration-dsl

如何在下面的JUnit类中运行IntegrationFlow?当前有例外情况

java.lang.AssertionError: Further request(s) expected leaving 1 unsatisfied expectation(s). 0 request(s) executed.

因为集成流程尚未启动。

JUnit类:

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@DirtiesContext
public class FlowTest {
private final RestTemplate restTemplate = new RestTemplate();

private MockRestServiceServer mockServer;

@Before
public void setup() {
    mockServer = MockRestServiceServer.createServer(restTemplate);
}

@Test
public void test() {
    mockServer.expect(requestTo("http://localhost:8080/data"));

    final IntegrationFlow integrationFlow = f -> f
            .handle(Http.outboundGateway("http://localhost:8080/data", restTemplate).httpMethod(HttpMethod.GET)
                    .expectedResponseType(String.class));

    mockServer.verify();
}

}

1 个答案:

答案 0 :(得分:0)

您不能只在测试方法中定义像这样的流程。该框架必须在后台进行大量组装。

在测试@Bean类中将流定义为@Configuration