use of io.servicecomb.codec.protobuf.definition.OperationProtobuf in project java-chassis by ServiceComb.
the class TestGrpcCodec method testDecodeRequest.
@Test
public void testDecodeRequest() {
boolean status = false;
try {
RoutingContext routingContext = Mockito.mock(RoutingContext.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Buffer bodyBuffer = Mockito.mock(Buffer.class);
Mockito.when(routingContext.getBody()).thenReturn(bodyBuffer);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
Mockito.when(routingContext.request()).thenReturn(request);
SchemaMeta schemaMeta = Mockito.mock(SchemaMeta.class);
Mockito.when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta);
Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
GrpcCodec.setGrpcTransport(new GrpcTransport());
GrpcCodec.decodeRequest(routingContext, operationMeta);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
use of io.servicecomb.codec.protobuf.definition.OperationProtobuf in project java-chassis by ServiceComb.
the class TestGrpcTransport method testSend.
@Test
public void testSend() {
boolean status = false;
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
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);
IpPort ipPort = Mockito.mock(IpPort.class);
Mockito.when(lEndpoint.getAddress()).thenReturn(ipPort);
Mockito.when(ipPort.getHostOrIp()).thenReturn("127.0.0.1");
Mockito.when(ipPort.getPort()).thenReturn(80);
new MockUp<ClientPoolManager<HttpClientWithContext>>() {
@Mock
public HttpClientWithContext findThreadBindClientPool() {
return Mockito.mock(HttpClientWithContext.class);
}
};
try {
transport.send(invocation, asyncResp);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
use of io.servicecomb.codec.protobuf.definition.OperationProtobuf in project java-chassis by ServiceComb.
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 io.servicecomb.codec.protobuf.definition.OperationProtobuf in project java-chassis by ServiceComb.
the class TestGrpcServerInvoke method testSendSuccessResponseException.
@Test
public void testSendSuccessResponseException() {
boolean status = false;
try {
MockUtil.getInstance().mockMicroserviceMetaManager();
Invocation invocation = Mockito.mock(Invocation.class);
Response response = Mockito.mock(Response.class);
Mockito.when(response.getResult()).thenReturn("test");
Mockito.when(routingContext.response()).thenReturn(Mockito.mock(HttpServerResponse.class));
try {
Deencapsulation.invoke(lGrpcServerInvoke, "onProviderResponse", invocation, response);
} catch (Exception e) {
}
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
Mockito.when(response.getResult()).thenReturn("test");
Mockito.when(operationProtobuf.getResponseSchema()).thenReturn(Mockito.mock(WrapSchema.class));
Deencapsulation.setField(lGrpcServerInvoke, "operationProtobuf", operationProtobuf);
Deencapsulation.invoke(lGrpcServerInvoke, "sendSuccessResponse", invocation, response);
} catch (Exception e) {
status = true;
}
Assert.assertTrue(status);
}
use of io.servicecomb.codec.protobuf.definition.OperationProtobuf in project java-chassis by ServiceComb.
the class TestGrpcServerInvoke method testSendSuccessResponseExptn.
@Test
public void testSendSuccessResponseExptn() {
boolean status = false;
try {
MockUtil.getInstance().mockMicroserviceMetaManager();
Invocation invocation = Mockito.mock(Invocation.class);
Response response = Mockito.mock(Response.class);
Mockito.when(response.getResult()).thenReturn("test");
Mockito.when(routingContext.response()).thenReturn(Mockito.mock(HttpServerResponse.class));
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
Mockito.when(response.getResult()).thenReturn("test");
Mockito.when(operationProtobuf.getResponseSchema()).thenReturn(Mockito.mock(WrapSchema.class));
Deencapsulation.invoke(lGrpcServerInvoke, "sendSuccessResponse", invocation, response);
} catch (Exception e) {
status = true;
}
Assert.assertTrue(status);
}
Aggregations