Package org.springframework.test.web.server

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


  @Test
  public void userAuthenticates() throws Exception {
    final String username = "user";
    mockMvc.perform(post("/j_spring_security_check").param("j_username", username).param("j_password", "password"))
      .andExpect(redirectedUrl("/"))
      .andExpect(new ResultMatcher() {
        public void match(MvcResult mvcResult) throws Exception {
          HttpSession session = mvcResult.getRequest().getSession();
          SecurityContext securityContext = (SecurityContext) session.getAttribute(SEC_CONTEXT_ATTR);
          Assert.assertEquals(securityContext.getAuthentication().getName(), username);
        }
View Full Code Here


  @Test
  public void userAuthenticateFails() throws Exception {
    final String username = "user";
    mockMvc.perform(post("/j_spring_security_check").param("j_username", username).param("j_password", "invalid"))
      .andExpect(redirectedUrl("/spring_security_login?login_error"))
      .andExpect(new ResultMatcher() {
        public void match(MvcResult mvcResult) throws Exception {
          HttpSession session = mvcResult.getRequest().getSession();
          SecurityContext securityContext = (SecurityContext) session.getAttribute(SEC_CONTEXT_ATTR);
          Assert.assertNull(securityContext);
        }
View Full Code Here

  /**
   * Assert the response status code with the given Hamcrest {@link Matcher}.
   */
  public ResultMatcher is(final Matcher<Integer> matcher) {
    return new ResultMatcher() {
      public void match(MvcResult result) throws Exception {
        MatcherAssert.assertThat("Status: ", result.getResponse().getStatus(), matcher);
      }
    };
  }
View Full Code Here

  /**
   * Assert the Servlet response error message with the given Hamcrest {@link Matcher}.
   */
  public ResultMatcher reason(final Matcher<? super String> matcher) {
    return new ResultMatcher() {
      public void match(MvcResult result) throws Exception {
        MatcherAssert.assertThat("Status reason: ", result.getResponse().getErrorMessage(), matcher);
      }
    };
  }
View Full Code Here

    /**
   * Match the expected response status to that of the HttpServletResponse
   */
    private ResultMatcher matcher(final HttpStatus status) {
    return new ResultMatcher() {
      public void match(MvcResult result) {
        assertEquals("Status", status.value(), result.getResponse().getStatus());
      }
    };
  }
View Full Code Here

  /**
   * Assert the selected view name with the given Hamcrest {@link Matcher}.
   */
  public ResultMatcher name(final Matcher<? super String> matcher) {
    return new ResultMatcher() {
      public void match(MvcResult result) throws Exception {
        ModelAndView mav = result.getModelAndView();
        assertTrue("No ModelAndView found", mav != null);
        MatcherAssert.assertThat("View name", mav.getViewName(), matcher);
      }
View Full Code Here

  /**
   * Assert a response header with the given Hamcrest {@link Matcher}.
   */
  public ResultMatcher string(final String name, final Matcher<? super String> matcher) {
    return new ResultMatcher() {
      public void match(MvcResult result) {
        MatcherAssert.assertThat("Response header", result.getResponse().getHeader(name), matcher);
      }
    };
  }
View Full Code Here

  /**
   * Assert the primary value of a response header as a {@link Long}.
   */
  public ResultMatcher longValue(final String name, final long value) {
    return new ResultMatcher() {
      public void match(MvcResult result) {
        assertEquals("Response header " + name, value, Long.parseLong(result.getResponse().getHeader(name)));
      }
    };
  }
View Full Code Here

  /**
   * Assert a flash attribute's value with the given Hamcrest {@link Matcher}.
   */
  public <T> ResultMatcher attribute(final String name, final Matcher<T> matcher) {
    return new ResultMatcher() {
      @SuppressWarnings("unchecked")
      public void match(MvcResult result) throws Exception {
        MatcherAssert.assertThat("Flash attribute", (T) result.getFlashMap().get(name), matcher);
      }
    };
View Full Code Here

  /**
   * Assert the existence of the given flash attributes.
   */
  public <T> ResultMatcher attributeExists(final String... names) {
    return new ResultMatcher() {
      public void match(MvcResult result) throws Exception {
        for (String name : names) {
          attribute(name, Matchers.notNullValue()).match(result);
        }
      }
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.