Search in sources :

Example 21 with RuntimeExceptionWithoutStackTrace

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

the class TestRestClientInvocation method testSetCseContext_failed.

@Test
public void testSetCseContext_failed() throws JsonProcessingException {
    LogCollector logCollector = new LogCollector();
    logCollector.setLogLevel(RestClientInvocation.class.getName(), Level.DEBUG);
    new Expectations(JsonUtils.class) {

        {
            JsonUtils.writeValueAsString(any);
            result = new RuntimeExceptionWithoutStackTrace();
        }
    };
    restClientInvocation.setCseContext();
    Assert.assertEquals("Failed to encode and set cseContext, message=cause:RuntimeExceptionWithoutStackTrace,message:null.", logCollector.getEvents().get(0).getMessage());
    logCollector.teardown();
}
Also used : LogCollector(org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector) Expectations(mockit.Expectations) RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) Test(org.junit.Test)

Example 22 with RuntimeExceptionWithoutStackTrace

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

the class TestMicroserviceWatchTask method testWatchFailed.

@Test
public void testWatchFailed(@Mocked ServiceRegistryConfig serviceRegistryConfig, @Mocked ServiceRegistryClient srClient, @Mocked Microservice microservice) {
    initWatch(serviceRegistryConfig, srClient, microservice);
    new MockUp<ServiceRegistryClient>(srClient) {

        @Mock
        void watch(String selfMicroserviceId, AsyncResultCallback<MicroserviceInstanceChangedEvent> callback, AsyncResultCallback<Void> onOpen, AsyncResultCallback<Void> onClose) {
            callback.fail(new RuntimeExceptionWithoutStackTrace("test failed"));
        }
    };
    Holder<Throwable> holder = new Holder<>();
    eventBus.register(new Object() {

        @Subscribe
        public void onException(ExceptionEvent event) {
            holder.value = event.getThrowable();
        }
    });
    Assert.assertNull(holder.value);
    microserviceWatchTask.run();
    Assert.assertEquals("test failed", holder.value.getMessage());
}
Also used : RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) ExceptionEvent(org.apache.servicecomb.serviceregistry.event.ExceptionEvent) Holder(org.apache.servicecomb.foundation.common.Holder) MockUp(mockit.MockUp) Subscribe(com.google.common.eventbus.Subscribe) AsyncResultCallback(org.apache.servicecomb.foundation.vertx.AsyncResultCallback) Test(org.junit.Test)

Example 23 with RuntimeExceptionWithoutStackTrace

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

the class AsyncUtilsTest method should_convert_fail_async_to_sync.

@Test
void should_convert_fail_async_to_sync() {
    RuntimeExceptionWithoutStackTrace throwable = new RuntimeExceptionWithoutStackTrace();
    CompletableFuture<String> future = AsyncUtils.completeExceptionally(throwable);
    Throwable catchThrowable = catchThrowable(() -> AsyncUtils.toSync(future));
    assertThat(catchThrowable).isSameAs(throwable);
}
Also used : RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.jupiter.api.Test)

Example 24 with RuntimeExceptionWithoutStackTrace

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

the class TestJvmUtils method findMainClass_jar_readFailed.

@Test
public void findMainClass_jar_readFailed() throws Exception {
    URL url = PowerMockito.mock(URL.class);
    String command = "a.jar";
    String manifestUri = "jar:file:" + new File(command).getAbsolutePath() + "!/" + JarFile.MANIFEST_NAME;
    PowerMockito.whenNew(URL.class).withParameterTypes(String.class).withArguments(manifestUri).thenReturn(url);
    PowerMockito.when(url.openStream()).thenThrow(new RuntimeExceptionWithoutStackTrace());
    System.setProperty(JvmUtils.SUN_JAVA_COMMAND, command + " arg");
    Assert.assertNull(JvmUtils.findMainClass());
}
Also used : RuntimeExceptionWithoutStackTrace(org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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