use of org.onap.so.apihandlerinfra.tasksbeans.RequestDetails in project so by onap.
the class ManualTasksTest method completeTaskBpelResponseError.
@Test
public void completeTaskBpelResponseError() throws IOException {
wireMockServer.stubFor(post(urlPathEqualTo("/sobpmnengine/task/55/complete")).willReturn(aResponse().withHeader("Content-Type", "application/json").withFault(Fault.EMPTY_RESPONSE)));
String taskId = "55";
TasksRequest taskReq = new TasksRequest();
RequestDetails reqDetail = new RequestDetails();
RequestInfo reqInfo = new RequestInfo();
reqInfo.setRequestorId("testId");
reqInfo.setSource("testSource");
reqInfo.setResponseValue(ValidResponses.skip);
reqDetail.setRequestInfo(reqInfo);
taskReq.setRequestDetails(reqDetail);
RequestError expectedResponse = new RequestError();
ServiceException se = new ServiceException();
se.setMessageId("SVC1000");
se.setText("Client from http://localhost:" + env.getProperty("wiremock.server.port") + "/sobpmnengine/task/55/complete failed to connect or respond");
expectedResponse.setServiceException(se);
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON);
headers.set("Content-Type", MediaType.APPLICATION_JSON);
headers.set(ECOMP_REQUEST_ID, "987654321");
headers.set(ONAP_PARTNER_NAME, "VID");
HttpEntity<TasksRequest> entity = new HttpEntity<TasksRequest>(taskReq, headers);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(basePath) + taskId + "/complete");
ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
assertEquals(Response.Status.BAD_GATEWAY.getStatusCode(), response.getStatusCode().value());
assertThat(realResponse, sameBeanAs(expectedResponse));
}
use of org.onap.so.apihandlerinfra.tasksbeans.RequestDetails in project so by onap.
the class ManualTasksTest method testCreateOpEnvObjectMapperError.
@Test
public void testCreateOpEnvObjectMapperError() throws IOException {
TestAppender.events.clear();
wireMockServer.stubFor(post(urlPathEqualTo("/sobpmnengine/task/55/complete")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK)));
String taskId = "55";
TasksRequest taskReq = new TasksRequest();
RequestDetails reqDetail = new RequestDetails();
RequestInfo reqInfo = new RequestInfo();
reqInfo.setRequestorId("testId");
reqInfo.setSource("testSource");
reqInfo.setResponseValue(ValidResponses.skip);
reqDetail.setRequestInfo(reqInfo);
taskReq.setRequestDetails(reqDetail);
// expected response
TaskRequestReference expectedResponse = new TaskRequestReference();
expectedResponse.setTaskId(taskId);
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON);
headers.set("Content-Type", MediaType.APPLICATION_JSON);
headers.set(ECOMP_REQUEST_ID, "987654321");
headers.set(ONAP_PARTNER_NAME, "VID");
HttpEntity<TasksRequest> entity = new HttpEntity<TasksRequest>(taskReq, headers);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(basePath) + taskId + "/complete");
ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
TaskRequestReference realResponse = mapper.readValue(response.getBody(), TaskRequestReference.class);
// then
assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
assertThat(realResponse, sameBeanAs(expectedResponse));
}
use of org.onap.so.apihandlerinfra.tasksbeans.RequestDetails in project so by onap.
the class ManualTasksTest method completeTaskValidationError.
@Test
public void completeTaskValidationError() throws IOException {
String taskId = "55";
TasksRequest taskReq = new TasksRequest();
RequestDetails reqDetail = new RequestDetails();
RequestInfo reqInfo = new RequestInfo();
reqInfo.setSource("testSource");
reqInfo.setResponseValue(ValidResponses.skip);
reqDetail.setRequestInfo(reqInfo);
taskReq.setRequestDetails(reqDetail);
RequestError expectedResponse = new RequestError();
ServiceException se = new ServiceException();
se.setMessageId("SVC0002");
se.setText("Mapping of request to JSON Object failed. No valid requestorId is specified");
expectedResponse.setServiceException(se);
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON);
headers.set("Content-Type", MediaType.APPLICATION_JSON);
headers.set(ECOMP_REQUEST_ID, "987654321");
headers.set(ONAP_PARTNER_NAME, "VID");
HttpEntity<TasksRequest> entity = new HttpEntity<TasksRequest>(taskReq, headers);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(basePath) + taskId + "/complete");
ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
assertThat(realResponse, sameBeanAs(expectedResponse));
}
Aggregations