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.
Merge pull request quarkusio#42003 from geoand/quarkusio#41996
Unwrap CompletionException when dealing with CompletionStage in REST server
- Loading branch information
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...t/src/test/java/io/quarkus/resteasy/reactive/server/test/MutinyAsCompletionStageTest.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,68 @@ | ||
package io.quarkus.resteasy.reactive.server.test; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
import java.util.function.Supplier; | ||
|
||
import jakarta.ws.rs.BadRequestException; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
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.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public class MutinyAsCompletionStageTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClass(TestResource.class); | ||
} | ||
}); | ||
|
||
@Test | ||
public void testOk() { | ||
RestAssured.get("/test/ok") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("test")); | ||
} | ||
|
||
@Test | ||
public void testError() { | ||
RestAssured.get("/test/error") | ||
.then() | ||
.statusCode(400); | ||
} | ||
|
||
@Path("test") | ||
public static class TestResource { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Path("/ok") | ||
public CompletionStage<String> ok() { | ||
return Uni.createFrom().item("test").subscribeAsCompletionStage(); | ||
} | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
@Path("/error") | ||
public CompletionStage<String> error() { | ||
return Uni.createFrom().<String> failure(new BadRequestException()).subscribeAsCompletionStage(); | ||
} | ||
} | ||
|
||
} |
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