Support loading WebApplicationContexts in the TCF #160
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to this commit, the Spring TestContext Framework only supported
loading an ApplicationContext in integration tests from either XML or
Java Properties files (since Spring 2.5), and Spring 3.1 introduced
support for loading an ApplicationContext in integration tests from
annotated classes (e.g., @configuration classes). All of the
ContextLoader implementations used to provide this support load a
GenericApplicationContext. However, a GenericApplicationContext is not
suitable for testing a web application since a web application relies on
an implementation of WebApplicationContext (WAC).
This commit makes it possible to integration test Spring-powered web
applications by adding the following functionality to the Spring
TestContext Framework.
subclasses:
AbstractGenericContextLoader into AbstractContextLoader to allow it
to be shared across web and non-web context loaders.
AnnotationConfigContextLoader accordingly. These utils are also used
by AnnotationConfigWebContextLoader.
ApplicationContext loaded for a test should be a WAC and to configure
the base resource path for the root directory of a web application.
MergedContextConfiguration with support for a baseResourcePath for
the root directory of a web application.
WebMergedContextConfiguration instead of a standard
MergedContextConfiguration if @WebAppConfiguration is present on the
test class.
AbstractGenericWebContextLoader that is responsible for creating a
MockServletContext with a proper ResourceLoader for the
resourceBasePath configured in the WebMergedContextConfiguration. The
resulting mock ServletContext is set in the WAC, and the WAC is
stored as the Root WAC in the ServletContext.
local state via RequestContextHolder before each test method by using
the MockServletContext already present in the WAC and by creating a
MockHttpServletRequest, MockHttpServletResponse, and
ServletWebRequest that is set in the RequestContextHolder. WTEL also
ensures that the MockHttpServletResponse and ServletWebRequest can be
injected into the test instance (e.g., via @Autowired) and cleans up
thread locals after each test method.
TestExecutionListener before DependencyInjectionTestExecutionListener
DelegatingSmartContextLoader and introduced a new
WebDelegatingSmartContextLoader.
class name based on the presence of @WebAppConfiguration on the test
class.
ContextLoader to load a WebApplicationContext. Instead, they now
rely on new core functionality provided in this commit.
Issue: SPR-5243