| 1 | package fr.sii.ogham.testing.extension.junit.sms.config; | |
| 2 | ||
| 3 | import fr.sii.ogham.testing.sms.simulator.config.Credentials; | |
| 4 | import fr.sii.ogham.testing.sms.simulator.config.*; | |
| 5 | import fr.sii.ogham.testing.util.RandomPortUtils; | |
| 6 | import ogham.testing.io.github.resilience4j.retry.RetryConfig; | |
| 7 | ||
| 8 | import java.util.ArrayList; | |
| 9 | import java.util.Arrays; | |
| 10 | import java.util.List; | |
| 11 | ||
| 12 | import static fr.sii.ogham.testing.extension.junit.sms.config.SlowConfig.noWait; | |
| 13 | import static fr.sii.ogham.testing.extension.junit.sms.config.SlowConfig.waitFor; | |
| 14 | import static fr.sii.ogham.testing.util.RandomPortUtils.PORT_RANGE_MAX; | |
| 15 | import static fr.sii.ogham.testing.util.RandomPortUtils.PORT_RANGE_MIN; | |
| 16 | import static java.time.Duration.ofMillis; | |
| 17 | import static java.util.stream.Collectors.toList; | |
| 18 | import static ogham.testing.io.github.resilience4j.core.IntervalFunction.ofExponentialBackoff; | |
| 19 | ||
| 20 | /** | |
| 21 | * Builder to generate a {@link SimulatorConfiguration}. | |
| 22 | * | |
| 23 | * <p> | |
| 24 | * Default configuration: | |
| 25 | * <ul> | |
| 26 | * <li>Starts on random port</li> | |
| 27 | * <li>No delay</li> | |
| 28 | * <li>No credentials</li> | |
| 29 | * <li>Do not keep messages between tests</li> | |
| 30 | * </ul> | |
| 31 | * | |
| 32 | * @author Aurélien Baudet | |
| 33 | */ | |
| 34 | public class ServerConfig { | |
| 35 | private PortConfig portConfig; | |
| 36 | private final List<Credentials> credentials = new ArrayList<>(); | |
| 37 | private SmppServerConfig annotationConfig; | |
| 38 | private SlowConfig slowConfig; | |
| 39 | private boolean keepMessages; | |
| 40 | private RetryConfig startRetryConfig; | |
| 41 | ||
| 42 | /** | |
| 43 | * Start the server with a fixed port. | |
| 44 | * | |
| 45 | * @param port the port value | |
| 46 | * @return this instance for fluent chaining | |
| 47 | */ | |
| 48 | public ServerConfig port(int port) { | |
| 49 | this.portConfig = new FixedPortConfig(port); | |
| 50 |
1
1. port : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::port → NO_COVERAGE |
return this; |
| 51 | } | |
| 52 | ||
| 53 | /** | |
| 54 | * Start the server with a random port. | |
| 55 | * <p> | |
| 56 | * The port is contained in the range | |
| 57 | * [{@link RandomPortUtils#PORT_RANGE_MIN}, | |
| 58 | * {@link RandomPortUtils#PORT_RANGE_MAX}]. | |
| 59 | * | |
| 60 | * @return this instance for fluent chaining | |
| 61 | */ | |
| 62 | public ServerConfig randomPort() { | |
| 63 |
1
1. randomPort : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::randomPort → NO_COVERAGE |
return randomPort(PORT_RANGE_MAX); |
| 64 | } | |
| 65 | ||
| 66 | /** | |
| 67 | * Start the server with a random port. | |
| 68 | * <p> | |
| 69 | * The port is contained in the range | |
| 70 | * [{@link RandomPortUtils#PORT_RANGE_MIN}, {@code maxPort}]. | |
| 71 | * | |
| 72 | * @param maxPort the maximum port value | |
| 73 | * @return this instance for fluent chaining | |
| 74 | */ | |
| 75 | public ServerConfig randomPort(int maxPort) { | |
| 76 |
1
1. randomPort : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::randomPort → NO_COVERAGE |
return randomPort(PORT_RANGE_MIN, maxPort); |
| 77 | } | |
| 78 | ||
| 79 | /** | |
| 80 | * Start the server with a random port. | |
| 81 | * <p> | |
| 82 | * The port is contained in the range [{@code minPort}, {@code maxPort}]. | |
| 83 | * | |
| 84 | * @param minPort the minimum port value | |
| 85 | * @param maxPort the maximum port value | |
| 86 | * @return this instance for fluent chaining | |
| 87 | */ | |
| 88 | public ServerConfig randomPort(int minPort, int maxPort) { | |
| 89 | this.portConfig = new RandomPortConfig(minPort, maxPort); | |
| 90 |
1
1. randomPort : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::randomPort → NO_COVERAGE |
return this; |
| 91 | } | |
| 92 | ||
| 93 | /** | |
| 94 | * Register allowed credentials. | |
| 95 | * | |
| 96 | * @param systemId the system_id | |
| 97 | * @param password the password | |
| 98 | * @return this instance for fluent chaining | |
| 99 | */ | |
| 100 | public ServerConfig credentials(String systemId, String password) { | |
| 101 | credentials.add(new Credentials(systemId, password)); | |
| 102 |
1
1. credentials : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::credentials → NO_COVERAGE |
return this; |
| 103 | } | |
| 104 | ||
| 105 | /** | |
| 106 | * Configure the simulator to behave like a slow server. | |
| 107 | * | |
| 108 | * @return the builder to control slow delays | |
| 109 | */ | |
| 110 | public SlowConfig slow() { | |
| 111 |
1
1. slow : negated conditional → NO_COVERAGE |
if (slowConfig == null) { |
| 112 | slowConfig = new SlowConfig(this); | |
| 113 | } | |
| 114 |
1
1. slow : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::slow → NO_COVERAGE |
return slowConfig; |
| 115 | } | |
| 116 | ||
| 117 | /** | |
| 118 | * Merge with configuration provided by annotation. | |
| 119 | * <p> | |
| 120 | * The configuration provided by the annotation takes precedence over | |
| 121 | * configuration using builder methods. The aim is to be able to provide | |
| 122 | * common configuration for the test class using JUnit rules and be able to | |
| 123 | * override some configuration for a particular test. | |
| 124 | * | |
| 125 | * @param annotationConfig the annotation configuration | |
| 126 | * @return this instance for fluent chaining | |
| 127 | */ | |
| 128 | public ServerConfig annotationConfig(SmppServerConfig annotationConfig) { | |
| 129 | this.annotationConfig = annotationConfig; | |
| 130 |
1
1. annotationConfig : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::annotationConfig → RUN_ERROR |
return this; |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * If the server is restarted, it indicates if received messages in the | |
| 135 | * previous session should be kept (true) or dropped (false). | |
| 136 | * | |
| 137 | * @param keep indicate if messages should be kept or not between sessions | |
| 138 | * @return this instance for fluent chaining | |
| 139 | */ | |
| 140 | public ServerConfig keepMessages(boolean keep) { | |
| 141 | keepMessages = keep; | |
| 142 |
1
1. keepMessages : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::keepMessages → NO_COVERAGE |
return this; |
| 143 | } | |
| 144 | ||
| 145 | /** | |
| 146 | * Server may not start correctly (because port was available but is not | |
| 147 | * available anymore for example). | |
| 148 | * <p> | |
| 149 | * In such case, the server will be restarted until it starts successfully, or | |
| 150 | * it fails due to maximum attempts reached. | |
| 151 | * | |
| 152 | * @param retryConfig the retry configuration | |
| 153 | * @return this instance for fluent chaining | |
| 154 | */ | |
| 155 | public ServerConfig startRetry(RetryConfig retryConfig) { | |
| 156 | this.startRetryConfig = retryConfig; | |
| 157 |
1
1. startRetry : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::startRetry → NO_COVERAGE |
return this; |
| 158 | } | |
| 159 | ||
| 160 | /** | |
| 161 | * Create the final {@link SimulatorConfiguration} that is used by the SMPP | |
| 162 | * server. | |
| 163 | * | |
| 164 | * @return the simulator configuration | |
| 165 | */ | |
| 166 | public SimulatorConfiguration build() { | |
| 167 | SimulatorConfiguration config = new SimulatorConfiguration(); | |
| 168 |
1
1. build : removed call to fr/sii/ogham/testing/sms/simulator/config/SimulatorConfiguration::setPort → RUN_ERROR |
config.setPort(buildPort()); |
| 169 |
1
1. build : removed call to fr/sii/ogham/testing/sms/simulator/config/SimulatorConfiguration::setCredentials → RUN_ERROR |
config.setCredentials(buildCredentials()); |
| 170 |
1
1. build : removed call to fr/sii/ogham/testing/sms/simulator/config/SimulatorConfiguration::setServerDelays → RUN_ERROR |
config.setServerDelays(buildServerDelays()); |
| 171 |
1
1. build : removed call to fr/sii/ogham/testing/sms/simulator/config/SimulatorConfiguration::setKeepMessages → RUN_ERROR |
config.setKeepMessages(keepMessages); |
| 172 |
1
1. build : removed call to fr/sii/ogham/testing/sms/simulator/config/SimulatorConfiguration::setStartRetryConfig → RUN_ERROR |
config.setStartRetryConfig(buildStartRetryConfig()); |
| 173 |
1
1. build : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::build → RUN_ERROR |
return config; |
| 174 | } | |
| 175 | ||
| 176 | private ServerPortProvider buildPort() { | |
| 177 |
1
1. buildPort : negated conditional → RUN_ERROR |
if (portConfig == null) { |
| 178 |
1
1. buildPort : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::buildPort → RUN_ERROR |
return new RandomPortConfig(PORT_RANGE_MIN, PORT_RANGE_MAX).build(); |
| 179 | } | |
| 180 |
1
1. buildPort : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::buildPort → NO_COVERAGE |
return portConfig.build(); |
| 181 | } | |
| 182 | ||
| 183 | private List<Credentials> buildCredentials() { | |
| 184 |
1
1. buildCredentials : negated conditional → RUN_ERROR |
if (annotationConfig != null) { |
| 185 |
2
1. buildCredentials : replaced return value with Collections.emptyList for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::buildCredentials → NO_COVERAGE 2. lambda$buildCredentials$0 : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::lambda$buildCredentials$0 → NO_COVERAGE |
return Arrays.stream(annotationConfig.credentials()).map(c -> new Credentials(c.systemId(), c.password())).collect(toList()); |
| 186 | } | |
| 187 |
1
1. buildCredentials : replaced return value with Collections.emptyList for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::buildCredentials → RUN_ERROR |
return credentials; |
| 188 | } | |
| 189 | ||
| 190 | private ServerDelays buildServerDelays() { | |
| 191 |
1
1. buildServerDelays : negated conditional → RUN_ERROR |
if (annotationConfig != null) { |
| 192 |
1
1. buildServerDelays : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::buildServerDelays → NO_COVERAGE |
return buildServerDelays(annotationConfig.slow()); |
| 193 | } | |
| 194 |
1
1. buildServerDelays : negated conditional → RUN_ERROR |
if (slowConfig != null) { |
| 195 |
1
1. buildServerDelays : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::buildServerDelays → NO_COVERAGE |
return slowConfig.build(); |
| 196 | } | |
| 197 | return null; | |
| 198 | } | |
| 199 | ||
| 200 | private RetryConfig buildStartRetryConfig() { | |
| 201 |
1
1. buildStartRetryConfig : negated conditional → RUN_ERROR |
if (startRetryConfig != null) { |
| 202 |
1
1. buildStartRetryConfig : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::buildStartRetryConfig → NO_COVERAGE |
return startRetryConfig; |
| 203 | } | |
| 204 |
1
1. buildStartRetryConfig : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::buildStartRetryConfig → RUN_ERROR |
return RetryConfig.custom() |
| 205 | .maxAttempts(5) | |
| 206 | .intervalFunction(ofExponentialBackoff(ofMillis(100))) | |
| 207 | .failAfterMaxAttempts(true) | |
| 208 | .build(); | |
| 209 | } | |
| 210 | ||
| 211 | private static ServerDelays buildServerDelays(Slow slow) { | |
| 212 | ServerDelays delays = new ServerDelays(); | |
| 213 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendAlertNotificationWaiting → NO_COVERAGE |
delays.setSendAlertNotificationWaiting(toAwaiter(slow.sendAlertNotificationDelay())); |
| 214 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendBindWaiting → NO_COVERAGE |
delays.setSendBindWaiting(toAwaiter(slow.sendBindDelay())); |
| 215 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendBindRespWaiting → NO_COVERAGE |
delays.setSendBindRespWaiting(toAwaiter(slow.sendBindRespDelay())); |
| 216 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendCancelSmWaiting → NO_COVERAGE |
delays.setSendCancelSmWaiting(toAwaiter(slow.sendCancelSmDelay())); |
| 217 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendCancelSmRespWaiting → NO_COVERAGE |
delays.setSendCancelSmRespWaiting(toAwaiter(slow.sendCancelSmRespDelay())); |
| 218 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendDataSmWaiting → NO_COVERAGE |
delays.setSendDataSmWaiting(toAwaiter(slow.sendDataSmDelay())); |
| 219 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendDataSmRespWaiting → NO_COVERAGE |
delays.setSendDataSmRespWaiting(toAwaiter(slow.sendDataSmRespDelay())); |
| 220 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendDeliverSmWaiting → NO_COVERAGE |
delays.setSendDeliverSmWaiting(toAwaiter(slow.sendDeliverSmDelay())); |
| 221 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendDeliverSmRespWaiting → NO_COVERAGE |
delays.setSendDeliverSmRespWaiting(toAwaiter(slow.sendDeliverSmRespDelay())); |
| 222 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendEnquireLinkWaiting → NO_COVERAGE |
delays.setSendEnquireLinkWaiting(toAwaiter(slow.sendEnquireLinkDelay())); |
| 223 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendEnquireLinkRespWaiting → NO_COVERAGE |
delays.setSendEnquireLinkRespWaiting(toAwaiter(slow.sendEnquireLinkRespDelay())); |
| 224 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendGenericNackWaiting → NO_COVERAGE |
delays.setSendGenericNackWaiting(toAwaiter(slow.sendGenericNackDelay())); |
| 225 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendHeaderWaiting → NO_COVERAGE |
delays.setSendHeaderWaiting(toAwaiter(slow.sendHeaderDelay())); |
| 226 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendOutbindWaiting → NO_COVERAGE |
delays.setSendOutbindWaiting(toAwaiter(slow.sendOutbindDelay())); |
| 227 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendQuerySmWaiting → NO_COVERAGE |
delays.setSendQuerySmWaiting(toAwaiter(slow.sendQuerySmDelay())); |
| 228 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendQuerySmRespWaiting → NO_COVERAGE |
delays.setSendQuerySmRespWaiting(toAwaiter(slow.sendQuerySmRespDelay())); |
| 229 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendReplaceSmWaiting → NO_COVERAGE |
delays.setSendReplaceSmWaiting(toAwaiter(slow.sendReplaceSmDelay())); |
| 230 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendReplaceSmRespWaiting → NO_COVERAGE |
delays.setSendReplaceSmRespWaiting(toAwaiter(slow.sendReplaceSmRespDelay())); |
| 231 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendSubmitMultiWaiting → NO_COVERAGE |
delays.setSendSubmitMultiWaiting(toAwaiter(slow.sendSubmitMultiDelay())); |
| 232 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendSubmitMultiRespWaiting → NO_COVERAGE |
delays.setSendSubmitMultiRespWaiting(toAwaiter(slow.sendSubmitMultiRespDelay())); |
| 233 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendSubmitSmWaiting → NO_COVERAGE |
delays.setSendSubmitSmWaiting(toAwaiter(slow.sendSubmitSmDelay())); |
| 234 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendSubmitSmRespWaiting → NO_COVERAGE |
delays.setSendSubmitSmRespWaiting(toAwaiter(slow.sendSubmitSmRespDelay())); |
| 235 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendUnbindWaiting → NO_COVERAGE |
delays.setSendUnbindWaiting(toAwaiter(slow.sendUnbindDelay())); |
| 236 |
1
1. buildServerDelays : removed call to fr/sii/ogham/testing/sms/simulator/config/ServerDelays::setSendUnbindRespWaiting → NO_COVERAGE |
delays.setSendUnbindRespWaiting(toAwaiter(slow.sendUnbindRespDelay())); |
| 237 |
1
1. buildServerDelays : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::buildServerDelays → NO_COVERAGE |
return delays; |
| 238 | } | |
| 239 | ||
| 240 | private static Awaiter toAwaiter(long delayMs) { | |
| 241 |
1
1. toAwaiter : negated conditional → NO_COVERAGE |
if (delayMs == 0) { |
| 242 |
1
1. toAwaiter : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::toAwaiter → NO_COVERAGE |
return noWait(); |
| 243 | } | |
| 244 |
1
1. toAwaiter : replaced return value with null for fr/sii/ogham/testing/extension/junit/sms/config/ServerConfig::toAwaiter → NO_COVERAGE |
return waitFor(delayMs); |
| 245 | } | |
| 246 | } | |
Mutations | ||
| 50 |
1.1 |
|
| 63 |
1.1 |
|
| 76 |
1.1 |
|
| 90 |
1.1 |
|
| 102 |
1.1 |
|
| 111 |
1.1 |
|
| 114 |
1.1 |
|
| 130 |
1.1 |
|
| 142 |
1.1 |
|
| 157 |
1.1 |
|
| 168 |
1.1 |
|
| 169 |
1.1 |
|
| 170 |
1.1 |
|
| 171 |
1.1 |
|
| 172 |
1.1 |
|
| 173 |
1.1 |
|
| 177 |
1.1 |
|
| 178 |
1.1 |
|
| 180 |
1.1 |
|
| 184 |
1.1 |
|
| 185 |
1.1 2.2 |
|
| 187 |
1.1 |
|
| 191 |
1.1 |
|
| 192 |
1.1 |
|
| 194 |
1.1 |
|
| 195 |
1.1 |
|
| 201 |
1.1 |
|
| 202 |
1.1 |
|
| 204 |
1.1 |
|
| 213 |
1.1 |
|
| 214 |
1.1 |
|
| 215 |
1.1 |
|
| 216 |
1.1 |
|
| 217 |
1.1 |
|
| 218 |
1.1 |
|
| 219 |
1.1 |
|
| 220 |
1.1 |
|
| 221 |
1.1 |
|
| 222 |
1.1 |
|
| 223 |
1.1 |
|
| 224 |
1.1 |
|
| 225 |
1.1 |
|
| 226 |
1.1 |
|
| 227 |
1.1 |
|
| 228 |
1.1 |
|
| 229 |
1.1 |
|
| 230 |
1.1 |
|
| 231 |
1.1 |
|
| 232 |
1.1 |
|
| 233 |
1.1 |
|
| 234 |
1.1 |
|
| 235 |
1.1 |
|
| 236 |
1.1 |
|
| 237 |
1.1 |
|
| 241 |
1.1 |
|
| 242 |
1.1 |
|
| 244 |
1.1 |