use of org.apache.servicecomb.codec.protobuf.utils.WrapSchema in project incubator-servicecomb-java-chassis by apache.
the class TestOperationProtobuf method testOperationProtobuf.
@Test
public void testOperationProtobuf() throws Exception {
UnitTestMeta meta = new UnitTestMeta();
SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(Impl.class);
OperationMeta operationMeta = schemaMeta.findOperation("test");
OperationProtobuf operationProtobuf = ProtobufManager.getOrCreateOperation(operationMeta);
Assert.assertEquals(operationMeta, operationProtobuf.getOperationMeta());
Assert.assertEquals(ArgsNotWrapSchema.class, operationProtobuf.getRequestSchema().getClass());
Assert.assertEquals(NormalWrapSchema.class, operationProtobuf.getResponseSchema().getClass());
WrapSchema responseSchema = operationProtobuf.findResponseSchema(200);
Assert.assertEquals(operationProtobuf.getResponseSchema(), responseSchema);
responseSchema = operationProtobuf.findResponseSchema(300);
Assert.assertNotNull(responseSchema);
Assert.assertNotEquals(operationProtobuf.getResponseSchema(), responseSchema);
}
use of org.apache.servicecomb.codec.protobuf.utils.WrapSchema 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.codec.protobuf.utils.WrapSchema in project incubator-servicecomb-java-chassis by apache.
the class HighwayCodec method decodeRequest.
public static void decodeRequest(Invocation invocation, RequestHeader header, OperationProtobuf operationProtobuf, Buffer bodyBuffer, ProtobufFeature protobufFeature) throws Exception {
WrapSchema schema = operationProtobuf.getRequestSchema();
Object[] args = schema.readObject(bodyBuffer, protobufFeature);
invocation.setSwaggerArguments(args);
invocation.setContext(header.getContext());
}
use of org.apache.servicecomb.codec.protobuf.utils.WrapSchema in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayTransport method commonHighwayMock.
private void commonHighwayMock(Invocation invocation) {
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Endpoint lEndpoint = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getEndpoint()).thenReturn(lEndpoint);
WrapSchema lWrapSchema = Mockito.mock(WrapSchema.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(lWrapSchema);
URIEndpointObject ep = Mockito.mock(URIEndpointObject.class);
Mockito.when(lEndpoint.getAddress()).thenReturn(ep);
Mockito.when(ep.getHostOrIp()).thenReturn("127.0.0.1");
Mockito.when(ep.getPort()).thenReturn(80);
}
use of org.apache.servicecomb.codec.protobuf.utils.WrapSchema in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayCodec method testEncodeResponse.
@Test
public void testEncodeResponse() {
boolean status = true;
WrapSchema bodySchema = Mockito.mock(WrapSchema.class);
try {
commonMock();
HighwayCodec.encodeResponse(23432142, null, bodySchema, new Object(), new ProtobufFeature());
} catch (Exception e) {
status = false;
}
Assert.assertTrue(status);
}
Aggregations