Search in sources :

Example 6 with RuntimeExceptionWithoutStackTrace

use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.

the class TestAbstractRestInvocation method scheduleInvocationTimeout.

@Test
public void scheduleInvocationTimeout(@Mocked OperationMeta operationMeta) {
    Executor executor = Runnable::run;
    new Expectations() {

        {
            restOperation.getOperationMeta();
            result = operationMeta;
            operationMeta.getExecutor();
            result = executor;
            operationMeta.getMicroserviceQualifiedName();
            result = "sayHi";
        }
    };
    requestEx = new AbstractHttpServletRequestForTest();
    restInvocation = new AbstractRestInvocationForTest() {

        @Override
        protected void runOnExecutor() {
            throw new RuntimeExceptionWithoutStackTrace("run on executor");
        }
    };
    restInvocation.requestEx = requestEx;
    restInvocation.restOperationMeta = restOperation;
    // will not throw exception
    restInvocation.scheduleInvocation();
    invocation.onFinish(Response.ok(null));
}
Also used : Expectations(mockit.Expectations) RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) Executor(java.util.concurrent.Executor) HttpServerFilterBaseForTest(org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest) Test(org.junit.Test)

Example 7 with RuntimeExceptionWithoutStackTrace

use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.

the class TestHttpServerFilterBeforeSendResponseExecutor method runFail.

@Test
public void runFail() throws InterruptedException, ExecutionException {
    httpServerFilters.add(new HttpServerFilterBaseForTest() {

        @Override
        public CompletableFuture<Void> beforeSendResponseAsync(Invocation invocation, HttpServletResponseEx responseEx) {
            throw new RuntimeExceptionWithoutStackTrace();
        }
    });
    CompletableFuture<Void> result = executor.run();
    expectedException.expect(ExecutionException.class);
    expectedException.expectCause(Matchers.instanceOf(RuntimeExceptionWithoutStackTrace.class));
    result.get();
}
Also used : RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) CompletableFuture(java.util.concurrent.CompletableFuture) Invocation(org.apache.servicecomb.core.Invocation) HttpServletResponseEx(org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx) Test(org.junit.Test)

Example 8 with RuntimeExceptionWithoutStackTrace

use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.

the class TestAbstractRestInvocation method sendFailResponseNoProduceProcessor.

@Test
public void sendFailResponseNoProduceProcessor() {
    invocation.onStart(0);
    restInvocation.produceProcessor = null;
    restInvocation.sendFailResponse(new RuntimeExceptionWithoutStackTrace());
    Assert.assertSame(ProduceProcessorManager.INSTANCE.findDefaultJsonProcessor(), restInvocation.produceProcessor);
}
Also used : RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) HttpServerFilterBaseForTest(org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest) Test(org.junit.Test)

Example 9 with RuntimeExceptionWithoutStackTrace

use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.

the class TestAbstractEdgeDispatcher method onFailure.

@Test
public void onFailure(@Mocked RoutingContext context) {
    Map<String, Object> map = new HashMap<>();
    HttpServerResponse response = new MockUp<HttpServerResponse>() {

        @Mock
        HttpServerResponse setStatusCode(int statusCode) {
            map.put("code", statusCode);
            return null;
        }

        @Mock
        HttpServerResponse setStatusMessage(String statusMessage) {
            map.put("msg", statusMessage);
            return null;
        }
    }.getMockInstance();
    new Expectations() {

        {
            context.failure();
            returns(new RuntimeExceptionWithoutStackTrace("failed"), null);
            context.response();
            result = response;
        }
    };
    AbstractEdgeDispatcherForTest dispatcher = new AbstractEdgeDispatcherForTest();
    dispatcher.onFailure(context);
    Assert.assertEquals(502, map.get("code"));
    Assert.assertEquals("Bad Gateway", map.get("msg"));
    new Expectations() {

        {
            context.failure();
            returns(new InvocationException(401, "unauthorized", "unauthorized"), new InvocationException(401, "unauthorized", "unauthorized"));
            context.response();
            result = response;
        }
    };
    dispatcher = new AbstractEdgeDispatcherForTest();
    dispatcher.onFailure(context);
    Assert.assertEquals(401, map.get("code"));
    Assert.assertEquals("unauthorized", map.get("msg"));
}
Also used : Expectations(mockit.Expectations) RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) HashMap(java.util.HashMap) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Mock(mockit.Mock) Test(org.junit.Test)

Example 10 with RuntimeExceptionWithoutStackTrace

use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.

the class TestInspectorImpl method downloadSchemas_failed.

@Test
public void downloadSchemas_failed() {
    SchemaFormat format = SchemaFormat.SWAGGER;
    new Expectations(format) {

        {
            format.getSuffix();
            result = new RuntimeExceptionWithoutStackTrace("zip failed.");
        }
    };
    try (LogCollector logCollector = new LogCollector()) {
        Response response = inspector.downloadSchemas(format);
        Assert.assertEquals("failed to create schemas zip file, format=SWAGGER.", logCollector.getLastEvents().getMessage());
        InvocationException invocationException = response.getResult();
        Assert.assertEquals(Status.INTERNAL_SERVER_ERROR, invocationException.getStatus());
        Assert.assertEquals("failed to create schemas zip file, format=SWAGGER.", ((CommonExceptionData) invocationException.getErrorData()).getMessage());
        Assert.assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode());
        Assert.assertEquals(Status.INTERNAL_SERVER_ERROR.getReasonPhrase(), response.getReasonPhrase());
    }
}
Also used : Expectations(mockit.Expectations) RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) LogCollector(org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector) Response(org.apache.servicecomb.swagger.invocation.Response) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) SchemaFormat(org.apache.servicecomb.inspector.internal.swagger.SchemaFormat) Test(org.junit.Test)

Aggregations

RuntimeExceptionWithoutStackTrace (org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace)24 Test (org.junit.Test)20 Expectations (mockit.Expectations)15 HttpServerFilterBaseForTest (org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest)8 Response (org.apache.servicecomb.swagger.invocation.Response)6 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)6 MockUp (mockit.MockUp)4 LogCollector (org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector)4 HashMap (java.util.HashMap)3 Holder (org.apache.servicecomb.foundation.common.Holder)3 MultiMap (io.vertx.core.MultiMap)2 Map (java.util.Map)2 Executor (java.util.concurrent.Executor)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Invocation (org.apache.servicecomb.core.Invocation)2 ReactiveExecutor (org.apache.servicecomb.core.executor.ReactiveExecutor)2 AsyncResultCallback (org.apache.servicecomb.foundation.vertx.AsyncResultCallback)2 AbstractHttpServletResponse (org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletResponse)2 Test (org.junit.jupiter.api.Test)2 EventBus (com.google.common.eventbus.EventBus)1