The Spring Framework

org.springframework.test.web
Class ModelAndViewAssert

java.lang.Object
  extended by org.springframework.test.web.ModelAndViewAssert

public abstract class ModelAndViewAssert
extends Object

A collection of assertions intended to simplify testing scenarios dealing with Spring Web MVC ModelAndView objects. Intended for use with JUnit 4 and TestNG.

All assert*() methods throw AssertionErrors.

Since:
2.5
Author:
Sam Brannen, Alef Arendsen, Bram Smeets
See Also:
ModelAndView

Constructor Summary
ModelAndViewAssert()
           
 
Method Summary
static Object assertAndReturnModelAttributeOfType(ModelAndView mav, Object modelName, Class expectedType)
          Checks whether the model value under the given modelName exists and checks it type, based on the expectedType.
static void assertCompareListModelAttribute(ModelAndView mav, Object modelName, List expectedList)
          Compare each individual entry in a list, without first sorting the lists.
static void assertModelAttributeAvailable(ModelAndView mav, Object modelName)
          Assert whether or not a model attribute is available.
static void assertModelAttributeValue(ModelAndView mav, Object modelName, Object expectedValue)
          Compare a given expectedValue to the value from the model bound under the given modelName.
static void assertModelAttributeValues(ModelAndView mav, Map expectedModel)
          Inspect the expectedModel to see if all elements in the model appear and are equal.
static void assertSortAndCompareListModelAttribute(ModelAndView mav, Object modelName, List expectedList, Comparator comparator)
          Compare each individual entry in a list after having sorted both lists (optionally using a comparator).
static void assertViewName(ModelAndView mav, String expectedName)
          Check to see if the view name in the ModelAndView matches the given expectedName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModelAndViewAssert

public ModelAndViewAssert()
Method Detail

assertAndReturnModelAttributeOfType

public static Object assertAndReturnModelAttributeOfType(ModelAndView mav,
                                                         Object modelName,
                                                         Class expectedType)
                                                  throws AssertionError
Checks whether the model value under the given modelName exists and checks it type, based on the expectedType. If the model entry exists and the type matches, the model value is returned.

Parameters:
mav - ModelAndView to test against (never null)
modelName - name of the object to add to the model (never null)
expectedType - expected type of the model value
Returns:
the model value
Throws:
AssertionError

assertCompareListModelAttribute

public static void assertCompareListModelAttribute(ModelAndView mav,
                                                   Object modelName,
                                                   List expectedList)
                                            throws AssertionError
Compare each individual entry in a list, without first sorting the lists.

Parameters:
mav - ModelAndView to test against (never null)
modelName - name of the object to add to the model (never null)
expectedList - the expected list
Throws:
AssertionError

assertModelAttributeAvailable

public static void assertModelAttributeAvailable(ModelAndView mav,
                                                 Object modelName)
                                          throws AssertionError
Assert whether or not a model attribute is available.

Parameters:
mav - ModelAndView to test against (never null)
modelName - name of the object to add to the model (never null)
Throws:
AssertionError

assertModelAttributeValue

public static void assertModelAttributeValue(ModelAndView mav,
                                             Object modelName,
                                             Object expectedValue)
                                      throws AssertionError
Compare a given expectedValue to the value from the model bound under the given modelName.

Parameters:
mav - ModelAndView to test against (never null)
modelName - name of the object to add to the model (never null)
expectedValue - the model value
Throws:
AssertionError

assertModelAttributeValues

public static void assertModelAttributeValues(ModelAndView mav,
                                              Map expectedModel)
                                       throws AssertionError
Inspect the expectedModel to see if all elements in the model appear and are equal.

Parameters:
mav - ModelAndView to test against (never null)
expectedModel - the expected model
Throws:
AssertionError

assertSortAndCompareListModelAttribute

public static void assertSortAndCompareListModelAttribute(ModelAndView mav,
                                                          Object modelName,
                                                          List expectedList,
                                                          Comparator comparator)
                                                   throws AssertionError
Compare each individual entry in a list after having sorted both lists (optionally using a comparator).

Parameters:
mav - ModelAndView to test against (never null)
modelName - name of the object to add to the model (never null)
expectedList - the expected list
comparator - the comparator to use (may be null). If not specifying the comparator, both lists will be sorted not using any comparator.
Throws:
AssertionError

assertViewName

public static void assertViewName(ModelAndView mav,
                                  String expectedName)
                           throws AssertionError
Check to see if the view name in the ModelAndView matches the given expectedName.

Parameters:
mav - ModelAndView to test against (never null)
expectedName - the name of the model value
Throws:
AssertionError

The Spring Framework

Copyright © 2002-2007 The Spring Framework.