Search in sources :

Example 1 with RuntimeExceptionWithoutStackTrace

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

the class TestSwaggerUtils method swaggerToStringException.

@Test
public void swaggerToStringException(@Mocked Swagger swagger) {
    new Expectations() {

        {
            swagger.getBasePath();
            result = new RuntimeExceptionWithoutStackTrace();
        }
    };
    expectedException.expect(ServiceCombException.class);
    expectedException.expectMessage("Convert swagger to string failed, ");
    SwaggerUtils.swaggerToString(swagger);
}
Also used : Expectations(mockit.Expectations) RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) Test(org.junit.Test)

Example 2 with RuntimeExceptionWithoutStackTrace

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

the class TestAbstractRestInvocation method sendResponseQuietlyException.

@Test
public void sendResponseQuietlyException(@Mocked Response response) {
    restInvocation = new AbstractRestInvocationForTest() {

        @Override
        protected void doInvoke() {
        }

        @Override
        protected void sendResponse(Response response) {
            throw new RuntimeExceptionWithoutStackTrace();
        }
    };
    initRestInvocation();
    restInvocation.sendResponseQuietly(response);
// just log, check nothing
}
Also used : AbstractHttpServletResponse(org.apache.servicecomb.foundation.vertx.http.AbstractHttpServletResponse) Response(org.apache.servicecomb.swagger.invocation.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) HttpServerFilterBaseForTest(org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest) Test(org.junit.Test)

Example 3 with RuntimeExceptionWithoutStackTrace

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

the class TestAbstractRestInvocation method should_ignore_content_length_and_transfer_encoding_when_copy_header_to_http_response.

@Test
public void should_ignore_content_length_and_transfer_encoding_when_copy_header_to_http_response(@Mocked Response response) {
    MultiMap headers = MultiMap.caseInsensitiveMultiMap().set(CONTENT_LENGTH, "10").set(TRANSFER_ENCODING, "encoding");
    new Expectations() {

        {
            response.getResult();
            result = new RuntimeExceptionWithoutStackTrace("stop");
            response.getHeaders();
            result = headers;
        }
    };
    MultiMap resultHeaders = MultiMap.caseInsensitiveMultiMap();
    responseEx = new MockUp<HttpServletResponseEx>() {

        private Map<String, Object> attributes = new HashMap<>();

        @Mock
        public void setAttribute(String key, Object value) {
            this.attributes.put(key, value);
        }

        @Mock
        public Object getAttribute(String key) {
            return this.attributes.get(key);
        }

        @Mock
        void addHeader(String name, String value) {
            resultHeaders.add(name, value);
        }
    }.getMockInstance();
    invocation.onStart(0);
    initRestInvocation();
    restInvocation.sendResponse(response);
    assertThat(headers).isEmpty();
    assertThat(resultHeaders).isEmpty();
}
Also used : Expectations(mockit.Expectations) RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) MultiMap(io.vertx.core.MultiMap) MockUp(mockit.MockUp) MultiMap(io.vertx.core.MultiMap) Map(java.util.Map) HashMap(java.util.HashMap) HttpServerFilterBaseForTest(org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest) Test(org.junit.Test)

Example 4 with RuntimeExceptionWithoutStackTrace

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

the class TestAbstractRestInvocation method scheduleInvocationException.

@Test
public void scheduleInvocationException(@Mocked OperationMeta operationMeta) {
    Executor executor = new ReactiveExecutor();
    requestEx = new AbstractHttpServletRequestForTest();
    requestEx.setAttribute(RestConst.REST_REQUEST, requestEx);
    new Expectations() {

        {
            restOperation.getOperationMeta();
            result = operationMeta;
            operationMeta.getExecutor();
            result = executor;
        }
    };
    Holder<Throwable> result = new Holder<>();
    RuntimeException error = new RuntimeExceptionWithoutStackTrace("run on executor");
    restInvocation = new AbstractRestInvocationForTest() {

        @Override
        protected void runOnExecutor() {
            throw error;
        }

        @Override
        public void sendFailResponse(Throwable throwable) {
            result.value = throwable;
            invocation.onFinish(Response.ok(null));
        }
    };
    restInvocation.requestEx = requestEx;
    restInvocation.restOperationMeta = restOperation;
    restInvocation.scheduleInvocation();
    Assert.assertSame(error, result.value);
}
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) Holder(org.apache.servicecomb.foundation.common.Holder) ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) HttpServerFilterBaseForTest(org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest) Test(org.junit.Test)

Example 5 with RuntimeExceptionWithoutStackTrace

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

the class TestAbstractRestInvocation method invokeFilterException.

@Test
public void invokeFilterException(@Mocked HttpServerFilter filter) {
    Exception error = new RuntimeExceptionWithoutStackTrace();
    new Expectations() {

        {
            filter.enabled();
            result = true;
            filter.afterReceiveRequest(invocation, requestEx);
            result = error;
        }
    };
    Holder<Throwable> result = new Holder<>();
    restInvocation = new AbstractRestInvocationForTest() {

        @Override
        public void sendFailResponse(Throwable throwable) {
            result.value = throwable;
        }

        @Override
        protected void doInvoke() {
        }
    };
    initRestInvocation();
    restInvocation.httpServerFilters = Arrays.asList(filter);
    restInvocation.invoke();
    Assert.assertSame(error, result.value);
}
Also used : RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) Expectations(mockit.Expectations) Holder(org.apache.servicecomb.foundation.common.Holder) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExpectedException(org.junit.rules.ExpectedException) HttpServerFilterBaseForTest(org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest) 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