Skip to content

Commit 12244a8

Browse files
Remove use of Thymeleaf from smoke tests
Closes gh-28788
1 parent 03e283a commit 12244a8

File tree

67 files changed

+237
-791
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+237
-791
lines changed

spring-boot-project/spring-boot-devtools/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ dependencies {
7676
testImplementation("org.springframework:spring-websocket")
7777
testImplementation("org.springframework.hateoas:spring-hateoas")
7878
testImplementation("org.springframework.security:spring-security-test")
79-
testImplementation("org.thymeleaf:thymeleaf")
80-
testImplementation("org.thymeleaf:thymeleaf-spring5")
81-
testImplementation("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect")
79+
testImplementation("org.freemarker:freemarker")
8280

8381
testRuntimeOnly("org.aspectj:aspectjweaver")
8482
testRuntimeOnly("org.yaml:snakeyaml")

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/RemoteUrlPropertyExtractorTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -64,7 +64,6 @@ void multipleUrls() {
6464
void validUrl() {
6565
ApplicationContext context = doTest("http://localhost:8080");
6666
assertThat(context.getEnvironment().getProperty("remoteUrl")).isEqualTo("http://localhost:8080");
67-
assertThat(context.getEnvironment().getProperty("spring.thymeleaf.cache")).isNull();
6867
}
6968

7069
@Test

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,12 +29,11 @@
2929
import org.junit.jupiter.api.AfterEach;
3030
import org.junit.jupiter.api.Test;
3131
import org.junit.jupiter.api.extension.ExtendWith;
32-
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
3332

3433
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
3534
import org.springframework.boot.SpringApplication;
3635
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
37-
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
36+
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
3837
import org.springframework.boot.autoconfigure.web.WebProperties;
3938
import org.springframework.boot.autoconfigure.web.WebProperties.Resources;
4039
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
@@ -55,6 +54,7 @@
5554
import org.springframework.data.redis.connection.RedisConnectionFactory;
5655
import org.springframework.data.redis.core.RedisTemplate;
5756
import org.springframework.test.util.ReflectionTestUtils;
57+
import org.springframework.web.servlet.view.AbstractTemplateViewResolver;
5858

5959
import static org.assertj.core.api.Assertions.assertThat;
6060
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -83,18 +83,11 @@ void cleanup() {
8383
}
8484
}
8585

86-
@Test
87-
void thymeleafCacheIsFalse() throws Exception {
88-
this.context = getContext(() -> initializeAndRun(Config.class));
89-
SpringResourceTemplateResolver resolver = this.context.getBean(SpringResourceTemplateResolver.class);
90-
assertThat(resolver.isCacheable()).isFalse();
91-
}
92-
9386
@Test
9487
void defaultPropertyCanBeOverriddenFromCommandLine() throws Exception {
95-
this.context = getContext(() -> initializeAndRun(Config.class, "--spring.thymeleaf.cache=true"));
96-
SpringResourceTemplateResolver resolver = this.context.getBean(SpringResourceTemplateResolver.class);
97-
assertThat(resolver.isCacheable()).isTrue();
88+
this.context = getContext(() -> initializeAndRun(Config.class, "--spring.freemarker.cache=true"));
89+
AbstractTemplateViewResolver resolver = this.context.getBean(AbstractTemplateViewResolver.class);
90+
assertThat(resolver.isCache()).isTrue();
9891
}
9992

10093
@Test
@@ -103,8 +96,8 @@ void defaultPropertyCanBeOverriddenFromUserHomeProperties() throws Exception {
10396
System.setProperty("user.home", new File("src/test/resources/user-home").getAbsolutePath());
10497
try {
10598
this.context = getContext(() -> initializeAndRun(Config.class));
106-
SpringResourceTemplateResolver resolver = this.context.getBean(SpringResourceTemplateResolver.class);
107-
assertThat(resolver.isCacheable()).isTrue();
99+
AbstractTemplateViewResolver resolver = this.context.getBean(AbstractTemplateViewResolver.class);
100+
assertThat(resolver.isCache()).isTrue();
108101
}
109102
finally {
110103
System.setProperty("user.home", userHome);
@@ -267,7 +260,6 @@ private ConfigurableApplicationContext initializeAndRun(Class<?> config, Map<Str
267260

268261
private Map<String, Object> getDefaultProperties(Map<String, Object> specifiedProperties) {
269262
Map<String, Object> properties = new HashMap<>();
270-
properties.put("spring.thymeleaf.check-template-location", false);
271263
properties.put("spring.devtools.livereload.port", 0);
272264
properties.put("server.port", 0);
273265
properties.putAll(specifiedProperties);
@@ -276,14 +268,14 @@ private Map<String, Object> getDefaultProperties(Map<String, Object> specifiedPr
276268

277269
@Configuration(proxyBeanMethods = false)
278270
@Import({ ServletWebServerFactoryAutoConfiguration.class, LocalDevToolsAutoConfiguration.class,
279-
ThymeleafAutoConfiguration.class })
271+
FreeMarkerAutoConfiguration.class })
280272
static class Config {
281273

282274
}
283275

284276
@Configuration(proxyBeanMethods = false)
285277
@ImportAutoConfiguration({ ServletWebServerFactoryAutoConfiguration.class, LocalDevToolsAutoConfiguration.class,
286-
ThymeleafAutoConfiguration.class })
278+
FreeMarkerAutoConfiguration.class })
287279
static class ConfigWithMockLiveReload {
288280

289281
@Bean
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
spring.thymeleaf.cache=true
1+
spring.freemarker.cache=true

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ configurations {
1313
dependencies {
1414
developmentOnly project(":spring-boot-project:spring-boot-devtools")
1515

16-
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-thymeleaf"))
1716
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))
1817

1918
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,15 +16,9 @@
1616

1717
package smoketest.devtools;
1818

19-
import java.util.Date;
20-
2119
import javax.annotation.PostConstruct;
22-
import javax.servlet.http.HttpSession;
2320

2421
import org.springframework.stereotype.Controller;
25-
import org.springframework.ui.ModelMap;
26-
import org.springframework.web.bind.annotation.GetMapping;
27-
import org.springframework.web.servlet.ModelAndView;
2822

2923
@Controller
3024
public class MyController {
@@ -34,15 +28,4 @@ public void slowRestart() throws InterruptedException {
3428
Thread.sleep(5000);
3529
}
3630

37-
@GetMapping("/")
38-
public ModelAndView get(HttpSession session) {
39-
Object sessionVar = session.getAttribute("var");
40-
if (sessionVar == null) {
41-
sessionVar = new Date();
42-
session.setAttribute("var", sessionVar);
43-
}
44-
ModelMap model = new ModelMap("message", Message.MESSAGE).addAttribute("sessionVar", sessionVar);
45-
return new ModelAndView("hello", model);
46-
}
47-
4831
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-devtools/src/main/resources/templates/hello.html

Lines changed: 0 additions & 23 deletions
This file was deleted.

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ description = "Spring Boot web method security smoke test"
88
dependencies {
99
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator"))
1010
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-security"))
11-
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-thymeleaf"))
1211
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))
1312

1413
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-web-method-security/src/main/java/smoketest/security/method/SampleMethodSecurityApplication.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
1616

1717
package smoketest.security.method;
1818

19-
import java.util.Date;
20-
import java.util.Map;
21-
2219
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
2320
import org.springframework.boot.autoconfigure.SpringBootApplication;
2421
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -32,7 +29,6 @@
3229
import org.springframework.security.core.userdetails.User;
3330
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
3431
import org.springframework.security.web.SecurityFilterChain;
35-
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
3632
import org.springframework.stereotype.Controller;
3733
import org.springframework.web.bind.annotation.GetMapping;
3834
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
@@ -71,17 +67,11 @@ public InMemoryUserDetailsManager inMemoryUserDetailsManager() throws Exception
7167
protected static class ApplicationSecurity {
7268

7369
@Bean
74-
SecurityFilterChain appSecurity(HttpSecurity http) throws Exception {
75-
http.authorizeRequests((requests) -> {
76-
requests.antMatchers("/login").permitAll();
77-
requests.anyRequest().fullyAuthenticated();
78-
});
79-
http.formLogin((form) -> {
80-
form.loginPage("/login");
81-
form.failureUrl("/login?error");
82-
});
83-
http.logout((logout) -> logout.logoutRequestMatcher(new AntPathRequestMatcher("/logout")));
84-
http.exceptionHandling((exceptions) -> exceptions.accessDeniedPage("/access?error"));
70+
SecurityFilterChain configure(HttpSecurity http) throws Exception {
71+
http.csrf().disable();
72+
http.authorizeRequests((requests) -> requests.anyRequest().fullyAuthenticated());
73+
http.formLogin((form) -> form.loginPage("/login").permitAll());
74+
http.exceptionHandling((exceptions) -> exceptions.accessDeniedPage("/access"));
8575
return http.build();
8676
}
8777

@@ -93,6 +83,7 @@ protected static class ActuatorSecurity {
9383

9484
@Bean
9585
SecurityFilterChain actuatorSecurity(HttpSecurity http) throws Exception {
86+
http.csrf().disable();
9687
http.requestMatcher(EndpointRequest.toAnyEndpoint());
9788
http.authorizeRequests((requests) -> requests.anyRequest().authenticated());
9889
http.httpBasic();
@@ -106,10 +97,7 @@ protected static class HomeController {
10697

10798
@GetMapping("/")
10899
@Secured("ROLE_ADMIN")
109-
public String home(Map<String, Object> model) {
110-
model.put("message", "Hello World");
111-
model.put("title", "Hello Home");
112-
model.put("date", new Date());
100+
public String home() {
113101
return "home";
114102
}
115103

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
spring.thymeleaf.cache: false
2-
logging.level.org.springframework.security: INFO
1+
logging.level.org.springframework.security=INFO
32
management.endpoints.web.exposure.include=*
3+
spring.mvc.view.prefix=/templates/
4+
spring.mvc.view.suffix=.html

0 commit comments

Comments
 (0)