Package org.springframework.test.web.servlet

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


   * This method can be used when a controller method returns {@link Callable}
   * or {@link WebAsyncTask}. The value matched is the value returned from the
   * {@code Callable} or the exception raised.
   */
  public <T> ResultMatcher asyncResult(final Object expectedResult) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) {
        HttpServletRequest request = result.getRequest();
        assertEquals("Async started", true, request.isAsyncStarted());
        assertEquals("Async result", expectedResult, result.getAsyncResult());
View Full Code Here


  /**
   * Assert a request attribute value with the given Hamcrest {@link Matcher}.
   */
  public <T> ResultMatcher attribute(final String name, final Matcher<T> matcher) {
    return new ResultMatcher() {
      @Override
      @SuppressWarnings("unchecked")
      public void match(MvcResult result) {
        T value = (T) result.getRequest().getAttribute(name);
        assertThat("Request attribute", value, matcher);
View Full Code Here

  /**
   * Assert a request attribute value.
   */
  public <T> ResultMatcher attribute(final String name, final Object expectedValue) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) {
        assertEquals("Request attribute", expectedValue, result.getRequest().getAttribute(name));
      }
    };
View Full Code Here

  /**
   * Assert a session attribute value with the given Hamcrest {@link Matcher}.
   */
  public <T> ResultMatcher sessionAttribute(final String name, final Matcher<T> matcher) {
    return new ResultMatcher() {
      @Override
      @SuppressWarnings("unchecked")
      public void match(MvcResult result) {
        T value = (T) result.getRequest().getSession().getAttribute(name);
        assertThat("Request attribute", value, matcher);
View Full Code Here

  /**
   * Assert a session attribute value..
   */
  public <T> ResultMatcher sessionAttribute(final String name, final Object value) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) {
        assertEquals("Request attribute", value, result.getRequest().getSession().getAttribute(name));
      }
    };
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

      MockHttpServletResponse response = new MockHttpServletResponse();
      response.setStatus(status.value());
      MvcResult mvcResult = new StubMvcResult(request, null, null, null, null, null, response);
      try {
        Method method = getMethodForHttpStatus(status);
        ResultMatcher matcher = (ResultMatcher) ReflectionUtils.invokeMethod(method, this.matchers);
        try {
          matcher.match(mvcResult);
        }
        catch (AssertionError error) {
          failures.add(error);
        }
      }
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.