Example #1
0
 @Test
 public void aliasMiss() throws Exception {
   AliasHandler handler = new AliasHandler(commandProcessor, true, pathAliases);
   Continuation continuation = mock(Continuation.class);
   when(request.getAttribute(Continuation.ATTRIBUTE)).thenReturn(continuation);
   handler.handle("/missPath", baseRequest, request, response);
   verify(commandProcessor, times(1)).process(any(HttpCommand.class));
 }
Example #2
0
  @Test
  public void aliasHit() throws IOException, ServletException {
    AliasHandler handler = new AliasHandler(commandProcessor, true, pathAliases);
    pathAliases.put("/hitPath", "/context/alternatePath");

    ServletContext origContext = mock(ServletContext.class);
    ServletContext newContext = mock(ServletContext.class);
    when(request.getServletContext()).thenReturn(origContext);
    ArgumentCaptor<String> requestContextPath = ArgumentCaptor.forClass(String.class);
    when(origContext.getContext(requestContextPath.capture())).thenReturn(newContext);
    when(newContext.getContextPath()).thenReturn("/context");
    RequestDispatcher requestDispatcher = mock(RequestDispatcher.class);
    ArgumentCaptor<String> requestDispatcherPath = ArgumentCaptor.forClass(String.class);
    when(newContext.getRequestDispatcher(requestDispatcherPath.capture()))
        .thenReturn(requestDispatcher);

    handler.handle("/hitPath", baseRequest, request, response);
    verify(requestDispatcher, times(1)).forward(request, response);

    assertEquals("/context/alternatePath", requestContextPath.getValue());
    assertEquals("/alternatePath", requestDispatcherPath.getValue());
  }