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.
Fixes quarkusio#38543 - LinksProcessor ID field error for native clas…
…s HalCollectionWrapper
- Loading branch information
Bas Passon
committed
Feb 7, 2024
1 parent
11bef66
commit 9855040
Showing
11 changed files
with
168 additions
and
31 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
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
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
63 changes: 63 additions & 0 deletions
63
...yment/src/test/java/io/quarkus/resteasy/reactive/links/deployment/HalWrapperResource.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,63 @@ | ||
package io.quarkus.resteasy.reactive.links.deployment; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.Link; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.UriInfo; | ||
|
||
import org.jboss.resteasy.reactive.common.util.RestMediaType; | ||
|
||
import io.quarkus.hal.HalCollectionWrapper; | ||
import io.quarkus.hal.HalEntityWrapper; | ||
import io.quarkus.hal.HalService; | ||
import io.quarkus.resteasy.reactive.links.InjectRestLinks; | ||
import io.quarkus.resteasy.reactive.links.RestLink; | ||
import io.quarkus.resteasy.reactive.links.RestLinkType; | ||
|
||
@Path("/hal") | ||
public class HalWrapperResource { | ||
|
||
@Inject | ||
HalService halService; | ||
|
||
@GET | ||
@Produces({ MediaType.APPLICATION_JSON, RestMediaType.APPLICATION_HAL_JSON }) | ||
@RestLink(rel = "list") | ||
@InjectRestLinks | ||
public HalCollectionWrapper<TestRecordWithIdAndPersistenceIdAndRestLinkId> getRecords(@Context UriInfo uriInfo) { | ||
List<TestRecordWithIdAndPersistenceIdAndRestLinkId> items = List.of( | ||
new TestRecordWithIdAndPersistenceIdAndRestLinkId(1, 10, 100, "one"), | ||
new TestRecordWithIdAndPersistenceIdAndRestLinkId(2, 20, 200, "two")); | ||
|
||
HalCollectionWrapper<TestRecordWithIdAndPersistenceIdAndRestLinkId> halCollection = halService.toHalCollectionWrapper( | ||
items, | ||
"collectionName", TestRecordWithIdAndPersistenceIdAndRestLinkId.class); | ||
halCollection.addLinks( | ||
Link.fromUriBuilder(uriInfo.getBaseUriBuilder().path(String.format("/hal/%d", 1))).rel("first-record").build()); | ||
|
||
return halCollection; | ||
} | ||
|
||
@GET | ||
@Path("/{id}") | ||
@Produces({ MediaType.APPLICATION_JSON, RestMediaType.APPLICATION_HAL_JSON }) | ||
@RestLink(rel = "self") | ||
@InjectRestLinks(RestLinkType.INSTANCE) | ||
public HalEntityWrapper<TestRecordWithIdAndPersistenceIdAndRestLinkId> getRecord(@PathParam("id") int id, | ||
@Context UriInfo uriInfo) { | ||
|
||
HalEntityWrapper<TestRecordWithIdAndPersistenceIdAndRestLinkId> halEntity = halService.toHalWrapper( | ||
new TestRecordWithIdAndPersistenceIdAndRestLinkId(1, 10, 100, "one")); | ||
halEntity.addLinks(Link.fromUriBuilder(uriInfo.getBaseUriBuilder().path(String.format("/hal/%d/parent", id))) | ||
.rel("parent-record").build()); | ||
|
||
return halEntity; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...t/src/test/java/io/quarkus/resteasy/reactive/links/deployment/HalWrapperResourceTest.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,65 @@ | ||
package io.quarkus.resteasy.reactive.links.deployment; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.ws.rs.core.HttpHeaders; | ||
|
||
import org.jboss.resteasy.reactive.common.util.RestMediaType; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.builder.Version; | ||
import io.quarkus.maven.dependency.Dependency; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.restassured.response.Response; | ||
|
||
public class HalWrapperResourceTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(HalWrapperResource.class, TestRecordWithIdAndPersistenceIdAndRestLinkId.class)) | ||
.setForcedDependencies(List.of( | ||
Dependency.of("io.quarkus", "quarkus-resteasy-reactive-jackson", Version.getVersion()), | ||
Dependency.of("io.quarkus", "quarkus-hal", Version.getVersion()))); | ||
|
||
@TestHTTPResource("hal") | ||
String recordsUrl; | ||
|
||
@TestHTTPResource("hal/{id}") | ||
String recordIdUrl; | ||
|
||
@Test | ||
void shouldGetAllRecordsWithCustomHalMetadata() { | ||
Response response = given() | ||
.header(HttpHeaders.ACCEPT, RestMediaType.APPLICATION_HAL_JSON) | ||
.get(recordsUrl).thenReturn(); | ||
|
||
assertThat(response.body().jsonPath().getString("_embedded['collectionName'][0].restLinkId")).isEqualTo("1"); | ||
assertThat(response.body().jsonPath().getString("_embedded['collectionName'][0]._links.self.href")).endsWith("/hal/1"); | ||
assertThat(response.body().jsonPath().getString("_embedded['collectionName'][0]._links.list.href")).endsWith("/hal"); | ||
assertThat(response.body().jsonPath().getString("_embedded['collectionName'][1].restLinkId")).isEqualTo("2"); | ||
assertThat(response.body().jsonPath().getString("_embedded['collectionName'][1]._links.self.href")).endsWith("/hal/2"); | ||
assertThat(response.body().jsonPath().getString("_embedded['collectionName'][1]._links.list.href")).endsWith("/hal"); | ||
assertThat(response.body().jsonPath().getString("_links.first-record.href")).endsWith("/hal/1"); | ||
assertThat(response.body().jsonPath().getString("_links.list.href")).endsWith("/hal"); | ||
} | ||
|
||
@Test | ||
void shouldGetSingleRecordWithCustomHalMetadata() { | ||
Response response = given() | ||
.header(HttpHeaders.ACCEPT, RestMediaType.APPLICATION_HAL_JSON) | ||
.get(recordIdUrl, 1L) | ||
.thenReturn(); | ||
|
||
assertThat(response.body().jsonPath().getString("restLinkId")).isEqualTo("1"); | ||
assertThat(response.body().jsonPath().getString("_links.parent-record.href")).endsWith("/hal/1/parent"); | ||
assertThat(response.body().jsonPath().getString("_links.self.href")).endsWith("/hal/1"); | ||
assertThat(response.body().jsonPath().getString("_links.list.href")).endsWith("/hal"); | ||
|
||
} | ||
} |