我是REST Assured API测试的新手,我已经在库中添加了jackson-databind,jackson-annotations和jackson-core所有2.9.6版本。
下面是我的代码:
public class SerializeAndDeserialize {
@Test
public void RegistrationSuccessful()
{
RestAssured.baseURI ="http://restapi.demoqa.com/customer";
RequestSpecification request = RestAssured.given();
JSONObject requestParams = new JSONObject();
requestParams.put("FirstName", "Virkjdender"); // Cast
requestParams.put("LastName", "Scklxjingh");
requestParams.put("UserName", "63userf2d3cn,mxd2011");
requestParams.put("Password", "passwors000mxzmd1");
requestParams.put("Email", "ed26dfdasdf39@gmail.com");
request.body(requestParams.toJSONString());
Response response = request.post("/register");
ResponseBody body = response.getBody();
System.out.println(response.body().asString());
System.out.println(response.contentType());
System.out.println(response.getStatusCode());
if(response.statusCode() == 200)
{
// Deserialize the Response body into RegistrationFailureResponse
RegistrationFailureResponse responseBody = body.as(RegistrationFailureResponse.class);
Assert.assertEquals("User already exists", responseBody.FaultId);
Assert.assertEquals("FAULT_USER_ALREADY_EXISTS", responseBody.fault);
}
else if (response.statusCode() == 201)
{
// Deserialize the Response body into RegistrationSuccessResponse
RegistrationSuccessResponse responseBody = body.as(RegistrationSuccessResponse.class);
Assert.assertEquals("OPERATION_SUCCESS", responseBody.SuccessCode);
Assert.assertEquals("Operation completed successfully", responseBody.Message);
}
}
}
和相关的类如下:
public class RegistrationFailureResponse {
@JsonIgnoreProperties(ignoreUnknown = true)
String FaultId;
String fault;
}
请帮忙,我用谷歌搜索了解决方案,但都与我在这里面临的问题无关
HUX布斯
相关分类