use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayCodec method testDecodeResponse.
@Test
public void testDecodeResponse() throws Exception {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(operationProtobuf.findResponseSchema(200)).thenReturn(Mockito.mock(WrapSchema.class));
Map<String, String> context = new HashMap<>();
Mockito.when(invocation.getContext()).thenReturn(context);
TcpData tcpData = Mockito.mock(TcpData.class);
Mockito.when(tcpData.getHeaderBuffer()).thenReturn(bodyBuffer);
commonMock();
ResponseHeader header = new ResponseHeader();
header.setStatusCode(200);
header.setContext(new HashMap<>());
header.getContext().put("a", "10");
Buffer responseBuf = HighwayCodec.encodeResponse(0, header, null, null, new ProtobufFeature());
TcpData tcp = new TcpData(responseBuf.slice(23, responseBuf.length()), null);
Response response = HighwayCodec.decodeResponse(invocation, operationProtobuf, tcp, null);
Assert.assertEquals("10", invocation.getContext().get("a"));
Assert.assertEquals(200, response.getStatusCode());
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class HighwayCodec method decodeResponse.
public static Response decodeResponse(Invocation invocation, OperationProtobuf operationProtobuf, TcpData tcpData, ProtobufFeature protobufFeature) throws Exception {
ResponseHeader header = ResponseHeader.readObject(tcpData.getHeaderBuffer(), protobufFeature);
if (header.getContext() != null) {
invocation.getContext().putAll(header.getContext());
}
WrapSchema bodySchema = operationProtobuf.findResponseSchema(header.getStatusCode());
Object body = bodySchema.readObject(tcpData.getBodyBuffer(), protobufFeature);
Response response = Response.create(header.getStatusCode(), header.getReasonPhrase(), body);
response.setHeaders(header.getHeaders());
return response;
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestResponseMapperFactorys method createResponseMapper_cseResponse.
@Test
public void createResponseMapper_cseResponse() {
ConsumerResponseMapper mapper = consumerResponseMapperFactorys.createResponseMapper(String.class, Response.class);
Response response = Response.ok(null);
Object result = mapper.mapResponse(response);
Assert.assertSame(response, result);
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestCompletableFutureProducerResponseMapperFactory method completableFuture.
@Test
public void completableFuture() {
Method producerMethod = ReflectUtils.findMethod(this.getClass(), "producer");
Method swaggerMethod = ReflectUtils.findMethod(this.getClass(), "swagger");
ProducerResponseMapper mapper = factory.createResponseMapper(factorys, swaggerMethod.getGenericReturnType(), producerMethod.getGenericReturnType());
Response response = mapper.mapResponse(Status.OK, new String[] { "a", "b" });
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 TestCseResponseProducerResponseMapperFactory method createResponseMapper.
@Test
public void createResponseMapper() {
ProducerResponseMapper mapper = factory.createResponseMapper(null, null, Response.class);
Response response = Response.ok(null);
Assert.assertSame(response, mapper.mapResponse(Status.OK, response));
}
Aggregations