Package org.springframework.web.method

Examples of org.springframework.web.method.HandlerMethod


  }

  @Test
  public void globMatch() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bar");
    HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(request).getHandler();
    assertEquals(this.barMethod.getMethod(), hm.getMethod());
  }
View Full Code Here


  }

  @Test
  public void emptyPathMatch() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
    HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(request).getHandler();
    assertEquals(this.emptyMethod.getMethod(), hm.getMethod());

    request = new MockHttpServletRequest("GET", "/");
    hm = (HandlerMethod) this.handlerMapping.getHandler(request).getHandler();
    assertEquals(this.emptyMethod.getMethod(), hm.getMethod());
  }
View Full Code Here

  @Test
  public void bestMatch() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
    request.setParameter("p", "anything");
    HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(request).getHandler();
    assertEquals(this.fooParamMethod.getMethod(), hm.getMethod());
  }
View Full Code Here

    System.setProperty("systemHeader", "systemHeaderValue");
    Map<String, String> uriTemplateVars = new HashMap<String, String>();
    uriTemplateVars.put("pathvar", "pathvarValue");
    request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);

    HandlerMethod handlerMethod = handlerMethod("handle", parameterTypes);
    ModelAndView mav = handlerAdapter.handle(request, response, handlerMethod);
    ModelMap model = mav.getModelMap();

    assertEquals("viewName", mav.getViewName());
    assertEquals(99, model.get("cookie"));
View Full Code Here

    Class<?>[] parameterTypes = new Class<?>[] { byte[].class };

    request.addHeader("Content-Type", "text/plain; charset=utf-8");
    request.setContent("Hello Server".getBytes("UTF-8"));

    HandlerMethod handlerMethod = handlerMethod("handleRequestBody", parameterTypes);

    ModelAndView mav = handlerAdapter.handle(request, response, handlerMethod);

    assertNull(mav);
    assertEquals("Handled requestBody=[Hello Server]", new String(response.getContentAsByteArray(), "UTF-8"));
View Full Code Here

    Class<?>[] parameterTypes = new Class<?>[] { TestBean.class, Errors.class };

    request.addHeader("Content-Type", "text/plain; charset=utf-8");
    request.setContent("Hello Server".getBytes("UTF-8"));

    HandlerMethod handlerMethod = handlerMethod("handleAndValidateRequestBody", parameterTypes);

    ModelAndView mav = handlerAdapter.handle(request, response, handlerMethod);

    assertNull(mav);
    assertEquals("Error count [1]", new String(response.getContentAsByteArray(), "UTF-8"));
View Full Code Here

    Class<?>[] parameterTypes = new Class<?>[] { HttpEntity.class };

    request.addHeader("Content-Type", "text/plain; charset=utf-8");
    request.setContent("Hello Server".getBytes("UTF-8"));

    HandlerMethod handlerMethod = handlerMethod("handleHttpEntity", parameterTypes);

    ModelAndView mav = handlerAdapter.handle(request, response, handlerMethod);

    assertNull(mav);
    assertEquals(HttpStatus.ACCEPTED.value(), response.getStatus());
View Full Code Here

  @Test
  public void handleRequestPart() throws Exception {
    MockMultipartHttpServletRequest multipartRequest = new MockMultipartHttpServletRequest();
    multipartRequest.addFile(new MockMultipartFile("requestPart", "", "text/plain", "content".getBytes("UTF-8")));

    HandlerMethod handlerMethod = handlerMethod("handleRequestPart", String.class, Model.class);
    ModelAndView mav = handlerAdapter.handle(multipartRequest, response, handlerMethod);

    assertNotNull(mav);
    assertEquals("content", mav.getModelMap().get("requestPart"));
  }
View Full Code Here

  @Test
  public void handleAndValidateRequestPart() throws Exception {
    MockMultipartHttpServletRequest multipartRequest = new MockMultipartHttpServletRequest();
    multipartRequest.addFile(new MockMultipartFile("requestPart", "", "text/plain", "content".getBytes("UTF-8")));

    HandlerMethod handlerMethod = handlerMethod("handleAndValidateRequestPart", String.class, Errors.class, Model.class);
    ModelAndView mav = handlerAdapter.handle(multipartRequest, response, handlerMethod);

    assertNotNull(mav);
    assertEquals(1, mav.getModelMap().get("error count"));
  }
View Full Code Here

    assertEquals(1, mav.getModelMap().get("error count"));
  }

  @Test
  public void handleAndCompleteSession() throws Exception {
    HandlerMethod handlerMethod = handlerMethod("handleAndCompleteSession", SessionStatus.class);
    handlerAdapter.handle(request, response, handlerMethod);

    assertFalse(request.getSession().getAttributeNames().hasMoreElements());
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.method.HandlerMethod

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.