Skip to content

Commit bad1833

Browse files
Copilotrashidi
andauthored
Fix test failures in data-rest-validation and data-rest-composite-id
- data-rest-validation: Add missing spring-boot-restclient dependency and replace ValidationError with local DTO (Spring Data REST 5.x made constructor private) - data-rest-composite-id: Restore @GeneratedValue on Author.Id.id field (erroneously removed by OpenRewrite recipe during Spring Boot 4 upgrade) Agent-Logs-Url: https://github.com/rashidi/spring-boot-tutorials/sessions/b0bdf128-5dc8-4e3a-a405-e09e45e57664 Co-authored-by: rashidi <380073+rashidi@users.noreply.github.com>
1 parent d9b3c63 commit bad1833

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

data-rest-composite-id/src/main/java/zin/rashidi/datarest/compositeid/book/Author.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Author {
1919
@Embeddable
2020
static class Id implements Serializable {
2121

22+
@GeneratedValue
2223
private Long id;
2324

2425
public Long id() {

data-rest-validation/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dependencies {
2222
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
2323
implementation("org.springframework.boot:spring-boot-starter-data-rest")
2424
runtimeOnly("com.mysql:mysql-connector-j")
25+
testImplementation("org.springframework.boot:spring-boot-restclient")
2526
testImplementation("org.springframework.boot:spring-boot-resttestclient")
2627
testImplementation("org.springframework.boot:spring-boot-starter-test")
2728
testImplementation("org.springframework.boot:spring-boot-testcontainers")

data-rest-validation/src/test/java/zin/rashidi/boot/data/rest/book/CreateBookTests.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.springframework.boot.test.context.SpringBootTest;
1818
import org.springframework.boot.resttestclient.TestRestTemplate;
1919
import org.springframework.context.annotation.Import;
20-
import org.springframework.data.rest.webmvc.support.RepositoryConstraintViolationExceptionMessage.ValidationError;
2120
import org.springframework.http.HttpEntity;
2221
import org.springframework.http.HttpHeaders;
2322

@@ -75,6 +74,35 @@ private HttpHeaders headers() {
7574
return headers;
7675
}
7776

77+
static class ValidationError {
78+
79+
private String entity;
80+
private String property;
81+
private Object invalidValue;
82+
private String message;
83+
84+
public String getMessage() {
85+
return message;
86+
}
87+
88+
public void setEntity(String entity) {
89+
this.entity = entity;
90+
}
91+
92+
public void setProperty(String property) {
93+
this.property = property;
94+
}
95+
96+
public void setInvalidValue(Object invalidValue) {
97+
this.invalidValue = invalidValue;
98+
}
99+
100+
public void setMessage(String message) {
101+
this.message = message;
102+
}
103+
104+
}
105+
78106
static class RepositoryRestErrorResponse {
79107

80108
private List<ValidationError> errors = new ArrayList<>();

0 commit comments

Comments
 (0)