DefaultSendGridV2Configurer.java

1
package fr.sii.ogham.email.sendgrid.v2.builder.sendgrid;
2
3
import fr.sii.ogham.core.builder.MessagingBuilder;
4
import fr.sii.ogham.core.builder.configurer.ConfigurerFor;
5
import fr.sii.ogham.core.builder.configurer.MessagingConfigurer;
6
import fr.sii.ogham.core.builder.context.BuildContext;
7
import fr.sii.ogham.core.builder.mimetype.MimetypeDetectionBuilder;
8
import fr.sii.ogham.core.exception.configurer.ConfigureException;
9
import fr.sii.ogham.core.exception.configurer.MissingImplementationException;
10
import fr.sii.ogham.core.util.ClasspathUtils;
11
12
import static fr.sii.ogham.email.sendgrid.SendGridConstants.DEFAULT_SENDGRID_CONFIGURER_PRIORITY;
13
14
/**
15
 * Default SendGrid configurer that is automatically applied every time a
16
 * {@link MessagingBuilder} instance is created through
17
 * {@link MessagingBuilder#standard()}.
18
 * 
19
 * <p>
20
 * The configurer has a priority of 30000 in order to be applied after
21
 * templating configurers and JavaMail configurer.
22
 * </p>
23
 * 
24
 * This configurer is applied only if {@code com.sendgrid.SendGrid} is present
25
 * in the classpath. If not present, SendGrid implementation is not registered
26
 * at all.
27
 * 
28
 * <p>
29
 * This configurer inherits environment configuration (see
30
 * {@link BuildContext}).
31
 * </p>
32
 * <p>
33
 * This configurer inherits mimetype configuration (see
34
 * {@link MimetypeDetectionBuilder} and
35
 * {@link SendGridV2Builder#mimetype(MimetypeDetectionBuilder)}).
36
 * </p>
37
 * 
38
 * <p>
39
 * This configurer applies the following configuration:
40
 * <ul>
41
 * <li>Configures authentication:
42
 * <ul>
43
 * <li>Either by providing an <a href=
44
 * "https://sendgrid.com/docs/Classroom/Send/How_Emails_Are_Sent/api_keys.html">API
45
 * key</a>: using the property "ogham.email.sendgrid.api-key"</li>
46
 * <li>Or using username/password: using the properties
47
 * "ogham.email.sendgrid.username" and "ogham.email.sendgrid.password"</li>
48
 * </ul>
49
 * </li>
50
 * </ul>
51
 * 
52
 * @author Aurélien Baudet
53
 *
54
 */
55
public final class DefaultSendGridV2Configurer {
56
	@ConfigurerFor(targetedBuilder = "standard", priority = DEFAULT_SENDGRID_CONFIGURER_PRIORITY)
57
	public static class SendGridV2Configurer implements MessagingConfigurer {
58
		@Override
59
		public void configure(MessagingBuilder msgBuilder) throws ConfigureException {
60 1 1. configure : removed call to fr/sii/ogham/email/sendgrid/v2/builder/sendgrid/DefaultSendGridV2Configurer$SendGridV2Configurer::checkCanUseSendGrid → RUN_ERROR
			checkCanUseSendGrid();
61
62
			// @formatter:off
63
			SendGridV2Builder builder = msgBuilder.email().sender(SendGridV2Builder.class);
64
			// inherit mimetype configuration as parent builder
65
			builder.mimetype(msgBuilder.mimetype());
66
			builder
67
				.apiKey().properties("${ogham.email.sendgrid.api-key}").and()
68
				.username().properties("${ogham.email.sendgrid.username}").and()
69
				.password().properties("${ogham.email.sendgrid.password}").and()
70
				.url().properties("${ogham.email.sendgrid.url}");
71
			// @formatter:on
72
		}
73
74
		private static void checkCanUseSendGrid() throws ConfigureException {
75 1 1. checkCanUseSendGrid : negated conditional → RUN_ERROR
			if (!isSendGridV2Present()) {
76
				throw new MissingImplementationException("Can't send Email using SendGrid v2 sender because SendGrid v2 implementation is not present in the classpath", "com.sendgrid.SendGrid", "com.sendgrid.SendGrid$Email");
77
			}
78
		}
79
80
		private static boolean isSendGridV2Present() {
81 3 1. isSendGridV2Present : negated conditional → RUN_ERROR
2. isSendGridV2Present : negated conditional → RUN_ERROR
3. isSendGridV2Present : replaced boolean return with true for fr/sii/ogham/email/sendgrid/v2/builder/sendgrid/DefaultSendGridV2Configurer$SendGridV2Configurer::isSendGridV2Present → RUN_ERROR
			return ClasspathUtils.exists("com.sendgrid.SendGrid") && ClasspathUtils.exists("com.sendgrid.SendGrid$Email");
82
		}
83
	}
84
85
	private DefaultSendGridV2Configurer() {
86
		super();
87
	}
88
}

Mutations

60

1.1
Location : configure
Killed by :
removed call to fr/sii/ogham/email/sendgrid/v2/builder/sendgrid/DefaultSendGridV2Configurer$SendGridV2Configurer::checkCanUseSendGrid → RUN_ERROR

75

1.1
Location : checkCanUseSendGrid
Killed by :
negated conditional → RUN_ERROR

81

1.1
Location : isSendGridV2Present
Killed by :
negated conditional → RUN_ERROR

2.2
Location : isSendGridV2Present
Killed by :
negated conditional → RUN_ERROR

3.3
Location : isSendGridV2Present
Killed by :
replaced boolean return with true for fr/sii/ogham/email/sendgrid/v2/builder/sendgrid/DefaultSendGridV2Configurer$SendGridV2Configurer::isSendGridV2Present → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1