| 1 | package fr.sii.ogham.testing.extension.spring; | |
| 2 | ||
| 3 | import org.slf4j.Logger; | |
| 4 | import org.slf4j.LoggerFactory; | |
| 5 | import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition; | |
| 6 | import org.springframework.beans.factory.config.BeanDefinition; | |
| 7 | import org.springframework.context.ApplicationContext; | |
| 8 | import org.springframework.context.ApplicationContextInitializer; | |
| 9 | import org.springframework.context.ConfigurableApplicationContext; | |
| 10 | import org.springframework.context.support.GenericApplicationContext; | |
| 11 | import org.springframework.core.env.Environment; | |
| 12 | import org.springframework.test.context.support.TestPropertySourceUtils; | |
| 13 | ||
| 14 | import com.github.tomakehurst.wiremock.junit.WireMockRule; | |
| 15 | ||
| 16 | import fr.sii.ogham.testing.util.RandomPortUtils; | |
| 17 | ||
| 18 | /** | |
| 19 | * Initializer for Spring Boot tests that registers: | |
| 20 | * <ul> | |
| 21 | * <li>{@code "wiremock.server.port"} property in Spring {@link Environment}</li> | |
| 22 | * <li>{@link WireMockRule} bean in Spring {@link ApplicationContext} through | |
| 23 | * {@link WireMockTestConfiguration} in order to use the port defined by | |
| 24 | * {@code "wiremock.server.port"} property</li> | |
| 25 | * </ul> | |
| 26 | * | |
| 27 | * @author Aurélien Baudet | |
| 28 | * | |
| 29 | */ | |
| 30 | public class WireMockInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | |
| 31 | private static final Logger LOG = LoggerFactory.getLogger(WireMockInitializer.class); | |
| 32 | ||
| 33 | @Override | |
| 34 | public void initialize(ConfigurableApplicationContext applicationContext) { | |
| 35 |
1
1. initialize : negated conditional → NO_COVERAGE |
if (applicationContext instanceof GenericApplicationContext) { |
| 36 | BeanDefinition configBean = new AnnotatedGenericBeanDefinition(WireMockTestConfiguration.class); | |
| 37 |
1
1. initialize : removed call to org/springframework/context/support/GenericApplicationContext::registerBeanDefinition → NO_COVERAGE |
((GenericApplicationContext) applicationContext).registerBeanDefinition("wiremockServerTestConfiguration", configBean); |
| 38 | } | |
| 39 | int port = RandomPortUtils.findAvailableTcpPort(); | |
| 40 | LOG.debug("Registering {} port for WireMock server", port); | |
| 41 |
1
1. initialize : removed call to org/springframework/test/context/support/TestPropertySourceUtils::addInlinedPropertiesToEnvironment → NO_COVERAGE |
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(applicationContext, "wiremock.server.port=" + port); |
| 42 | } | |
| 43 | } | |
Mutations | ||
| 35 |
1.1 |
|
| 37 |
1.1 |
|
| 41 |
1.1 |