Search in sources :

Example 1 with RequestHandlersImplementer

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

the class RequestHandlersImplementerTest method implementOneFailed.

@Test
public void implementOneFailed() {
    // given
    RequestHandlersImplementer sut = new RequestHandlersImplementer();
    Controller controller = new Controller();
    RequestHandlerManager manager = new RequestHandlerManager();
    // when
    Throwable e = Asserts.assertThrows(() -> manager.addHandlers(sut.implement(Collections.singletonList(controller))));
    // then
    Asserts.assertThat(e).isEqualsType(DuplicateURIMappingHandlerException.class);
}
Also used : RequestHandlersImplementer(com.tvd12.ezyhttp.server.core.asm.RequestHandlersImplementer) RequestHandlerManager(com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager) Test(org.testng.annotations.Test)

Example 2 with RequestHandlersImplementer

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

the class RequestHandlersImplementerTest method implementOneWithURIDecorator.

@Test
public void implementOneWithURIDecorator() {
    // given
    RequestHandlersImplementer sut = new RequestHandlersImplementer();
    Controller controller = new Controller();
    RequestHandlerManager manager = new RequestHandlerManager();
    manager.setAllowOverrideURI(true);
    RequestURIDecorator requestURIDecorator = mock(RequestURIDecorator.class);
    when(requestURIDecorator.decorate(any(), any())).thenReturn("hello-world");
    sut.setRequestURIDecorator(requestURIDecorator);
    // when
    manager.addHandlers(sut.implement(Collections.singletonList(controller)));
    // then
    RequestURI uri = new RequestURI(HttpMethod.GET, "/hello-world", false);
    Asserts.assertThat(manager.getHandlerListByURI().get(uri).size()).isEqualsTo(2);
}
Also used : RequestHandlersImplementer(com.tvd12.ezyhttp.server.core.asm.RequestHandlersImplementer) RequestHandlerManager(com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager) RequestURI(com.tvd12.ezyhttp.server.core.request.RequestURI) RequestURIDecorator(com.tvd12.ezyhttp.server.core.handler.RequestURIDecorator) Test(org.testng.annotations.Test)

Example 3 with RequestHandlersImplementer

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

the class ApplicationContextBuilder method addRequestHandlers.

protected void addRequestHandlers(EzyBeanContext beanContext) {
    List<Object> controllerList = controllerManager.getControllers();
    RequestHandlersImplementer implementer = newRequestHandlersImplementer();
    implementer.setRequestURIDecorator(beanContext.getSingleton(RequestURIDecorator.class));
    Map<RequestURI, List<RequestHandler>> requestHandlers = implementer.implement(controllerList);
    requestHandlerManager.addHandlers(requestHandlers);
}
Also used : RequestHandlersImplementer(com.tvd12.ezyhttp.server.core.asm.RequestHandlersImplementer) RequestURI(com.tvd12.ezyhttp.server.core.request.RequestURI) List(java.util.List) ArrayList(java.util.ArrayList) RequestURIDecorator(com.tvd12.ezyhttp.server.core.handler.RequestURIDecorator)

Example 4 with RequestHandlersImplementer

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

the class RequestHandlersImplementerTest method implementMultiFailed.

@Test
public void implementMultiFailed() {
    // given
    RequestHandlersImplementer sut = new RequestHandlersImplementer();
    Controller2 controller2 = new Controller2();
    Controller3 controller3 = new Controller3();
    RequestHandlerManager manager = new RequestHandlerManager();
    // when
    Throwable e = Asserts.assertThrows(() -> manager.addHandlers(sut.implement(Arrays.asList(controller2, controller3))));
    // then
    Asserts.assertThat(e).isEqualsType(DuplicateURIMappingHandlerException.class);
}
Also used : RequestHandlersImplementer(com.tvd12.ezyhttp.server.core.asm.RequestHandlersImplementer) RequestHandlerManager(com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager) Test(org.testng.annotations.Test)

Example 5 with RequestHandlersImplementer

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

the class RequestHandlersImplementerTest method implementOneAllowOverrideURI.

@Test
public void implementOneAllowOverrideURI() {
    // given
    RequestHandlersImplementer sut = new RequestHandlersImplementer();
    Controller controller = new Controller();
    RequestHandlerManager manager = new RequestHandlerManager();
    manager.setAllowOverrideURI(true);
    // when
    manager.addHandlers(sut.implement(Collections.singletonList(controller)));
    // then
    RequestURI uri = new RequestURI(HttpMethod.GET, "/get", false);
    Asserts.assertThat(manager.getHandlerListByURI().get(uri).size()).isEqualsTo(2);
}
Also used : RequestHandlersImplementer(com.tvd12.ezyhttp.server.core.asm.RequestHandlersImplementer) RequestHandlerManager(com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager) RequestURI(com.tvd12.ezyhttp.server.core.request.RequestURI) Test(org.testng.annotations.Test)

Aggregations

RequestHandlersImplementer (com.tvd12.ezyhttp.server.core.asm.RequestHandlersImplementer)5 RequestHandlerManager (com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager)4 Test (org.testng.annotations.Test)4 RequestURI (com.tvd12.ezyhttp.server.core.request.RequestURI)3 RequestURIDecorator (com.tvd12.ezyhttp.server.core.handler.RequestURIDecorator)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1