开发者

WSRequest POST a JSON object in FunctionalTest would end up getting 404

I have the following test case that I want to post a piece of json data, but I am getting 404 now, am I doing something wrong here?

@Test
public void testIndex() {
    User user = new User("test@foo.com", "secret", "test", "(111)111-1111");
    Gson gson = new Gson();
    String postJson = gson.toJson(user);

    // post to add the new user
    WSRequest postRequest = W开发者_C百科S.url("http://localhost:9001/user/add");
    postRequest.body = postJson;
    HttpResponse postResponse = postRequest.post();
    assertEquals(postResponse.getStatus(), (Integer)200);
}


An HTTP 404 means either your path is not correct, or inside the method that receives the POST request in your controller you are trying to do a redirect to a page that doesn't exist.

Seeing your code (direct check of status) I would bet on the first. Can you add the code of your routes file in here? And verify that Play is running in 9001, not 9000?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜