use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.
the class TestConsumer method testInvocation.
@Test
public void testInvocation() {
OperationMeta oOperationMeta = Mockito.mock(OperationMeta.class);
SchemaMeta oSchemaMeta = Mockito.mock(SchemaMeta.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
List<Handler> oHandlerList = new ArrayList<>();
Mockito.when(oSchemaMeta.getProviderHandlerChain()).thenReturn(oHandlerList);
Mockito.when(oSchemaMeta.getMicroserviceName()).thenReturn("TMK");
Mockito.when(oOperationMeta.getSchemaMeta()).thenReturn(oSchemaMeta);
Endpoint oEndpoint = Mockito.mock(Endpoint.class);
Transport oTransport = Mockito.mock(Transport.class);
Mockito.when(oEndpoint.getTransport()).thenReturn(oTransport);
Mockito.when(oOperationMeta.getOperationId()).thenReturn("TMK");
Invocation oInvocation = new Invocation(oEndpoint, oOperationMeta, null);
Assert.assertNotNull(oInvocation.getTransport());
Assert.assertNotNull(oInvocation.getInvocationType());
oInvocation.setResponseExecutor(Mockito.mock(Executor.class));
Assert.assertNotNull(oInvocation.getResponseExecutor());
Assert.assertNotNull(oInvocation.getSchemaMeta());
Assert.assertNotNull(oInvocation.getOperationMeta());
Assert.assertNull(oInvocation.getArgs());
Assert.assertNotNull(oInvocation.getEndpoint());
oInvocation.setEndpoint(null);
Map<String, String> map = oInvocation.getContext();
Assert.assertNotNull(map);
String str = oInvocation.getSchemaId();
Assert.assertEquals(null, str);
String str1 = oInvocation.getMicroserviceName();
Assert.assertEquals("TMK", str1);
Map<String, Object> mapp = oInvocation.getHandlerContext();
Assert.assertNotNull(mapp);
Assert.assertEquals(true, oInvocation.getHandlerIndex() >= 0);
oInvocation.setHandlerIndex(8);
Assert.assertEquals("TMK", oInvocation.getOperationName());
Assert.assertEquals("TMK", oInvocation.getMicroserviceName());
boolean validAssert;
try {
validAssert = true;
oInvocation.next(asyncResp);
} catch (Exception e) {
validAssert = false;
}
Assert.assertFalse(validAssert);
}
use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.
the class TestConsumerSchemaFactory method testGetOrCreateConsumer.
@Test
public void testGetOrCreateConsumer() {
MicroserviceMeta microserviceMeta = consumerSchemaFactory.getOrCreateMicroserviceMeta("ms", "latest");
OperationMeta operationMeta = microserviceMeta.ensureFindOperation("schema.add");
Assert.assertEquals("add", operationMeta.getOperationId());
}
use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.
the class TestProducerSchemaFactory method testGetOrCreateProducer.
@Test
public void testGetOrCreateProducer() throws Exception {
OperationMeta operationMeta = schemaMeta.ensureFindOperation("add");
Assert.assertEquals("add", operationMeta.getOperationId());
SwaggerProducerOperation producerOperation = operationMeta.getExtData(Const.PRODUCER_OPERATION);
Object addBody = Class.forName("cse.gen.app.ms.schema.addBody").newInstance();
ReflectUtils.setField(addBody, "x", 1);
ReflectUtils.setField(addBody, "y", 2);
Invocation invocation = new Invocation((Endpoint) null, operationMeta, new Object[] { addBody }) {
@Override
public String getInvocationQualifiedName() {
return "";
}
};
Holder<Response> holder = new Holder<>();
producerOperation.invoke(invocation, resp -> {
holder.value = resp;
});
Assert.assertEquals(3, (int) holder.value.getResult());
invocation.setSwaggerArguments(new Object[] { 1, 2 });
producerOperation.invoke(invocation, resp -> {
holder.value = resp;
});
Assert.assertEquals(true, holder.value.isFailed());
InvocationException exception = (InvocationException) holder.value.getResult();
CommonExceptionData data = (CommonExceptionData) exception.getErrorData();
Assert.assertEquals("Cse Internal Server Error", data.getMessage());
}
use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.
the class TestInvokerUtils method testSyncInvokeInvocationWithException.
@Test
public void testSyncInvokeInvocationWithException() throws InterruptedException {
Invocation invocation = Mockito.mock(Invocation.class);
Response response = Mockito.mock(Response.class);
new MockUp<SyncResponseExecutor>() {
@Mock
public Response waitResponse() throws InterruptedException {
return Mockito.mock(Response.class);
}
};
Mockito.when(response.isSuccessed()).thenReturn(true);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
Mockito.when(operationMeta.getMicroserviceQualifiedName()).thenReturn("test");
try {
InvokerUtils.syncInvoke(invocation);
} catch (InvocationException e) {
Assert.assertEquals(490, e.getStatusCode());
}
}
use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.
the class ClientRestArgsFilter method beforeSendRequest.
@Override
public void beforeSendRequest(Invocation invocation, HttpServletRequestEx requestEx) {
RestClientRequestImpl restClientRequest = (RestClientRequestImpl) invocation.getHandlerContext().get(RestConst.INVOCATION_HANDLER_REQUESTCLIENT);
OperationMeta operationMeta = invocation.getOperationMeta();
RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
try {
RestCodec.argsToRest(invocation.getArgs(), swaggerRestOperation, restClientRequest);
requestEx.setBodyBuffer(restClientRequest.getBodyBuffer());
} catch (Throwable e) {
throw ExceptionFactory.convertConsumerException(e);
}
}
Aggregations