Package org.springframework.web.servlet

Examples of org.springframework.web.servlet.HandlerMapping


    wac.setConfigLocations(new String[] {CONF});
    wac.refresh();
  }

  public void testRequestsWithoutHandlers() throws Exception {
    HandlerMapping hm = (HandlerMapping) wac.getBean("handlerMapping");

    MockHttpServletRequest req = new MockHttpServletRequest("GET", "/mypath/nonsense.html");
    req.setContextPath("/myapp");
    Object h = hm.getHandler(req);
    assertTrue("Handler is null", h == null);

    req = new MockHttpServletRequest("GET", "/foo/bar/baz.html");
    h = hm.getHandler(req);
    assertTrue("Handler is null", h == null);
  }
View Full Code Here


    h = hm.getHandler(req);
    assertTrue("Handler is null", h == null);
  }

  public void testRequestsWithSubPaths() throws Exception {
    HandlerMapping hm = (HandlerMapping) wac.getBean("handlerMapping");
    doTestRequestsWithSubPaths(hm);
  }
View Full Code Here

    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
  }

  public void testAsteriskMatches() throws Exception {
    HandlerMapping hm = (HandlerMapping) wac.getBean("handlerMapping");
    Object bean = wac.getBean("godCtrl");

    MockHttpServletRequest req = new MockHttpServletRequest("GET", "/mypath/test.html");
    HandlerExecutionChain hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/mypath/testarossa");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);

    req = new MockHttpServletRequest("GET", "/mypath/tes");
    hec = hm.getHandler(req);
    assertTrue("Handler is correct bean", hec == null);
  }
View Full Code Here

    wac.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map2.xml"});
    wac.refresh();
    Object bean = wac.getBean("mainController");
    Object otherBean = wac.getBean("otherController");
    Object defaultBean = wac.getBean("starController");
    HandlerMapping hm = (HandlerMapping) wac.getBean(beanName);

    MockHttpServletRequest req = new MockHttpServletRequest("GET", "/welcome.html");
    HandlerExecutionChain hec = getHandler(hm, req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
    assertEquals("/welcome.html", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE));
View Full Code Here

    verify(springMVCRequestNameDeterminerAspect, times(useNameDeterminerAspect ? 1 : 0))
        .aroundGetHandler(any(HttpServletRequest.class), any(HandlerExecutionChain.class));
  }

  private HandlerMapping createExceptionThrowingHandlerMapping() throws Exception {
    HandlerMapping requestMappingHandlerMapping = mock(HandlerMapping.class);
    when(requestMappingHandlerMapping.getHandler((HttpServletRequest) any())).thenThrow(new Exception("This is a test exeption"));
    return requestMappingHandlerMapping;
  }
View Full Code Here

    when(requestMappingHandlerMapping.getHandler((HttpServletRequest) any())).thenThrow(new Exception("This is a test exeption"));
    return requestMappingHandlerMapping;
  }

  private HandlerMapping createHandlerMappingNotReturningHandlerMethod() throws Exception {
    HandlerMapping requestMappingHandlerMapping = mock(HandlerMapping.class);
    HandlerExecutionChain handlerExecutionChain = mock(HandlerExecutionChain.class);

    when(handlerExecutionChain.getHandler()).thenReturn(new Object());
    when(requestMappingHandlerMapping.getHandler((HttpServletRequest) any())).thenReturn(handlerExecutionChain);
    return requestMappingHandlerMapping;
  }
View Full Code Here

    return requestMappingHandlerMapping;
  }

  private HandlerMapping createHandlerMapping(MockHttpServletRequest request, Method requestMappingMethod) throws Exception {
    System.out.println("createHandlerMapping"+request);
    HandlerMapping requestMappingHandlerMapping = mock(HandlerMapping.class);
    HandlerExecutionChain handlerExecutionChain = mock(HandlerExecutionChain.class);
    HandlerMethod handlerMethod = mock(HandlerMethod.class);

    when(handlerMethod.getMethod()).thenReturn(requestMappingMethod);
    when(handlerExecutionChain.getHandler()).thenReturn(handlerMethod);
    when(requestMappingHandlerMapping.getHandler(Matchers.argThat(new Matcher<HttpServletRequest>() {
      @Override
      public boolean matches(Object item) {
        return ((HttpServletRequest) item).getRequestURI().equals("/test/requestName");
      }
View Full Code Here

  @Test
  @SuppressWarnings("unchecked")
  public void webSocketHandlersAttributes() {
    loadBeanDefinitions("websocket-config-handlers-attributes.xml");

    HandlerMapping handlerMapping = this.appContext.getBean(HandlerMapping.class);
    assertNotNull(handlerMapping);
    assertTrue(handlerMapping instanceof SimpleUrlHandlerMapping);

    SimpleUrlHandlerMapping urlHandlerMapping = (SimpleUrlHandlerMapping) handlerMapping;
    assertEquals(2, urlHandlerMapping.getOrder());
View Full Code Here

  @Test
  public void simpleBroker() throws Exception {
    loadBeanDefinitions("websocket-config-broker-simple.xml");

    HandlerMapping hm = this.appContext.getBean(HandlerMapping.class);
    assertThat(hm, Matchers.instanceOf(SimpleUrlHandlerMapping.class));
    SimpleUrlHandlerMapping suhm = (SimpleUrlHandlerMapping) hm;
    assertThat(suhm.getUrlMap().keySet(), Matchers.hasSize(4));
    assertThat(suhm.getUrlMap().values(), Matchers.hasSize(4));
View Full Code Here

  @Test
  public void stompBrokerRelay() {
    loadBeanDefinitions("websocket-config-broker-relay.xml");

    HandlerMapping hm = this.appContext.getBean(HandlerMapping.class);
    assertNotNull(hm);
    assertThat(hm, Matchers.instanceOf(SimpleUrlHandlerMapping.class));

    SimpleUrlHandlerMapping suhm = (SimpleUrlHandlerMapping) hm;
    assertThat(suhm.getUrlMap().keySet(), Matchers.hasSize(1));
View Full Code Here

TOP

Related Classes of org.springframework.web.servlet.HandlerMapping

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.