-
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.
REST Data with Panache should not produce links when hal is disabled
This is related to #35167. Even though HAL is disabled by default, it's still used to generate unexpected links and to set the location.
- Loading branch information
Showing
14 changed files
with
193 additions
and
40 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...bernate/orm/rest/data/panache/deployment/entity/PanacheEntityResourceHalDisabledTest.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,49 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.entity; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.hamcrest.Matchers.endsWith; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.orm.rest.data.panache.deployment.AbstractPutMethodTest; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.response.Response; | ||
|
||
class PanacheEntityResourceHalDisabledTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Project.class, ProjectResource.class) | ||
.addAsResource("application.properties")); | ||
|
||
@Test | ||
void shouldHalNotBeSupported() { | ||
given().accept("application/hal+json") | ||
.when().get("/group/projects/1") | ||
.then().statusCode(406); | ||
} | ||
|
||
@Test | ||
void shouldNotContainLocationAndLinks() { | ||
Response response = given().accept("application/json") | ||
.and().contentType("application/json") | ||
.and().body("{\"name\": \"projectname\"}") | ||
.when().post("/group/projects") | ||
.thenReturn(); | ||
assertThat(response.statusCode()).isEqualTo(201); | ||
assertThat(response.header("Location")).isBlank(); | ||
assertThat(response.getHeaders().getList("Link")).isEmpty(); | ||
|
||
response = given().accept("application/json") | ||
.when().get("/group/projects/projectname") | ||
.thenReturn(); | ||
assertThat(response.statusCode()).isEqualTo(200); | ||
assertThat(response.header("Location")).isBlank(); | ||
assertThat(response.getHeaders().getList("Link")).isEmpty(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...t/src/test/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/entity/Project.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,12 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.entity; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheEntityBase; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
|
||
@Entity | ||
public class Project extends PanacheEntityBase { | ||
|
||
@Id | ||
public String name; | ||
} |
11 changes: 11 additions & 0 deletions
11
...st/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/entity/ProjectResource.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,11 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.entity; | ||
|
||
import io.quarkus.hibernate.orm.rest.data.panache.PanacheEntityResource; | ||
import io.quarkus.rest.data.panache.ResourceProperties; | ||
|
||
/** | ||
* Having a path param in the path reproduces the issue of having HAL enabled spites it should be disabled by default. | ||
*/ | ||
@ResourceProperties(path = "/{group}/projects") | ||
public interface ProjectResource extends PanacheEntityResource<Project, String> { | ||
} |
45 changes: 45 additions & 0 deletions
45
...te/reactive/rest/data/panache/deployment/entity/PanacheEntityResourceHalDisabledTest.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,45 @@ | ||
package io.quarkus.hibernate.reactive.rest.data.panache.deployment.entity; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.response.Response; | ||
|
||
class PanacheEntityResourceHalDisabledTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(Project.class, ProjectResource.class) | ||
.addAsResource("application.properties")); | ||
|
||
@Test | ||
void shouldHalNotBeSupported() { | ||
given().accept("application/hal+json") | ||
.when().get("/group/projects/1") | ||
.then().statusCode(406); | ||
} | ||
|
||
@Test | ||
void shouldNotContainLocationAndLinks() { | ||
Response response = given().accept("application/json") | ||
.and().contentType("application/json") | ||
.and().body("{\"name\": \"projectname\"}") | ||
.when().post("/group/projects") | ||
.thenReturn(); | ||
assertThat(response.statusCode()).isEqualTo(201); | ||
assertThat(response.header("Location")).isBlank(); | ||
assertThat(response.getHeaders().getList("Link")).isEmpty(); | ||
|
||
response = given().accept("application/json") | ||
.when().get("/group/projects/projectname") | ||
.thenReturn(); | ||
assertThat(response.statusCode()).isEqualTo(200); | ||
assertThat(response.header("Location")).isBlank(); | ||
assertThat(response.getHeaders().getList("Link")).isEmpty(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
.../test/java/io/quarkus/hibernate/reactive/rest/data/panache/deployment/entity/Project.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,12 @@ | ||
package io.quarkus.hibernate.reactive.rest.data.panache.deployment.entity; | ||
|
||
import io.quarkus.hibernate.reactive.panache.PanacheEntityBase; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
|
||
@Entity | ||
public class Project extends PanacheEntityBase { | ||
|
||
@Id | ||
public String name; | ||
} |
11 changes: 11 additions & 0 deletions
11
...va/io/quarkus/hibernate/reactive/rest/data/panache/deployment/entity/ProjectResource.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,11 @@ | ||
package io.quarkus.hibernate.reactive.rest.data.panache.deployment.entity; | ||
|
||
import io.quarkus.hibernate.reactive.rest.data.panache.PanacheEntityResource; | ||
import io.quarkus.rest.data.panache.ResourceProperties; | ||
|
||
/** | ||
* Having a path param in the path reproduces the issue of having HAL enabled spites it should be disabled by default. | ||
*/ | ||
@ResourceProperties(path = "/{group}/projects") | ||
public interface ProjectResource extends PanacheEntityResource<Project, String> { | ||
} |
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