|
1 | 1 | package io.quarkus.resteasy.reactive.server.test.resource.basic;
|
2 | 2 |
|
3 | 3 | import static io.restassured.RestAssured.given;
|
| 4 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 5 | +import static org.hamcrest.Matchers.containsInAnyOrder; |
4 | 6 | import static org.hamcrest.Matchers.is;
|
| 7 | +import static org.hamcrest.Matchers.notNullValue; |
5 | 8 |
|
| 9 | +import java.util.Arrays; |
6 | 10 | import java.util.function.Supplier;
|
7 | 11 |
|
| 12 | +import jakarta.ws.rs.HttpMethod; |
8 | 13 | import jakarta.ws.rs.client.Client;
|
9 | 14 | import jakarta.ws.rs.client.ClientBuilder;
|
10 | 15 | import jakarta.ws.rs.client.Entity;
|
|
22 | 27 | import org.junit.jupiter.api.Test;
|
23 | 28 | import org.junit.jupiter.api.extension.RegisterExtension;
|
24 | 29 |
|
| 30 | +import io.quarkus.resteasy.reactive.server.test.resource.basic.resource.CorsPreflightResource; |
25 | 31 | import io.quarkus.resteasy.reactive.server.test.resource.basic.resource.ResourceLocatorAbstractAnnotationFreeResource;
|
26 | 32 | import io.quarkus.resteasy.reactive.server.test.resource.basic.resource.ResourceLocatorAnnotationFreeSubResource;
|
27 | 33 | import io.quarkus.resteasy.reactive.server.test.resource.basic.resource.ResourceLocatorBaseResource;
|
@@ -68,7 +74,7 @@ public JavaArchive get() {
|
68 | 74 | JavaArchive war = ShrinkWrap.create(JavaArchive.class);
|
69 | 75 | war.addClass(ResourceLocatorQueueReceiver.class).addClass(ResourceLocatorReceiver.class)
|
70 | 76 | .addClass(ResourceLocatorRootInterface.class).addClass(ResourceLocatorSubInterface.class)
|
71 |
| - .addClass(ResourceLocatorSubresource3Interface.class); |
| 77 | + .addClass(ResourceLocatorSubresource3Interface.class).addClass(CorsPreflightResource.class); |
72 | 78 | war.addClasses(PortProviderUtil.class, ResourceLocatorAbstractAnnotationFreeResource.class,
|
73 | 79 | ResourceLocatorAnnotationFreeSubResource.class, ResourceLocatorBaseResource.class,
|
74 | 80 | ResourceLocatorCollectionResource.class, ResourceLocatorDirectory.class,
|
@@ -114,6 +120,48 @@ public void testSubresource() throws Exception {
|
114 | 120 | }
|
115 | 121 | }
|
116 | 122 |
|
| 123 | + /** |
| 124 | + * @tpTestDetails Return custom handler for HTTP OPTIONS method in subresource redirection. The |
| 125 | + * {@link CorsPreflightResource} instance should be returned |
| 126 | + */ |
| 127 | + @Test |
| 128 | + @DisplayName("Test custom HTTP OPTIONS handler in subresource") |
| 129 | + public void testOptionsMethodInSubresource() { |
| 130 | + try (Response response = client.target(generateURL("/sub3/something/resources/test-options-method")).request() |
| 131 | + .options()) { |
| 132 | + assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode())); |
| 133 | + |
| 134 | + var customHeader = response.getHeaderString(CorsPreflightResource.TEST_PREFLIGHT_HEADER); |
| 135 | + assertThat(customHeader, notNullValue()); |
| 136 | + assertThat(customHeader, is("test")); |
| 137 | + |
| 138 | + var allowHeader = response.getHeaderString("Allow"); |
| 139 | + assertThat(allowHeader, notNullValue()); |
| 140 | + assertThat(Arrays.asList(allowHeader.split(", ")), |
| 141 | + containsInAnyOrder(HttpMethod.GET, HttpMethod.POST, HttpMethod.OPTIONS, HttpMethod.HEAD)); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * @tpTestDetails Custom handler for HTTP OPTIONS method in subresource. |
| 147 | + */ |
| 148 | + @Test |
| 149 | + @DisplayName("Test custom explicit HTTP OPTIONS handler in subresource") |
| 150 | + public void testOptionsMethodExplicitInSubresource() { |
| 151 | + try (Response response = client.target(generateURL("/sub3/something/resources/test-options-method-explicit")).request() |
| 152 | + .options()) { |
| 153 | + assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode())); |
| 154 | + |
| 155 | + var customHeader = response.getHeaderString(ResourceLocatorSubresource2.TEST_PREFLIGHT_HEADER); |
| 156 | + assertThat(customHeader, notNullValue()); |
| 157 | + assertThat(customHeader, is("test")); |
| 158 | + |
| 159 | + var allowHeader = response.getHeaderString("Allow"); |
| 160 | + assertThat(allowHeader, notNullValue()); |
| 161 | + assertThat(Arrays.asList(allowHeader.split(", ")), containsInAnyOrder(HttpMethod.GET)); |
| 162 | + } |
| 163 | + } |
| 164 | + |
117 | 165 | /**
|
118 | 166 | * @tpTestDetails Two matching methods, one a resource locator, the other a resource method.
|
119 | 167 | * @tpSince RESTEasy 3.0.20
|
|
0 commit comments