-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Take conditional annotation into account for @ServerExceptionMapper
Closes: #29043
- Loading branch information
Showing
11 changed files
with
436 additions
and
17 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
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
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
141 changes: 141 additions & 0 deletions
141
...arkus/resteasy/reactive/server/test/customexceptions/ConditionalExceptionMappersTest.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,141 @@ | ||
package io.quarkus.resteasy.reactive.server.test.customexceptions; | ||
|
||
import static io.restassured.RestAssured.*; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Priorities; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.jboss.resteasy.reactive.RestResponse; | ||
import org.jboss.resteasy.reactive.server.ServerExceptionMapper; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.lookup.LookupUnlessProperty; | ||
import io.quarkus.arc.profile.IfBuildProfile; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public class ConditionalExceptionMappersTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(AbstractException.class, FirstException.class, SecondException.class, | ||
WontBeEnabledMappers.class, WillBeEnabledMappers.class, AlwaysEnabledMappers.class, | ||
TestResource.class); | ||
} | ||
}); | ||
|
||
@Test | ||
public void test() { | ||
get("/first").then().statusCode(903); | ||
get("/second").then().statusCode(801); | ||
get("/third").then().statusCode(555); | ||
} | ||
|
||
@Path("") | ||
public static class TestResource { | ||
|
||
@Path("first") | ||
@GET | ||
public String first() { | ||
throw new FirstException(); | ||
} | ||
|
||
@Path("second") | ||
@GET | ||
public String second() { | ||
throw new SecondException(); | ||
} | ||
|
||
@Path("third") | ||
@GET | ||
public String third() { | ||
throw new ThirdException(); | ||
} | ||
} | ||
|
||
public static abstract class AbstractException extends RuntimeException { | ||
|
||
public AbstractException() { | ||
setStackTrace(new StackTraceElement[0]); | ||
} | ||
} | ||
|
||
public static class FirstException extends AbstractException { | ||
|
||
} | ||
|
||
public static class SecondException extends AbstractException { | ||
|
||
} | ||
|
||
public static class ThirdException extends AbstractException { | ||
|
||
} | ||
|
||
@IfBuildProfile("dummy") | ||
public static class WontBeEnabledMappers { | ||
|
||
@ServerExceptionMapper(FirstException.class) | ||
public Response first() { | ||
return Response.status(900).build(); | ||
} | ||
|
||
@ServerExceptionMapper(value = FirstException.class, priority = Priorities.USER - 100) | ||
public Response firstWithLowerPriority() { | ||
return Response.status(901).build(); | ||
} | ||
|
||
@ServerExceptionMapper(priority = Priorities.USER - 100) | ||
public Response second(SecondException ignored) { | ||
return Response.status(800).build(); | ||
} | ||
} | ||
|
||
@LookupUnlessProperty(name = "notexistingproperty", stringValue = "true", lookupIfMissing = true) | ||
public static class WillBeEnabledMappers { | ||
|
||
@ServerExceptionMapper(value = FirstException.class, priority = Priorities.USER + 10) | ||
public Response first() { | ||
return Response.status(902).build(); | ||
} | ||
|
||
@ServerExceptionMapper(value = FirstException.class, priority = Priorities.USER - 10) | ||
public Response firstWithLowerPriority() { | ||
return Response.status(903).build(); | ||
} | ||
|
||
@ServerExceptionMapper(priority = Priorities.USER - 10) | ||
public RestResponse<Void> second(SecondException ignored) { | ||
return RestResponse.status(801); | ||
} | ||
} | ||
|
||
public static class AlwaysEnabledMappers { | ||
|
||
@ServerExceptionMapper(value = FirstException.class, priority = Priorities.USER + 1000) | ||
public Response first() { | ||
return Response.status(555).build(); | ||
} | ||
|
||
@ServerExceptionMapper(value = SecondException.class, priority = Priorities.USER + 1000) | ||
public Response second() { | ||
return Response.status(555).build(); | ||
} | ||
|
||
@ServerExceptionMapper(value = ThirdException.class, priority = Priorities.USER + 1000) | ||
public Uni<Response> third() { | ||
return Uni.createFrom().item(Response.status(555).build()); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...quarkus/resteasy/reactive/server/test/customexceptions/InvalidConditionalΜappersTest.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,62 @@ | ||
package io.quarkus.resteasy.reactive.server.test.customexceptions; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.jboss.resteasy.reactive.server.ServerExceptionMapper; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.profile.IfBuildProfile; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class InvalidConditionalΜappersTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(TestResource.class, Mappers.class); | ||
} | ||
}).assertException(t -> { | ||
String message = t.getMessage(); | ||
assertTrue(message.contains("@ServerExceptionMapper")); | ||
assertTrue(message.contains("request")); | ||
assertTrue(message.contains(Mappers.class.getName())); | ||
}); | ||
|
||
@Test | ||
public void test() { | ||
fail("Should never have been called"); | ||
} | ||
|
||
@Path("test") | ||
public static class TestResource { | ||
|
||
@GET | ||
public String hello() { | ||
return "hello"; | ||
} | ||
|
||
} | ||
|
||
public static class Mappers { | ||
|
||
@IfBuildProfile("test") | ||
@ServerExceptionMapper | ||
public Response request(IllegalArgumentException ignored) { | ||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); | ||
} | ||
|
||
} | ||
} |
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
Oops, something went wrong.