CssInliningBuilder.java

1
package fr.sii.ogham.email.builder;
2
3
import java.util.List;
4
5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
7
8
import fr.sii.ogham.core.builder.Builder;
9
import fr.sii.ogham.core.builder.context.BuildContext;
10
import fr.sii.ogham.core.builder.env.EnvironmentBuilder;
11
import fr.sii.ogham.core.builder.resolution.ClassPathResolutionBuilder;
12
import fr.sii.ogham.core.builder.resolution.FileResolutionBuilder;
13
import fr.sii.ogham.core.builder.resolution.ResourceResolutionBuilder;
14
import fr.sii.ogham.core.builder.resolution.ResourceResolutionBuilderHelper;
15
import fr.sii.ogham.core.builder.resolution.StringResolutionBuilder;
16
import fr.sii.ogham.core.fluent.AbstractParent;
17
import fr.sii.ogham.core.resource.path.LookupAwareRelativePathResolver;
18
import fr.sii.ogham.core.resource.path.RelativePathResolver;
19
import fr.sii.ogham.core.resource.resolver.FirstSupportingResourceResolver;
20
import fr.sii.ogham.core.resource.resolver.ResourceResolver;
21
import fr.sii.ogham.core.translator.content.ContentTranslator;
22
import fr.sii.ogham.html.inliner.CssInliner;
23
import fr.sii.ogham.html.inliner.impl.jsoup.JsoupCssInliner;
24
import fr.sii.ogham.html.translator.InlineCssTranslator;
25
26
/**
27
 * Configures how CSS are applied on HTML emails.
28
 * 
29
 * Inlining CSS means that CSS styles are loaded and applied on the matching
30
 * HTML nodes using the {@code style} HTML attribute.
31
 * 
32
 * @author Aurélien Baudet
33
 *
34
 */
35
public class CssInliningBuilder extends AbstractParent<CssHandlingBuilder> implements ResourceResolutionBuilder<CssInliningBuilder>, Builder<ContentTranslator> {
36
	private static final Logger LOG = LoggerFactory.getLogger(CssInliningBuilder.class);
37
38
	private final BuildContext buildContext;
39
	private ResourceResolutionBuilderHelper<CssInliningBuilder> resourceResolutionBuilderHelper;
40
	private boolean useJsoup;
41
42
	/**
43
	 * Initializes the builder with a parent builder. The parent builder is used
44
	 * when calling {@link #and()} method. The {@link EnvironmentBuilder} is
45
	 * used to evaluate properties when {@link #build()} method is called.
46
	 * 
47
	 * @param parent
48
	 *            the parent builder
49
	 * @param buildContext
50
	 *            for registering instances and property evaluation
51
	 */
52
	public CssInliningBuilder(CssHandlingBuilder parent, BuildContext buildContext) {
53
		super(parent);
54
		this.buildContext = buildContext;
55
		resourceResolutionBuilderHelper = new ResourceResolutionBuilderHelper<>(this, buildContext);
56
	}
57
58
	/**
59
	 * Enable CSS inlining: CSS styles are loaded and applied on the matching
60
	 * HTML nodes using the {@code style} HTML attribute.
61
	 * 
62
	 * The implementation uses <a href="https://jsoup.org/">jsoup</a> to parse
63
	 * HTML content.
64
	 * 
65
	 * @return this instance for fluent chaining
66
	 */
67
	public CssInliningBuilder jsoup() {
68
		useJsoup = true;
69 8 1. jsoup : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → NO_COVERAGE
2. jsoup : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → KILLED
3. jsoup : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → KILLED
4. jsoup : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → KILLED
5. jsoup : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → KILLED
6. jsoup : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → KILLED
7. jsoup : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → KILLED
8. jsoup : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → KILLED
		return this;
70
	}
71
72
	@Override
73
	public ClassPathResolutionBuilder<CssInliningBuilder> classpath() {
74 8 1. classpath : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → NO_COVERAGE
2. classpath : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → KILLED
3. classpath : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → KILLED
4. classpath : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → KILLED
5. classpath : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → KILLED
6. classpath : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → KILLED
7. classpath : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → KILLED
8. classpath : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → KILLED
		return resourceResolutionBuilderHelper.classpath();
75
	}
76
77
	@Override
78
	public FileResolutionBuilder<CssInliningBuilder> file() {
79 8 1. file : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → NO_COVERAGE
2. file : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → KILLED
3. file : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → KILLED
4. file : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → KILLED
5. file : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → KILLED
6. file : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → KILLED
7. file : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → KILLED
8. file : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → KILLED
		return resourceResolutionBuilderHelper.file();
80
	}
81
82
	@Override
83
	public StringResolutionBuilder<CssInliningBuilder> string() {
84 8 1. string : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → NO_COVERAGE
2. string : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → KILLED
3. string : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → KILLED
4. string : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → KILLED
5. string : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → KILLED
6. string : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → KILLED
7. string : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → KILLED
8. string : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → KILLED
		return resourceResolutionBuilderHelper.string();
85
	}
86
87
	@Override
88
	public CssInliningBuilder resolver(ResourceResolver resolver) {
89 1 1. resolver : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::resolver → NO_COVERAGE
		return resourceResolutionBuilderHelper.resolver(resolver);
90
	}
91
92
	@Override
93
	public ContentTranslator build() {
94
		CssInliner cssInliner = buildInliner();
95 3 1. build : negated conditional → SURVIVED
2. build : negated conditional → NO_COVERAGE
3. build : negated conditional → KILLED
		if (cssInliner == null) {
96
			LOG.info("CSS won't be applied on HTML content of your emails because no inliner is configured");
97
			return null;
98
		}
99 3 1. build : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::build → SURVIVED
2. build : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::build → NO_COVERAGE
3. build : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::build → KILLED
		return buildContext.register(new InlineCssTranslator(cssInliner, buildResolver(), buildRelativePathProvider()));
100
	}
101
102
	private CssInliner buildInliner() {
103 3 1. buildInliner : negated conditional → NO_COVERAGE
2. buildInliner : negated conditional → SURVIVED
3. buildInliner : negated conditional → KILLED
		if (useJsoup) {
104 3 1. buildInliner : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildInliner → SURVIVED
2. buildInliner : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildInliner → NO_COVERAGE
3. buildInliner : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildInliner → KILLED
			return buildContext.register(new JsoupCssInliner());
105
		}
106
		return null;
107
	}
108
109
	private ResourceResolver buildResolver() {
110
		List<ResourceResolver> resolvers = resourceResolutionBuilderHelper.buildResolvers();
111 3 1. buildResolver : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildResolver → SURVIVED
2. buildResolver : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildResolver → NO_COVERAGE
3. buildResolver : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildResolver → KILLED
		return buildContext.register(new FirstSupportingResourceResolver(resolvers));
112
	}
113
114
	private RelativePathResolver buildRelativePathProvider() {
115 3 1. buildRelativePathProvider : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildRelativePathProvider → SURVIVED
2. buildRelativePathProvider : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildRelativePathProvider → NO_COVERAGE
3. buildRelativePathProvider : replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildRelativePathProvider → KILLED
		return buildContext.register(new LookupAwareRelativePathResolver(resourceResolutionBuilderHelper.getAllLookups()));
116
	}
117
}

Mutations

69

1.1
Location : jsoup
Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → KILLED

2.2
Location : jsoup
Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → KILLED

3.3
Location : jsoup
Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → KILLED

4.4
Location : jsoup
Killed by : none
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → NO_COVERAGE

5.5
Location : jsoup
Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → KILLED

6.6
Location : jsoup
Killed by : oghamcore.it.core.service.CleanupTest.manualCleanupShouldAutomaticallyCleanTheSenders(oghamcore.it.core.service.CleanupTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → KILLED

7.7
Location : jsoup
Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.notHtml(oghamall.it.html.translator.JsoupInlineCssTranslatorTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → KILLED

8.8
Location : jsoup
Killed by : oghamjavamail.it.UnreadableAttachmentTest.attachmentUnreadable(oghamjavamail.it.UnreadableAttachmentTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::jsoup → KILLED

74

1.1
Location : classpath
Killed by : oghamcore.it.core.service.CleanupTest.manualCleanupShouldAutomaticallyCleanTheSenders(oghamcore.it.core.service.CleanupTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → KILLED

2.2
Location : classpath
Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → KILLED

3.3
Location : classpath
Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → KILLED

4.4
Location : classpath
Killed by : none
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → NO_COVERAGE

5.5
Location : classpath
Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → KILLED

6.6
Location : classpath
Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → KILLED

7.7
Location : classpath
Killed by : oghamjavamail.it.UnreadableAttachmentTest.attachmentUnreadable(oghamjavamail.it.UnreadableAttachmentTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → KILLED

8.8
Location : classpath
Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.notHtml(oghamall.it.html.translator.JsoupInlineCssTranslatorTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::classpath → KILLED

79

1.1
Location : file
Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → KILLED

2.2
Location : file
Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.notHtml(oghamall.it.html.translator.JsoupInlineCssTranslatorTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → KILLED

3.3
Location : file
Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → KILLED

4.4
Location : file
Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → KILLED

5.5
Location : file
Killed by : none
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → NO_COVERAGE

6.6
Location : file
Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → KILLED

7.7
Location : file
Killed by : oghamcore.it.core.service.CleanupTest.manualCleanupShouldAutomaticallyCleanTheSenders(oghamcore.it.core.service.CleanupTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → KILLED

8.8
Location : file
Killed by : oghamjavamail.it.UnreadableAttachmentTest.attachmentUnreadable(oghamjavamail.it.UnreadableAttachmentTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::file → KILLED

84

1.1
Location : string
Killed by : oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests.oghamAloneShouldUseOghamProperties(oghamspringbootv1autoconfigure.it.OghamSpringBoot1JavaMailAutoConfigurationTests)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → KILLED

2.2
Location : string
Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → KILLED

3.3
Location : string
Killed by : oghamall.it.html.translator.JsoupInlineCssTranslatorTest.notHtml(oghamall.it.html.translator.JsoupInlineCssTranslatorTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → KILLED

4.4
Location : string
Killed by : none
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → NO_COVERAGE

5.5
Location : string
Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → KILLED

6.6
Location : string
Killed by : oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests.oghamPropertiesWithSpringPropsShouldUseOghamPropertiesPrecedence(oghamspringbootv2autoconfigure.it.OghamSpringBoot2JavaMailAutoConfigurationTests)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → KILLED

7.7
Location : string
Killed by : oghamjavamail.it.UnreadableAttachmentTest.attachmentUnreadable(oghamjavamail.it.UnreadableAttachmentTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → KILLED

8.8
Location : string
Killed by : oghamcore.it.core.service.CleanupTest.manualCleanupShouldAutomaticallyCleanTheSenders(oghamcore.it.core.service.CleanupTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::string → KILLED

89

1.1
Location : resolver
Killed by : none
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::resolver → NO_COVERAGE

95

1.1
Location : build
Killed by : oghamall.it.resolver.FreemarkerRelativeResourcesTests.relativeToPrefixSuffixAndPath(oghamall.it.resolver.FreemarkerRelativeResourcesTests)
negated conditional → KILLED

2.2
Location : build
Killed by : none
negated conditional → SURVIVED

3.3
Location : build
Killed by : none
negated conditional → NO_COVERAGE

99

1.1
Location : build
Killed by : none
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::build → SURVIVED

2.2
Location : build
Killed by : none
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::build → NO_COVERAGE

3.3
Location : build
Killed by : oghamall.it.resolver.FreemarkerRelativeResourcesTests.relativeToPrefixSuffixAndPath(oghamall.it.resolver.FreemarkerRelativeResourcesTests)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::build → KILLED

103

1.1
Location : buildInliner
Killed by : oghamall.it.resolver.FreemarkerRelativeResourcesTests.relativeToPrefixSuffixAndPath(oghamall.it.resolver.FreemarkerRelativeResourcesTests)
negated conditional → KILLED

2.2
Location : buildInliner
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : buildInliner
Killed by : none
negated conditional → SURVIVED

104

1.1
Location : buildInliner
Killed by : none
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildInliner → SURVIVED

2.2
Location : buildInliner
Killed by : oghamall.it.resolver.FreemarkerRelativeResourcesTests.relativeToPrefixSuffixAndPath(oghamall.it.resolver.FreemarkerRelativeResourcesTests)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildInliner → KILLED

3.3
Location : buildInliner
Killed by : none
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildInliner → NO_COVERAGE

111

1.1
Location : buildResolver
Killed by : none
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildResolver → SURVIVED

2.2
Location : buildResolver
Killed by : none
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildResolver → NO_COVERAGE

3.3
Location : buildResolver
Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithInvalidResourcePath(oghamall.it.email.EmailMultiTemplateTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildResolver → KILLED

115

1.1
Location : buildRelativePathProvider
Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithInvalidResourcePath(oghamall.it.email.EmailMultiTemplateTest)
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildRelativePathProvider → KILLED

2.2
Location : buildRelativePathProvider
Killed by : none
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildRelativePathProvider → SURVIVED

3.3
Location : buildRelativePathProvider
Killed by : none
replaced return value with null for fr/sii/ogham/email/builder/CssInliningBuilder::buildRelativePathProvider → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM