|
5 | 5 |
|
6 | 6 | import java.util.function.Supplier;
|
7 | 7 |
|
| 8 | +import io.quarkus.resteasy.reactive.server.test.resource.basic.resource.CorsPreflightResource; |
8 | 9 | import jakarta.ws.rs.client.Client;
|
9 | 10 | import jakarta.ws.rs.client.ClientBuilder;
|
10 | 11 | import jakarta.ws.rs.client.Entity;
|
|
37 | 38 | import io.quarkus.resteasy.reactive.server.test.resource.basic.resource.ResourceLocatorSubresource3Interface;
|
38 | 39 | import io.quarkus.resteasy.reactive.server.test.simple.PortProviderUtil;
|
39 | 40 | import io.quarkus.test.QuarkusUnitTest;
|
| 41 | +import jakarta.ws.rs.HttpMethod; |
| 42 | + |
| 43 | +import java.util.Arrays; |
| 44 | + |
| 45 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 46 | +import static org.hamcrest.Matchers.containsInAnyOrder; |
| 47 | +import static org.hamcrest.Matchers.notNullValue; |
40 | 48 |
|
41 | 49 | /**
|
42 | 50 | * @tpSubChapter Resource
|
@@ -68,7 +76,7 @@ public JavaArchive get() {
|
68 | 76 | JavaArchive war = ShrinkWrap.create(JavaArchive.class);
|
69 | 77 | war.addClass(ResourceLocatorQueueReceiver.class).addClass(ResourceLocatorReceiver.class)
|
70 | 78 | .addClass(ResourceLocatorRootInterface.class).addClass(ResourceLocatorSubInterface.class)
|
71 |
| - .addClass(ResourceLocatorSubresource3Interface.class); |
| 79 | + .addClass(ResourceLocatorSubresource3Interface.class).addClass(CorsPreflightResource.class); |
72 | 80 | war.addClasses(PortProviderUtil.class, ResourceLocatorAbstractAnnotationFreeResource.class,
|
73 | 81 | ResourceLocatorAnnotationFreeSubResource.class, ResourceLocatorBaseResource.class,
|
74 | 82 | ResourceLocatorCollectionResource.class, ResourceLocatorDirectory.class,
|
@@ -114,6 +122,44 @@ public void testSubresource() throws Exception {
|
114 | 122 | }
|
115 | 123 | }
|
116 | 124 |
|
| 125 | + /** |
| 126 | + * @tpTestDetails Return custom handler for HTTP OPTIONS method in subresource redirection. The {@link CorsPreflightResource} instance should be returned |
| 127 | + */ |
| 128 | + @Test |
| 129 | + @DisplayName("Test custom HTTP OPTIONS handler in subresource") |
| 130 | + public void testOptionsMethodInSubresource() { |
| 131 | + try (Response response = client.target(generateURL("/sub3/something/resources/test-options-method")).request().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(", ")), containsInAnyOrder(HttpMethod.GET, HttpMethod.POST, HttpMethod.OPTIONS, HttpMethod.HEAD)); |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * @tpTestDetails Custom handler for HTTP OPTIONS method in subresource. |
| 146 | + */ |
| 147 | + @Test |
| 148 | + @DisplayName("Test custom explicit HTTP OPTIONS handler in subresource") |
| 149 | + public void testOptionsMethodExplicitInSubresource() { |
| 150 | + try (Response response = client.target(generateURL("/sub3/something/resources/test-options-method-explicit")).request().options()) { |
| 151 | + assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode())); |
| 152 | + |
| 153 | + var customHeader = response.getHeaderString(ResourceLocatorSubresource2.TEST_PREFLIGHT_HEADER); |
| 154 | + assertThat(customHeader, notNullValue()); |
| 155 | + assertThat(customHeader, is("test")); |
| 156 | + |
| 157 | + var allowHeader = response.getHeaderString("Allow"); |
| 158 | + assertThat(allowHeader, notNullValue()); |
| 159 | + assertThat(Arrays.asList(allowHeader.split(", ")), containsInAnyOrder(HttpMethod.GET)); |
| 160 | + } |
| 161 | + } |
| 162 | + |
117 | 163 | /**
|
118 | 164 | * @tpTestDetails Two matching methods, one a resource locator, the other a resource method.
|
119 | 165 | * @tpSince RESTEasy 3.0.20
|
|
0 commit comments