2
votes

I am a beginner, and am trying to check response for given url. I have written a very simple code, but am recieving an exception. I have tried a lot of things, but I have not been able to resolve it. Please help me.

Code:

public class RestAPITest {

    @Test
    public void test() {
        final String url = "http//:127.0.0.1:8080/myproject/api/";
        given().parameter("HEADER_NAME", "X-Auth-Token", "MY_DEFAULT_TOKEN", "_MY_REST_TOKEN").
        contentType("application/json; charset=UTF-16").when().get(url).then().statusCode(200);
    }
}

Exception Occured:

java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET
    at com.jayway.restassured.config.EncoderConfig.<init>(EncoderConfig.java:48)
    at com.jayway.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
    at com.jayway.restassured.RestAssured.<clinit>(RestAssured.java:423)
    at com.rest.RestAPITest.test(RestAPITest.java:59)
1

1 Answers

0
votes

It seems to be a dependency issue. See this thread on the official issues tracker.

I had the same error and solved it by changing the httpcore version. The library was in my classpath, downloaded as global dependency but it was the version 4.0.1. I guess the minimal requirement is 4.4.x.

In the project settings, I removed the version 4.0.1 of httpcore. I downloaded the version 4.4.6 using Maven and added it to the project.