DefaultSendGridV2Configurer.java

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

Mutations

63

1.1
Location : configure
Killed by : oghamall.it.configuration.SendGridConfigurationTest.asDeveloperIDefineApiKeyUsingProperties(oghamall.it.configuration.SendGridConfigurationTest)
negated conditional → KILLED

2.2
Location : configure
Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1SendGridAutoConfigurationTests.oghamWithSendGridAutoConfigShouldUseSpringSendGridClient(oghamspringbootv1autoconfigure.it.OghamSpringBoot1SendGridAutoConfigurationTests)
negated conditional → KILLED

3.3
Location : configure
Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2FreeMarkerAutoConfigurationTests.oghamWithFreemarkerAutoConfigWithoutWebContextShouldUseSpringFreemarkerConfiguration(oghamspringbootv2autoconfigure.it.OghamSpringBoot2FreeMarkerAutoConfigurationTests)
negated conditional → KILLED

4.4
Location : configure
Killed by : oghamsendgridv2.it.SendGridTranslationTest.forBasicTextEmail
negated conditional → KILLED

81

1.1
Location : canUseSendGrid
Killed by : oghamall.it.configuration.SendGridConfigurationTest.asDeveloperIDefineApiKeyUsingProperties(oghamall.it.configuration.SendGridConfigurationTest)
replaced boolean return with true for fr/sii/ogham/email/sendgrid/v2/builder/sendgrid/DefaultSendGridV2Configurer$SendGridV2Configurer::canUseSendGrid → KILLED

2.2
Location : canUseSendGrid
Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2FreeMarkerAutoConfigurationTests.oghamWithFreemarkerAutoConfigWithoutWebContextShouldUseSpringFreemarkerConfiguration(oghamspringbootv2autoconfigure.it.OghamSpringBoot2FreeMarkerAutoConfigurationTests)
replaced boolean return with true for fr/sii/ogham/email/sendgrid/v2/builder/sendgrid/DefaultSendGridV2Configurer$SendGridV2Configurer::canUseSendGrid → KILLED

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

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

5.5
Location : canUseSendGrid
Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1SendGridAutoConfigurationTests.oghamWithSendGridAutoConfigShouldUseSpringSendGridClient(oghamspringbootv1autoconfigure.it.OghamSpringBoot1SendGridAutoConfigurationTests)
negated conditional → KILLED

6.6
Location : canUseSendGrid
Killed by : oghamsendgridv2.it.SendGridTranslationTest.forBasicTextEmail
negated conditional → KILLED

7.7
Location : canUseSendGrid
Killed by : oghamsendgridv2.it.SendGridTranslationTest.forBasicTextEmail
negated conditional → KILLED

8.8
Location : canUseSendGrid
Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1SendGridAutoConfigurationTests.oghamWithSendGridAutoConfigShouldUseSpringSendGridClient(oghamspringbootv1autoconfigure.it.OghamSpringBoot1SendGridAutoConfigurationTests)
negated conditional → KILLED

9.9
Location : canUseSendGrid
Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2FreeMarkerAutoConfigurationTests.oghamWithFreemarkerAutoConfigWithoutWebContextShouldUseSpringFreemarkerConfiguration(oghamspringbootv2autoconfigure.it.OghamSpringBoot2FreeMarkerAutoConfigurationTests)
negated conditional → KILLED

10.10
Location : canUseSendGrid
Killed by : oghamall.it.configuration.SendGridConfigurationTest.asDeveloperIDefineApiKeyUsingProperties(oghamall.it.configuration.SendGridConfigurationTest)
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM