2013-02-11 102 views
3

我试图测试POST路由(在Playframework 2.1/Java上),并不断收到错误的请求 - 无效的JSON响应。Playframework 2.1测试POST请求中无效的JSON

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

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"); 
      } 

     }); 

回答