WebExpressionContextProvider.java

1
package fr.sii.ogham.spring.v3.template.thymeleaf;
2
3
import java.util.Map;
4
5
import org.springframework.context.ApplicationContext;
6
import org.thymeleaf.IEngineConfiguration;
7
import org.thymeleaf.ITemplateEngine;
8
import org.thymeleaf.context.IContext;
9
import org.thymeleaf.context.WebExpressionContext;
10
import org.thymeleaf.web.servlet.IServletWebExchange;
11
import org.thymeleaf.web.servlet.JakartaServletWebApplication;
12
13
import fr.sii.ogham.core.template.context.Context;
14
import fr.sii.ogham.spring.template.thymeleaf.ThymeleafWebContextProvider;
15
import fr.sii.ogham.spring.util.compat.HttpServletRequestWrapper;
16
import fr.sii.ogham.spring.util.compat.HttpServletResponseWrapper;
17
import fr.sii.ogham.spring.util.compat.ServletContextWrapper;
18
import jakarta.servlet.ServletContext;
19
import jakarta.servlet.http.HttpServletRequest;
20
import jakarta.servlet.http.HttpServletResponse;
21
22
/**
23
 * Generate an instance of {@link WebExpressionContext} for Thymeleaf v3 with Spring 6.
24
 *
25
 * This is used to mimic the behavior of {@link org.thymeleaf.spring6.view.ThymeleafView} in order to give
26
 * access to {@link HttpServletRequest}, {@link HttpServletResponse} and
27
 * {@link ServletContext} from templates.
28
 *
29
 * @author Aurélien Baudet
30
 *
31
 */
32
public class WebExpressionContextProvider implements ThymeleafWebContextProvider {
33
	private final ITemplateEngine viewTemplateEngine;
34
35
	public WebExpressionContextProvider(ITemplateEngine viewTemplateEngine) {
36
		super();
37
		this.viewTemplateEngine = viewTemplateEngine;
38
	}
39
40
	@Override
41
	public IContext getWebContext(Context context, IContext base, HttpServletRequestWrapper request, HttpServletResponseWrapper response, ServletContextWrapper servletContext, ApplicationContext applicationContext,
42
								  Map<String, Object> springModel) {
43
		final IEngineConfiguration configuration = viewTemplateEngine.getConfiguration();
44
		IServletWebExchange exchange = JakartaServletWebApplication.buildApplication(servletContext.get()).buildExchange(request.get(), response.get());
45 1 1. getWebContext : replaced return value with null for fr/sii/ogham/spring/v3/template/thymeleaf/WebExpressionContextProvider::getWebContext → KILLED
		return new WebExpressionContext(configuration, exchange, base.getLocale(), springModel);
46
	}
47
48
}

Mutations

45

1.1
Location : getWebContext
Killed by : oghamspringbootv3autoconfigure.it.SpringWebBeanResolutionTest.[engine:junit-jupiter]/[class:oghamspringbootv3autoconfigure.it.SpringWebBeanResolutionTest]/[method:smsUsingThymeleafTemplateShouldResolveBeansAndUrls()]
replaced return value with null for fr/sii/ogham/spring/v3/template/thymeleaf/WebExpressionContextProvider::getWebContext → KILLED

Active mutators

Tests examined


Report generated by PIT 1.13.1