-
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.
Browse files
Browse the repository at this point in the history
Add configuration option for resuming on 404
- Loading branch information
Showing
4 changed files
with
174 additions
and
1 deletion.
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
90 changes: 90 additions & 0 deletions
90
...ment/src/test/java/io/quarkus/resteasy/reactive/server/test/ResumeOn404BuildItemTest.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,90 @@ | ||
package io.quarkus.resteasy.reactive.server.test; | ||
|
||
import static io.restassured.RestAssured.get; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import jakarta.enterprise.context.RequestScoped; | ||
import jakarta.enterprise.event.Observes; | ||
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.builder.BuildChainBuilder; | ||
import io.quarkus.resteasy.reactive.server.spi.ResumeOn404BuildItem; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.vertx.ext.web.Router; | ||
|
||
public class ResumeOn404BuildItemTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Resource.class, CustomRoute.class); | ||
} | ||
}) | ||
.addBuildChainCustomizer(buildCustomizer()); | ||
|
||
protected static Consumer<BuildChainBuilder> buildCustomizer() { | ||
return new Consumer<>() { | ||
// This represents the extension. | ||
@Override | ||
public void accept(BuildChainBuilder builder) { | ||
builder.addBuildStep(context -> { | ||
context.produce(new ResumeOn404BuildItem()); | ||
}) | ||
.produces(ResumeOn404BuildItem.class) | ||
.build(); | ||
} | ||
}; | ||
} | ||
|
||
@Test | ||
public void matchingFromResteasyReactive() { | ||
get("/test") | ||
.then() | ||
.statusCode(200); | ||
} | ||
|
||
@Test | ||
public void matchingFromCustomRoute() { | ||
get("/main") | ||
.then() | ||
.statusCode(200); | ||
} | ||
|
||
@Test | ||
public void missing() { | ||
get("/dummy") | ||
.then() | ||
.statusCode(404); | ||
} | ||
|
||
@Path("/test") | ||
@RequestScoped | ||
public static class Resource { | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello() { | ||
return "test"; | ||
} | ||
|
||
} | ||
|
||
public static class CustomRoute { | ||
|
||
public void initMain(@Observes Router router) { | ||
router.get("/main").handler(rc -> rc.response().end("main")); | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...loyment/src/test/java/io/quarkus/resteasy/reactive/server/test/ResumeOn404ConfigTest.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,73 @@ | ||
package io.quarkus.resteasy.reactive.server.test; | ||
|
||
import static io.restassured.RestAssured.get; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import jakarta.enterprise.context.RequestScoped; | ||
import jakarta.enterprise.event.Observes; | ||
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.vertx.ext.web.Router; | ||
|
||
public class ResumeOn404ConfigTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Resource.class, CustomRoute.class); | ||
} | ||
}) | ||
.overrideRuntimeConfigKey("quarkus.resteasy-reactive.resume-on-404", "true"); | ||
|
||
@Test | ||
public void matchingFromResteasyReactive() { | ||
get("/test") | ||
.then() | ||
.statusCode(200); | ||
} | ||
|
||
@Test | ||
public void matchingFromCustomRoute() { | ||
get("/main") | ||
.then() | ||
.statusCode(200); | ||
} | ||
|
||
@Test | ||
public void missing() { | ||
get("/dummy") | ||
.then() | ||
.statusCode(404); | ||
} | ||
|
||
@Path("/test") | ||
@RequestScoped | ||
public static class Resource { | ||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello() { | ||
return "test"; | ||
} | ||
|
||
} | ||
|
||
public static class CustomRoute { | ||
|
||
public void initMain(@Observes Router router) { | ||
router.get("/main").handler(rc -> rc.response().end("main")); | ||
} | ||
} | ||
} |