Closed
Description
Sam Brannen opened SPR-9863 and commented
Overview
This issue picks up where #9917 left off. Specifically this issue focuses on adding support for WebApplicationContext
hierarchies within single test classes as well as within test class hierarchies.
Consequently, this issue is heavily dependent on the completion of both #9917 and #10284.
Goals
- Ensure that common WAC hierarchies can be configured in integration tests (e.g., root and dispatcher WACs in a parent-child relationship).
Deliverables
- Ensure that hierarchies of WACs can be configured using
@ContextHierarchy
(see Provide support for context hierarchies in the TestContext Framework [SPR-5613] #10284) - Ensure that the type of the root WAC can differ from that of its parent (e.g., a standard
ApplicationContext
loaded for an EAR) - Set a loaded context as the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
in theMockServletContext
when context hierarchies are used:- if an
ApplicationContext
has no parent and the context is a WAC, set the context as the root WAC - if an
ApplicationContext
has a parent that is not a WAC and the context itself is a WAC, set the context as the root WAC
- if an
Pseudocode Examples
Root WAC & Dispatcher WAC
@WebAppConfiguration // path defaults to "file:src/main/webapp"
@ContextHierarchy({
@ContextConfiguration(name="root", classes = WebAppConfig.class),
@ContextConfiguration(name="dispatcher", locations="/spring/dispatcher-config.xml")
})
public class ControllerIntegrationTests {}
Class & Context Hierarchies
@WebAppConfiguration
@ContextConfiguration("file:src/main/webapp/WEB-INF/applicationContext.xml")
public abstract class AbstractWebTests {}
@ContextHierarchy(@ContextConfiguration("/spring/soap-ws-config.xml")
public class SoapWebServiceTests extends AbstractWebTests {}
@ContextHierarchy(@ContextConfiguration("/spring/rest-ws-config.xml")
public class RestWebServiceTests extends AbstractWebTests {}
Class & Context Hierarchies with Merged and Overridden Configuration
In ExtendedControllerIntegrationTests
the configuration for the root WAC will be overridden, and the configuration for the dispatcher WAC will be merged.
@WebAppConfiguration // defaults to "file:src/main/webapp"
@ContextHierarchy({
@ContextConfiguration(name="root", classes = WebAppConfig.class),
@ContextConfiguration(name="dispatcher", locations="/spring/user-config.xml")
})
public class ControllerIntegrationTests {}
@ContextHierarchy({
@ContextConfiguration(name="root", locations="/spring/root2.xml", inheritLocations=false),
@ContextConfiguration(name="dispatcher", locations="/spring/orders-config.xml"),
})
public class ExtendedControllerIntegrationTests extends ControllerIntegrationTests {}
Affects: 2.5 final
Issue Links:
- Support loading WebApplicationContexts with the TestContext Framework [SPR-5243] #9917 Support loading WebApplicationContexts with the TestContext Framework ("depends on")
- Provide support for context hierarchies in the TestContext Framework [SPR-5613] #10284 Provide support for context hierarchies in the TestContext Framework ("depends on")
- Document context hierarchy support in the TestContext framework [SPR-10357] #14989 Document context hierarchy support in the TestContext framework ("is depended on by")
- Load dedicated child ApplicationContext for test instance in the TestContext framework [SPR-4632] #9309 Load dedicated child ApplicationContext for test instance in the TestContext framework
Referenced from: commits 98074e7
3 votes, 7 watchers