Package org.springframework.test.web.servlet

Examples of org.springframework.test.web.servlet.ResultMatcher


  /**
   * Assert the model has errors.
   */
  public <T> ResultMatcher hasErrors() {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) throws Exception {
        int count = getErrorCount(getModelAndView(result).getModelMap());
        assertTrue("Expected binding/validation errors", count != 0);
      }
View Full Code Here


  /**
   * Assert the model has no errors.
   */
  public <T> ResultMatcher hasNoErrors() {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) throws Exception {
        ModelAndView mav = getModelAndView(result);
        for (Object value : mav.getModel().values()) {
          if (value instanceof Errors) {
View Full Code Here

  /**
   * Assert the number of model attributes.
   */
  public <T> ResultMatcher size(final int size) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) throws Exception {
        ModelAndView mav = getModelAndView(result);
        int actual = 0;
        for (String key : mav.getModel().keySet()) {
View Full Code Here

  /**
   * Assert the type of the handler that processed the request.
   */
  public ResultMatcher handlerType(final Class<?> type) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) throws Exception {
        Object handler = result.getHandler();
        assertTrue("No handler: ", handler != null);
        Class<?> actual = handler.getClass();
View Full Code Here

   *
   * <p>Use of this method implies annotated controllers are processed with
   * {@link RequestMappingHandlerMapping} and {@link RequestMappingHandlerAdapter}.
   */
  public ResultMatcher methodName(final Matcher<? super String> matcher) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) throws Exception {
        Object handler = assertHandlerMethod(result);
        assertThat("HandlerMethod", ((HandlerMethod) handler).getMethod().getName(), matcher);
      }
View Full Code Here

   *
   * <p>Use of this method implies annotated controllers are processed with
   * {@link RequestMappingHandlerMapping} and {@link RequestMappingHandlerAdapter}.
   */
  public ResultMatcher methodName(final String name) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) throws Exception {
        Object handler = assertHandlerMethod(result);
        assertEquals("HandlerMethod", name, ((HandlerMethod) handler).getMethod().getName());
      }
View Full Code Here

   *
   * <p>Use of this method implies annotated controllers are processed with
   * {@link RequestMappingHandlerMapping} and {@link RequestMappingHandlerAdapter}.
   */
  public ResultMatcher method(final Method method) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) throws Exception {
        Object handler = assertHandlerMethod(result);
        assertEquals("HandlerMethod", method, ((HandlerMethod) handler).getMethod());
      }
View Full Code Here

   * The given content type must fully match including type, sub-type, and
   * parameters. For checking only the type and sub-type see
   * {@link #contentTypeCompatibleWith(MediaType)}.
   */
  public ResultMatcher contentType(final MediaType contentType) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) throws Exception {
        String actual = result.getResponse().getContentType();
        assertTrue("Content type not set", actual != null);
        assertEquals("Content type", contentType, MediaType.parseMediaType(actual));
View Full Code Here

  /**
   * Assert the ServletResponse content type is compatible with the given
   * content type as defined by {@link MediaType#isCompatibleWith(MediaType)}.
   */
  public ResultMatcher contentTypeCompatibleWith(final MediaType contentType) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) throws Exception {
        String actual = result.getResponse().getContentType();
        assertTrue("Content type not set", actual != null);
        MediaType actualContentType = MediaType.parseMediaType(actual);
View Full Code Here

  /**
   * Assert the character encoding in the ServletResponse.
   * @see HttpServletResponse#getCharacterEncoding()
   */
  public ResultMatcher encoding(final String characterEncoding) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) {
        String actual = result.getResponse().getCharacterEncoding();
        assertEquals("Character encoding", characterEncoding, actual);
      }
View Full Code Here

TOP

Related Classes of org.springframework.test.web.servlet.ResultMatcher

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.