Search in sources :

Example 1 with EzyRequestControllerProxy

use of com.tvd12.ezyfoxserver.support.reflect.EzyRequestControllerProxy in project ezyfox-server by youngmonkeys.

the class EzyRequestControllerTest method test.

@Test
public void test() {
    Object instance = new HelloController();
    EzyRequestControllerProxy controllerProxy = new EzyRequestControllerProxy(instance);
    assert controllerProxy.getInstance() == instance;
    // noinspection ConstantConditions
    assert controllerProxy.getExceptionHandlerMethods().size() >= 0;
    System.out.println(controllerProxy);
}
Also used : HelloController(com.tvd12.ezyfoxserver.support.test.controller.HelloController) EzyRequestControllerProxy(com.tvd12.ezyfoxserver.support.reflect.EzyRequestControllerProxy) Test(org.testng.annotations.Test)

Example 2 with EzyRequestControllerProxy

use of com.tvd12.ezyfoxserver.support.reflect.EzyRequestControllerProxy in project ezyfox-server by youngmonkeys.

the class EzyRequestHandlersImplementerTest method testImplementFailedCase.

@Test(expectedExceptions = IllegalStateException.class)
public void testImplementFailedCase() {
    EzyRequestControllerProxy proxy = new EzyRequestControllerProxy(new HelloController());
    EzyRequestHandlerImplementer implementer = new EzyRequestHandlerImplementer(proxy, proxy.getRequestHandlerMethods().get(0)) {

        @Override
        protected EzyAsmRequestHandler doImplement() {
            throw new RuntimeException("test");
        }
    };
    implementer.implement();
}
Also used : EzyRequestHandlerImplementer(com.tvd12.ezyfoxserver.support.asm.EzyRequestHandlerImplementer) EzyRequestControllerProxy(com.tvd12.ezyfoxserver.support.reflect.EzyRequestControllerProxy) HelloController(com.tvd12.ezyfoxserver.support.test.controller.HelloController) Test(org.testng.annotations.Test)

Example 3 with EzyRequestControllerProxy

use of com.tvd12.ezyfoxserver.support.reflect.EzyRequestControllerProxy in project ezyfox-server by youngmonkeys.

the class EzyRequestHandlersImplementer method implement.

private Map<String, EzyUserRequestHandler> implement(Object controller) {
    Map<String, EzyUserRequestHandler> handlers = new HashMap<>();
    EzyRequestControllerProxy proxy = new EzyRequestControllerProxy(controller);
    String feature = proxy.getFeature();
    for (EzyRequestHandlerMethod method : proxy.getRequestHandlerMethods()) {
        EzyRequestHandlerImplementer implementer = newImplementer(proxy, method);
        EzyAsmRequestHandler handler = implementer.implement();
        String command = handler.getCommand();
        handlers.put(command, handler);
        requestCommandManager.addCommand(command);
        if (proxy.isManagement() || method.isManagement()) {
            requestCommandManager.addManagementCommand(command);
        }
        if (proxy.isPayment() || method.isPayment()) {
            requestCommandManager.addPaymentCommand(command);
        }
        String methodFeature = feature != null ? feature : method.getFeature();
        if (EzyStrings.isNotBlank(methodFeature)) {
            featureCommandManager.addFeatureCommand(methodFeature, command);
        }
    }
    return handlers;
}
Also used : HashMap(java.util.HashMap) EzyRequestControllerProxy(com.tvd12.ezyfoxserver.support.reflect.EzyRequestControllerProxy) EzyUserRequestHandler(com.tvd12.ezyfoxserver.support.handler.EzyUserRequestHandler) EzyRequestHandlerMethod(com.tvd12.ezyfoxserver.support.reflect.EzyRequestHandlerMethod)

Aggregations

EzyRequestControllerProxy (com.tvd12.ezyfoxserver.support.reflect.EzyRequestControllerProxy)3 HelloController (com.tvd12.ezyfoxserver.support.test.controller.HelloController)2 Test (org.testng.annotations.Test)2 EzyRequestHandlerImplementer (com.tvd12.ezyfoxserver.support.asm.EzyRequestHandlerImplementer)1 EzyUserRequestHandler (com.tvd12.ezyfoxserver.support.handler.EzyUserRequestHandler)1 EzyRequestHandlerMethod (com.tvd12.ezyfoxserver.support.reflect.EzyRequestHandlerMethod)1 HashMap (java.util.HashMap)1