这是我的控制器类
@PostMapping(path = "/appformsubmission")
public ChanelResponse<AppFormSubmissionResponse> saveAppForm(
@RequestBody ChanelRequest<AppFormDetails> requestObject) throws JsonProcessingException {
logger.info("MwController -saveAppForm ");
if (logger.isDebugEnabled()) {
logger.debug("Entering MwController() method");
logger.debug("requestObject : {}", Utility.toJsonString(requestObject));
}
return appFormService.submitApplicationForm(requestObject);
}
服务等级
public ChanelResponse<AppFormSubmissionResponse> submitApplicationForm(ChanelRequest<AppFormDetails> request) throws JsonProcessingException{
AppFormDetails appFormDetails = new ObjectMapper().convertValue(request.getPayload().getDataEntity().get(0), AppFormDetails.class);
HttpEntity<?> httpEntity = new HttpEntity<>(appFormDetails);
String submitApplicationUrl = env.getProperty("bo.appformsubmission.url")+env.getProperty("bo.appformsubmission.path");
String applicationFormDetails =new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(appFormDetails);
logger.info("Request To BO ->{}" , applicationFormDetails);
AppFormSubmissionBOResponse appFormSubmissionBOResponse=apiCallImpl.invokeSubmitApplicationForm(submitApplicationUrl, httpEntity);
String appFormSubBOResponse= new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(appFormSubmissionBOResponse);
logger.info("Response from BO {}" , appFormSubBOResponse);
Status status = new Status();
AppFormSubmissionResponse appFormSubmissionResponse = new AppFormSubmissionResponse();
appFormSubmissionResponse.setApplicationNumber(appFormSubmissionBOResponse.getApplicationNumber());
appFormSubmissionResponse.setPdfUrl(appFormSubmissionBOResponse.getPdfUrl());
Payload<AppFormSubmissionResponse> appFormPayload = new Payload<>();
List<AppFormSubmissionResponse> dataEntityList = new ArrayList<>();
dataEntityList.add(appFormSubmissionResponse);
appFormPayload.setDataEntity(dataEntityList );
status.setCode(appFormSubmissionBOResponse.getStatus());
status.setServerStatusCd("SUCCESS");
Severity severity =new Severity();
severity.setCDE("CodeDescVO_1.0.0");
severity.setDSC("INFO");
severity.setVer("Info");
status.setSeverity(severity);
status.setVer("StatusVO_1.0.0");
ChanelResponse<AppFormSubmissionResponse> responseObject = new ChanelResponse<>();
responseObject.setPayload(appFormPayload);
responseObject.setStatus(status);
return responseObject;
}
这是我的测试用例
@Test
public void appFormSubmissionTest() throws Exception {
AppFormSubmissionBOResponse response = new ObjectMapper().readValue(
AppFormSubmissionBOResponse.class.getResourceAsStream("/appFormSubmission_BO_Resp.json"),
new TypeReference<AppFormSubmissionBOResponse>() { });
ChanelRequest<AppFormDetails> appForm = new ObjectMapper()
.readValue(ChanelRequest.class.getResourceAsStream("/appFormSubmissionChanelRequest.json"),
new TypeReference<ChanelRequest<AppFormDetails>>() {});
Mockito.when(apiCallImpl.invokeSubmitApplicationForm(any(String.class), any(HttpEntity.class))).thenReturn(response);
mockMvc.perform(MockMvcRequestBuilders.post("/appformsubmission").accept(MediaType.APPLICATION_JSON_UTF8_VALUE)
.content(new ObjectMapper()
.writeValueAsString(appForm)).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
}
我遇到了错误。 org.springframework.web.util.NestedServletException:请求处理失败;嵌套的异常是org.springframework.web.client.HttpServerErrorException $ InternalServerError:500内部服务器错误
有什么建议吗?