Playframework 2.1测试POST请求中的JSON无效 [英] Invalid JSON in Playframework 2.1 Test POST Request

查看:81
本文介绍了Playframework 2.1测试POST请求中的JSON无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试测试POST路由(在Playframework 2.1/Java上),并不断收到Bad Request-无效的JSON响应.

I am trying to test a POST route (on Playframework 2.1/ Java) and keep getting Bad Request - Invalid JSON response.

请让我知道我在做什么错.我的测试代码如下.

Please let me know what I am doing wrong. My Test code is below.

 running(fakeApplication(), new Runnable() {
                        public void run() {

            Map map = new HashMap();
            map.put("key1", "val1");
            map.put("key2", 2);
            map.put("key3", true);
            JsonNode df= Json.toJson(map);

            Result result = route
                    (fakeRequest(POST, "/item").withHeader("Content-Type", "application/json").withSession(AccountTest.USER_KEY, "some key")
                            .withSession(AccountTest.PROVIDER_KEY, "facebook").withJsonBody(df));

            Logger.debug("result is "  + contentAsString(result));
            System.out.println("result is "  + contentAsString(result));

                assertThat(result).isNotNull();

//                assertThat(result).isNotNull();
//                assertThat(result).isEqualTo("hello");
            }

        });

推荐答案

这是Play 2.1(Java)中已记录的错误.请参考此处的错误以及git-pull请求

This a documented bug in Play 2.1 (Java). Please refer to the bug here and the git-pull request https://play.lighthouseapp.com/projects/82401/tickets/984-adding-json-body-to-play-21-java-returns-invalid-json-message#ticket-984-8

这篇关于Playframework 2.1测试POST请求中的JSON无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆