April 2018
Intermediate to advanced
432 pages
10h 38m
English
To conclude everything that has been said in the last two sections, we will now prepare component tests using an in-memory, embedded MongoDB, Hoverfly (to simulate HTTP responses), and disabled service discovery. The correct configuration settings prepared especially for our testing purposes are available under profiles test and no-discovery. Every component test is initialized by the TestRestTemplate, which calls order-service HTTP endpoints. The test result verification may be performed based on the HTTP response or data stored in the embedded MongoDB. Here's a sample implementation of component tests for order-service:
@RunWith(SpringRunner.class)@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)@FixMethodOrder(MethodSorters.NAME_ASCENDING) ...