Skip to content
This repository has been archived by the owner on Jun 14, 2018. It is now read-only.

Commit

Permalink
[75] Adding Bean Validations to sample app and integration test
Browse files Browse the repository at this point in the history
See #75
  • Loading branch information
fabiocarvalho777 committed Jul 29, 2017
1 parent b7262c0 commit 91c7746
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public void invalidBaseUrlTest() {
response.then().statusCode(404).body("status", equalTo(404)).body("error", equalTo("Not Found"));
}

@Test
public void invalidNoPayloadTest() {
// Notice that the endpoint we are sending a request to uses Bean Validations to assure
// the request message payload is valid. If that is not the case (a blank payload for example),
// then the server is expected to return a 400 response message
Response response = given().body("").post("/echo");
response.then().statusCode(400).body(equalTo("[PARAMETER]\r[echo.arg0]\r[may not be empty]\r[]\r\r"));
}

@Test
public void actuatorTest() throws InterruptedException {
Response response = given().basePath("/").get("/health");
Expand Down
3 changes: 3 additions & 0 deletions resteasy-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>


<!-- Test dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand Down
8 changes: 8 additions & 0 deletions sample-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<resteasy.version>3.1.3.Final</resteasy.version>
</properties>

<dependencies>
Expand All @@ -43,6 +44,13 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>

<!-- Adding RESTEasy support to Bean Validations -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-validator-provider-11</artifactId>
<version>${resteasy.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 3 additions & 1 deletion sample-app/src/main/java/com/sample/app/Echo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.hibernate.validator.constraints.NotEmpty;

/**
* Echo REST endpoint class
*
Expand All @@ -33,7 +35,7 @@ public class Echo {
@POST
@Consumes({ MediaType.TEXT_PLAIN })
@Produces({ MediaType.APPLICATION_JSON })
public EchoMessage echo(String echoText) {
public EchoMessage echo(@NotEmpty String echoText) {
return echoer.createEchoMessage(echoText);
}

Expand Down

0 comments on commit 91c7746

Please sign in to comment.