forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bubble up WebApplicationExceptions in RestDataResourceMethodListener …
…implementations - Fixes quarkusio#35169
- Loading branch information
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...rest/data/panache/deployment/entity/PanacheEntityResourceMethodListenerExceptionTest.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,43 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.entity; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.ws.rs.ForbiddenException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.orm.rest.data.panache.RestDataResourceMethodListener; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
class PanacheEntityResourceMethodListenerExceptionTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Collection.class, CollectionsResource.class, AbstractEntity.class, AbstractItem.class, | ||
Item.class, ItemsResource.class, WebApplicationExceptionResourceMethodListener.class) | ||
.addAsResource("application.properties") | ||
.addAsResource("import.sql")); | ||
|
||
@Test | ||
void shouldReceiveWebApplicationException() { | ||
given().accept("application/json") | ||
.and().contentType("application/json") | ||
.and().body("{\"name\": \"test-simple\", \"collection\": {\"id\": \"full\"}}") | ||
.when().post("/items") | ||
.then() | ||
.statusCode(403); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class WebApplicationExceptionResourceMethodListener implements RestDataResourceMethodListener<Item> { | ||
|
||
@Override | ||
public void onBeforeAdd(Item item) { | ||
throw new ForbiddenException("You shall not pass"); | ||
} | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...rest/data/panache/deployment/entity/PanacheEntityResourceMethodListenerExceptionTest.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,43 @@ | ||
package io.quarkus.hibernate.reactive.rest.data.panache.deployment.entity; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.ws.rs.ForbiddenException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.reactive.rest.data.panache.RestDataResourceMethodListener; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
class PanacheEntityResourceMethodListenerExceptionTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Collection.class, CollectionsResource.class, AbstractEntity.class, AbstractItem.class, | ||
Item.class, ItemsResource.class, WebApplicationExceptionResourceMethodListener.class) | ||
.addAsResource("application.properties") | ||
.addAsResource("import.sql")); | ||
|
||
@Test | ||
void shouldReceiveWebApplicationException() { | ||
given().accept("application/json") | ||
.and().contentType("application/json") | ||
.and().body("{\"name\": \"test-simple\", \"collection\": {\"id\": \"full\"}}") | ||
.when().post("/items") | ||
.then() | ||
.statusCode(403); | ||
Check failure on line 31 in extensions/panache/hibernate-reactive-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/rest/data/panache/deployment/entity/PanacheEntityResourceMethodListenerExceptionTest.java GitHub Actions / Build summary for 6e3b906242d8853f81a51978d7e965d50a7b1f34JVM Tests - JDK 17
Raw output
Check failure on line 31 in extensions/panache/hibernate-reactive-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/rest/data/panache/deployment/entity/PanacheEntityResourceMethodListenerExceptionTest.java GitHub Actions / Build summary for 6e3b906242d8853f81a51978d7e965d50a7b1f34JVM Tests - JDK 21
Raw output
|
||
} | ||
|
||
@ApplicationScoped | ||
public static class WebApplicationExceptionResourceMethodListener implements RestDataResourceMethodListener<Item> { | ||
|
||
@Override | ||
public void onBeforeAdd(Item item) { | ||
throw new ForbiddenException("You shall not pass"); | ||
} | ||
} | ||
|
||
} |
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