javaunit-testingrest-assured

The method given() is undefined for the type - http://rest-assured.io/


I am trying to write a unit test for a web service in Java using io-rest-assured. Looks like so much have changed since I last used it. I am getting the error The method given() is undefined for the type. I have imported almost all the required jars as appears to me. Any suggestions as what am I missing?

import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import io.restassured.RestAssured.*;
import io.restassured.matcher.RestAssuredMatchers.*;
import org.hamcrest.Matchers.*;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.web.servlet.request.RequestPostProcessor;
import io.restassured.module.jsv.JsonSchemaValidator.*;
import io.restassured.module.mockmvc.RestAssuredMockMvc.*;

public class ProxyIntegrationTest_RA extends MockControllerIntegrationTest{

    private static final String REQUEST_MAPPING = "/xy/v1/fax";

    @Test
    public void testGetServices_success() throws Exception {
        final String niv = "1234567890";

        given().
            param("store","0123").
        when().
            get(REQUEST_MAPPING + "/vehicles/{niv}/serviceHistory", niv).
        then().
            statusCode(200);
    }
}

given(), when(), then() none is recognised.


Solution

  • Either use a static import for the static given() method :

        import static io.restassured.matcher.RestAssuredMatchers.given;
    

    Or import the class, and call the static method as usual :

        import io.restassured.matcher.RestAssuredMatchers;
    

    ...

        RestAssuredMatchers.given().
            param("store","0123").
        when().
            get(REQUEST_MAPPING + "/vehicles/{niv}/serviceHistory", niv).
        then().
            statusCode(200);