SmppServerExtension.java

1
package fr.sii.ogham.testing.extension.junit.sms;
2
3
import org.junit.jupiter.api.extension.AfterEachCallback;
4
import org.junit.jupiter.api.extension.BeforeEachCallback;
5
import org.junit.jupiter.api.extension.Extension;
6
import org.junit.jupiter.api.extension.ExtensionContext;
7
import org.junit.platform.commons.support.AnnotationSupport;
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
10
11
import fr.sii.ogham.testing.extension.junit.sms.config.ServerConfig;
12
import fr.sii.ogham.testing.extension.junit.sms.config.SmppServerConfig;
13
import fr.sii.ogham.testing.sms.simulator.config.SimulatorConfiguration;
14
15
/**
16
 * JUnit {@link Extension} for starting a local SMPP server for integration
17
 * tests.
18
 * 
19
 * <p>
20
 * The extension starts the server before every test, execute the test and stops
21
 * the server.
22
 * </p>
23
 * <p>
24
 * The server stores the received messages (raw messages). These messages are
25
 * available in testing through {@link #getReceivedMessages()}.
26
 * </p>
27
 * 
28
 * @param <M>
29
 *            The type of the received messages
30
 * 
31
 * @author Aurélien Baudet
32
 *
33
 */
34
public abstract class SmppServerExtension<M> extends AbstractJUnitSmppServerExt<M> implements BeforeEachCallback, AfterEachCallback {
35
	private static final Logger LOG = LoggerFactory.getLogger(SmppServerExtension.class);
36
37
	/**
38
	 * Initializes with the default configuration to use for the SMPP server:
39
	 * <ul>
40
	 * <li>Starts on random port</li>
41
	 * <li>No delay</li>
42
	 * <li>No credentials</li>
43
	 * <li>Do not keep messages between tests</li>
44
	 * </ul>
45
	 */
46
	public SmppServerExtension() {
47
		super();
48
	}
49
50
	/**
51
	 * Initializes with the configuration to use for the SMPP server
52
	 * 
53
	 * @param builder
54
	 *            the configuration for the server
55
	 */
56
	public SmppServerExtension(ServerConfig builder) {
57
		super(builder);
58
	}
59
60
	@Override
61
	public void beforeEach(ExtensionContext context) throws Exception {
62
		SmppServerConfig config = AnnotationSupport.findAnnotation(context.getElement(), SmppServerConfig.class).orElse(null);
63
		SimulatorConfiguration serverConfig = builder.annotationConfig(config).build();
64
		server = initServer(serverConfig);
65
		LOG.info("starting SMPP server on port {}...", getPort());
66 1 1. beforeEach : removed call to fr/sii/ogham/testing/sms/simulator/SmppServerSimulator::start → NO_COVERAGE
		server.start();
67
		LOG.info("SMPP server started on port {}", getPort());
68
	}
69
70
	@Override
71
	public void afterEach(ExtensionContext context) throws Exception {
72
		LOG.info("stopping SMPP server...");
73 1 1. afterEach : removed call to fr/sii/ogham/testing/sms/simulator/SmppServerSimulator::stop → NO_COVERAGE
		server.stop();
74
		LOG.info("SMPP server stopped");
75
	}
76
}

Mutations

66

1.1
Location : beforeEach
Killed by : none
removed call to fr/sii/ogham/testing/sms/simulator/SmppServerSimulator::start → NO_COVERAGE

73

1.1
Location : afterEach
Killed by : none
removed call to fr/sii/ogham/testing/sms/simulator/SmppServerSimulator::stop → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM