use of io.servicecomb.core.Response 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.Response 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.Response 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.Response 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);
}
use of io.servicecomb.core.Response in project java-chassis by ServiceComb.
the class TestConsumerResponseMapper method test.
@Test
public void test() {
ConsumerResponseMapperFactory factory = new ConsumerResponseMapperFactory();
ConsumerResponseMapper m1 = new ConsumerResponseCseSame();
ConsumerResponseMapper m2 = new ConsumerResponseSame();
factory.setMapperList(Arrays.asList(m1, m2));
Assert.assertEquals(m1, factory.createResponseMapper(Response.class));
Assert.assertEquals(m2, factory.createResponseMapper(String.class));
Response r = Response.ok(1);
Response r1 = (Response) m1.mapResponse(r);
Assert.assertEquals(r, r1);
Object result = m2.mapResponse(r);
Assert.assertEquals(1, (int) result);
}
Aggregations