Failed to make POST action

1,763 views
Skip to first unread message

mahadi hasan

unread,
Sep 30, 2014, 7:03:26 AM9/30/14
to rest-a...@googlegroups.com
Hello,  when i am trying to test POST action then its always failed with: Expected status code <201> doesn't match actual status code <400>.


 given().log().all().contentType(ContentType.JSON).parameters("country", "sweden").expect().statusCode(201)
         
.when().post("http://order-statistics.testing.qfdev.net:31010/cities");


It returns:
Request method:    POST
Request path:    http://order-statistics.testing.qfdev.net:31010/cities
Proxy:            <none>
Request params:    country=sweden
Query params:    <none>
Form params:    <none>
Path params:    <none>
Multiparts:        <none>
Headers:        Content-Type=application/json
Cookies:        <none>
Body:            <none>
FAILED
: testGetSingleUser
java
.lang.AssertionError: 1 expectation failed.
Expected status code <201> doesn't match actual status code <400>.

Would be great if some one can figure out if i we are doing something wrong and please let me know if you need more information.

Best Regards,
Mahadi

Johan Haleby

unread,
Oct 1, 2014, 1:35:14 AM10/1/14
to rest-a...@googlegroups.com
What your showing is the request log not the response log. You need add "log().all()" after expect in order to log the response:

 given().contentType(ContentType.JSON).parameters("country", "sweden").expect().log().all().statusCode(201).when().post("http://order-statistics.testing.qfdev.net:31010/cities");

or preferably:

 given().
         contentType(ContentType.JSON).
         parameters("country", "sweden").
 when().
 then().
        log().all().
        statusCode(201);

/Johan


--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mahadi hasan

unread,
Oct 7, 2014, 5:38:00 AM10/7/14
to rest-a...@googlegroups.com
Hello Johan,

Thanks a lot for your quick replay and i am sorry for the late response.

So i modified my test as like yours input. Now it returns me the actual error, which is "Invalid JSON content"

HTTP/1.1 400 Bad Request
Server: nginx/1.1.19
Date: Tue, 07 Oct 2014 09:29:57 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
X
-Powered-By: PHP/5.3.10-1ubuntu3.14

"Invalid JSON content"

FAILED
: testGetSingleUser
java
.lang.AssertionError: 1 expectation failed.
Expected status code <201> doesn't match actual status code <400>.

Here it is the actual post action captured by the firebug: http://screencast.com/t/KgN6fHEFYJc

Please let me know if you need more information to figure out it.

Best Regards,
Mahadi Hasan

Johan Haleby

unread,
Oct 7, 2014, 5:55:29 AM10/7/14
to rest-a...@googlegroups.com
Are you supposed to send JSON in the POST request? Right now you send a form parameter and not JSON. You send body content using "given().contentType(JSON).body(..). .."

/Johan

mahadi hasan

unread,
Oct 7, 2014, 7:39:20 AM10/7/14
to rest-a...@googlegroups.com
Thanks Johan,

Finally i have get it working as you described.

Best Regards,
Mahadi
Reply all
Reply to author
Forward
0 new messages