use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
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<String, String>());
header.getContext().put("a", "10");
Buffer responseBuf = HighwayCodec.encodeResponse(0, header, null, null);
TcpData tcp = new TcpData(responseBuf.slice(23, responseBuf.length()), null);
Response response = HighwayCodec.decodeResponse(invocation, operationProtobuf, tcp);
Assert.assertEquals("10", invocation.getContext().get("a"));
Assert.assertEquals(200, response.getStatusCode());
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestVertxGetMethod method testVertxGetMethod.
@Test
public void testVertxGetMethod() {
HttpClient client = Mockito.mock(HttpClient.class);
Invocation invocation = Mockito.mock(Invocation.class);
IpPort ipPort = Mockito.mock(IpPort.class);
Mockito.when(ipPort.getPort()).thenReturn(10);
assertEquals(10, ipPort.getPort());
Mockito.when(ipPort.getHostOrIp()).thenReturn("ever");
assertEquals("ever", ipPort.getHostOrIp());
RestOperationMeta operation = Mockito.mock(RestOperationMeta.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
HttpClientRequest obj = VertxGetMethod.INSTANCE.createRequest(client, invocation, ipPort, "good", operation, asyncResp);
Assert.assertNull(obj);
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestHighwayTransport method testSendException.
@Test
public void testSendException() throws Exception {
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
commonHighwayMock(invocation);
Holder<Boolean> sended = new Holder<Boolean>(false);
new MockUp<HighwayClient>() {
@Mock
public void send(Invocation invocation, AsyncResponse asyncResp) throws Exception {
sended.value = true;
}
};
transport.send(invocation, asyncResp);
Assert.assertTrue(sended.value);
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestHighwayTransport method testHighway.
@Test
public void testHighway() {
Invocation invocation = Mockito.mock(Invocation.class);
commonHighwayMock(invocation);
Assert.assertEquals("highway", transport.getName());
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestVertxHttpMethod method testSetCseContext.
@Test
public void testSetCseContext() {
boolean status = false;
try {
Invocation invocation = Mockito.mock(Invocation.class);
HttpClientResponse httpResponse = Mockito.mock(HttpClientResponse.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
RestOperationMeta swaggerRestOperation = Mockito.mock(RestOperationMeta.class);
HttpClientRequest request = Mockito.mock(HttpClientRequest.class);
Endpoint endpoint = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
URLPathBuilder urlPathBuilder = Mockito.mock(URLPathBuilder.class);
Mockito.when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
Mockito.when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
Mockito.when(invocation.getEndpoint()).thenReturn(endpoint);
String contentType = httpResponse.getHeader("Content-Type");
ProduceProcessor produceProcessor = Mockito.mock(ProduceProcessor.class);
Mockito.when(swaggerRestOperation.findProduceProcessor(contentType)).thenReturn(produceProcessor);
this.setCseContext(invocation, request);
} catch (Exception ex) {
status = true;
}
Assert.assertFalse(status);
}
Aggregations