Skip to content

Commit fe31720

Browse files
Spring7 mock mvc55x backport (#1856)
* Spring Framework 7 runtime support (#1852) * feat: Added support for spring-web7 * feat: Added support for spring-web7, fixed missing reflections * feat: added spring7 jdk17 build (cherry picked from commit 08811b4) * Backports runtime support of Spring 7 * Removed the accidental duplicate check property extraction
1 parent d3fa59c commit fe31720

24 files changed

Lines changed: 1877 additions & 40 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
java-version: ${{ matrix.java }}
2929
distribution: 'zulu'
3030
- name: Verify with Maven
31-
run: mvn verify -B
31+
run: mvn verify -B -Pspring7

examples/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,11 @@
4444
<module>rest-assured-itest-java-osgi</module>
4545
</modules>
4646
</profile>
47+
<profile>
48+
<id>spring7</id>
49+
<modules>
50+
<module>spring7-mvc-webapp</module>
51+
</modules>
52+
</profile>
4753
</profiles>
4854
</project>
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2019 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<parent>
21+
<groupId>io.rest-assured.examples</groupId>
22+
<artifactId>example-parent</artifactId>
23+
<version>5.5.7-SNAPSHOT</version>
24+
</parent>
25+
<modelVersion>4.0.0</modelVersion>
26+
27+
<artifactId>spring7-mvc-webapp</artifactId>
28+
<packaging>war</packaging>
29+
<name>Spring7 MVC example</name>
30+
<description>Spring7 MVC example that's used for integration testing rest-assured</description>
31+
32+
<properties>
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
<junit-bom.version>6.0.1</junit-bom.version>
35+
<logback.version>1.4.14</logback.version>
36+
<spring.version>7.0.1</spring.version>
37+
<spring.security.version>6.5.7</spring.security.version>
38+
<jetty.version>11.0.26</jetty.version>
39+
40+
<duplicate-finder-mavwen-plugin.phase>none</duplicate-finder-mavwen-plugin.phase>
41+
</properties>
42+
43+
<dependencyManagement>
44+
<dependencies>
45+
<dependency>
46+
<groupId>org.junit</groupId>
47+
<artifactId>junit-bom</artifactId>
48+
<version>${junit-bom.version}</version>
49+
<type>pom</type>
50+
<scope>import</scope>
51+
</dependency>
52+
</dependencies>
53+
</dependencyManagement>
54+
55+
<build>
56+
<plugins>
57+
<plugin>
58+
<groupId>org.apache.maven.plugins</groupId>
59+
<artifactId>maven-war-plugin</artifactId>
60+
<version>3.5.1</version>
61+
<configuration>
62+
<failOnMissingWebXml>false</failOnMissingWebXml>
63+
</configuration>
64+
</plugin>
65+
<plugin>
66+
<artifactId>maven-surefire-plugin</artifactId>
67+
<version>3.5.4</version>
68+
</plugin>
69+
</plugins>
70+
</build>
71+
72+
73+
<dependencies>
74+
<!-- Test -->
75+
<dependency>
76+
<groupId>io.rest-assured</groupId>
77+
<artifactId>spring-mock-mvc</artifactId>
78+
<version>5.5.7-SNAPSHOT</version>
79+
<scope>test</scope>
80+
<exclusions>
81+
<exclusion>
82+
<groupId>org.springframework</groupId>
83+
<artifactId>*</artifactId>
84+
</exclusion>
85+
</exclusions>
86+
</dependency>
87+
<dependency>
88+
<groupId>org.junit.jupiter</groupId>
89+
<artifactId>junit-jupiter</artifactId>
90+
<scope>test</scope>
91+
</dependency>
92+
<dependency>
93+
<groupId>ch.qos.logback</groupId>
94+
<artifactId>logback-classic</artifactId>
95+
<version>${logback.version}</version>
96+
<scope>test</scope>
97+
</dependency>
98+
<dependency>
99+
<groupId>org.eclipse.jetty</groupId>
100+
<artifactId>jetty-webapp</artifactId>
101+
<version>${jetty.version}</version>
102+
<scope>test</scope>
103+
</dependency>
104+
<dependency>
105+
<groupId>org.springframework.security</groupId>
106+
<artifactId>spring-security-test</artifactId>
107+
<version>${spring.security.version}</version>
108+
<exclusions>
109+
<exclusion>
110+
<groupId>org.springframework</groupId>
111+
<artifactId>spring-core</artifactId>
112+
</exclusion>
113+
</exclusions>
114+
<scope>test</scope>
115+
</dependency>
116+
<dependency>
117+
<groupId>org.eclipse.jetty</groupId>
118+
<artifactId>jetty-annotations</artifactId>
119+
<version>${jetty.version}</version>
120+
<scope>test</scope>
121+
</dependency>
122+
<!-- Jakarta EE 8 -->
123+
<dependency>
124+
<groupId>javax.xml.bind</groupId>
125+
<artifactId>jaxb-api</artifactId>
126+
<scope>test</scope>
127+
</dependency>
128+
<dependency>
129+
<groupId>com.sun.xml.bind</groupId>
130+
<artifactId>jaxb-impl</artifactId>
131+
<scope>test</scope>
132+
</dependency>
133+
<!-- Jakarta EE 9 -->
134+
<dependency>
135+
<groupId>jakarta.xml.bind</groupId>
136+
<artifactId>jakarta.xml.bind-api</artifactId>
137+
<scope>test</scope>
138+
</dependency>
139+
<dependency>
140+
<groupId>org.glassfish.jaxb</groupId>
141+
<artifactId>jaxb-runtime</artifactId>
142+
<scope>test</scope>
143+
</dependency>
144+
145+
<dependency>
146+
<groupId>jakarta.servlet</groupId>
147+
<artifactId>jakarta.servlet-api</artifactId>
148+
<version>6.1.0</version>
149+
<scope>provided</scope>
150+
</dependency>
151+
<dependency>
152+
<groupId>org.springframework</groupId>
153+
<artifactId>spring-webmvc</artifactId>
154+
<version>${spring.version}</version>
155+
</dependency>
156+
<!-- Spring Security -->
157+
<dependency>
158+
<groupId>org.springframework.security</groupId>
159+
<artifactId>spring-security-web</artifactId>
160+
<version>${spring.security.version}</version>
161+
</dependency>
162+
<dependency>
163+
<groupId>org.springframework.security</groupId>
164+
<artifactId>spring-security-config</artifactId>
165+
<version>${spring.security.version}</version>
166+
<exclusions>
167+
<exclusion>
168+
<groupId>org.springframework</groupId>
169+
<artifactId>spring-aop</artifactId>
170+
</exclusion>
171+
</exclusions>
172+
</dependency>
173+
<dependency>
174+
<groupId>org.springframework</groupId>
175+
<artifactId>spring-aop</artifactId>
176+
<version>${spring.version}</version>
177+
</dependency>
178+
179+
<!-- File Upload -->
180+
<dependency>
181+
<groupId>commons-fileupload</groupId>
182+
<artifactId>commons-fileupload</artifactId>
183+
<version>1.3.3</version>
184+
</dependency>
185+
<dependency>
186+
<groupId>commons-io</groupId>
187+
<artifactId>commons-io</artifactId>
188+
<version>2.8.0</version>
189+
</dependency>
190+
191+
<dependency>
192+
<groupId>com.fasterxml.jackson.core</groupId>
193+
<artifactId>jackson-databind</artifactId>
194+
<version>${jackson2.version}</version>
195+
<scope>test</scope>
196+
</dependency>
197+
</dependencies>
198+
199+
<profiles>
200+
<profile>
201+
<id>dev</id>
202+
<build>
203+
<plugins>
204+
<plugin>
205+
<groupId>org.eclipse.jetty</groupId>
206+
<artifactId>jetty-maven-plugin</artifactId>
207+
<configuration>
208+
<stopKey>foo</stopKey>
209+
<stopPort>1.8079</stopPort>
210+
</configuration>
211+
</plugin>
212+
</plugins>
213+
</build>
214+
</profile>
215+
</profiles>
216+
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.restassured.examples.springmvc.config;
18+
19+
import io.restassured.examples.springmvc.controller.FileUploadController;
20+
import org.springframework.context.annotation.Bean;
21+
import org.springframework.context.annotation.ComponentScan;
22+
import org.springframework.context.annotation.Configuration;
23+
import org.springframework.context.annotation.Import;
24+
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
25+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
26+
27+
@Configuration
28+
@EnableWebMvc
29+
@ComponentScan(basePackageClasses = FileUploadController.class)
30+
@Import(SecurityConfiguration.class)
31+
public class MainConfiguration {
32+
33+
@Bean
34+
public StandardServletMultipartResolver multipartResolver() {
35+
return new StandardServletMultipartResolver();
36+
}
37+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.restassured.examples.springmvc.config;
18+
19+
import org.springframework.context.annotation.Bean;
20+
import org.springframework.context.annotation.Configuration;
21+
import org.springframework.security.config.Customizer;
22+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
23+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
24+
import org.springframework.security.core.userdetails.User;
25+
import org.springframework.security.core.userdetails.UserDetails;
26+
import org.springframework.security.core.userdetails.UserDetailsService;
27+
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
28+
import org.springframework.security.crypto.password.PasswordEncoder;
29+
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
30+
import org.springframework.security.web.SecurityFilterChain;
31+
32+
@Configuration
33+
@EnableWebSecurity
34+
public class SecurityConfiguration {
35+
36+
public static final String ROLE_USER = "USER";
37+
38+
@Bean
39+
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
40+
http.authorizeHttpRequests(auth -> auth
41+
.requestMatchers("/secured/**").hasRole(ROLE_USER)
42+
.anyRequest().permitAll()
43+
).httpBasic(Customizer.withDefaults());
44+
45+
return http.build();
46+
}
47+
48+
@Bean
49+
public UserDetailsService userDetailsService(PasswordEncoder passwordEncoder) {
50+
UserDetails user = User.builder()
51+
.username("username")
52+
.password(passwordEncoder.encode("password"))
53+
.roles(ROLE_USER)
54+
.build();
55+
return new InMemoryUserDetailsManager(user);
56+
}
57+
58+
@Bean
59+
public PasswordEncoder passwordEncoder() {
60+
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
61+
}
62+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.restassured.examples.springmvc.config;
18+
19+
import jakarta.servlet.MultipartConfigElement;
20+
import jakarta.servlet.ServletRegistration;
21+
22+
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
23+
24+
public class WebApp extends AbstractAnnotationConfigDispatcherServletInitializer {
25+
@Override
26+
protected Class<?>[] getRootConfigClasses() {
27+
return new Class<?>[0];
28+
}
29+
30+
@Override
31+
protected Class<?>[] getServletConfigClasses() {
32+
return new Class<?>[]{MainConfiguration.class};
33+
}
34+
35+
@Override
36+
protected String[] getServletMappings() {
37+
return new String[]{"/"};
38+
}
39+
40+
@Override
41+
protected void customizeRegistration(ServletRegistration.Dynamic registration) {
42+
registration.setMultipartConfig(new MultipartConfigElement(""));
43+
}
44+
}

0 commit comments

Comments
 (0)