ThymeleafV3EmailBuilder.java

1
package fr.sii.ogham.template.thymeleaf.v3.buider;
2
3
import org.thymeleaf.TemplateEngine;
4
import org.thymeleaf.templateresolver.ITemplateResolver;
5
6
import fr.sii.ogham.core.builder.context.BuildContext;
7
import fr.sii.ogham.core.builder.context.DefaultBuildContext;
8
import fr.sii.ogham.core.builder.env.EnvironmentBuilder;
9
import fr.sii.ogham.core.template.detector.TemplateEngineDetector;
10
import fr.sii.ogham.email.builder.EmailBuilder;
11
import fr.sii.ogham.template.thymeleaf.common.adapter.ClassPathResolverAdapter;
12
import fr.sii.ogham.template.thymeleaf.common.adapter.FileResolverAdapter;
13
import fr.sii.ogham.template.thymeleaf.common.adapter.FirstSupportingResolverAdapter;
14
import fr.sii.ogham.template.thymeleaf.common.adapter.TemplateResolverAdapter;
15
import fr.sii.ogham.template.thymeleaf.common.buider.AbstractThymeleafMultiContentBuilder;
16
import fr.sii.ogham.template.thymeleaf.v3.ThymeLeafV3FirstSupportingTemplateResolver;
17
import fr.sii.ogham.template.thymeleaf.v3.ThymeleafV3TemplateDetector;
18
import fr.sii.ogham.template.thymeleaf.v3.adapter.StringResolverAdapter;
19
import fr.sii.ogham.template.thymeleaf.v3.adapter.ThymeleafV3TemplateOptionsApplier;
20
21
/**
22
 * Configures parsing of templates using Thymeleaf.
23
 * 
24
 * Specific resource resolution can be configured to use template prefix/suffix
25
 * paths:
26
 * 
27
 * <pre>
28
 * <code>
29
 * .classpath()
30
 *   .pathPrefix("email/")
31
 *   .pathSuffix(".html")
32
 *   .and()
33
 * .file()
34
 *   .pathPrefix("/data/myapplication/templates/email")
35
 *   .pathSuffix(".html")
36
 * </code>
37
 * </pre>
38
 * 
39
 * You can customize default Thymeleaf {@link TemplateEngine}:
40
 * 
41
 * <pre>
42
 * <code>
43
 * .engine()
44
 *   .addDialect("foo", myDialect)
45
 *   .addMessageResolver(myMessageResolver)
46
 * </code>
47
 * </pre>
48
 * 
49
 * Or you can use a particular Thymeleaf {@link TemplateEngine}:
50
 * 
51
 * <pre>
52
 * <code>
53
 * .engine(new MyTemplateEngine())
54
 * </code>
55
 * </pre>
56
 * 
57
 * 
58
 * Email protocol supports several contents (main and alternative). The main
59
 * content is often an HTML email to display a beautiful email to users. The
60
 * alternative content is often a textual fallback (when email client can't
61
 * display HTML version like mobile phones that tries to display a summary of
62
 * the email). You can configure which file extensions are supported by
63
 * Thymeleaf to automatically load variants (HTML: main, TEXT: alternative):
64
 * 
65
 * <pre>
66
 * <code>
67
 * .variant(EmailVariant.HTML, "html")
68
 * .variant(EmailVariant.TEXT, "txt")
69
 * </code>
70
 * </pre>
71
 * 
72
 * Thanks to that configuration, you can send an email without specifying the
73
 * extension:
74
 * 
75
 * <pre>
76
 * <code>
77
 * service.send(new Email()
78
 *   .content(new MultiTemplateContent("email/sample", new SampleBean("foo", 42)))
79
 *   .to("foo.bar@sii.fr"))
80
 * </code>
81
 * </pre>
82
 * 
83
 * Ogham will then be able to detect which files exist and choose the right
84
 * behavior:
85
 * <ul>
86
 * <li>If you provide an ".html" file (either in classpath or on filesytem), the
87
 * HTML template is used as main content</li>
88
 * <li>If you provide an ".txt" file (either in classpath or on filesytem), the
89
 * text template is used as main content</li>
90
 * <li>If you provide both files, the HTML template is used as main content and
91
 * text template as alternative</li>
92
 * </ul>
93
 * 
94
 * 
95
 * @author Aurélien Baudet
96
 *
97
 */
98
public class ThymeleafV3EmailBuilder extends AbstractThymeleafMultiContentBuilder<ThymeleafV3EmailBuilder, EmailBuilder, ThymeleafV3EngineConfigBuilder<ThymeleafV3EmailBuilder>> {
99
	/**
100
	 * Default constructor when using Thymeleaf without all Ogham work.
101
	 * 
102
	 * <strong>WARNING: use is only if you know what you are doing !</strong>
103
	 */
104
	public ThymeleafV3EmailBuilder() {
105
		super(ThymeleafV3EmailBuilder.class, null, new DefaultBuildContext());
106
	}
107
108
	/**
109
	 * Initializes the builder with a parent builder. The parent builder is used
110
	 * when calling {@link #and()} method. The {@link EnvironmentBuilder} is
111
	 * used to evaluate properties when {@link #build()} method is called.
112
	 * 
113
	 * @param parent
114
	 *            the parent builder
115
	 * @param buildContext
116
	 *            for registering instances and property evaluation
117
	 */
118
	public ThymeleafV3EmailBuilder(EmailBuilder parent, BuildContext buildContext) {
119
		super(ThymeleafV3EmailBuilder.class, parent, buildContext);
120
	}
121
122
	@Override
123
	protected TemplateEngineDetector createTemplateDetector() {
124 3 1. createTemplateDetector : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::createTemplateDetector → NO_COVERAGE
2. createTemplateDetector : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::createTemplateDetector → KILLED
3. createTemplateDetector : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::createTemplateDetector → KILLED
		return buildContext.register(new ThymeleafV3TemplateDetector(buildResolver()));
125
	}
126
127
	@Override
128
	protected ITemplateResolver buildTemplateResolver(TemplateEngine builtEngine) {
129 4 1. buildTemplateResolver : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildTemplateResolver → NO_COVERAGE
2. buildTemplateResolver : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildTemplateResolver → KILLED
3. buildTemplateResolver : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildTemplateResolver → KILLED
4. buildTemplateResolver : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildTemplateResolver → KILLED
		return buildContext.register(new ThymeLeafV3FirstSupportingTemplateResolver(buildResolver(), buildAdapters()));
130
	}
131
132
	@Override
133
	protected ThymeleafV3EngineConfigBuilder<ThymeleafV3EmailBuilder> getThymeleafEngineConfigBuilder() {
134 1 1. getThymeleafEngineConfigBuilder : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::getThymeleafEngineConfigBuilder → NO_COVERAGE
		return buildContext.register(new ThymeleafV3EngineConfigBuilder<>(myself, buildContext));
135
	}
136
137
	@Override
138
	protected FirstSupportingResolverAdapter buildAdapters() {
139
		FirstSupportingResolverAdapter adapter = buildContext.register(new FirstSupportingResolverAdapter());
140
		for (TemplateResolverAdapter custom : customAdapters) {
141 1 1. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → NO_COVERAGE
			adapter.addAdapter(custom);
142
		}
143
		ThymeleafV3TemplateOptionsApplier applier = buildContext.register(new ThymeleafV3TemplateOptionsApplier());
144 4 1. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → SURVIVED
2. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → NO_COVERAGE
3. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → KILLED
4. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → KILLED
		adapter.addAdapter(buildContext.register(new ClassPathResolverAdapter(applier)));
145 4 1. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → NO_COVERAGE
2. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → SURVIVED
3. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → KILLED
4. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → KILLED
		adapter.addAdapter(buildContext.register(new FileResolverAdapter(applier)));
146 3 1. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → NO_COVERAGE
2. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → SURVIVED
3. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → KILLED
		adapter.addAdapter(buildContext.register(new StringResolverAdapter(applier)));
147 4 1. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::setOptions → NO_COVERAGE
2. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::setOptions → KILLED
3. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::setOptions → KILLED
4. buildAdapters : removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::setOptions → KILLED
		adapter.setOptions(buildTemplateResolverOptions());
148 4 1. buildAdapters : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildAdapters → NO_COVERAGE
2. buildAdapters : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildAdapters → KILLED
3. buildAdapters : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildAdapters → KILLED
4. buildAdapters : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildAdapters → KILLED
		return adapter;
149
	}
150
}

Mutations

124

1.1
Location : createTemplateDetector
Killed by : none
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::createTemplateDetector → NO_COVERAGE

2.2
Location : createTemplateDetector
Killed by : oghamall.it.template.TemplateErrorTest.singleTemplateNotFound(oghamall.it.template.TemplateErrorTest)
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::createTemplateDetector → KILLED

3.3
Location : createTemplateDetector
Killed by : oghamspringbootv2autoconfigure.it.StaticMethodAccessTest.emailUsingFreemarkerTemplateAndStaticMethodAccessDisabledShouldFail(oghamspringbootv2autoconfigure.it.StaticMethodAccessTest)
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::createTemplateDetector → KILLED

129

1.1
Location : buildTemplateResolver
Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests)
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildTemplateResolver → KILLED

2.2
Location : buildTemplateResolver
Killed by : none
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildTemplateResolver → NO_COVERAGE

3.3
Location : buildTemplateResolver
Killed by : oghamthymeleafv3.it.ExternalFileTest.fileUnreadable(oghamthymeleafv3.it.ExternalFileTest)
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildTemplateResolver → KILLED

4.4
Location : buildTemplateResolver
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredAndTemplateParsersOnlyRegisteredCantHandleTemplateContentDueToResourceResolutionNotConfigured(oghamall.it.configuration.EmptyBuilderTest)
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildTemplateResolver → KILLED

134

1.1
Location : getThymeleafEngineConfigBuilder
Killed by : none
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::getThymeleafEngineConfigBuilder → NO_COVERAGE

141

1.1
Location : buildAdapters
Killed by : none
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → NO_COVERAGE

144

1.1
Location : buildAdapters
Killed by : none
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → SURVIVED

2.2
Location : buildAdapters
Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithInvalidResourcePath(oghamall.it.email.EmailMultiTemplateTest)
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → KILLED

3.3
Location : buildAdapters
Killed by : oghamspringbootv2autoconfigure.it.SpringBeanResolutionTest.missingBeanErrorUsingThymeleaf(oghamspringbootv2autoconfigure.it.SpringBeanResolutionTest)
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → KILLED

4.4
Location : buildAdapters
Killed by : none
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → NO_COVERAGE

145

1.1
Location : buildAdapters
Killed by : none
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → NO_COVERAGE

2.2
Location : buildAdapters
Killed by : oghamthymeleafv3.it.ExternalFileTest.fileUnreadable(oghamthymeleafv3.it.ExternalFileTest)
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → KILLED

3.3
Location : buildAdapters
Killed by : none
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → SURVIVED

4.4
Location : buildAdapters
Killed by : oghamall.it.email.ExternalFileTest.thymeleafHtmlFileFreemarkerTextFile(oghamall.it.email.ExternalFileTest)
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → KILLED

146

1.1
Location : buildAdapters
Killed by : none
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → NO_COVERAGE

2.2
Location : buildAdapters
Killed by : oghamall.it.email.FluentEmailTest.bodyTemplateString(oghamall.it.email.FluentEmailTest)
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → KILLED

3.3
Location : buildAdapters
Killed by : none
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::addAdapter → SURVIVED

147

1.1
Location : buildAdapters
Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithInvalidResourcePath(oghamall.it.email.EmailMultiTemplateTest)
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::setOptions → KILLED

2.2
Location : buildAdapters
Killed by : oghamspringbootv2autoconfigure.it.SpringBeanResolutionTest.missingBeanErrorUsingThymeleaf(oghamspringbootv2autoconfigure.it.SpringBeanResolutionTest)
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::setOptions → KILLED

3.3
Location : buildAdapters
Killed by : none
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::setOptions → NO_COVERAGE

4.4
Location : buildAdapters
Killed by : oghamthymeleafv3.it.ExternalFileTest.fileUnreadable(oghamthymeleafv3.it.ExternalFileTest)
removed call to fr/sii/ogham/template/thymeleaf/common/adapter/FirstSupportingResolverAdapter::setOptions → KILLED

148

1.1
Location : buildAdapters
Killed by : oghamspringbootv2autoconfigure.it.SpringBeanResolutionTest.missingBeanErrorUsingThymeleaf(oghamspringbootv2autoconfigure.it.SpringBeanResolutionTest)
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildAdapters → KILLED

2.2
Location : buildAdapters
Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithInvalidResourcePath(oghamall.it.email.EmailMultiTemplateTest)
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildAdapters → KILLED

3.3
Location : buildAdapters
Killed by : none
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildAdapters → NO_COVERAGE

4.4
Location : buildAdapters
Killed by : oghamthymeleafv3.it.ExternalFileTest.fileUnreadable(oghamthymeleafv3.it.ExternalFileTest)
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/buider/ThymeleafV3EmailBuilder::buildAdapters → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM