Skip to content

Commit 5b7d139

Browse files
authored
Convert maintained JAX-RS samples to JUnit 5 (#24173)
* Convert maintained JAX-RS samples to JUnit 5 Use JUnit Jupiter Engine 5.14.4 for generated non-Spring tests and update generated Surefire/Failsafe plugin declarations to 3.5.6 so Maven runs the JUnit Platform tests instead of silently ignoring them. Keep the old Spring Boot CXF server path on JUnit 4 because Spring Boot 1.5 / Spring Framework 4.3 is not compatible with the JUnit Jupiter SpringExtension. Do not force Java 8 compiler settings into the CXF client POM template because the useJackson3 branch depends on CXF 4.2.0 and Jackson 3.1.2, which require a newer JDK. Users on very old JVM/compiler defaults will need to configure their build. Leave the unmaintained generator outputs and templates out of this conversion, including java-pkmst and cxf-ext. * Align generated JUnit 5 sample POMs
1 parent ca63448 commit 5b7d139

59 files changed

Lines changed: 295 additions & 197 deletions

File tree

Some content is hidden

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

modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pom.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@
417417
<jakarta-annotation-version>1.3.5</jakarta-annotation-version>
418418
<beanvalidation-version>2.0.2</beanvalidation-version>
419419
{{/useJakartaEe}}
420-
<junit-version>5.10.0</junit-version>
420+
<junit-version>5.14.4</junit-version>
421421
{{#hasHttpSignatureMethods}}
422422
<http-signature-version>1.8</http-signature-version>
423423
{{/hasHttpSignatureMethods}}

modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/api_test.mustache

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ package {{package}};
44

55
{{#imports}}import {{import}};
66
{{/imports}}
7+
{{#generateSpringBootApplication}}
78
import org.junit.Test;
89
import org.junit.Before;
910
import static org.junit.Assert.*;
11+
{{/generateSpringBootApplication}}
12+
{{^generateSpringBootApplication}}
13+
import org.junit.jupiter.api.Test;
14+
import org.junit.jupiter.api.BeforeEach;
15+
import static org.junit.jupiter.api.Assertions.*;
16+
{{/generateSpringBootApplication}}
1017

1118
{{#useBeanValidation}}
1219
import {{javaxPackage}}.validation.Valid;
@@ -78,7 +85,7 @@ public class {{classname}}Test {
7885

7986
private {{classname}} api;
8087

81-
@Before
88+
{{#generateSpringBootApplication}}@Before{{/generateSpringBootApplication}}{{^generateSpringBootApplication}}@BeforeEach{{/generateSpringBootApplication}}
8289
public void setup() {
8390
JacksonJsonProvider provider = new JacksonJsonProvider();
8491
List providers = new ArrayList();

modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/pom.mustache

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
<build>
2121
<sourceDirectory>src/main/java</sourceDirectory>
2222
<plugins>
23+
<plugin>
24+
<artifactId>maven-surefire-plugin</artifactId>
25+
<version>3.5.6</version>
26+
</plugin>
2327
<plugin>
2428
<artifactId>maven-failsafe-plugin</artifactId>
25-
<version>2.6</version>
29+
<version>3.5.6</version>
2630
<executions>
2731
<execution>
2832
<goals>
@@ -147,8 +151,8 @@ for this project used jakarta.validation-api -->
147151
<scope>compile</scope>
148152
</dependency>
149153
<dependency>
150-
<groupId>junit</groupId>
151-
<artifactId>junit</artifactId>
154+
<groupId>org.junit.jupiter</groupId>
155+
<artifactId>junit-jupiter-engine</artifactId>
152156
<version>${junit-version}</version>
153157
<scope>test</scope>
154158
</dependency>
@@ -253,7 +257,7 @@ for this project used jakarta.validation-api -->
253257
<swagger-annotations-version>2.2.7</swagger-annotations-version>
254258
{{/swagger2AnnotationLibrary}}
255259
<jetty-version>9.2.9.v20150224</jetty-version>
256-
<junit-version>4.13.2</junit-version>
260+
<junit-version>5.14.4</junit-version>
257261
<logback-version>1.5.33</logback-version>
258262
{{#useBeanValidation}}
259263
<beanvalidation-version>2.0.2</beanvalidation-version>

modules/openapi-generator/src/main/resources/JavaJaxRS/cxf/server/pom.mustache

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
<build>
2121
<sourceDirectory>src/main/java</sourceDirectory>
2222
<plugins>
23+
<plugin>
24+
<artifactId>maven-surefire-plugin</artifactId>
25+
<version>3.5.6</version>
26+
</plugin>
2327
<plugin>
2428
<artifactId>maven-failsafe-plugin</artifactId>
25-
<version>2.6</version>
29+
<version>3.5.6</version>
2630
<executions>
2731
<execution>
2832
<goals>
@@ -156,8 +160,8 @@ for this project used jakarta.validation-api -->
156160
<scope>compile</scope>
157161
</dependency>
158162
<dependency>
159-
<groupId>junit</groupId>
160-
<artifactId>junit</artifactId>
163+
<groupId>org.junit.jupiter</groupId>
164+
<artifactId>junit-jupiter-engine</artifactId>
161165
<version>${junit-version}</version>
162166
<scope>test</scope>
163167
</dependency>
@@ -310,7 +314,7 @@ for this project used jakarta.validation-api -->
310314
<swagger-annotations-version>2.2.7</swagger-annotations-version>
311315
{{/swagger2AnnotationLibrary}}
312316
<jetty-version>9.2.9.v20150224</jetty-version>
313-
<junit-version>4.13.2</junit-version>
317+
<junit-version>5.14.4</junit-version>
314318
<logback-version>1.5.33</logback-version>
315319
{{#useBeanValidation}}
316320
<beanvalidation-version>2.0.2</beanvalidation-version>

modules/openapi-generator/src/main/resources/JavaJaxRS/libraries/jersey3/pom.mustache

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@
2929
<artifactId>maven-war-plugin</artifactId>
3030
<version>3.1.0</version>
3131
</plugin>
32+
<plugin>
33+
<artifactId>maven-surefire-plugin</artifactId>
34+
<version>3.5.6</version>
35+
</plugin>
3236
<plugin>
3337
<artifactId>maven-failsafe-plugin</artifactId>
34-
<version>2.6</version>
38+
<version>3.5.6</version>
3539
<executions>
3640
<execution>
3741
<goals>
@@ -138,8 +142,8 @@
138142
<scope>compile</scope>
139143
</dependency>
140144
<dependency>
141-
<groupId>junit</groupId>
142-
<artifactId>junit</artifactId>
145+
<groupId>org.junit.jupiter</groupId>
146+
<artifactId>junit-jupiter-engine</artifactId>
143147
<version>${junit-version}</version>
144148
<scope>test</scope>
145149
</dependency>
@@ -221,7 +225,7 @@
221225
<jetty-version>11.0.15</jetty-version>
222226
<jersey3-version>3.1.3</jersey3-version>
223227
<jackson-version>2.17.1</jackson-version>
224-
<junit-version>4.13.2</junit-version>
228+
<junit-version>5.14.4</junit-version>
225229
<logback-version>1.5.33</logback-version>
226230
<servlet-api-version>5.0.0</servlet-api-version>
227231
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

modules/openapi-generator/src/main/resources/JavaJaxRS/pom.mustache

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@
3030
<artifactId>maven-war-plugin</artifactId>
3131
<version>3.1.0</version>
3232
</plugin>
33+
<plugin>
34+
<artifactId>maven-surefire-plugin</artifactId>
35+
<version>3.5.6</version>
36+
</plugin>
3337
<plugin>
3438
<artifactId>maven-failsafe-plugin</artifactId>
35-
<version>2.6</version>
39+
<version>3.5.6</version>
3640
<executions>
3741
<execution>
3842
<goals>
@@ -138,8 +142,8 @@ for this project used jakarta.validation-api -->
138142
<scope>compile</scope>
139143
</dependency>
140144
<dependency>
141-
<groupId>junit</groupId>
142-
<artifactId>junit</artifactId>
145+
<groupId>org.junit.jupiter</groupId>
146+
<artifactId>junit-jupiter-engine</artifactId>
143147
<version>${junit-version}</version>
144148
<scope>test</scope>
145149
</dependency>
@@ -221,7 +225,7 @@ for this project used jakarta.validation-api -->
221225
<jetty-version>9.2.9.v20150224</jetty-version>
222226
<jersey2-version>2.35</jersey2-version>
223227
<jackson-version>2.17.1</jackson-version>
224-
<junit-version>4.13.2</junit-version>
228+
<junit-version>5.14.4</junit-version>
225229
<logback-version>1.5.33</logback-version>
226230
<servlet-api-version>4.0.4</servlet-api-version>
227231
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

modules/openapi-generator/src/main/resources/JavaJaxRS/spec/libraries/thorntail/pom.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<properties>
2020
<version.thorntail>2.5.0.Final</version.thorntail>
21-
<version.junit>4.8.1</version.junit>
21+
<version.junit>5.14.4</version.junit>
2222
<maven.compiler.source>1.8</maven.compiler.source>
2323
<maven.compiler.target>1.8</maven.compiler.target>
2424
<failOnMissingWebXml>false</failOnMissingWebXml>
@@ -45,8 +45,8 @@
4545
<artifactId>microprofile-openapi</artifactId>
4646
</dependency>
4747
<dependency>
48-
<groupId>junit</groupId>
49-
<artifactId>junit</artifactId>
48+
<groupId>org.junit.jupiter</groupId>
49+
<artifactId>junit-jupiter-engine</artifactId>
5050
<version>${version.junit}</version>
5151
<scope>test</scope>
5252
</dependency>

modules/openapi-generator/src/main/resources/JavaJaxRS/spec/pom.mustache

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,13 @@
5252
<failOnMissingWebXml>false</failOnMissingWebXml>
5353
</configuration>
5454
</plugin>
55+
<plugin>
56+
<artifactId>maven-surefire-plugin</artifactId>
57+
<version>3.5.6</version>
58+
</plugin>
5559
<plugin>
5660
<artifactId>maven-failsafe-plugin</artifactId>
57-
<version>2.6</version>
61+
<version>3.5.6</version>
5862
<executions>
5963
<execution>
6064
<goals>
@@ -135,8 +139,8 @@
135139
<version>3.0.2</version>
136140
</dependency>
137141
<dependency>
138-
<groupId>junit</groupId>
139-
<artifactId>junit</artifactId>
142+
<groupId>org.junit.jupiter</groupId>
143+
<artifactId>junit-jupiter-engine</artifactId>
140144
<version>${junit-version}</version>
141145
<scope>test</scope>
142146
</dependency>
@@ -185,7 +189,7 @@
185189
<maven.compiler.target>${java.version}</maven.compiler.target>
186190
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
187191
<jackson-version>2.19.2</jackson-version>
188-
<junit-version>4.13.2</junit-version>
192+
<junit-version>5.14.4</junit-version>
189193
<joda-version>2.10.13</joda-version>
190194
{{#useJakartaEe}}
191195
<javax.annotation-api-version>2.1.1</javax.annotation-api-version>

samples/client/others/java/jersey2-oneOf-Mixed/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@
336336
<jackson-databind-nullable-version>0.2.10</jackson-databind-nullable-version>
337337
<jakarta-annotation-version>1.3.5</jakarta-annotation-version>
338338
<beanvalidation-version>2.0.2</beanvalidation-version>
339-
<junit-version>5.10.0</junit-version>
339+
<junit-version>5.14.4</junit-version>
340340
<spotless.version>2.21.0</spotless.version>
341341
</properties>
342342
</project>

samples/client/others/java/jersey2-oneOf-duplicates/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@
336336
<jackson-databind-nullable-version>0.2.10</jackson-databind-nullable-version>
337337
<jakarta-annotation-version>1.3.5</jakarta-annotation-version>
338338
<beanvalidation-version>2.0.2</beanvalidation-version>
339-
<junit-version>5.10.0</junit-version>
339+
<junit-version>5.14.4</junit-version>
340340
<spotless.version>2.21.0</spotless.version>
341341
</properties>
342342
</project>

0 commit comments

Comments
 (0)