org.springframework.test.web
Class AbstractModelAndViewTests

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.springframework.test.web.AbstractModelAndViewTests
All Implemented Interfaces:
junit.framework.Test

public abstract class AbstractModelAndViewTests
extends junit.framework.TestCase

Convenient JUnit 3.8 base class for tests dealing with Spring Web MVC ModelAndView objects.

All assert*() methods throw AssertionFailedErrors.

Consider the use of ModelAndViewAssert with JUnit 4 and TestNG.

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

Constructor Summary
AbstractModelAndViewTests()
           
 
Method Summary
protected  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.
protected  void assertCompareListModelAttribute(ModelAndView mav, Object modelName, List expectedList)
          Compare each individual entry in a list, without first sorting the lists.
protected  void assertModelAttributeAvailable(ModelAndView mav, Object modelName)
          Assert whether or not a model attribute is available.
protected  void assertModelAttributeValue(ModelAndView mav, Object modelName, Object expectedValue)
          Compare a given expectedValue to the value from the model bound under the given modelName.
protected  void assertModelAttributeValues(ModelAndView mav, Map expectedModel)
          Inspect the expectedModel to see if all elements in the model appear and are equal.
protected  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).
protected  void assertViewName(ModelAndView mav, String expectedName)
          Check to see if the view name in the ModelAndView matches the given expectedName.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractModelAndViewTests

public AbstractModelAndViewTests()
Method Detail

assertAndReturnModelAttributeOfType

protected 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. 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

assertCompareListModelAttribute

protected void assertCompareListModelAttribute(ModelAndView mav,
                                               Object modelName,
                                               List expectedList)
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

assertModelAttributeAvailable

protected void assertModelAttributeAvailable(ModelAndView mav,
                                             Object modelName)
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)

assertModelAttributeValue

protected void assertModelAttributeValue(ModelAndView mav,
                                         Object modelName,
                                         Object expectedValue)
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

assertModelAttributeValues

protected void assertModelAttributeValues(ModelAndView mav,
                                          Map expectedModel)
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

assertSortAndCompareListModelAttribute

protected 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).

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.

assertViewName

protected void assertViewName(ModelAndView mav,
                              String expectedName)
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


Copyright © 2002-2008 The Spring Framework.