2013-02-11 67 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"); 
      } 

     }); 

回答