@Override public <T> T forwardTo(Class<T> controller) { return use(logic()).forwardTo(controller); }
@Override public <T> T onErrorForwardTo(Class<T> controller) { return onErrorUse(logic()).forwardTo(controller); }
@Override public <T> T redirectTo(Class<T> controller) { return use(logic()).redirectTo(controller); }
@Override public <T> T onErrorRedirectTo(Class<T> controller) { return onErrorUse(logic()).redirectTo(controller); }
@Test public void whenRefererMatchesAControllerShouldRedirectToIt() throws Exception { LogicResult logic = mock(LogicResult.class); RefererController controller = mock(RefererController.class); Method index = RefererController.class.getMethod("index"); ControllerMethod method = DefaultControllerMethod.instanceFor(RefererController.class, index); when(request.getHeader("Referer")).thenReturn("http://localhost:8080/vraptor/no-controller"); when(request.getContextPath()).thenReturn("/vraptor"); when(router.parse("/no-controller", HttpMethod.GET, request)).thenReturn(method); doReturn(logic).when(result).use(logic()); when(logic.redirectTo(RefererController.class)).thenReturn(controller); refererResult.redirect(); verify(logic).redirectTo(RefererController.class); verify(controller).index(); } @Test
@Override public void redirect() throws IllegalStateException { String referer = getReferer(); try { ControllerMethod method = router.parse(referer, HttpMethod.GET, request); executeMethod(method, result.use(logic()).redirectTo(method.getController().getType())); } catch (ControllerNotFoundException | MethodNotAllowedException e) { logger.warn("Could not find or doesn't allowed to get controller method", e); result.use(page()).redirectTo(referer); } }
@Override public void forward() throws IllegalStateException { String referer = getReferer(); try { ControllerMethod method = router.parse(referer, HttpMethod.GET, request); executeMethod(method, result.use(logic()).forwardTo(method.getController().getType())); } catch (ControllerNotFoundException | MethodNotAllowedException e) { logger.warn("Could not find or doesn't allowed to get controller method", e); result.use(page()).forwardTo(referer); } }