Spring 集成 Java DSL:如何 运行 JUnit 中的集成流程?
Spring Integration Java DSL: How to run the integration flow in the JUnit?
如何运行下面JUnit中的integrationFlow class?目前出现异常
java.lang.AssertionError: Further request(s) expected leaving 1 unsatisfied expectation(s). 0 request(s) executed.
因为集成流程没有启动。
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();
}
}
您不能只在测试方法中定义这样的流程;该框架必须在幕后进行大量组装。
在测试中将流定义为 @Bean
@Configuration
class。
如何运行下面JUnit中的integrationFlow class?目前出现异常
java.lang.AssertionError: Further request(s) expected leaving 1 unsatisfied expectation(s). 0 request(s) executed.
因为集成流程没有启动。
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();
}
}
您不能只在测试方法中定义这样的流程;该框架必须在幕后进行大量组装。
在测试中将流定义为 @Bean
@Configuration
class。