Skip to content

Commit

Permalink
[RESTEASY-3477] Migrate the resteasy-netty4-cdi to JUnit 5.
Browse files Browse the repository at this point in the history
https://issues.redhat.com/browse/RESTEASY-3477
Signed-off-by: James R. Perkins <jperkins@redhat.com>
  • Loading branch information
jamezp committed Mar 22, 2024
1 parent a4f1e8f commit 84f5c38
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
9 changes: 4 additions & 5 deletions server-adapters/resteasy-netty4-cdi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@
</dependency>

<!-- Test dependencies -->
<!-- Have to stay on Junit4 for this module due to arquillian dependency. see issue https://issues.redhat.com/browse/RESTEASY-3398-->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -73,8 +72,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<groupId>org.jboss.arquillian.junit5</groupId>
<artifactId>arquillian-junit5-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import jakarta.ws.rs.core.Response;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit5.ArquillianExtension;
import org.jboss.jandex.Index;
import org.jboss.resteasy.cdi.CdiInjectorFactory;
import org.jboss.resteasy.core.ResteasyDeploymentImpl;
Expand All @@ -15,20 +15,20 @@
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Created by John.Ament on 2/23/14.
*/
@RunWith(Arquillian.class)
@ExtendWith(ArquillianExtension.class)
public class CdiNettyTest {

private CdiNettyJaxrsServer server;
private int port;
private static CdiNettyJaxrsServer server;
private static int port;

@Deployment
public static JavaArchive createArchive() {
Expand All @@ -46,10 +46,10 @@ public static JavaArchive createArchive() {
.addAsManifestResource(new StringAsset(beans), "beans.xml");
}

@Before
public void init() throws Exception {
@BeforeAll
public static void init() throws Exception {
while (port < 8000)
this.port = (int) ((new Random().nextDouble() * 8000) + 1000);
port = (int) ((new Random().nextDouble() * 8000) + 1000);
CdiNettyJaxrsServer netty = new CdiNettyJaxrsServer();
ResteasyDeployment rd = new ResteasyDeploymentImpl();
final ResourceScanner scanner = ResourceScanner.of(Index.of(EchoResource.class, DefaultExceptionMapper.class));
Expand All @@ -60,25 +60,25 @@ public void init() throws Exception {
netty.setPort(port);
netty.setRootResourcePath("/api");
netty.start();
this.server = netty;
server = netty;
}

@After
public void shutdown() {
this.server.stop();
@AfterAll
public static void shutdown() {
server.stop();
}

@Test
public void testLoadSuccess() {
String value = ClientBuilder.newClient().target("http://localhost:" + port)
.path("/api/echo").queryParam("name", "Bob").request().buildGet().invoke(String.class);
Assert.assertEquals("Hello, Bob!", value);
Assertions.assertEquals("Hello, Bob!", value);
}

@Test
public void testLoadFailure() {
Response response = ClientBuilder.newClient().target("http://localhost:" + port)
.path("/api/echo").queryParam("name", "null").request().buildGet().invoke();
Assert.assertEquals(406, response.getStatus());
Assertions.assertEquals(406, response.getStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import jakarta.ws.rs.core.Response;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit5.ArquillianExtension;
import org.jboss.jandex.Index;
import org.jboss.resteasy.cdi.CdiInjectorFactory;
import org.jboss.resteasy.cdi.ResteasyCdiExtension;
Expand All @@ -17,20 +17,20 @@
import org.jboss.resteasy.spi.ResteasyDeployment;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Test for cdi2.0 api SeContainer
*/
@RunWith(Arquillian.class)
@ExtendWith(ArquillianExtension.class)
public class SeCdiNettyTest {

private CdiNettyJaxrsServer server;
private int port;
private static CdiNettyJaxrsServer server;
private static int port;

@Deployment
public static JavaArchive createArchive() {
Expand All @@ -40,10 +40,10 @@ public static JavaArchive createArchive() {
}

@SuppressWarnings("unchecked")
@Before
public void init() throws Exception {
@BeforeAll
public static void init() throws Exception {
while (port < 8000)
this.port = (int) ((new Random().nextDouble() * 8000) + 1000);
port = (int) ((new Random().nextDouble() * 8000) + 1000);
SeContainerInitializer initializer = SeContainerInitializer.newInstance();

SeContainer container = initializer.disableDiscovery().addBeanClasses(EchoResource.class)
Expand All @@ -59,25 +59,25 @@ public void init() throws Exception {
netty.setPort(port);
netty.setRootResourcePath("/api");
netty.start();
this.server = netty;
server = netty;
}

@After
public void shutdown() {
this.server.stop();
@AfterAll
public static void shutdown() {
server.stop();
}

@Test
public void testLoadSuccess() {
String value = ClientBuilder.newClient().target("http://localhost:" + port)
.path("/api/echo").queryParam("name", "Bob").request().buildGet().invoke(String.class);
Assert.assertEquals("Hello, Bob!", value);
Assertions.assertEquals("Hello, Bob!", value);
}

@Test
public void testLoadFailure() {
Response response = ClientBuilder.newClient().target("http://localhost:" + port)
.path("/api/echo").queryParam("name", "null").request().buildGet().invoke();
Assert.assertEquals(406, response.getStatus());
Assertions.assertEquals(406, response.getStatus());
}
}

0 comments on commit 84f5c38

Please sign in to comment.