Package org.springframework.test.web.servlet

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


  /**
   * Assert a model attribute value.
   */
  public ResultMatcher attribute(final String name, final Object value) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) throws Exception {
        ModelAndView mav = getModelAndView(result);
        assertEquals("Model attribute '" + name + "'", value, mav.getModel().get(name));
      }
View Full Code Here


  /**
   * Assert the given model attributes exist.
   */
  public ResultMatcher attributeExists(final String... names) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) throws Exception {
        ModelAndView mav = getModelAndView(result);
        for (String name : names) {
          assertTrue("Model attribute '" + name + "' does not exist", mav.getModel().get(name) != null);
View Full Code Here

    /**
     * Assert the given model attributes do not exist
     */
    public ResultMatcher attributeDoesNotExist(final String... names) {
        return new ResultMatcher() {
            @Override
            public void match(MvcResult result) throws Exception {
                ModelAndView mav = getModelAndView(result);
                for (String name : names) {
                    assertTrue("Model attribute '" + name + "' exists", mav.getModel().get(name) == null);
View Full Code Here

  /**
   * Assert the given model attribute(s) have errors.
   */
  public ResultMatcher attributeErrorCount(final String name, final int expectedCount) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) throws Exception {
        ModelAndView mav = getModelAndView(result);
        Errors errors = getBindingResult(mav, name);
        assertEquals("Binding/validation error count for attribute [" + name + "], ",
View Full Code Here

  /**
   * Assert the given model attribute(s) have errors.
   */
  public ResultMatcher attributeHasErrors(final String... names) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult mvcResult) throws Exception {
        ModelAndView mav = getModelAndView(mvcResult);
        for (String name : names) {
          BindingResult result = getBindingResult(mav, name);
View Full Code Here

  /**
   * Assert the given model attribute(s) do not have errors.
   */
  public ResultMatcher attributeHasNoErrors(final String... names) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult mvcResult) throws Exception {
        ModelAndView mav = getModelAndView(mvcResult);
        for (String name : names) {
          BindingResult result = getBindingResult(mav, name);
View Full Code Here

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

  /**
   * Assert a field error code for a model attribute using exact String match.
   * @since 4.1
   */
  public ResultMatcher attributeHasFieldErrorCode(final String name, final String fieldName, final String error) {
    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());

View Full Code Here

   * @since 4.1
   */
  public <T> ResultMatcher attributeHasFieldErrorCode(final String name, final String fieldName,
      final Matcher<? super String> matcher) {

    return new ResultMatcher() {
      @Override
      public void match(MvcResult mvcResult) throws Exception {
        ModelAndView mav = getModelAndView(mvcResult);
        BindingResult result = getBindingResult(mav, name);
        assertTrue("No errors for attribute: [" + name + "]", result.hasErrors());
View Full Code Here

  /**
   * Assert the total number of errors in the model.
   */
  public <T> ResultMatcher errorCount(final int expectedCount) {
    return new ResultMatcher() {
      @Override
      public void match(MvcResult result) throws Exception {
        int actualCount = getErrorCount(getModelAndView(result).getModelMap());
        assertEquals("Binding/validation error count", expectedCount, actualCount);
      }
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.