use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestVertxRestTransport method testSendException.
@Test
public void testSendException() {
boolean validAssert;
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
URIEndpointObject endpoint = Mockito.mock(URIEndpointObject.class);
Endpoint end = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getEndpoint()).thenReturn(end);
Mockito.when(invocation.getEndpoint().getAddress()).thenReturn(endpoint);
try {
validAssert = true;
instance.send(invocation, asyncResp);
} catch (Exception e) {
validAssert = false;
}
Assert.assertFalse(validAssert);
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TraceIdItemTest method testGetFormattedElement.
@Test
public void testGetFormattedElement() {
AccessLogParam<RoutingContext> param = new AccessLogParam<>();
RoutingContext routingContext = Mockito.mock(RoutingContext.class);
Map<String, Object> data = new HashMap<>();
RestProducerInvocation restProducerInvocation = new RestProducerInvocation();
Invocation invocation = Mockito.mock(Invocation.class);
String traceIdTest = "traceIdTest";
Mockito.when(invocation.getContext(Const.TRACE_ID_NAME)).thenReturn(traceIdTest);
Deencapsulation.setField(restProducerInvocation, "invocation", invocation);
Mockito.when(routingContext.data()).thenReturn(data);
data.put("servicecomb-rest-producer-invocation", restProducerInvocation);
param.setContextData(routingContext);
String result = ELEMENT.getFormattedItem(param);
Assert.assertThat(result, is(traceIdTest));
}
use of org.apache.servicecomb.core.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TraceIdItemTest method testGetFormattedElementOnTraceIdNotFound.
@Test
public void testGetFormattedElementOnTraceIdNotFound() {
AccessLogParam<RoutingContext> param = new AccessLogParam<>();
RoutingContext routingContext = Mockito.mock(RoutingContext.class);
Map<String, Object> data = new HashMap<>();
RestProducerInvocation restProducerInvocation = new RestProducerInvocation();
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getContext(Const.TRACE_ID_NAME)).thenReturn("");
Deencapsulation.setField(restProducerInvocation, "invocation", invocation);
Mockito.when(routingContext.data()).thenReturn(data);
data.put("servicecomb-rest-producer-invocation", restProducerInvocation);
param.setContextData(routingContext);
String result = ELEMENT.getFormattedItem(param);
Assert.assertThat(result, is("-"));
Mockito.when(invocation.getContext(Const.TRACE_ID_NAME)).thenReturn(null);
result = ELEMENT.getFormattedItem(param);
Assert.assertThat(result, is("-"));
}
use of org.apache.servicecomb.core.Invocation 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.Invocation in project incubator-servicecomb-java-chassis by apache.
the class TestShutdownHookHandler method testShutdownHookHandlerReject.
@Test
public void testShutdownHookHandlerReject() throws Exception {
Deencapsulation.setField(ShutdownHookHandler.INSTANCE, "shuttingDown", true);
Holder<InvocationType> typeHolder = new Holder<>(InvocationType.PRODUCER);
Invocation invocation = new MockUp<Invocation>() {
@Mock
public InvocationType getInvocationType() {
return typeHolder.value;
}
}.getMockInstance();
ShutdownHookHandler handler = ShutdownHookHandler.INSTANCE;
handler.handle(invocation, asyncResp -> {
InvocationException e = asyncResp.getResult();
Assert.assertEquals(((CommonExceptionData) e.getErrorData()).getMessage(), "shutting down in progress");
Assert.assertEquals(e.getStatusCode(), 590);
});
typeHolder.value = InvocationType.CONSUMER;
handler.handle(invocation, asyncResp -> {
InvocationException e = asyncResp.getResult();
Assert.assertEquals(((CommonExceptionData) e.getErrorData()).getMessage(), "shutting down in progress");
Assert.assertEquals(e.getStatusCode(), 490);
});
}
Aggregations