Search in sources :

Example 1 with ExceptionHandlerProxy

use of com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerProxy in project ezyhttp by youngmonkeys.

the class ExceptionHandlerImplementerTest method test.

@Test
public void test() {
    ExceptionHandlerImplementer.setDebug(true);
    ExceptionHandlerProxy exceptionHandler = new ExceptionHandlerProxy(new GlobalExceptionHandler());
    for (ExceptionHandlerMethod method : exceptionHandler.getExceptionHandlerMethods()) {
        ExceptionHandlerImplementer implementer = new ExceptionHandlerImplementer(exceptionHandler, method);
        implementer.implement();
    }
}
Also used : GlobalExceptionHandler(com.tvd12.ezyhttp.server.core.test.controller.GlobalExceptionHandler) ExceptionHandlerImplementer(com.tvd12.ezyhttp.server.core.asm.ExceptionHandlerImplementer) ExceptionHandlerProxy(com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerProxy) ExceptionHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerMethod) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 2 with ExceptionHandlerProxy

use of com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerProxy in project ezyhttp by youngmonkeys.

the class ExceptionHandlerImplementerTest method implementOneFailed.

@Test
public void implementOneFailed() throws Exception {
    // given
    ExceptionHandlerProxy handler = new ExceptionHandlerProxy(new ExceptionHandler());
    ExceptionHandlerMethod handlerMethod = new ExceptionHandlerMethod(new EzyMethod(ExceptionHandler.class.getDeclaredMethod("handle", Exception.class)));
    ExceptionHandlerImplementer sut = new ExceptionHandlerImplementer(handler, handlerMethod);
    // when
    Throwable e = Asserts.assertThrows(sut::implement);
    // then
    Asserts.assertThat(e).isEqualsType(IllegalStateException.class);
}
Also used : ExceptionHandlerImplementer(com.tvd12.ezyhttp.server.core.asm.ExceptionHandlerImplementer) ExceptionHandlerProxy(com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerProxy) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod) ExceptionHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerMethod) Test(org.testng.annotations.Test)

Example 3 with ExceptionHandlerProxy

use of com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerProxy in project ezyhttp by youngmonkeys.

the class ExceptionHandlerImplementerTest method test.

@Test
public void test() {
    ExceptionHandlerImplementer.setDebug(true);
    ExceptionHandlerProxy exceptionHandler = new ExceptionHandlerProxy(new GlobalExceptionHandler());
    for (ExceptionHandlerMethod method : exceptionHandler.getExceptionHandlerMethods()) {
        ExceptionHandlerImplementer implementer = new ExceptionHandlerImplementer(exceptionHandler, method);
        implementer.implement();
    }
}
Also used : GlobalExceptionHandler(com.tvd12.ezyhttp.server.jetty.test.controller.GlobalExceptionHandler) ExceptionHandlerImplementer(com.tvd12.ezyhttp.server.core.asm.ExceptionHandlerImplementer) ExceptionHandlerProxy(com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerProxy) ExceptionHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerMethod) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 4 with ExceptionHandlerProxy

use of com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerProxy in project ezyhttp by youngmonkeys.

the class ExceptionHandlerProxyTest method test.

@Test
public void test() {
    // given
    ExceptionHandler handler = new ExceptionHandler();
    ExceptionHandlerProxy sut = new ExceptionHandlerProxy(handler);
    // when
    // then
    System.out.println(sut);
}
Also used : ExceptionHandlerProxy(com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerProxy) Test(org.testng.annotations.Test)

Example 5 with ExceptionHandlerProxy

use of com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerProxy in project ezyhttp by youngmonkeys.

the class ExceptionHandlersImplementer method implement.

public Map<Class<?>, UncaughtExceptionHandler> implement(Object exceptionHandler) {
    Map<Class<?>, UncaughtExceptionHandler> handlers = new HashMap<>();
    ExceptionHandlerProxy proxy = new ExceptionHandlerProxy(exceptionHandler);
    for (ExceptionHandlerMethod method : proxy.getExceptionHandlerMethods()) {
        ExceptionHandlerImplementer implementer = newImplementer(proxy, method);
        UncaughtExceptionHandler handler = implementer.implement();
        for (Class<?> exceptionClass : method.getExceptionClasses()) {
            handlers.put(exceptionClass, handler);
        }
    }
    return handlers;
}
Also used : HashMap(java.util.HashMap) ExceptionHandlerProxy(com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerProxy) UncaughtExceptionHandler(com.tvd12.ezyhttp.server.core.handler.UncaughtExceptionHandler) ExceptionHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerMethod)

Aggregations

ExceptionHandlerProxy (com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerProxy)6 ExceptionHandlerMethod (com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerMethod)5 Test (org.testng.annotations.Test)5 ExceptionHandlerImplementer (com.tvd12.ezyhttp.server.core.asm.ExceptionHandlerImplementer)4 BaseTest (com.tvd12.test.base.BaseTest)3 EzyMethod (com.tvd12.ezyfox.reflect.EzyMethod)1 GlobalExceptionHandler (com.tvd12.ezyhttp.server.boot.test.controller.GlobalExceptionHandler)1 UncaughtExceptionHandler (com.tvd12.ezyhttp.server.core.handler.UncaughtExceptionHandler)1 GlobalExceptionHandler (com.tvd12.ezyhttp.server.core.test.controller.GlobalExceptionHandler)1 GlobalExceptionHandler (com.tvd12.ezyhttp.server.jetty.test.controller.GlobalExceptionHandler)1 HashMap (java.util.HashMap)1