ThymeLeafV3FirstSupportingTemplateResolver.java

1
package fr.sii.ogham.template.thymeleaf.v3;
2
3
import java.util.Map;
4
5
import org.thymeleaf.IEngineConfiguration;
6
import org.thymeleaf.templateresolver.ITemplateResolver;
7
import org.thymeleaf.templateresolver.TemplateResolution;
8
9
import fr.sii.ogham.core.resource.path.ResolvedPath;
10
import fr.sii.ogham.core.resource.path.ResourcePath;
11
import fr.sii.ogham.core.resource.path.UnresolvedPath;
12
import fr.sii.ogham.core.resource.resolver.FirstSupportingResourceResolver;
13
import fr.sii.ogham.core.resource.resolver.ResourceResolver;
14
import fr.sii.ogham.template.exception.NoResolverAdapterException;
15
import fr.sii.ogham.template.exception.ResolverAdapterNotFoundException;
16
import fr.sii.ogham.template.thymeleaf.common.adapter.FirstSupportingResolverAdapter;
17
import fr.sii.ogham.template.thymeleaf.common.exception.TemplateResolutionException;
18
19
/**
20
 * <p>
21
 * Decorator resolver that is able to manage {@link ResourcePath}.
22
 * </p>
23
 * <p>
24
 * It delegates to a {@link FirstSupportingResourceResolver} the link between
25
 * path, {@link ResourcePath} and {@link ResourceResolver}. each lookup to a
26
 * dedicated {@link ResourceResolver}.
27
 * </p>
28
 * <p>
29
 * It delegates to a {@link FirstSupportingResolverAdapter} the link between
30
 * {@link ResourceResolver} and the {@link ITemplateResolver} implementation to
31
 * use with the given path.
32
 * </p>
33
 * 
34
 * @author Cyril Dejonghe
35
 * @see FirstSupportingResourceResolver
36
 * @see FirstSupportingResolverAdapter
37
 *
38
 */
39
public class ThymeLeafV3FirstSupportingTemplateResolver implements ITemplateResolver {
40
41
	private FirstSupportingResourceResolver resolver;
42
	private FirstSupportingResolverAdapter resolverAdapter;
43
44
	public ThymeLeafV3FirstSupportingTemplateResolver(FirstSupportingResourceResolver resolver, FirstSupportingResolverAdapter resolverAdapter) {
45
		super();
46
		this.resolver = resolver;
47
		this.resolverAdapter = resolverAdapter;
48
	}
49
50
	@Override
51
	public String getName() {
52 3 1. getName : replaced return value with "" for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::getName → NO_COVERAGE
2. getName : replaced return value with "" for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::getName → SURVIVED
3. getName : replaced return value with "" for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::getName → TIMED_OUT
		return "ThymeLeafFirstSupportingTemplateResolver";
53
	}
54
55
	@Override
56
	public Integer getOrder() {
57
		return 0;
58
	}
59
60
	@Override
61
	public TemplateResolution resolveTemplate(IEngineConfiguration configuration, String ownerTemplate, String template, Map<String, Object> templateResolutionAttributes) {
62
		try {
63
			ResourceResolver supportingResolver = resolver.getSupportingResolver(new UnresolvedPath(template));
64
			ITemplateResolver templateResolver = resolverAdapter.adapt(supportingResolver);
65
			ResolvedPath resourcePath = supportingResolver.resolve(new UnresolvedPath(template));
66
			String resolvedPath = resourcePath.getResolvedPath();
67
			TemplateResolution resolution = templateResolver.resolveTemplate(configuration, ownerTemplate, resolvedPath, templateResolutionAttributes);
68 4 1. resolveTemplate : negated conditional → NO_COVERAGE
2. resolveTemplate : negated conditional → TIMED_OUT
3. resolveTemplate : negated conditional → KILLED
4. resolveTemplate : negated conditional → KILLED
			if(!templateExists(resolution)) {
69
				throw new TemplateResolutionException("Failed to find template "+template+" ("+resolvedPath+")", template, resourcePath);
70
			}
71 4 1. resolveTemplate : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::resolveTemplate → NO_COVERAGE
2. resolveTemplate : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::resolveTemplate → TIMED_OUT
3. resolveTemplate : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::resolveTemplate → KILLED
4. resolveTemplate : replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::resolveTemplate → KILLED
			return resolution;
72
		} catch (NoResolverAdapterException e) {
73
			throw new ResolverAdapterNotFoundException("Unable to resolve template cause no adapter supporting template name '" + template + "' was found.", e);
74
75
		}
76
	}
77
78
	private static boolean templateExists(TemplateResolution resolution) {
79
		// Thymeleaf can check existence of template but only if option is set.
80
		// If set and the template doesn't exist, resolution will be null.
81 4 1. templateExists : negated conditional → NO_COVERAGE
2. templateExists : negated conditional → TIMED_OUT
3. templateExists : negated conditional → KILLED
4. templateExists : negated conditional → KILLED
		if(resolution == null) {
82 1 1. templateExists : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → NO_COVERAGE
			return false;
83
		}
84
		// If option is not set, then check existence manually to be consistent
85
		// with other template engines
86 4 1. templateExists : negated conditional → NO_COVERAGE
2. templateExists : negated conditional → TIMED_OUT
3. templateExists : negated conditional → KILLED
4. templateExists : negated conditional → KILLED
		if(!resolution.isTemplateResourceExistenceVerified()) {
87 8 1. templateExists : replaced boolean return with false for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → NO_COVERAGE
2. templateExists : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → NO_COVERAGE
3. templateExists : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → SURVIVED
4. templateExists : replaced boolean return with false for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → TIMED_OUT
5. templateExists : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → TIMED_OUT
6. templateExists : replaced boolean return with false for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → KILLED
7. templateExists : replaced boolean return with false for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → KILLED
8. templateExists : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → KILLED
			return resolution.getTemplateResource().exists();
88
		}
89 1 1. templateExists : replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → NO_COVERAGE
		return false;
90
	}
91
92
}

Mutations

52

1.1
Location : getName
Killed by : none
replaced return value with "" for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::getName → NO_COVERAGE

2.2
Location : getName
Killed by : none
replaced return value with "" for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::getName → TIMED_OUT

3.3
Location : getName
Killed by : none
replaced return value with "" for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::getName → SURVIVED

68

1.1
Location : resolveTemplate
Killed by : oghamthymeleafv3.it.resolver.StringResourceResolverTest.text(oghamthymeleafv3.it.resolver.StringResourceResolverTest)
negated conditional → KILLED

2.2
Location : resolveTemplate
Killed by : none
negated conditional → TIMED_OUT

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

4.4
Location : resolveTemplate
Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithInvalidResourcePath(oghamall.it.email.EmailMultiTemplateTest)
negated conditional → KILLED

71

1.1
Location : resolveTemplate
Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithInvalidResourcePath(oghamall.it.email.EmailMultiTemplateTest)
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::resolveTemplate → KILLED

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

3.3
Location : resolveTemplate
Killed by : none
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::resolveTemplate → TIMED_OUT

4.4
Location : resolveTemplate
Killed by : oghamthymeleafv3.it.resolver.StringResourceResolverTest.text(oghamthymeleafv3.it.resolver.StringResourceResolverTest)
replaced return value with null for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::resolveTemplate → KILLED

81

1.1
Location : templateExists
Killed by : oghamthymeleafv3.it.resolver.StringResourceResolverTest.text(oghamthymeleafv3.it.resolver.StringResourceResolverTest)
negated conditional → KILLED

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

3.3
Location : templateExists
Killed by : none
negated conditional → TIMED_OUT

4.4
Location : templateExists
Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithInvalidResourcePath(oghamall.it.email.EmailMultiTemplateTest)
negated conditional → KILLED

82

1.1
Location : templateExists
Killed by : none
replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → NO_COVERAGE

86

1.1
Location : templateExists
Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithInvalidResourcePath(oghamall.it.email.EmailMultiTemplateTest)
negated conditional → KILLED

2.2
Location : templateExists
Killed by : oghamthymeleafv3.it.resolver.StringResourceResolverTest.text(oghamthymeleafv3.it.resolver.StringResourceResolverTest)
negated conditional → KILLED

3.3
Location : templateExists
Killed by : none
negated conditional → TIMED_OUT

4.4
Location : templateExists
Killed by : none
negated conditional → NO_COVERAGE

87

1.1
Location : templateExists
Killed by : none
replaced boolean return with false for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → TIMED_OUT

2.2
Location : templateExists
Killed by : none
replaced boolean return with false for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → NO_COVERAGE

3.3
Location : templateExists
Killed by : oghamall.it.email.EmailMultiTemplateTest.withThymeleafOneVariantWithInvalidResourcePath(oghamall.it.email.EmailMultiTemplateTest)
replaced boolean return with false for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → KILLED

4.4
Location : templateExists
Killed by : oghamthymeleafv3.it.resolver.StringResourceResolverTest.text(oghamthymeleafv3.it.resolver.StringResourceResolverTest)
replaced boolean return with false for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → KILLED

5.5
Location : templateExists
Killed by : none
replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → TIMED_OUT

6.6
Location : templateExists
Killed by : none
replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → NO_COVERAGE

7.7
Location : templateExists
Killed by : oghamthymeleafv3.it.ExternalFileTest.fileNotFound(oghamthymeleafv3.it.ExternalFileTest)
replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → KILLED

8.8
Location : templateExists
Killed by : none
replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → SURVIVED

89

1.1
Location : templateExists
Killed by : none
replaced boolean return with true for fr/sii/ogham/template/thymeleaf/v3/ThymeLeafV3FirstSupportingTemplateResolver::templateExists → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM