Re: [rest-assured] ResponseSpecification.contentType behavior

59 views
Skip to first unread message

Johan Haleby

unread,
Jul 26, 2012, 2:41:02 AM7/26/12
to rest-a...@googlegroups.com
I've tried it and this works for me:

expect().contentType(is("application/json; charset=UTF-8")).when().get("/hello");


Regards
/Johan

On Wed, Jul 25, 2012 at 9:01 PM, rtoal <ray....@gmail.com> wrote:
Hi

I am trying to validate that a response has the content type  application/x-javascript.

I cannot use

    expect().contentType(ContentType.JSONP).when().get(url);

because there is no such enum constant.  I tried

    expect().contentType(is("application/x-javascript")).when().get(url);

but that I got a 500 from Tomcat with the following beginning of a stack trace:

    SEVERE: Servlet.service() for servlet mvc threw exception
    java.lang.IllegalArgumentException: Invalid token character ' ' in token "is "application"
        at org.springframework.http.MediaType.checkToken(MediaType.java:352)
        at org.springframework.http.MediaType.<init>(MediaType.java:324)

Yes I am using org.hamcrest.Matchers.is here, but you see the problem: the "is" somehow got confused with its argument.  I am not sure if this is a hamcrest problem, a tomcat problem, a Rest-Assured problem, or a me problem.

Note that I *can* just say

    expect().contentType("application/x-javascript").when().get(url);

but I thought the issue with the hamcrest matcher was interesting.  Is this worth filing an issue about?

Thanks







Reply all
Reply to author
Forward
0 new messages