-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
73 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
deployment/src/test/java/io/quarkiverse/renarde/test/ExceptionMappers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.quarkiverse.renarde.test; | ||
|
||
import java.net.URL; | ||
|
||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.jboss.resteasy.reactive.server.ServerExceptionMapper; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.renarde.Controller; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.restassured.RestAssured; | ||
|
||
public class ExceptionMappers { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(MyController.class, MyException.class) | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")); | ||
|
||
@TestHTTPResource | ||
URL url; | ||
|
||
@Test | ||
public void testExceptionMapper() { | ||
RestAssured | ||
.when() | ||
.get("/exception").then() | ||
.statusCode(200) | ||
.body(Matchers.is("OK")); | ||
} | ||
|
||
public static class MyException extends RuntimeException { | ||
} | ||
|
||
public static class MyController extends Controller { | ||
|
||
@Path("/exception") | ||
public String exception() { | ||
throw new MyException(); | ||
} | ||
|
||
@ServerExceptionMapper | ||
public Response map(MyException x) { | ||
return Response.ok("OK").build(); | ||
} | ||
} | ||
} |