java - 在 Rest-assured 中使用 Json 文件作为负载

标签 java json rest junit rest-assured

我有一个巨大的 JSON 文件要作为测试目的的 rest api 调用的有效负载发布。我试过类似的东西:

    public void RestTest() throws Exception {
    File file = new File("/Users/bmishra/Code_Center/stash/experiments/src/main/resources/Search.json");
    String content = null;

    given().body(file).with().contentType("application/json").then().expect().
            statusCode(200).
            body(equalTo("true")).when().post("http://devsearch");


}

并得到错误:

java.lang.UnsupportedOperationException: Internal error: Can't encode /Users/bmishra/Code_Center/stash/experiments/src/main/resources/Search.json to JSON.

我可以通过读取文件并将正文作为字符串传递来运行,这可行,但我发现我可以直接传递文件对象,但这行不通。

经过充分研究后,它似乎不起作用。我放心地打开了问题。 https://github.com/jayway/rest-assured/issues/674

最佳答案

与放心的团队发布问题后。我有办法解决。我测试了修复程序,现在问题已解决。

安心寄语:

它现在应该已修复,所以我现在部署了一个应该可以解决此问题的新快照。请在添加以下 Maven 存储库后尝试版本 2.9.1-SNAPSHOT:

<repositories>
        <repository>
            <id>sonatype</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <snapshots />
        </repository>
</repositories>

更多信息:https://github.com/jayway/rest-assured/issues/674#issuecomment-210455811

关于java - 在 Rest-assured 中使用 Json 文件作为负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36579155/

相关文章:

web-services - 将 Spark RDD 上传到 REST webservice POST 方法

c# - 如何指定API版本?

java - 在自定义 Eclipse 透视图中显示 View

java - 对于 https URL,HttpsURLConnection 可以工作,但 HttpClient 不能

java - 这个静态方法使用哪个类,StringBuffer 还是 StringBuilder?

java - spring BeanCreationException 关于映射的困惑

sql - 带有 ORDER BY 的雪花 JSON 扁平化

ios - 使用 Restkit 从 JSON 数组映射关系

javascript - 使用 Javascript 过滤多个 HTML 表中的 JSON 数据

rest - 如何在 RESTful Web 服务中指定一系列数据或多个实体