EverySupportingMessagingService.java

1
package fr.sii.ogham.core.service;
2
3
import static fr.sii.ogham.core.util.LogUtils.logString;
4
5
import java.util.Arrays;
6
import java.util.List;
7
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
10
11
import fr.sii.ogham.core.exception.MessageNotSentException;
12
import fr.sii.ogham.core.exception.MessagingException;
13
import fr.sii.ogham.core.message.Message;
14
import fr.sii.ogham.core.sender.ConditionalSender;
15
16
/**
17
 * Implementation that will ask each sender if it is able to handle the message.
18
 * If the sender can, then the service asks the sender to really send the
19
 * message.
20
 * 
21
 * If several senders can handle the message, then each sender that is able to
22
 * handle it will be used.
23
 * 
24
 * @author Aurélien Baudet
25
 * @see ConditionalSender
26
 */
27
public class EverySupportingMessagingService implements MessagingService {
28
	private static final Logger LOG = LoggerFactory.getLogger(EverySupportingMessagingService.class);
29
30
	/**
31
	 * The list of senders used to handle messages
32
	 */
33
	private List<ConditionalSender> senders;
34
35
	/**
36
	 * Initialize the service with none, one or several sender implementations.
37
	 * The registration order has no consequence.
38
	 * 
39
	 * @param senders
40
	 *            the senders to register
41
	 */
42
	public EverySupportingMessagingService(ConditionalSender... senders) {
43
		this(Arrays.asList(senders));
44
	}
45
46
	/**
47
	 * Initialize the service with the provided sender implementations. The
48
	 * registration order has no consequence.
49
	 * 
50
	 * @param senders
51
	 *            the senders to register
52
	 */
53
	public EverySupportingMessagingService(List<ConditionalSender> senders) {
54
		super();
55
		this.senders = senders;
56
	}
57
58
	/**
59
	 * Sends the message. The message can be anything with any content and that
60
	 * must be delivered to something or someone.
61
	 * 
62
	 * Ask each sender if it is able to handle the message. Each sender that
63
	 * can't handle the message is skipped. Each sender that is able to handle
64
	 * it will be called in order to really send the message.
65
	 * 
66
	 * @param message
67
	 *            the message to send
68
	 * @throws MessagingException
69
	 *             when the message couldn't be sent
70
	 * @throws MessageNotSentException
71
	 *             when no sender could handle the message
72
	 */
73
	@Override
74
	public void send(Message message) throws MessagingException {
75
		LOG.info("Sending message...");
76
		LOG.trace("{}", message);
77
		LOG.debug("Find senders that is able to send the message {}", logString(message));
78
		boolean sent = false;
79
		for (ConditionalSender sender : senders) {
80 6 1. send : negated conditional → NO_COVERAGE
2. send : negated conditional → TIMED_OUT
3. send : negated conditional → KILLED
4. send : negated conditional → KILLED
5. send : negated conditional → KILLED
6. send : negated conditional → KILLED
			if (sender.supports(message)) {
81
				LOG.debug("Sending message {} using sender {}...", logString(message), sender);
82 6 1. send : removed call to fr/sii/ogham/core/sender/ConditionalSender::send → NO_COVERAGE
2. send : removed call to fr/sii/ogham/core/sender/ConditionalSender::send → TIMED_OUT
3. send : removed call to fr/sii/ogham/core/sender/ConditionalSender::send → KILLED
4. send : removed call to fr/sii/ogham/core/sender/ConditionalSender::send → KILLED
5. send : removed call to fr/sii/ogham/core/sender/ConditionalSender::send → KILLED
6. send : removed call to fr/sii/ogham/core/sender/ConditionalSender::send → KILLED
				sender.send(message);
83
				LOG.debug("Message {} sent using sender {}", logString(message), sender);
84
				sent = true;
85
			} else {
86
				LOG.debug("Sender {} can't handle the message {}", sender, logString(message));
87
			}
88
		}
89 5 1. send : negated conditional → NO_COVERAGE
2. send : negated conditional → TIMED_OUT
3. send : negated conditional → KILLED
4. send : negated conditional → KILLED
5. send : negated conditional → KILLED
		if(sent) {
90
			LOG.info("Message sent");
91
			LOG.trace("{}", message);
92
		} else {
93
			throw new MessageNotSentException("No sender available to send the message", message);
94
		}
95
	}
96
97
	/**
98
	 * Register a new sender. The sender is added at the end.
99
	 * 
100
	 * @param sender
101
	 *            the sender to register
102
	 * @return this instance for fluent chaining
103
	 */
104
	public EverySupportingMessagingService addSender(ConditionalSender sender) {
105
		senders.add(sender);
106 1 1. addSender : replaced return value with null for fr/sii/ogham/core/service/EverySupportingMessagingService::addSender → NO_COVERAGE
		return this;
107
	}
108
}

Mutations

80

1.1
Location : send
Killed by : oghamcore.it.core.sender.AutoRetryTest.smsSentSuccessfullyOnFirstExecution(oghamcore.it.core.sender.AutoRetryTest)
negated conditional → KILLED

2.2
Location : send
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
negated conditional → KILLED

3.3
Location : send
Killed by : oghamjavamail.it.builder.JavaMailCustomConfigurationTest.noHostDefinedShouldFail(oghamjavamail.it.builder.JavaMailCustomConfigurationTest)
negated conditional → KILLED

4.4
Location : send
Killed by : none
negated conditional → TIMED_OUT

5.5
Location : send
Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest)
negated conditional → KILLED

6.6
Location : send
Killed by : none
negated conditional → NO_COVERAGE

82

1.1
Location : send
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
removed call to fr/sii/ogham/core/sender/ConditionalSender::send → KILLED

2.2
Location : send
Killed by : none
removed call to fr/sii/ogham/core/sender/ConditionalSender::send → TIMED_OUT

3.3
Location : send
Killed by : oghamjavamail.it.builder.JavaMailCustomConfigurationTest.oghamPropertyShouldOverride(oghamjavamail.it.builder.JavaMailCustomConfigurationTest)
removed call to fr/sii/ogham/core/sender/ConditionalSender::send → KILLED

4.4
Location : send
Killed by : oghamcore.it.core.sender.AutoRetryTest.smsSentSuccessfullyOnFirstExecution(oghamcore.it.core.sender.AutoRetryTest)
removed call to fr/sii/ogham/core/sender/ConditionalSender::send → KILLED

5.5
Location : send
Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest)
removed call to fr/sii/ogham/core/sender/ConditionalSender::send → KILLED

6.6
Location : send
Killed by : none
removed call to fr/sii/ogham/core/sender/ConditionalSender::send → NO_COVERAGE

89

1.1
Location : send
Killed by : oghamjavamail.it.builder.JavaMailCustomConfigurationTest.noHostDefinedShouldFail(oghamjavamail.it.builder.JavaMailCustomConfigurationTest)
negated conditional → KILLED

2.2
Location : send
Killed by : oghamall.it.configuration.EmptyBuilderTest.unconfiguredServiceCantSendSms(oghamall.it.configuration.EmptyBuilderTest)
negated conditional → KILLED

3.3
Location : send
Killed by : none
negated conditional → NO_COVERAGE

4.4
Location : send
Killed by : oghamcore.it.core.service.CleanupTest.manualCleanupShouldAutomaticallyCleanTheSenders(oghamcore.it.core.service.CleanupTest)
negated conditional → KILLED

5.5
Location : send
Killed by : none
negated conditional → TIMED_OUT

106

1.1
Location : addSender
Killed by : none
replaced return value with null for fr/sii/ogham/core/service/EverySupportingMessagingService::addSender → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM