Package org.springframework.test.web.server

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


  /**
   * Assert the given model attribute field(s) have errors.
   */
  public ResultMatcher attributeHasFieldErrors(final String name, final String... fieldNames) {
    return new ResultMatcher() {
      public void match(MvcResult mvcResult) throws Exception {
        ModelAndView mav = getModelAndView(mvcResult);
        BindingResult result = getBindingResult(mav, name);
        assertTrue("No errors for attribute: '" + name + "'", result.hasErrors());
        for (final String fieldName : fieldNames) {
View Full Code Here


  /**
   * Assert the model has no errors.
   */
  public <T> ResultMatcher hasNoErrors() {
    return new ResultMatcher() {
      public void match(MvcResult result) throws Exception {
        ModelAndView mav = getModelAndView(result);
        for (Object value : mav.getModel().values()) {
          if (value instanceof BindingResult) {
            assertTrue("Unexpected binding error(s): " + value, !((BindingResult) value).hasErrors());
View Full Code Here

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

  /**
   * Assert the type of the handler that processed the request.
   */
  public ResultMatcher handlerType(final Class<?> type) {
    return new ResultMatcher() {
      public void match(MvcResult result) throws Exception {
        Object handler = result.getHandler();
        assertTrue("No handler: ", handler != null);
        Class<?> actual = handler.getClass();
        if (HandlerMethod.class.isInstance(handler)) {
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() {
      public void match(MvcResult result) throws Exception {
        Object handler = result.getHandler();
        assertTrue("No handler: ", handler != null);
        assertTrue("Not a HandlerMethod: " + handler, HandlerMethod.class.isInstance(handler));
        MatcherAssert.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 method(final Method method) {
    return new ResultMatcher() {
      public void match(MvcResult result) throws Exception {
        Object handler = result.getHandler();
        assertTrue("No handler: ", handler != null);
        assertTrue("Not a HandlerMethod: " + handler, HandlerMethod.class.isInstance(handler));
        assertEquals("HandlerMethod", method, ((HandlerMethod) handler).getMethod());
View Full Code Here

  /**
   * Assert the ServletResponse content type after parsing it as a MediaType.
   */
  public ResultMatcher mimeType(final MediaType contentType) {
    return new ResultMatcher() {
      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 character encoding in the ServletResponse.
   * @see HttpServletResponse#getCharacterEncoding()
   */
  public ResultMatcher encoding(final String characterEncoding) {
    return new ResultMatcher() {
      public void match(MvcResult result) {
        String actual = result.getResponse().getCharacterEncoding();
        assertEquals("Character encoding", characterEncoding, actual);
      }
    };
View Full Code Here

   * mockMvc.perform(get("/path"))
   *   .andExpect(content(containsString("text")));
   * </pre>
   */
  public ResultMatcher string(final Matcher<? super String> matcher) {
    return new ResultMatcher() {
      public void match(MvcResult result) throws Exception {
        MatcherAssert.assertThat("Response content", result.getResponse().getContentAsString(), matcher);
      }
    };
  }
View Full Code Here

  /**
   * Assert the response body content as a byte array.
   */
  public ResultMatcher bytes(final byte[] expectedContent) {
    return new ResultMatcher() {
      public void match(MvcResult result) throws Exception {
        byte[] content = result.getResponse().getContentAsByteArray();
        MatcherAssert.assertThat("Response content", content, Matchers.equalTo(expectedContent));
      }
    };
View Full Code Here

TOP

Related Classes of org.springframework.test.web.server.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.