Skip to content

Commit 3d131db

Browse files
jbescosjansupol
authored andcommitted
JerseyTest is not compatible with JUnit 5
Signed-off-by: Jorge Bescos Gascon <[email protected]>
1 parent 209b6a2 commit 3d131db

File tree

6 files changed

+125
-2
lines changed

6 files changed

+125
-2
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,12 @@
19691969
<version>4.13.1</version>
19701970
<scope>test</scope>
19711971
</dependency>
1972+
<dependency>
1973+
<groupId>org.junit.jupiter</groupId>
1974+
<artifactId>junit-jupiter</artifactId>
1975+
<version>${junit5.version}</version>
1976+
<scope>test</scope>
1977+
</dependency>
19721978
<dependency>
19731979
<groupId>org.junit.jupiter</groupId>
19741980
<artifactId>junit-jupiter-engine</artifactId>

test-framework/core/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@
6969
<artifactId>testng</artifactId>
7070
<scope>provided</scope>
7171
</dependency>
72+
<dependency>
73+
<groupId>org.junit.jupiter</groupId>
74+
<artifactId>junit-jupiter</artifactId>
75+
<scope>provided</scope>
76+
</dependency>
7277
</dependencies>
7378

7479
<profiles>

test-framework/core/src/main/java/org/glassfish/jersey/test/JerseyTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -55,6 +55,8 @@
5555

5656
import org.junit.After;
5757
import org.junit.Before;
58+
import org.junit.jupiter.api.AfterEach;
59+
import org.junit.jupiter.api.BeforeEach;
5860

5961
/**
6062
* Parent class for testing JAX-RS and Jersey-based applications using Jersey test framework.
@@ -614,6 +616,7 @@ public final Client client() {
614616
* @throws Exception if an exception is thrown during setting up the test environment.
615617
*/
616618
@Before
619+
@BeforeEach
617620
public void setUp() throws Exception {
618621
final TestContainer testContainer = createTestContainer(context);
619622

@@ -634,6 +637,7 @@ public void setUp() throws Exception {
634637
* @throws Exception if an exception is thrown during tearing down the test environment.
635638
*/
636639
@After
640+
@AfterEach
637641
public void tearDown() throws Exception {
638642
if (isLogRecordingEnabled()) {
639643
unregisterLogHandler();

tests/integration/jersey-3662/pom.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v. 2.0, which is available at
8+
http://www.eclipse.org/legal/epl-2.0.
9+
10+
This Source Code may also be made available under the following Secondary
11+
Licenses when the conditions for such availability set forth in the
12+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
13+
version 2 with the GNU Classpath Exception, which is available at
14+
https://www.gnu.org/software/classpath/license.html.
15+
16+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17+
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<parent>
23+
<artifactId>project</artifactId>
24+
<groupId>org.glassfish.jersey.tests.integration</groupId>
25+
<version>2.35-SNAPSHOT</version>
26+
</parent>
27+
<modelVersion>4.0.0</modelVersion>
28+
29+
<description>
30+
Reproducer of JERSEY-3662
31+
</description>
32+
33+
<artifactId>jersey-3662</artifactId>
34+
35+
<dependencies>
36+
37+
<dependency>
38+
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
39+
<artifactId>jersey-test-framework-provider-grizzly2</artifactId>
40+
<version>${project.version}</version>
41+
<exclusions>
42+
<exclusion>
43+
<groupId>junit</groupId>
44+
<artifactId>junit</artifactId>
45+
</exclusion>
46+
</exclusions>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.junit.jupiter</groupId>
50+
<artifactId>junit-jupiter</artifactId>
51+
<scope>test</scope>
52+
</dependency>
53+
</dependencies>
54+
55+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package org.glassfish.jersey.tests.integration.jersey3662;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
21+
import javax.ws.rs.GET;
22+
import javax.ws.rs.Path;
23+
import javax.ws.rs.core.Application;
24+
import javax.ws.rs.core.Response;
25+
26+
import org.glassfish.jersey.server.ResourceConfig;
27+
import org.glassfish.jersey.test.JerseyTest;
28+
import org.junit.jupiter.api.Test;
29+
30+
public class Junit5Test extends JerseyTest {
31+
32+
@Path("test")
33+
public static class TestResource {
34+
@GET
35+
public String get() {
36+
return "test";
37+
}
38+
}
39+
40+
@Override
41+
protected Application configure() {
42+
return new ResourceConfig(TestResource.class);
43+
}
44+
45+
@Test
46+
public void success() {
47+
Response response = target().path("test").request().get();
48+
assertEquals(200, response.getStatus());
49+
assertEquals("test", response.readEntity(String.class));
50+
}
51+
52+
}

tests/integration/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
<module>jersey-2846</module>
8080
<module>jersey-2878</module>
8181
<module>jersey-2892</module>
82-
<module>jersey-3796</module>
82+
<module>jersey-3662</module>
83+
<module>jersey-3796</module>
8384
<module>jersey-780</module>
8485
<module>jersey-3670</module>
8586
<module>jersey-3992</module>

0 commit comments

Comments
 (0)