use of io.servicecomb.core.Invocation 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.core.Invocation 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);
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestGrpcServerInvoke method testSendSuccessResponse.
@Test
public void testSendSuccessResponse() {
boolean status = false;
try {
new MockUp<GrpcCodec>() {
@Mock
public Buffer encodeResponse(Invocation invocation, Response response, OperationProtobuf operationProtobuf) throws Exception {
return Mockito.mock(Buffer.class);
}
};
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.setField(lGrpcServerInvoke, "routingContext", routingContext);
Deencapsulation.invoke(lGrpcServerInvoke, "sendSuccessResponse", invocation, response);
} catch (Exception e) {
status = true;
}
Assert.assertTrue(status);
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestGrpcCodec method testEncodeResponse.
@Test
public void testEncodeResponse() {
boolean status = false;
try {
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
Invocation invocation = Mockito.mock(Invocation.class);
Response response = Mockito.mock(Response.class);
Mockito.when(response.getResult()).thenReturn("test");
Mockito.when(operationProtobuf.getResponseSchema()).thenReturn(Mockito.mock(WrapSchema.class));
GrpcCodec.encodeResponse(invocation, response, operationProtobuf);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestGrpcCodec method testDecodeResponseEx.
@Test
public void testDecodeResponseEx() {
boolean status = false;
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);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
SchemaMeta schemaMeta = Mockito.mock(SchemaMeta.class);
Mockito.when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta);
Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
Invocation invocation = Mockito.mock(Invocation.class);
Response response = Mockito.mock(Response.class);
Mockito.when(response.getResult()).thenReturn("test");
Mockito.when(operationProtobuf.getResponseSchema()).thenReturn(Mockito.mock(WrapSchema.class));
HttpClientResponse httpResponse = Mockito.mock(HttpClientResponse.class);
Buffer buffer = Mockito.mock(Buffer.class);
Mockito.when(httpResponse.statusCode()).thenReturn(200);
try {
GrpcCodec.decodeResponse(invocation, operationProtobuf, httpResponse, buffer);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
Aggregations