| 1 | package fr.sii.ogham.testing.extension.junit.sms; | |
| 2 | ||
| 3 | import fr.sii.ogham.testing.extension.junit.sms.config.ServerConfig; | |
| 4 | import fr.sii.ogham.testing.extension.junit.sms.config.SmppServerConfig; | |
| 5 | import fr.sii.ogham.testing.sms.simulator.SmppServerException; | |
| 6 | import fr.sii.ogham.testing.sms.simulator.SmppServerSimulator; | |
| 7 | import fr.sii.ogham.testing.sms.simulator.SmppServerStartException; | |
| 8 | import fr.sii.ogham.testing.sms.simulator.config.SimulatorConfiguration; | |
| 9 | import ogham.testing.io.github.resilience4j.retry.Retry; | |
| 10 | import ogham.testing.io.github.resilience4j.retry.RetryConfig; | |
| 11 | import ogham.testing.io.github.resilience4j.retry.RetryRegistry; | |
| 12 | import org.junit.jupiter.api.extension.*; | |
| 13 | import org.junit.platform.commons.support.AnnotationSupport; | |
| 14 | import org.slf4j.Logger; | |
| 15 | import org.slf4j.LoggerFactory; | |
| 16 | ||
| 17 | /** | |
| 18 | * JUnit {@link Extension} for starting a local SMPP server for integration | |
| 19 | * tests. | |
| 20 | * | |
| 21 | * <p> | |
| 22 | * The extension starts the server before every test, execute the test and stops | |
| 23 | * the server. | |
| 24 | * </p> | |
| 25 | * <p> | |
| 26 | * The server stores the received messages (raw messages). These messages are | |
| 27 | * available in testing through {@link #getReceivedMessages()}. | |
| 28 | * </p> | |
| 29 | * | |
| 30 | * @param <M> | |
| 31 | * The type of the received messages | |
| 32 | * | |
| 33 | * @author Aurélien Baudet | |
| 34 | * | |
| 35 | */ | |
| 36 | public abstract class SmppServerExtension<M> extends AbstractJUnitSmppServerExt<M> implements BeforeEachCallback, AfterEachCallback, ParameterResolver { | |
| 37 | private static final Logger LOG = LoggerFactory.getLogger(SmppServerExtension.class); | |
| 38 | ||
| 39 | /** | |
| 40 | * Initializes with the default configuration to use for the SMPP server: | |
| 41 | * <ul> | |
| 42 | * <li>Starts on random port</li> | |
| 43 | * <li>No delay</li> | |
| 44 | * <li>No credentials</li> | |
| 45 | * <li>Do not keep messages between tests</li> | |
| 46 | * </ul> | |
| 47 | */ | |
| 48 | public SmppServerExtension() { | |
| 49 | super(); | |
| 50 | } | |
| 51 | ||
| 52 | /** | |
| 53 | * Initializes with the configuration to use for the SMPP server | |
| 54 | * | |
| 55 | * @param builder | |
| 56 | * the configuration for the server | |
| 57 | */ | |
| 58 | public SmppServerExtension(ServerConfig builder) { | |
| 59 | super(builder); | |
| 60 | } | |
| 61 | ||
| 62 | @Override | |
| 63 | public void beforeEach(ExtensionContext context) throws Exception { | |
| 64 | RetryConfig retryConfig = builder.build().getStartRetryConfig(); | |
| 65 | Retry retry = RetryRegistry.of(retryConfig).retry("SmppServer.start()"); | |
| 66 | retry.getEventPublisher().onRetry((event) -> { | |
| 67 | LOG.info("SMPP server failed to start on port {}. Retrying...", getPort()); | |
| 68 | }); | |
| 69 | try { | |
| 70 | retry.<Void>executeCheckedSupplier(() -> { | |
| 71 |
1
1. lambda$beforeEach$e15e838a$1 : removed call to fr/sii/ogham/testing/extension/junit/sms/SmppServerExtension::start → RUN_ERROR |
start(context); |
| 72 | return null; | |
| 73 | }); | |
| 74 | } catch (Throwable e) { | |
| 75 | throw new SmppServerStartException("Failed to start SMPP server", e); | |
| 76 | } | |
| 77 | } | |
| 78 | ||
| 79 | private void start(ExtensionContext context) throws SmppServerException { | |
| 80 | SmppServerConfig config = AnnotationSupport.findAnnotation(context.getElement(), SmppServerConfig.class).orElse(null); | |
| 81 | SimulatorConfiguration serverConfig = builder.annotationConfig(config).build(); | |
| 82 | server = initServer(serverConfig); | |
| 83 | LOG.info("starting SMPP server on port {}...", getPort()); | |
| 84 |
1
1. start : removed call to fr/sii/ogham/testing/sms/simulator/SmppServerSimulator::start → RUN_ERROR |
server.start(); |
| 85 | LOG.info("SMPP server started on port {}", getPort()); | |
| 86 | } | |
| 87 | ||
| 88 | @Override | |
| 89 | public void afterEach(ExtensionContext context) throws Exception { | |
| 90 |
1
1. afterEach : removed call to fr/sii/ogham/testing/extension/junit/sms/SmppServerExtension::stop → RUN_ERROR |
stop(); |
| 91 | } | |
| 92 | ||
| 93 | private void stop() throws SmppServerException { | |
| 94 | LOG.info("stopping SMPP server..."); | |
| 95 |
1
1. stop : removed call to fr/sii/ogham/testing/sms/simulator/SmppServerSimulator::stop → RUN_ERROR |
server.stop(); |
| 96 | LOG.info("SMPP server stopped"); | |
| 97 | } | |
| 98 | ||
| 99 | @Override | |
| 100 | public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { | |
| 101 |
3
1. supportsParameter : negated conditional → NO_COVERAGE 2. supportsParameter : negated conditional → NO_COVERAGE 3. supportsParameter : replaced boolean return with true for fr/sii/ogham/testing/extension/junit/sms/SmppServerExtension::supportsParameter → NO_COVERAGE |
return isSmppServerSimulatorParam(parameterContext) || isSmppServerExtensionParam(parameterContext); |
| 102 | } | |
| 103 | ||
| 104 | @Override | |
| 105 | public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { | |
| 106 |
1
1. resolveParameter : negated conditional → NO_COVERAGE |
if (isSmppServerSimulatorParam(parameterContext)) { |
| 107 |
1
1. resolveParameter : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/SmppServerExtension::resolveParameter → NO_COVERAGE |
return server; |
| 108 | } | |
| 109 |
1
1. resolveParameter : negated conditional → NO_COVERAGE |
if (isSmppServerExtensionParam(parameterContext)) { |
| 110 |
1
1. resolveParameter : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/SmppServerExtension::resolveParameter → NO_COVERAGE |
return this; |
| 111 | } | |
| 112 | return null; | |
| 113 | } | |
| 114 | ||
| 115 | ||
| 116 | private boolean isSmppServerSimulatorParam(ParameterContext parameterContext) { | |
| 117 |
2
1. isSmppServerSimulatorParam : replaced boolean return with false for fr/sii/ogham/testing/extension/junit/sms/SmppServerExtension::isSmppServerSimulatorParam → NO_COVERAGE 2. isSmppServerSimulatorParam : replaced boolean return with true for fr/sii/ogham/testing/extension/junit/sms/SmppServerExtension::isSmppServerSimulatorParam → NO_COVERAGE |
return SmppServerSimulator.class.isAssignableFrom(parameterContext.getParameter().getType()); |
| 118 | } | |
| 119 | ||
| 120 | private boolean isSmppServerExtensionParam(ParameterContext parameterContext) { | |
| 121 |
2
1. isSmppServerExtensionParam : replaced boolean return with false for fr/sii/ogham/testing/extension/junit/sms/SmppServerExtension::isSmppServerExtensionParam → NO_COVERAGE 2. isSmppServerExtensionParam : replaced boolean return with true for fr/sii/ogham/testing/extension/junit/sms/SmppServerExtension::isSmppServerExtensionParam → NO_COVERAGE |
return SmppServerExtension.class.isAssignableFrom(parameterContext.getParameter().getType()); |
| 122 | } | |
| 123 | } | |
Mutations | ||
| 71 |
1.1 |
|
| 84 |
1.1 |
|
| 90 |
1.1 |
|
| 95 |
1.1 |
|
| 101 |
1.1 2.2 3.3 |
|
| 106 |
1.1 |
|
| 107 |
1.1 |
|
| 109 |
1.1 |
|
| 110 |
1.1 |
|
| 117 |
1.1 2.2 |
|
| 121 |
1.1 2.2 |