我有一个服务impl文件,该文件填充了DTO,而REST端点文件则发布了POST,并将响应放入变量中。我可以在端点文件中打印出DTO内容,但不能使用picocontainer DI在服务impl文件上打印响应数据。这是文件详细信息
// Endpoint File that does the POST and can correctly display the DTO details
// via Picoconntainer DI
import com.constantcontact.xyzreachsvc.domain.xyzPostDto;
import io.restassured.RestAssured;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.internal.RestAssuredResponseImpl;
import utilities.TestLogger;
public class xyzPostEndpoint extends RestAssured {
private RequestSpecBuilder request ;
private RestAssuredResponseImpl response;
private xyzPostDto xyzPostDto;
public xyzlPostEndpoint(
RequestSpecBuilder request,
RestAssuredResponseImpl response,
xyzPostDto xyzPostDto) {
this.response = response;
this.xyzPostDto = xyzPostDto;
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
this.request = request;
}
public void xyzPostPostMethod() {
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
TestLogger.info("*************************Starting the POST*************************");
response = (RestAssuredResponseImpl) given().spec(request.build()).when().post();
System.out.println("*****************>"+xyzPostDto.getMessage());//Get the correct string here
System.out.println("*****************>>"+xyzPostDto.getImageUrl());
System.out.println("*****************>"+response.getStatusCode());//Get 200 here
System.out.println("*****************>>"+response.getBody().asString());
}
}
这就是问题所在。这无法从上面的端点文件获取响应数据。它正在打印-1作为状态代码,并且尝试打印正文给了我NPE。
public class xyzPostImpl implements xyzPostI {
private xyzPostDto xyzPostDto;
private BuildRequest buildRequest;
private xyzPostEndpoint xyzPostEndpoint;
private RestAssuredResponseImpl response;
public xyzPostImpl(xyzPostDto xyzPostDto,
BuildRequest buildRequest,
xyzPostEndpoint xyzPostEndpoint ,
RestAssuredResponseImpl response
){
this.xyzPostDto = xyzPostDto;
this.buildRequest = buildRequest;
this.xyzPostEndpoint = xyzPostEndpoint;
this.response = response;
}
public void buildxyzlPostDto(String imageUrl, String message,
List<String> networkIds ){
xyzPostDto.setImageUrl(imageUrl);
xyzPostDto.setMessage(message);
xyzPostDto.setNetworkIds(networkIds);
}
public void buildxyzPostDtoRequest(){
buildRequest.buildRequest(xyzPostDto);
}
public void issuexyzPostDtoPost(){
xyzlPostEndpoint.xyzPostPostMethod();
}
public Boolean verifyResponseCode(Integer responseCode){
Boolean expectedResponseCode = false;
System.out.println("RESPONSE code = *******************************"+response.getStatusCode());//< get -1 here
if(response.getStatusCode() == responseCode) {
expectedResponseCode = true;
}
return expectedResponseCode;
}
}