DefaultThymeleafV2EmailConfigurer.java

1
package fr.sii.ogham.template.thymeleaf.v2.configure;
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.DefaultMessagingConfigurer;
6
import fr.sii.ogham.core.builder.configurer.MessagingConfigurerAdapter;
7
import fr.sii.ogham.core.builder.context.BuildContext;
8
import fr.sii.ogham.core.builder.resolution.ResourceResolutionBuilder;
9
import fr.sii.ogham.core.exception.configurer.ConfigureException;
10
import fr.sii.ogham.core.exception.configurer.MissingImplementationException;
11
import fr.sii.ogham.core.exception.configurer.NewerImplementationAvailableException;
12
import fr.sii.ogham.core.util.ClasspathUtils;
13
import fr.sii.ogham.template.thymeleaf.common.buider.AbstractThymeleafMultiContentBuilder;
14
import fr.sii.ogham.template.thymeleaf.common.configure.AbstractDefaultThymeleafEmailConfigurer;
15
import fr.sii.ogham.template.thymeleaf.v2.ThymeleafV2TemplateDetector;
16
import fr.sii.ogham.template.thymeleaf.v2.buider.ThymeleafV2EmailBuilder;
17
18
import static fr.sii.ogham.template.thymeleaf.common.ThymeleafConstants.DEFAULT_THYMELEAF_EMAIL_CONFIGURER_PRIORITY;
19
20
/**
21
 * Default configurer for Thymeleaf template engine that is automatically
22
 * applied every time a {@link MessagingBuilder} instance is created through
23
 * {@link MessagingBuilder#standard()} or {@link MessagingBuilder#minimal()}.
24
 * 
25
 * <p>
26
 * The configurer has a priority of 90000 in order to be applied after global
27
 * configurer but before any sender implementation.
28
 * </p>
29
 * 
30
 * This configurer is applied only if {@code org.thymeleaf.TemplateEngine} is
31
 * present in the classpath. If not present, template engine is not registered
32
 * at all.
33
 * 
34
 * <p>
35
 * This configurer inherits environment configuration (see
36
 * {@link BuildContext}).
37
 * </p>
38
 * <p>
39
 * It also copies resource resolution configuration of
40
 * {@link DefaultMessagingConfigurer} to inherit resource resolution lookups
41
 * (see {@link ResourceResolutionBuilder}).
42
 * </p>
43
 * 
44
 * <p>
45
 * This configurer applies the following configuration:
46
 * <ul>
47
 * <li>Configures template prefix/suffix paths:
48
 * <ul>
49
 * <li>Uses the first property that has a value for classpath resolution prefix:
50
 * <ol>
51
 * <li>"ogham.email.thymeleaf.classpath.path-prefix"</li>
52
 * <li>"ogham.email.template.classpath.path-prefix"</li>
53
 * <li>"ogham.email.thymeleaf.path-prefix"</li>
54
 * <li>"ogham.email.template.path-prefix"</li>
55
 * <li>"ogham.template.path-prefix"</li>
56
 * </ol>
57
 * </li>
58
 * <li>Uses the first property that has a value for classpath resolution suffix:
59
 * <ol>
60
 * <li>"ogham.email.thymeleaf.classpath.path-suffix"</li>
61
 * <li>"ogham.email.template.classpath.path-suffix"</li>
62
 * <li>"ogham.email.thymeleaf.path-suffix"</li>
63
 * <li>"ogham.email.template.path-suffix"</li>
64
 * <li>"ogham.template.path-suffix"</li>
65
 * </ol>
66
 * </li>
67
 * <li>Uses the first property that has a value for file resolution prefix:
68
 * <ol>
69
 * <li>"ogham.email.thymeleaf.file.path-prefix"</li>
70
 * <li>"ogham.email.template.file.path-prefix"</li>
71
 * <li>"ogham.email.thymeleaf.path-prefix"</li>
72
 * <li>"ogham.email.template.path-prefix"</li>
73
 * <li>"ogham.template.path-prefix"</li>
74
 * </ol>
75
 * </li>
76
 * <li>Uses the first property that has a value for file resolution suffix:
77
 * <ol>
78
 * <li>"ogham.email.thymeleaf.file.path-suffix"</li>
79
 * <li>"ogham.email.template.file.path-suffix"</li>
80
 * <li>"ogham.email.thymeleaf.path-suffix"</li>
81
 * <li>"ogham.email.template.path-suffix"</li>
82
 * <li>"ogham.template.path-suffix"</li>
83
 * </ol>
84
 * </li>
85
 * </ul>
86
 * </li>
87
 * <li>Configures email alternative content:
88
 * <ul>
89
 * <li>Automatically loads HTML template if extension is .html</li>
90
 * <li>Automatically loads text template if extension is .txt</li>
91
 * </ul>
92
 * </li>
93
 * <li>Configures template detection:
94
 * <ul>
95
 * <li>Uses {@link ThymeleafV2TemplateDetector} to detect if templates are
96
 * parseable by Thymeleaf</li>
97
 * </ul>
98
 * </li>
99
 * </ul>
100
 * 
101
 * @author Aurélien Baudet
102
 *
103
 */
104
public final class DefaultThymeleafV2EmailConfigurer {
105
	@ConfigurerFor(targetedBuilder = { "minimal", "standard" }, priority = DEFAULT_THYMELEAF_EMAIL_CONFIGURER_PRIORITY)
106
	public static class ThymeleafV2EmailConfigurer extends AbstractDefaultThymeleafEmailConfigurer {
107
		public ThymeleafV2EmailConfigurer() {
108
			super();
109
		}
110
111
		public ThymeleafV2EmailConfigurer(MessagingConfigurerAdapter delegate) {
112
			super(delegate);
113
		}
114
115
		@Override
116
		protected void checkCanUseThymeleaf() throws ConfigureException {
117 1 1. checkCanUseThymeleaf : negated conditional → NO_COVERAGE
			if (!isThymeleafV2Present()) {
118
				throw new MissingImplementationException("Can't parse templates using Thymeleaf v2 engine because Thymeleaf v2 implementation is not present in the classpath", "org.thymeleaf.TemplateEngine");
119
			}
120 1 1. checkCanUseThymeleaf : negated conditional → NO_COVERAGE
			if (isThymeleafV3Present()) {
121
				throw new NewerImplementationAvailableException("Can't parse templates using Thymeleaf v2 engine because Thymeleaf v3 is present in the classpath. Therefore Thymeleaf v3 is preferred");
122
			}
123
		}
124
125
		@Override
126
		protected Class<? extends AbstractThymeleafMultiContentBuilder<?, ?, ?>> getBuilderClass() {
127 1 1. getBuilderClass : replaced return value with null for fr/sii/ogham/template/thymeleaf/v2/configure/DefaultThymeleafV2EmailConfigurer$ThymeleafV2EmailConfigurer::getBuilderClass → NO_COVERAGE
			return ThymeleafV2EmailBuilder.class;
128
		}
129
130
		private static boolean isThymeleafV2Present() {
131 3 1. isThymeleafV2Present : negated conditional → NO_COVERAGE
2. isThymeleafV2Present : negated conditional → NO_COVERAGE
3. isThymeleafV2Present : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v2/configure/DefaultThymeleafV2EmailConfigurer$ThymeleafV2EmailConfigurer::isThymeleafV2Present → NO_COVERAGE
			return ClasspathUtils.exists("org.thymeleaf.TemplateEngine") && !ClasspathUtils.exists("org.thymeleaf.IEngineConfiguration");
132
		}
133
134
		private boolean isThymeleafV3Present() {
135 2 1. isThymeleafV3Present : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v2/configure/DefaultThymeleafV2EmailConfigurer$ThymeleafV2EmailConfigurer::isThymeleafV3Present → NO_COVERAGE
2. isThymeleafV3Present : replaced boolean return with false for fr/sii/ogham/template/thymeleaf/v2/configure/DefaultThymeleafV2EmailConfigurer$ThymeleafV2EmailConfigurer::isThymeleafV3Present → NO_COVERAGE
			return ClasspathUtils.exists("org.thymeleaf.IEngineConfiguration");
136
		}
137
	}
138
139
	private DefaultThymeleafV2EmailConfigurer() {
140
		super();
141
	}
142
}

Mutations

117

1.1
Location : checkCanUseThymeleaf
Killed by :
negated conditional → NO_COVERAGE

120

1.1
Location : checkCanUseThymeleaf
Killed by :
negated conditional → NO_COVERAGE

127

1.1
Location : getBuilderClass
Killed by :
replaced return value with null for fr/sii/ogham/template/thymeleaf/v2/configure/DefaultThymeleafV2EmailConfigurer$ThymeleafV2EmailConfigurer::getBuilderClass → NO_COVERAGE

131

1.1
Location : isThymeleafV2Present
Killed by :
negated conditional → NO_COVERAGE

2.2
Location : isThymeleafV2Present
Killed by :
negated conditional → NO_COVERAGE

3.3
Location : isThymeleafV2Present
Killed by :
replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v2/configure/DefaultThymeleafV2EmailConfigurer$ThymeleafV2EmailConfigurer::isThymeleafV2Present → NO_COVERAGE

135

1.1
Location : isThymeleafV3Present
Killed by :
replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v2/configure/DefaultThymeleafV2EmailConfigurer$ThymeleafV2EmailConfigurer::isThymeleafV3Present → NO_COVERAGE

2.2
Location : isThymeleafV3Present
Killed by :
replaced boolean return with false for fr/sii/ogham/template/thymeleaf/v2/configure/DefaultThymeleafV2EmailConfigurer$ThymeleafV2EmailConfigurer::isThymeleafV3Present → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.13.1