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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations