我从Azure登录REST调用返回了以下JSON:
{
"token_type": "Bearer",
"expires_in": "3600",
"ext_expires_in": "3600",
"expires_on": "1560857196",
"not_before": "1560853296",
"resource": "https://management.azure.com",
"access_token": "d9f9s..." //I cut the value significantly here...
}
我为此创建的POJO如下:
public class AzureLoginResponse {
private String tokenType;
private String expiresIn;
private String extExpiresIn;
private String expiresOn;
private String notBefore;
private String resource;
private String accessToken;
//setters\getters
}
当我这样做时:
@Given("^Azure Login Request Executed$")
public void azureLoginExecuted() {
RestAssured.baseURI = BASE_URI;
Response response =
given() //Add x-www-form-urlencoded body params:
.formParam(GRANT_TYPE_KEY, GRANT_TYPE_VALUE)
.formParam(AUTO_TEAM_CLIENT_ID_KEY, AUTO_TEAM_CLIENT_ID_VALUE)
.formParam(AUTO_TEAM_CLIENT_SECRET_KEY, AUTO_TEAM_CLIENT_SECRET_VALUE)
.formParam(RESOURCE_KEY, RESOURCE_VALUE)
.when()
.post(AUTO_TEAM_TENANT_ID + RESOURCE); //Send the request along with the resource
AzureLoginResponse azureLoginResponse = response.as(AzureLoginResponse.class);
}
azureLoginResponse获得以下数据:
azureLoginResponse = {AzureLoginResponse@3532}
tokenType = null
expiresIn = null
extExpiresIn = null
expiresOn = null
notBefore = null
resource = "https://management.azure.com"
accessToken = null
因此,只会填充'resource'属性,而类似
的测试assertThat(expires_in_val, greaterThan(min_expected_expires_in_val));
或
response.then().body("resource", equalTo(expected_resource));
顺利通过。
请告知。谢谢!
答案 0 :(得分:1)
您的POJO键与响应中的键不匹配,因此为空值。如您所见,响应的密钥是snake_case,而POJO中使用的密钥是camelCase。