Here is a basic Hello World example of REST Assured with Spring Boot.

Rest-Assured is a Java-based library that is used to test REST Services. This library provides a headless Client to access REST services. We can therefore create highly customizable HTTP Requests to send to the Restful server. This enables us to test a large variety of Request combinations and in turn test different business logic.
Rest-Assured library also has the ability to validate the HTTP Responses received from the server. For example, we can verify the Status code, Status message, Headers and even the Body of the response. This makes Rest-Assured a very flexible library that can be used for testing.

First off, make sure you include REST Assured dependency in your Spring Boot Project:

<dependency>
	<groupId>io.rest-assured</groupId>
	<artifactId>rest-assured</artifactId>
	<version>3.0.7</version>
	<scope>test</scope>
</dependency>

Now suppose you want to test this REST Service:

package com.example.testrest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class CustomerController {
    
    @Autowired
    CustomerRepository repository;

    @RequestMapping("/list")
    public List<Customer> findAll() {
        return repository.getData();
    }

    @RequestMapping("/one/{id}")
    public Customer findOne(@PathVariable int id) {
        return repository.getData().get(id);

    }
}

Where the CustomerRepository class if the following one:

package com.example.testrest;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
@Component
public class CustomerRepository {
    List<Customer> customerList = new ArrayList<Customer>();

    @PostConstruct
    public void init(){
        customerList.add(new Customer(1, "frank"));
        customerList.add(new Customer(2, "john"));
    }
    public List<Customer> getData() {
        return customerList;
    }
}

Then, here is how you can test all the Endpoint methods with REST Assured:

package com.example.testrest;

import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static io.restassured.RestAssured.get;
import static org.hamcrest.CoreMatchers.is;

@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests {

	@Test
	public void testCustomerList() {

		get("http://localhost:8080/list")
				.then()
				.assertThat()
				.statusCode(200)
				.body("size()", is(2));


		get("http://localhost:8080/one/0")
				.then()
				.assertThat()
				.statusCode(200)
				.body("name", Matchers.equalTo("frank"));

		get("http://localhost:8080/one/1")
				.then()
				.assertThat()
				.statusCode(200)
				.body("name", Matchers.equalTo("john"));

	}

}

You can find the full Spring Boot source code here: http://www.masterspringboot.com/develop-applications/rest-services/spring-boot-hello-world-rest-service

FREE WildFly Application Server - JBoss - Quarkus - Drools Tutorials