Search in sources :

Example 1 with RequestHandlerImplementer

use of com.tvd12.ezyhttp.server.core.asm.RequestHandlerImplementer in project ezyhttp by youngmonkeys.

the class RequestHandlerImplementerTest method test.

@Test
public void test() {
    RequestHandlerImplementer.setDebug(true);
    ControllerProxy homeController = new ControllerProxy(new HomeController());
    for (RequestHandlerMethod method : homeController.getRequestHandlerMethods()) {
        RequestHandlerImplementer implementer = new RequestHandlerImplementer(homeController, method);
        implementer.implement();
    }
}
Also used : RequestHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.RequestHandlerMethod) HomeController(com.tvd12.ezyhttp.server.core.test.controller.HomeController) RequestHandlerImplementer(com.tvd12.ezyhttp.server.core.asm.RequestHandlerImplementer) ControllerProxy(com.tvd12.ezyhttp.server.core.reflect.ControllerProxy) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 2 with RequestHandlerImplementer

use of com.tvd12.ezyhttp.server.core.asm.RequestHandlerImplementer 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 3 with RequestHandlerImplementer

use of com.tvd12.ezyhttp.server.core.asm.RequestHandlerImplementer in project ezyhttp by youngmonkeys.

the class RequestHandlerImplementerTest method test.

@Test
public void test() {
    RequestHandlerImplementer.setDebug(true);
    ControllerProxy homeController = new ControllerProxy(new HomeController());
    for (RequestHandlerMethod method : homeController.getRequestHandlerMethods()) {
        RequestHandlerImplementer implementer = new RequestHandlerImplementer(homeController, method);
        implementer.implement();
    }
}
Also used : RequestHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.RequestHandlerMethod) HomeController(com.tvd12.ezyhttp.server.boot.test.controller.HomeController) RequestHandlerImplementer(com.tvd12.ezyhttp.server.core.asm.RequestHandlerImplementer) ControllerProxy(com.tvd12.ezyhttp.server.core.reflect.ControllerProxy) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 4 with RequestHandlerImplementer

use of com.tvd12.ezyhttp.server.core.asm.RequestHandlerImplementer in project ezyhttp by youngmonkeys.

the class RequestHandlerImplementerTest method test.

@Test
public void test() {
    RequestHandlerImplementer.setDebug(true);
    ControllerProxy homeController = new ControllerProxy(new HomeController());
    for (RequestHandlerMethod method : homeController.getRequestHandlerMethods()) {
        RequestHandlerImplementer implementer = new RequestHandlerImplementer(homeController, method);
        implementer.implement();
    }
}
Also used : RequestHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.RequestHandlerMethod) HomeController(com.tvd12.ezyhttp.server.jetty.test.controller.HomeController) RequestHandlerImplementer(com.tvd12.ezyhttp.server.core.asm.RequestHandlerImplementer) ControllerProxy(com.tvd12.ezyhttp.server.core.reflect.ControllerProxy) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 5 with RequestHandlerImplementer

use of com.tvd12.ezyhttp.server.core.asm.RequestHandlerImplementer in project ezyhttp by youngmonkeys.

the class RequestHandlersImplementer method implement.

public Map<RequestURI, List<RequestHandler>> implement(Object controller) {
    Map<RequestURI, List<RequestHandler>> handlers = new HashMap<>();
    ControllerProxy proxy = new ControllerProxy(controller);
    String feature = proxy.getFeature();
    for (RequestHandlerMethod method : proxy.getRequestHandlerMethods()) {
        RequestHandlerImplementer implementer = newImplementer(proxy, method);
        RequestHandler handler = implementer.implement();
        HttpMethod httpMethod = handler.getMethod();
        String requestURI = handler.getRequestURI();
        String methodFeature = method.getFeature();
        RequestURIMeta uriMeta = RequestURIMeta.builder().api(method.isApi() || proxy.isApi()).authenticated(method.isAuthenticated() || proxy.isAuthenticated()).management(method.isManagement() || proxy.isManagement()).payment(method.isPayment() || proxy.isPayment()).feature(methodFeature != null ? methodFeature : feature).build();
        RequestURI uri = new RequestURI(httpMethod, requestURI, uriMeta);
        handlers.computeIfAbsent(uri, k -> new ArrayList<>()).add(handler);
    }
    return handlers;
}
Also used : Setter(lombok.Setter) Collection(java.util.Collection) EzyLoggable(com.tvd12.ezyfox.util.EzyLoggable) HashMap(java.util.HashMap) RequestURIDecorator(com.tvd12.ezyhttp.server.core.handler.RequestURIDecorator) ArrayList(java.util.ArrayList) List(java.util.List) RequestURIMeta(com.tvd12.ezyhttp.server.core.request.RequestURIMeta) Map(java.util.Map) ControllerProxy(com.tvd12.ezyhttp.server.core.reflect.ControllerProxy) HttpMethod(com.tvd12.ezyhttp.core.constant.HttpMethod) RequestHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.RequestHandlerMethod) RequestHandler(com.tvd12.ezyhttp.server.core.handler.RequestHandler) RequestURI(com.tvd12.ezyhttp.server.core.request.RequestURI) RequestHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.RequestHandlerMethod) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RequestURIMeta(com.tvd12.ezyhttp.server.core.request.RequestURIMeta) RequestHandler(com.tvd12.ezyhttp.server.core.handler.RequestHandler) ControllerProxy(com.tvd12.ezyhttp.server.core.reflect.ControllerProxy) RequestURI(com.tvd12.ezyhttp.server.core.request.RequestURI) ArrayList(java.util.ArrayList) List(java.util.List) HttpMethod(com.tvd12.ezyhttp.core.constant.HttpMethod)

Aggregations

ControllerProxy (com.tvd12.ezyhttp.server.core.reflect.ControllerProxy)5 RequestHandlerMethod (com.tvd12.ezyhttp.server.core.reflect.RequestHandlerMethod)5 RequestHandlerImplementer (com.tvd12.ezyhttp.server.core.asm.RequestHandlerImplementer)4 Test (org.testng.annotations.Test)4 BaseTest (com.tvd12.test.base.BaseTest)3 EzyMethod (com.tvd12.ezyfox.reflect.EzyMethod)1 EzyLoggable (com.tvd12.ezyfox.util.EzyLoggable)1 HttpMethod (com.tvd12.ezyhttp.core.constant.HttpMethod)1 HomeController (com.tvd12.ezyhttp.server.boot.test.controller.HomeController)1 RequestHandler (com.tvd12.ezyhttp.server.core.handler.RequestHandler)1 RequestURIDecorator (com.tvd12.ezyhttp.server.core.handler.RequestURIDecorator)1 RequestURI (com.tvd12.ezyhttp.server.core.request.RequestURI)1 RequestURIMeta (com.tvd12.ezyhttp.server.core.request.RequestURIMeta)1 HomeController (com.tvd12.ezyhttp.server.core.test.controller.HomeController)1 HomeController (com.tvd12.ezyhttp.server.jetty.test.controller.HomeController)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1