5

Currently in our project, we are using Spring Integration to integrate many service and some protocol related endpoints.

The project is a multi Spring Boot applications, more than one executable jars will be deployed in production.

The question is:

  1. How to run an end to end test which needs to run cross some of these applications, I have to run the one by one manually? In before none-Spring-Boot applications, I can use Maven tomcat7 plugin to complete this work(deploy the wars into an embedded tomcat and run it in pre-integration-test phase), now how to start up all related applications before I run my test. Assume I do not use Docker/Vagrant now.

    Similar question found on stackoverflow, End to end integration test for multiple spring boot applications under Maven

    How to run the end2end test automatically?

  2. In an Spring Integration test, sometime I have to mock a http endpoint, so I wrote a simple Controller in test package to archive this purpose, but I want to run it at a different port, which make it more like an outside resource. How to run different @SpringBootApplicaiton classes at varied ports at the same time in the test for this purpose?

I am using the latest Maven, Java 8, Spring Boot 1.3.1.RELEASE.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Hantsy
  • 8,006
  • 7
  • 64
  • 109
  • For the second question, I found Spring provides a `MockRestServiceServer`, which can mock the target remote REST API to archive this purpose in tests. – Hantsy Mar 22 '16 at 07:52

1 Answers1

0

Actually, Spring Boot comes with the embedded Servlet Container support. One of them is exactly Tomcat. The default on for the org.springframework.boot:spring-boot-starter-web.

With the org.springframework.boot:spring-boot-starter-test and its @SpringApplicationConfiguration and @WebIntegrationTest you can achieve your requirements, even with the random port.

Please, refer to the Spring Boot Reference Manual for more information:

To change the port you can add environment properties to @WebIntegrationTest as colon- or equals-separated name-value pairs, e.g. @WebIntegrationTest("server.port:9000"). Additionally you can set the server.port and management.port properties to 0 in order to run your integration tests using random ports.

With that your @SpringBootApplicaiton will be deployed to that embedded Tomcat and your test can get access to the ran services/controllers.

Note: it doesn't matter if your Spring Boot application has Spring Integration facilities. The behavior is the same: embedded Servlet Container and integration tests against @Value("${local.server.port}").

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • 2
    I know well about the `@IntegrationTest` and `@WebIntegrationTest` in Spring Boot applications. Maybe my expression confused you, I am none English guy. What I need is running my standalone end2end test before starts several Spring Boot applications(case 1 in my question). – Hantsy Jan 19 '16 at 06:00