ContentTranslatorSender.java

1
package fr.sii.ogham.core.sender;
2
3
import org.slf4j.Logger;
4
import org.slf4j.LoggerFactory;
5
6
import fr.sii.ogham.core.exception.MessageException;
7
import fr.sii.ogham.core.exception.MessageNotSentException;
8
import fr.sii.ogham.core.exception.handler.ContentTranslatorException;
9
import fr.sii.ogham.core.message.Message;
10
import fr.sii.ogham.core.translator.content.ContentTranslator;
11
12
/**
13
 * Decorator sender that transforms the content of the message before really
14
 * sending it. This sender relies on {@link ContentTranslator} to transform the
15
 * message content. Once the content has been updated, then this sender
16
 * delegates to a real implementation the sending of the message.
17
 * 
18
 * @author Aurélien Baudet
19
 * @see ContentTranslator
20
 */
21
public class ContentTranslatorSender implements ConditionalSender {
22
	private static final Logger LOG = LoggerFactory.getLogger(ContentTranslatorSender.class);
23
24
	/**
25
	 * The translator that transforms the content of the message
26
	 */
27
	private ContentTranslator translator;
28
29
	/**
30
	 * The decorated sender that will really send the message
31
	 */
32
	private MessageSender delegate;
33
34
	/**
35
	 * Initialize the sender with the provided translator and decorated sender.
36
	 * The translator implementation will transform the content of the message.
37
	 * The decorated sender will really send the message.
38
	 * 
39
	 * @param translator
40
	 *            the translator implementation that will transform the content
41
	 *            of the message
42
	 * @param delegate
43
	 *            The decorated sender will really send the message
44
	 */
45
	public ContentTranslatorSender(ContentTranslator translator, MessageSender delegate) {
46
		super();
47
		this.translator = translator;
48
		this.delegate = delegate;
49
	}
50
51
	@Override
52
	public boolean supports(Message message) {
53 6 1. supports : negated conditional → NO_COVERAGE
2. supports : negated conditional → SURVIVED
3. supports : negated conditional → TIMED_OUT
4. supports : negated conditional → KILLED
5. supports : negated conditional → KILLED
6. supports : negated conditional → KILLED
		if (delegate instanceof ConditionalSender) {
54 12 1. supports : replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → SURVIVED
2. supports : replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → NO_COVERAGE
3. supports : replaced boolean return with true for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → SURVIVED
4. supports : replaced boolean return with true for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → NO_COVERAGE
5. supports : replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → TIMED_OUT
6. supports : replaced boolean return with true for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → TIMED_OUT
7. supports : replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → KILLED
8. supports : replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → KILLED
9. supports : replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → KILLED
10. supports : replaced boolean return with true for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → KILLED
11. supports : replaced boolean return with true for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → KILLED
12. supports : replaced boolean return with true for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → KILLED
			return ((ConditionalSender) delegate).supports(message);
55
		}
56 1 1. supports : replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → NO_COVERAGE
		return true;
57
	}
58
59
	@Override
60
	public void send(Message message) throws MessageException {
61
		try {
62
			LOG.debug("Translate the message content using {}", translator);
63
			LOG.trace("content: {}", message.getContent());
64 4 1. send : removed call to fr/sii/ogham/core/message/Message::setContent → SURVIVED
2. send : removed call to fr/sii/ogham/core/message/Message::setContent → NO_COVERAGE
3. send : removed call to fr/sii/ogham/core/message/Message::setContent → TIMED_OUT
4. send : removed call to fr/sii/ogham/core/message/Message::setContent → KILLED
			message.setContent(translator.translate(message.getContent()));
65
			LOG.debug("Message content translated using {}", translator);
66
			LOG.trace("content: {}", message.getContent());
67
			LOG.debug("Sending translated message using {}", delegate);
68
			LOG.trace("message: {}", message);
69 5 1. send : removed call to fr/sii/ogham/core/sender/MessageSender::send → NO_COVERAGE
2. send : removed call to fr/sii/ogham/core/sender/MessageSender::send → TIMED_OUT
3. send : removed call to fr/sii/ogham/core/sender/MessageSender::send → KILLED
4. send : removed call to fr/sii/ogham/core/sender/MessageSender::send → KILLED
5. send : removed call to fr/sii/ogham/core/sender/MessageSender::send → KILLED
			delegate.send(message);
70
		} catch (ContentTranslatorException e) {
71
			throw new MessageNotSentException("Failed to send message due to content handler", message, e);
72
		}
73
	}
74
75
	@Override
76
	public String toString() {
77
		StringBuilder builder = new StringBuilder();
78
		builder.append("ContentTranslatorSender [translator=").append(translator).append(", delegate=").append(delegate).append("]");
79 3 1. toString : replaced return value with "" for fr/sii/ogham/core/sender/ContentTranslatorSender::toString → SURVIVED
2. toString : replaced return value with "" for fr/sii/ogham/core/sender/ContentTranslatorSender::toString → NO_COVERAGE
3. toString : replaced return value with "" for fr/sii/ogham/core/sender/ContentTranslatorSender::toString → TIMED_OUT
		return builder.toString();
80
	}
81
}

Mutations

53

1.1
Location : supports
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : supports
Killed by : none
negated conditional → TIMED_OUT

3.3
Location : supports
Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest)
negated conditional → KILLED

4.4
Location : supports
Killed by : none
negated conditional → SURVIVED

5.5
Location : supports
Killed by : oghamall.it.sms.SmsCustomImplTest.simple(oghamall.it.sms.SmsCustomImplTest)
negated conditional → KILLED

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

54

1.1
Location : supports
Killed by : oghamjavamail.it.UnreadableAttachmentTest.attachmentUnreadable(oghamjavamail.it.UnreadableAttachmentTest)
replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → KILLED

2.2
Location : supports
Killed by : none
replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → SURVIVED

3.3
Location : supports
Killed by : none
replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → TIMED_OUT

4.4
Location : supports
Killed by : none
replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → NO_COVERAGE

5.5
Location : supports
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredAndTemplateParsersOnlyRegisteredCantHandleTemplateContentDueToResourceResolutionNotConfigured(oghamall.it.configuration.EmptyBuilderTest)
replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → KILLED

6.6
Location : supports
Killed by : oghamcore.it.core.service.CleanupTest.manualCleanupShouldAutomaticallyCleanTheSenders(oghamcore.it.core.service.CleanupTest)
replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → KILLED

7.7
Location : supports
Killed by : none
replaced boolean return with true for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → SURVIVED

8.8
Location : supports
Killed by : oghamcore.it.core.sender.AutoRetryTest.smsSentSuccessfullyOnFirstExecution(oghamcore.it.core.sender.AutoRetryTest)
replaced boolean return with true for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → KILLED

9.9
Location : supports
Killed by : oghamall.it.sms.SmsCustomImplTest.simple(oghamall.it.sms.SmsCustomImplTest)
replaced boolean return with true for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → KILLED

10.10
Location : supports
Killed by : none
replaced boolean return with true for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → TIMED_OUT

11.11
Location : supports
Killed by : none
replaced boolean return with true for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → NO_COVERAGE

12.12
Location : supports
Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest)
replaced boolean return with true for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → KILLED

56

1.1
Location : supports
Killed by : none
replaced boolean return with false for fr/sii/ogham/core/sender/ContentTranslatorSender::supports → NO_COVERAGE

64

1.1
Location : send
Killed by : none
removed call to fr/sii/ogham/core/message/Message::setContent → SURVIVED

2.2
Location : send
Killed by : oghamall.it.email.EmailEmptyTemplateTest.emptyFreemarkerTemplateShouldNotReportAnError(oghamall.it.email.EmailEmptyTemplateTest)
removed call to fr/sii/ogham/core/message/Message::setContent → KILLED

3.3
Location : send
Killed by : none
removed call to fr/sii/ogham/core/message/Message::setContent → NO_COVERAGE

4.4
Location : send
Killed by : none
removed call to fr/sii/ogham/core/message/Message::setContent → TIMED_OUT

69

1.1
Location : send
Killed by : oghamall.it.sms.SmsCustomImplTest.simple(oghamall.it.sms.SmsCustomImplTest)
removed call to fr/sii/ogham/core/sender/MessageSender::send → KILLED

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

3.3
Location : send
Killed by : oghamjavamail.it.UnreadableAttachmentTest.attachmentUnreadable(oghamjavamail.it.UnreadableAttachmentTest)
removed call to fr/sii/ogham/core/sender/MessageSender::send → KILLED

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

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

79

1.1
Location : toString
Killed by : none
replaced return value with "" for fr/sii/ogham/core/sender/ContentTranslatorSender::toString → SURVIVED

2.2
Location : toString
Killed by : none
replaced return value with "" for fr/sii/ogham/core/sender/ContentTranslatorSender::toString → TIMED_OUT

3.3
Location : toString
Killed by : none
replaced return value with "" for fr/sii/ogham/core/sender/ContentTranslatorSender::toString → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM