Search in sources :

Example 11 with EzyMethod

use of com.tvd12.ezyfox.reflect.EzyMethod in project ezyhttp by youngmonkeys.

the class RequestHandlerImplementerTest method implementOneFailed.

@Test
public void implementOneFailed() throws Exception {
    // given
    ControllerProxy controller = new ControllerProxy(new Controller());
    RequestHandlerMethod handlerMethod = new RequestHandlerMethod("/", new EzyMethod(Controller.class.getDeclaredMethod("doGet")));
    RequestHandlerImplementer sut = new RequestHandlerImplementer(controller, handlerMethod);
    // when
    Throwable e = Asserts.assertThrows(sut::implement);
    // then
    Asserts.assertEquals(0, handlerMethod.getParameterTypes().length);
    Asserts.assertThat(e).isEqualsType(IllegalStateException.class);
}
Also used : RequestHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.RequestHandlerMethod) RequestHandlerImplementer(com.tvd12.ezyhttp.server.core.asm.RequestHandlerImplementer) ControllerProxy(com.tvd12.ezyhttp.server.core.reflect.ControllerProxy) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod) Test(org.testng.annotations.Test)

Example 12 with EzyMethod

use of com.tvd12.ezyfox.reflect.EzyMethod in project ezyhttp by youngmonkeys.

the class RequestHandlerMethodTest method isPaymentAndFeatureTest.

@Test
public void isPaymentAndFeatureTest() throws Exception {
    // given
    RequestHandlerMethod sut = new RequestHandlerMethod("/get", new EzyMethod(InternalController.class.getDeclaredMethod("buySomething")));
    // when
    // then
    Asserts.assertTrue(sut.isPayment());
    Asserts.assertEquals(sut.getFeature(), "hello.world");
}
Also used : RequestHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.RequestHandlerMethod) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 13 with EzyMethod

use of com.tvd12.ezyfox.reflect.EzyMethod in project ezyhttp by youngmonkeys.

the class ControllerProxy method fetchRequestHandlerMethods.

protected List<RequestHandlerMethod> fetchRequestHandlerMethods() {
    List<RequestHandlerMethod> list = new ArrayList<>();
    List<EzyMethod> methods = clazz.getPublicMethods(this::isRequestHandlerMethod);
    for (EzyMethod method : methods) {
        RequestHandlerMethod m = new RequestHandlerMethod(requestURI, method);
        list.add(m);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod)

Example 14 with EzyMethod

use of com.tvd12.ezyfox.reflect.EzyMethod in project ezyfox-server by youngmonkeys.

the class EzyRequestControllerProxy method fetchRequestHandlerMethods.

protected List<EzyRequestHandlerMethod> fetchRequestHandlerMethods() {
    List<EzyRequestHandlerMethod> list = new ArrayList<>();
    List<EzyMethod> methods = clazz.getPublicMethods(this::isRequestHandlerMethod);
    for (EzyMethod method : methods) {
        EzyRequestHandlerMethod m = new EzyRequestHandlerMethod(commandGroup, method);
        list.add(m);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod)

Example 15 with EzyMethod

use of com.tvd12.ezyfox.reflect.EzyMethod in project ezyfox-server by youngmonkeys.

the class EzyRequestHandlerImplementer method makeHandleExceptionMethodContent.

protected String makeHandleExceptionMethodContent() {
    EzyMethod method = getHandleExceptionMethod();
    EzyFunction function = new EzyFunction(method).throwsException();
    EzyBody body = function.body();
    Map<Class<?>, EzyExceptionHandlerMethod> exceptionHandlerMethodMap = controller.getExceptionHandlerMethodMap();
    Set<Class<?>> exceptionClasses = exceptionHandlerMethodMap.keySet();
    EzyClassTree exceptionTree = new EzyClassTree(exceptionClasses);
    for (Class<?> exceptionClass : exceptionTree.toList()) {
        EzyExceptionHandlerMethod m = exceptionHandlerMethodMap.get(exceptionClass);
        EzyInstruction instructionIf = new EzyInstruction("\t", "\n", false).append("if(arg3 instanceof ").append(exceptionClass.getName()).append(") {");
        body.append(instructionIf);
        EzyInstruction instructionHandle = new EzyInstruction("\t\t", "\n");
        instructionHandle.append("this.controller.").append(m.getName()).bracketopen();
        appendHandleExceptionMethodArguments(m, instructionHandle, exceptionClass);
        instructionHandle.bracketclose();
        body.append(instructionHandle);
        body.append(new EzyInstruction("\t", "\n", false).append("}"));
    }
    if (exceptionClasses.size() > 0) {
        body.append(new EzyInstruction("\t", "\n", false).append("else {"));
        body.append(new EzyInstruction("\t\t", "\n").append("throw arg3"));
        body.append(new EzyInstruction("\t", "\n", false).append("}"));
    } else {
        body.append(new EzyInstruction("\t", "\n").append("throw arg3"));
    }
    return function.toString();
}
Also used : EzyClassTree(com.tvd12.ezyfox.reflect.EzyClassTree) EzyBody(com.tvd12.ezyfox.asm.EzyFunction.EzyBody) EzyExceptionHandlerMethod(com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod) EzyInstruction(com.tvd12.ezyfox.asm.EzyInstruction) EzyFunction(com.tvd12.ezyfox.asm.EzyFunction) CtClass(javassist.CtClass) EzyClass(com.tvd12.ezyfox.reflect.EzyClass) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod)

Aggregations

EzyMethod (com.tvd12.ezyfox.reflect.EzyMethod)18 EzyFunction (com.tvd12.ezyfox.asm.EzyFunction)6 EzyBody (com.tvd12.ezyfox.asm.EzyFunction.EzyBody)6 EzyInstruction (com.tvd12.ezyfox.asm.EzyInstruction)6 ArrayList (java.util.ArrayList)6 Test (org.testng.annotations.Test)6 EzyClass (com.tvd12.ezyfox.reflect.EzyClass)4 EzyClassTree (com.tvd12.ezyfox.reflect.EzyClassTree)4 CtClass (javassist.CtClass)4 RequestHandlerMethod (com.tvd12.ezyhttp.server.core.reflect.RequestHandlerMethod)3 EzyTryCatch (com.tvd12.ezyfox.core.annotation.EzyTryCatch)2 EzyExceptionHandlerMethod (com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod)2 TryCatch (com.tvd12.ezyhttp.server.core.annotation.TryCatch)2 ExceptionHandlerMethod (com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerMethod)2 BaseTest (com.tvd12.test.base.BaseTest)2 EzyContext (com.tvd12.ezyfoxserver.context.EzyContext)1 EzyExceptionHandlerImplementer (com.tvd12.ezyfoxserver.support.asm.EzyExceptionHandlerImplementer)1 EzyUncaughtExceptionHandler (com.tvd12.ezyfoxserver.support.handler.EzyUncaughtExceptionHandler)1 EzyExceptionHandlerProxy (com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerProxy)1 EzyRequestHandlerMethod (com.tvd12.ezyfoxserver.support.reflect.EzyRequestHandlerMethod)1