use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayCodec method testDecodeRequest.
@Test
public void testDecodeRequest(@Mocked Endpoint endpoint) throws Exception {
commonMock();
Mockito.when(schemaMeta.getProviderHandlerChain()).thenReturn(Collections.emptyList());
Object[] args = new Object[] {};
Mockito.when(schema.readObject(bodyBuffer, null)).thenReturn(args);
Invocation invocation = new Invocation(endpoint, operationMeta, null);
HighwayCodec.decodeRequest(invocation, header, operationProtobuf, bodyBuffer, null);
Assert.assertSame(args, invocation.getSwaggerArguments());
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
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<>(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 org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestEdgeInvocation method createInvocation.
@Test
public void createInvocation(@Mocked MicroserviceVersionMeta microserviceVersionMeta, @Mocked MicroserviceVersionRule microserviceVersionRule, @Mocked RestOperationMeta restOperationMeta, @Mocked Microservice microservice) {
edgeInvocation.latestMicroserviceVersionMeta = microserviceVersionMeta;
edgeInvocation.microserviceVersionRule = microserviceVersionRule;
Deencapsulation.setField(edgeInvocation, "restOperationMeta", restOperationMeta);
new Expectations(RegistryUtils.class) {
{
RegistryUtils.getMicroservice();
result = microservice;
}
};
edgeInvocation.createInvocation();
Invocation invocation = Deencapsulation.getField(edgeInvocation, "invocation");
Assert.assertThat(invocation.getResponseExecutor(), Matchers.instanceOf(ReactiveResponseExecutor.class));
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestUrlWithServiceNameClientHttpRequestFactory method invoke_checkPath.
@Test
public void invoke_checkPath(@Mocked Invocation invocation, @Mocked RequestMeta requestMeta) {
Map<String, String> handlerContext = new HashMap<>();
UrlWithServiceNameClientHttpRequest request = new UrlWithServiceNameClientHttpRequest(uri, HttpMethod.GET) {
@Override
protected Response doInvoke(Invocation invocation) {
return Response.ok(null);
}
};
new Expectations(InvocationFactory.class) {
{
invocation.getHandlerContext();
result = handlerContext;
InvocationFactory.forConsumer((ReferenceConfig) any, (OperationMeta) any, (Object[]) any);
result = invocation;
}
};
Deencapsulation.setField(request, "requestMeta", requestMeta);
Deencapsulation.setField(request, "path", request.findUriPath(uri));
Deencapsulation.invoke(request, "invoke", new Object[] { new Object[] {} });
Assert.assertEquals("/ms/v1/path?null", handlerContext.get(RestConst.REST_CLIENT_REQUEST_PATH));
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class CseClientHttpRequest method invoke.
private CseClientHttpResponse invoke(Object[] args) {
Invocation invocation = InvocationFactory.forConsumer(requestMeta.getReferenceConfig(), requestMeta.getOperationMeta(), args);
invocation.getHandlerContext().put(RestConst.REST_CLIENT_REQUEST_PATH, path + "?" + this.uri.getRawQuery());
if (context != null) {
invocation.addContext(context);
}
invocation.getHandlerContext().put(RestConst.CONSUMER_HEADER, httpHeaders);
Response response = doInvoke(invocation);
if (response.isSuccessed()) {
return new CseClientHttpResponse(response);
}
throw ExceptionFactory.convertConsumerException((Throwable) response.getResult());
}
Aggregations