Skip to content

Commit

Permalink
REST Data extensions returns 400 when violations
Browse files Browse the repository at this point in the history
  • Loading branch information
Sgitario committed Mar 5, 2021
1 parent ddbe2a2 commit 49b9bf2
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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"));
}
}
4 changes: 0 additions & 4 deletions 011-quarkus-panache-rest-flyway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;

import org.acme.spring.data.rest.containers.PostgreSqlDatabaseTestResource;
import org.apache.http.HttpStatus;
import org.junit.Assert;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -117,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")
//);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
//);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.acme.spring.data.rest;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
Expand Down

0 comments on commit 49b9bf2

Please sign in to comment.