Spring Controller Unit Testing

This Spring controller unit test is based on

HATEOAS RESTFul Service with Spring tutorial. The request URL and JSON response content are shown below.

REQUEST URL: http://localhost:8080/simpleSpring/greeting?name=John
RESPONSE JSON: {“content”:”Hello, John!”,”links”:[{“rel”:”self”,”href”:”http://localhost:8080/simpleSpring/greeting?name=John”}]}

REQUEST URL: http://localhost:8080/simpleSpring/greeting
RESPONSE JSON:{“content”:”Hello, World!”,”links”:[{“rel”:”self”,”href”:”http://localhost:8080/simpleSpring/greeting?name=World”}]}

The first step is to have the relevant jars for testing in the pom.xml file.

Step 1: The pom.xml for the testing.

Step 2: The unit testing

Step 3: The Spring MVC controller class being tested


800+ Java & Big Data Interview Q&As

Top