From 7466f04ee995853e29b4df75a3a0e3e8d96be5a4 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Mon, 29 Jun 2020 02:45:30 +0430 Subject: [PATCH] Added the Rest Assured Example --- .../GreetControllerRealIntegrationTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java b/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java new file mode 100644 index 0000000000..05c6313e76 --- /dev/null +++ b/spring-mvc-java/src/test/java/com/baeldung/web/controller/GreetControllerRealIntegrationTest.java @@ -0,0 +1,34 @@ +package com.baeldung.web.controller; + +import io.restassured.RestAssured; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import static io.restassured.RestAssured.given; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = RANDOM_PORT) +@TestPropertySource(properties = {"spring.main.allow-bean-definition-overriding=true", "server.servlet.context-path=/"}) +public class GreetControllerRealIntegrationTest { + + @LocalServerPort + private int port; + + @Before + public void setUp() { + RestAssured.port = port; + } + + @Test + public void givenGreetURI_whenSendingReq_thenVerifyResponse() { + given().get("/greet") + .then() + .statusCode(200); + } +}