Mike
Mike

Reputation: 651

Spring Integration Java DSL: How to run the integration flow in the JUnit?

How to run the integrationFlow in the below JUnit class? Currently there comes the exception

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

because the integration flow is not started.

The JUnit class:

@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();
}

}

Upvotes: 1

Views: 357

Answers (1)

Gary Russell
Gary Russell

Reputation: 174729

You can't just define a flow like that in a test method; the framework has to do a bunch of assembly behind the scenes.

Define the flow as a @Bean in a test @Configuration class.

Upvotes: 0

Related Questions