Last active
October 26, 2018 14:06
-
-
Save dschulten/9fef5fed261cff098d8e7863f0e4f17a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(SpringRunner.class) | |
@SpringBootTest(classes = Application.class) | |
@SpringIntegrationTest | |
@ActiveProfiles("local") | |
@AutoConfigureMockMvc | |
@TestPropertySource(properties = { | |
"my.setting=watchamacallit" | |
}) | |
public class ApplicationTest { | |
@Autowired | |
private MockIntegrationContext mockIntegrationContext; | |
@Autowired | |
private MockMvc mockMvc; | |
@Autowired | |
private GatewayApplication.ConversionMessagingGateway conversionMessagingGateway; | |
@Autowired | |
private MyService myService; | |
@TestConfiguration | |
public static class Configuration { | |
@MockBean | |
private MyService myService; // injected in SUT and test | |
} | |
@Test | |
public void someRestFlow() throws Exception { | |
Bar response = new Bar(); | |
mockIntegrationContext.substituteMessageHandlerFor( | |
"fooBean", | |
MockIntegration.mockMessageHandler() | |
.handleNextAndReply(message -> response)); | |
when(myService.foo()).thenReturn(...); | |
mockMvc.perform( | |
MockMvcRequestBuilders.post("/foo") | |
.contentType(MediaType.APPLICATION_JSON).content("{}")) | |
.andExpect(MockMvcResultMatchers.status() | |
.isOk()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(SpringRunner.class) | |
@SpringBootTest(classes = GatewayApplication.class) | |
@SpringIntegrationTest | |
@ActiveProfiles("local") | |
public class ApplicationTest { | |
@Autowired | |
private ApplicationContext wac; | |
@Autowired | |
private MockIntegrationContext mockIntegrationContext; | |
private WebTestClient webTestClient; | |
@Autowired | |
private GatewayApplication.ConversionMessagingGateway conversionMessagingGateway; | |
@Before | |
public void setup() { | |
this.webTestClient = | |
WebTestClient.bindToApplicationContext(this.wac) | |
//.apply(SecurityMockServerConfigurers.springSecurity()) | |
.configureClient() | |
.build(); | |
} | |
@Test | |
public void someRestFlow() throws Exception { | |
ConversionRequestBuilder response = ConversionRequestBuilder.aConversionRequest(); | |
// currently not working, see https://jira.spring.io/browse/INT-4537 - inject mocked Pojo handler instead as workaround | |
mockIntegrationContext.substituteMessageHandlerFor( | |
"conversionFlow.org.springframework.integration.config.ConsumerEndpointFactoryBean#1", | |
MockIntegration.mockMessageHandler() | |
.handleNextAndReply(message -> response.withFileOriginal( | |
new File("document-with-" | |
+ ((ConversionRequest) message.getPayload()).getDimagID() | |
+ ".docx")))); | |
FluxExchangeResult<Object> documentIds = webTestClient.post() | |
.uri("/foo") | |
.contentType(MediaType.APPLICATION_JSON) | |
.syncBody("{}") | |
.exchange() | |
.expectStatus() | |
.isOk() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment