简体   繁体   English

放掉参数放心

[英]put parameters ignored rest assured

(solved): That's because the default parameter types for PUT is request parameters and not form parameters. (已解决):这是因为PUT的默认参数类型是请求参数,而不是表单参数。 Change "parameters(..)" to "formParameters(..)" and it'll work. 将“ parameters(..)”更改为“ formParameters(..)”即可使用。

My code: JUNIT test: (figure 1) 我的代码:JUNIT测试:(图1)

expect().statusCode(Status.NO_CONTENT.getStatusCode())
        .given()
        .parameters("name", name, "URL", URL)
        .cookie(cookie_name, newapi_session_id)
        .put("/IfdOrganization/"+orgGuid);

Server code: (figure 1) 服务器代码:(图1)

@PUT @Path("/IfdOrganization/{guid}") @Produces({APPLICATION_XML, APPLICATION_JSON})
public void update(@PathParam("guid") String guid, @FormParam("name") String name,@FormParam("URL") String URL,@CookieParam(session_cookie_name) String sessionId, @Context HttpHeaders headers) {
}

The problem: When doing a PUT in my JUnit test the parameters "name" and "URL"' value are null on the server (figure 1). 问题:在我的JUnit中进行PUT测试时,服务器上的参数“名称”和“ URL”的值为空(图1)。 If I change ".put()" to ".post()" on the JUnit test and change "@PUT" to "@POST" on the server the parameters' value is correct (figure 2). 如果在JUnit测试中将“ .put()”更改为“ .post()”,并且在服务器上将“ @PUT”更改为“ @POST”,则参数值正确(图2)。 Also, when using PUT in AJAX, the parameters gets the correct value, which means that the problem not comes from the server. 另外,在AJAX中使用PUT时,参数会获取正确的值,这意味着问题并非来自服务器。

I am using eclipse kepler, windows 8 and rest-assured-1.8.0 我正在使用Eclipse Kepler,Windows 8和Rest-assured-1.8.0

JUNIT test: (figure 2) JUNIT测试:(图2)

expect().statusCode(Status.NO_CONTENT.getStatusCode())
            .given()
            .parameters("name", name, "URL", URL)
            .cookie(cookie_name, newapi_session_id)
            .post("/IfdOrganization/"+orgGuid);

Server code: (figure 2) 服务器代码:(图2)

@POST @Path("/IfdOrganization/{guid}") @Produces({APPLICATION_XML, APPLICATION_JSON})
public void update(@PathParam("guid") String guid, @FormParam("name") String name,@FormParam("URL") String URL,@CookieParam(session_cookie_name) String sessionId, @Context HttpHeaders headers) {
}

Any help appreciated 任何帮助表示赞赏

This is a bug in the current version of RestAssured. 这是当前版本的RestAssured中的错误。 1.8.1 See here 1.8.1 见这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM