diff --git a/009-quarkus-infinispan-grpc-kafka/src/main/java/io/quarkus/qe/books/Book.java b/009-quarkus-infinispan-grpc-kafka/src/main/java/io/quarkus/qe/books/Book.java index 0ff0360c..58f8a819 100644 --- a/009-quarkus-infinispan-grpc-kafka/src/main/java/io/quarkus/qe/books/Book.java +++ b/009-quarkus-infinispan-grpc-kafka/src/main/java/io/quarkus/qe/books/Book.java @@ -24,7 +24,7 @@ public Book(String title, String description, int publicationYear) { this.publicationYear = publicationYear; } - @NotBlank(message = "Title may not be blank") + @NotBlank(message = "Title cannot be blank") @ProtoField(number = 1) public String getTitle() { return title; diff --git a/009-quarkus-infinispan-grpc-kafka/src/test/java/io/quarkus/qe/books/BookServiceTest.java b/009-quarkus-infinispan-grpc-kafka/src/test/java/io/quarkus/qe/books/BookServiceTest.java index ead97428..04f18bc2 100644 --- a/009-quarkus-infinispan-grpc-kafka/src/test/java/io/quarkus/qe/books/BookServiceTest.java +++ b/009-quarkus-infinispan-grpc-kafka/src/test/java/io/quarkus/qe/books/BookServiceTest.java @@ -1,6 +1,7 @@ package io.quarkus.qe.books; import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.http.HttpStatus; @@ -33,4 +34,14 @@ public void testBookResource() { assertEquals(BOOK, actual); } + + @Test + public void testBookResourceShouldValidateBook() { + given() + .contentType(ContentType.JSON) + .body(new Book()) + .when().post("/book/add") + .then().statusCode(HttpStatus.SC_BAD_REQUEST) + .body(containsString("Title cannot be blank")); + } } diff --git a/011-quarkus-panache-rest-flyway/README.md b/011-quarkus-panache-rest-flyway/README.md index 0703369d..674080da 100644 --- a/011-quarkus-panache-rest-flyway/README.md +++ b/011-quarkus-panache-rest-flyway/README.md @@ -8,7 +8,3 @@ Topics covered here: - https://quarkus.io/guides/flyway In the future, I would like to cover different database at the same time. - -## Disabled tests - -`PostgreSqlApplicationResourceTest#shouldReturnBadRequestIfApplicationNameIsNull` - see https://github.com/quarkusio/quarkus/issues/13307 diff --git a/011-quarkus-panache-rest-flyway/src/main/java/io/quarkus/qe/ApplicationEntity.java b/011-quarkus-panache-rest-flyway/src/main/java/io/quarkus/qe/ApplicationEntity.java index fc69857d..0359d89f 100644 --- a/011-quarkus-panache-rest-flyway/src/main/java/io/quarkus/qe/ApplicationEntity.java +++ b/011-quarkus-panache-rest-flyway/src/main/java/io/quarkus/qe/ApplicationEntity.java @@ -28,7 +28,7 @@ @Filter(name = "useLikeByName", condition = "name like '%' || :name || '%'") @FilterDef(name = "useServiceByName", parameters = { @ParamDef(name = "name", type = "string") }) public class ApplicationEntity extends PanacheEntity { - @NotEmpty + @NotEmpty(message = "name can't be null") @Column(unique = true, nullable = false) public String name; diff --git a/011-quarkus-panache-rest-flyway/src/test/java/io/quarkus/qe/PostgreSqlApplicationResourceTest.java b/011-quarkus-panache-rest-flyway/src/test/java/io/quarkus/qe/PostgreSqlApplicationResourceTest.java index eab5675b..8c4b848c 100644 --- a/011-quarkus-panache-rest-flyway/src/test/java/io/quarkus/qe/PostgreSqlApplicationResourceTest.java +++ b/011-quarkus-panache-rest-flyway/src/test/java/io/quarkus/qe/PostgreSqlApplicationResourceTest.java @@ -15,7 +15,6 @@ import org.apache.http.HttpStatus; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import io.quarkus.qe.containers.PostgreSqlDatabaseTestResource; @@ -68,16 +67,13 @@ public void shouldDeleteApplication() { thenApplicationsCountIs(0); } - /** - * This test is disabled because the conflict exception raised by hibernate validator is wrapping it up by the rollback - * exception which ends up in a HTTP 500 Internal Server Error instead of a HTTP 409 Conflict. - */ - @Disabled("Caused by https://github.com/quarkusio/quarkus/issues/13307.") @Test public void shouldReturnBadRequestIfApplicationNameIsNull() { applicationPath().body(new ApplicationEntity()).post() .then() - .statusCode(HttpStatus.SC_CONFLICT); + .statusCode(HttpStatus.SC_BAD_REQUEST); + // TODO: Body assertion is not working caused by https://github.com/quarkusio/quarkus/issues/15492 + // .body(containsString("name can't be null")); } @Test diff --git a/602-spring-data-rest/src/main/java/org/acme/spring/data/rest/BookRepository.java b/602-spring-data-rest/src/main/java/org/acme/spring/data/rest/BookRepository.java index de7e8f19..db5fb214 100644 --- a/602-spring-data-rest/src/main/java/org/acme/spring/data/rest/BookRepository.java +++ b/602-spring-data-rest/src/main/java/org/acme/spring/data/rest/BookRepository.java @@ -1,27 +1,29 @@ package org.acme.spring.data.rest; -import com.sun.xml.bind.v2.model.core.ID; +import java.util.List; +import java.util.Optional; + import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.data.rest.core.annotation.RestResource; -import java.util.List; -import java.util.Optional; - @RepositoryRestResource(exported=false, path = "books", collectionResourceRel = "books") public interface BookRepository extends PagingAndSortingRepository { + @Override @RestResource(exported = true) Page findAll(Pageable pageable); @RestResource(exported = true) List findByOrderByNameDesc(); + @Override @RestResource(path = "id") - Optional findById(ID id); + Optional findById(Long id); + @Override @RestResource() Book save(Book book); } diff --git a/602-spring-data-rest/src/main/java/org/acme/spring/data/rest/LibraryRepository.java b/602-spring-data-rest/src/main/java/org/acme/spring/data/rest/LibraryRepository.java index 1850b571..2c6eea05 100644 --- a/602-spring-data-rest/src/main/java/org/acme/spring/data/rest/LibraryRepository.java +++ b/602-spring-data-rest/src/main/java/org/acme/spring/data/rest/LibraryRepository.java @@ -1,12 +1,12 @@ package org.acme.spring.data.rest; -import com.sun.xml.bind.v2.model.core.ID; +import java.util.Optional; + import org.springframework.data.repository.CrudRepository; import org.springframework.data.rest.core.annotation.RestResource; -import java.util.Optional; - public interface LibraryRepository extends CrudRepository { + @Override @RestResource(path = "id") - Optional findById(ID id); + Optional findById(Long id); } \ No newline at end of file diff --git a/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/BookRepositoryTest.java b/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/BookRepositoryTest.java index aa66592d..56a6221b 100644 --- a/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/BookRepositoryTest.java +++ b/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/BookRepositoryTest.java @@ -1,22 +1,22 @@ package org.acme.spring.data.rest; -import io.quarkus.test.common.QuarkusTestResource; -import io.quarkus.test.junit.QuarkusTest; - -import io.restassured.response.Response; -import org.acme.spring.data.rest.containers.PostgreSqlDatabaseTestResource; -import org.hibernate.annotations.SQLUpdate; -import org.junit.Assert; -import org.junit.jupiter.api.Test; +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.core.IsNot.not; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static io.restassured.RestAssured.given; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.core.IsNot.not; +import org.acme.spring.data.rest.containers.PostgreSqlDatabaseTestResource; +import org.apache.http.HttpStatus; +import org.junit.Assert; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.response.Response; @QuarkusTest @QuarkusTestResource(PostgreSqlDatabaseTestResource.class) @@ -118,10 +118,11 @@ void testRepositoryValidator() throws InterruptedException{ .body("{\"name\": \"Q\", \"author\": \"Li\"}") .when().post("/books") .then() - .statusCode(500) - .body( - containsString("length must be between 2 and 50"), - containsString("propertyPath=name") - ); + .statusCode(HttpStatus.SC_BAD_REQUEST); + // TODO: Body assertion is not working caused by https://github.com/quarkusio/quarkus/issues/15492 + // .body( + // containsString("length must be between 2 and 50"), + // containsString("propertyPath=name") + //); } } diff --git a/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/LibraryRepositoryTest.java b/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/LibraryRepositoryTest.java index 1a26bad9..e572f362 100644 --- a/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/LibraryRepositoryTest.java +++ b/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/LibraryRepositoryTest.java @@ -3,6 +3,7 @@ import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; import org.acme.spring.data.rest.containers.PostgreSqlDatabaseTestResource; +import org.apache.http.HttpStatus; import org.junit.jupiter.api.Test; import static io.restassured.RestAssured.given; @@ -79,9 +80,10 @@ void testRepositoryValidator() throws InterruptedException{ .body("{\"name\": \"\"}") .when().post("/library") .then() - .statusCode(500) - .body( - containsString("Name may not be blank") - ); + .statusCode(HttpStatus.SC_BAD_REQUEST); + // TODO: Body assertion is not working caused by https://github.com/quarkusio/quarkus/issues/15492 + //.body( + // containsString("Name may not be blank") + //); } } diff --git a/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/NativeLibraryRepositoryTestIT.java b/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/NativeLibraryRepositoryTestIT.java index ffe2313f..aaffef6e 100644 --- a/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/NativeLibraryRepositoryTestIT.java +++ b/602-spring-data-rest/src/test/java/org/acme/spring/data/rest/NativeLibraryRepositoryTestIT.java @@ -1,6 +1,5 @@ package org.acme.spring.data.rest; -import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.NativeImageTest; @NativeImageTest