Package org.springframework.test.web.servlet

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


                .andExpect(request().asyncResult("index")).andReturn();
        mockMvc.perform(asyncDispatch(mvcResult)).andExpect(model().attribute("device", is(equalTo("mobile"))));
    }

    public <T> ResultMatcher asyncJsonPath(final String expression, final Matcher<T> matcher) {
        return new ResultMatcher() {
            @Override
            public void match(MvcResult result) throws ParseException, java.text.ParseException {
                HttpServletRequest request = result.getRequest();
                assertThat("Async not started.", request.isAsyncStarted());
                Object res = result.getAsyncResult();
View Full Code Here


    return jsonQueryResults;
  }

  protected ResultMatcher hasLinkWithRel(final String rel) {

    return new ResultMatcher() {

      @Override
      public void match(MvcResult result) throws Exception {

        MockHttpServletResponse response = result.getResponse();
View Full Code Here

    };
  }

  protected ResultMatcher doesNotHaveLinkWithRel(final String rel) {

    return new ResultMatcher() {

      @Override
      public void match(MvcResult result) throws Exception {

        MockHttpServletResponse response = result.getResponse();
View Full Code Here

    }

    @Test
    public void userAuthenticates() throws Exception {
        final String username = "user";
        ResultMatcher matcher = 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 userAuthenticationFails() throws Exception {
        final String username = "user";
        mockMvc.perform(post("/j_spring_security_check").param("j_username", username).param("j_password", "invalid"))
                .andExpect(redirectedUrl("/signin?error=1"))
                .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 a cookie value with the given Hamcrest {@link Matcher}.
   */
  public ResultMatcher value(final String name, final Matcher<? super String> matcher) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) {
        Cookie cookie = result.getResponse().getCookie(name);
        assertTrue("Response cookie not found: " + name, cookie != null);
        assertThat("Response cookie", cookie.getValue(), matcher);
View Full Code Here

  /**
   * Assert a cookie value.
   */
  public ResultMatcher value(final String name, final String expectedValue) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) {
        Cookie cookie = result.getResponse().getCookie(name);
        assertTrue("Response cookie not found: " + name, cookie != null);
        assertEquals("Response cookie", expectedValue, cookie.getValue());
View Full Code Here

  /**
   * Assert a cookie exists. The existence check is irrespective of whether
   * max age is 0 (i.e. expired).
   */
  public ResultMatcher exists(final String name) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) {
        Cookie cookie = result.getResponse().getCookie(name);
        assertTrue("No cookie with name: " + name, cookie != null);
      }
View Full Code Here

  /**
   * Assert a cookie does not exist. Note that the existence check is
   * irrespective of whether max age is 0, i.e. expired.
   */
  public ResultMatcher doesNotExist(final String name) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) {
        Cookie cookie = result.getResponse().getCookie(name);
        assertTrue("Unexpected cookie with name " + name, cookie == null);
      }
View Full Code Here

  /**
   * Assert a cookie's maxAge with a Hamcrest {@link Matcher}.
   */
  public ResultMatcher maxAge(final String name, final Matcher<? super Integer> matcher) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) {
        Cookie cookie = result.getResponse().getCookie(name);
        assertTrue("No cookie with name: " + name, cookie != null);
        assertThat("Response cookie maxAge", cookie.getMaxAge(), matcher);
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.