use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestSpringmvcConsumerResponseMapperFactory method createResponseMapper.
@Test
public void createResponseMapper() {
Method responseEntityMethod = ReflectUtils.findMethod(this.getClass(), "responseEntity");
Method listMethod = ReflectUtils.findMethod(this.getClass(), "list");
ConsumerResponseMapper mapper = factory.createResponseMapper(factorys, listMethod.getGenericReturnType(), responseEntityMethod.getGenericReturnType());
Assert.assertThat(mapper, Matchers.instanceOf(SpringmvcConsumerResponseMapper.class));
Response response = Response.ok(Arrays.asList("a", "b"));
@SuppressWarnings("unchecked") ResponseEntity<String[]> responseEntity = (ResponseEntity<String[]>) mapper.mapResponse(response);
Assert.assertThat(responseEntity.getBody(), Matchers.arrayContaining("a", "b"));
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestSpringmvcProducerResponseMapper method mapResponse_withoutHeader_sucess.
@SuppressWarnings("unchecked")
@Test
public void mapResponse_withoutHeader_sucess() {
ResponseEntity<String[]> responseEntity = new ResponseEntity<>(arrResult, org.springframework.http.HttpStatus.OK);
Response response = mapper.mapResponse(null, responseEntity);
Assert.assertThat((List<String>) response.getResult(), Matchers.contains("a", "b"));
Assert.assertEquals(Status.OK, response.getStatus());
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestSpringmvcProducerResponseMapper method mapResponse_withHeader.
@Test
public void mapResponse_withHeader() {
HttpHeaders headers = new HttpHeaders();
headers.add("h", "v");
ResponseEntity<String[]> responseEntity = new ResponseEntity<>(arrResult, headers, org.springframework.http.HttpStatus.OK);
Response response = mapper.mapResponse(null, responseEntity);
List<Object> hv = response.getHeaders().getHeader("h");
Assert.assertThat(hv, Matchers.contains("v"));
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestSpringmvcProducerResponseMapperFactory method createResponseMapper.
@Test
public void createResponseMapper() {
Method responseEntityMethod = ReflectUtils.findMethod(this.getClass(), "responseEntity");
Method listMethod = ReflectUtils.findMethod(this.getClass(), "list");
ProducerResponseMapper mapper = factory.createResponseMapper(factorys, listMethod.getGenericReturnType(), responseEntityMethod.getGenericReturnType());
Assert.assertThat(mapper, Matchers.instanceOf(SpringmvcProducerResponseMapper.class));
ResponseEntity<String[]> responseEntity = new ResponseEntity<String[]>(new String[] { "a", "b" }, HttpStatus.OK);
Response response = mapper.mapResponse(null, responseEntity);
Assert.assertThat(response.getResult(), Matchers.contains("a", "b"));
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class JaxrsProducerResponseMapper method mapResponse.
@Override
public Response mapResponse(StatusType status, Object response) {
javax.ws.rs.core.Response jaxrsResponse = (javax.ws.rs.core.Response) response;
Response cseResponse = Response.status(jaxrsResponse.getStatusInfo()).entity(jaxrsResponse.getEntity());
MultivaluedMap<String, Object> headers = jaxrsResponse.getHeaders();
for (Entry<String, List<Object>> entry : headers.entrySet()) {
if (entry.getValue() == null || entry.getValue().isEmpty()) {
continue;
}
cseResponse.getHeaders().addHeader(entry.getKey(), entry.getValue());
}
return cseResponse;
}
Aggregations