public class BroadleafGenericGroovyXmlWebContextLoader
extends org.springframework.test.context.support.AbstractContextLoader
This class was created due to AbstractGenericWebContextLoader utilizing the qualifier "final" for its loadContext(MergedContextConfiguration) method which we needed to override and provide our Broadleaf created MergeXmlWebApplicationContext object in place of the GenericWebApplicationContext it used. Since we are using Groovy/Spock, the other methods included are to support Groovy test classes. As such, are included some methods from the GenericGroovyXmlWebContextLoader and GenericXmlWebContextLoader classes, refactored to compensate for the levels of inheritance between them.
This class loader should be used with the @ContextConfiguration annotation to be placed in the 'loader' parameter for all Broadleaf integration tests which use the Spock testing framework.
| Constructor and Description |
|---|
BroadleafGenericGroovyXmlWebContextLoader() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
configureWebResources(org.broadleafcommerce.common.web.extensibility.MergeXmlWebApplicationContext context,
org.springframework.test.context.web.WebMergedContextConfiguration webMergedConfig)
Configures web resources for the supplied web application context (WAC).
|
protected String |
getResourceSuffix()
BroadleafGenericGroovyXmlWebContextLoader supports the XML merging that
Broadleaf's framework features, but this is handled during the .refresh() method
in the loadContext method so this method was only pulled from the original class
GenericGroovyXmlWebContextLoader in case of the Spring-Test framework requiring
this method to have a particular behavior. |
protected String[] |
getResourceSuffixes()
BroadleafGenericGroovyXmlWebContextLoader supports the XML merging that
Broadleaf's framework features, but this is handled during the .refresh() method
in the loadContext method so this method was only pulled from the original class
GenericGroovyXmlWebContextLoader in case of the Spring-Test framework requiring
this method to have a particular behavior. |
org.springframework.context.ConfigurableApplicationContext |
loadContext(org.springframework.test.context.MergedContextConfiguration mergedConfig)
Load a
MergeXmlWebApplicationContext from the supplied MergedContextConfiguration |
org.springframework.context.ApplicationContext |
loadContext(String... locations)
BroadleafGenericGroovyXmlWebContextLoader should be used as a
SmartContextLoader,
not as a legacy ContextLoader. |
protected void |
validateMergedContextConfiguration(org.springframework.test.context.web.WebMergedContextConfiguration webMergedConfig)
BroadleafGenericGroovyXmlWebContextLoader supports the XML merging that
Broadleaf's framework features, but this is handled during the .refresh() method
in the loadContext method so this method was only pulled from the original class
GenericXmlWebContextLoader in case of the Spring-Test framework requiring
this method to have a particular behavior. |
public BroadleafGenericGroovyXmlWebContextLoader()
protected String[] getResourceSuffixes()
BroadleafGenericGroovyXmlWebContextLoader supports the XML merging that
Broadleaf's framework features, but this is handled during the .refresh() method
in the loadContext method so this method was only pulled from the original class
GenericGroovyXmlWebContextLoader in case of the Spring-Test framework requiring
this method to have a particular behavior.getResourceSuffixes in class org.springframework.test.context.support.AbstractContextLoaderprotected String getResourceSuffix()
BroadleafGenericGroovyXmlWebContextLoader supports the XML merging that
Broadleaf's framework features, but this is handled during the .refresh() method
in the loadContext method so this method was only pulled from the original class
GenericGroovyXmlWebContextLoader in case of the Spring-Test framework requiring
this method to have a particular behavior.getResourceSuffix in class org.springframework.test.context.support.AbstractContextLoaderprotected void validateMergedContextConfiguration(org.springframework.test.context.web.WebMergedContextConfiguration webMergedConfig)
BroadleafGenericGroovyXmlWebContextLoader supports the XML merging that
Broadleaf's framework features, but this is handled during the .refresh() method
in the loadContext method so this method was only pulled from the original class
GenericXmlWebContextLoader in case of the Spring-Test framework requiring
this method to have a particular behavior.AbstractGenericWebContextLoader.validateMergedContextConfiguration(org.springframework.test.context.web.WebMergedContextConfiguration)public final org.springframework.context.ApplicationContext loadContext(String... locations) throws Exception
BroadleafGenericGroovyXmlWebContextLoader should be used as a
SmartContextLoader,
not as a legacy ContextLoader.
Consequently, this method is not supported.
This method was pulled from AbstractGenericWebContextLoader.UnsupportedOperationExceptionExceptionContextLoader.loadContext(java.lang.String[])public org.springframework.context.ConfigurableApplicationContext loadContext(org.springframework.test.context.MergedContextConfiguration mergedConfig)
throws Exception
MergeXmlWebApplicationContext from the supplied MergedContextConfiguration
Implementation details:
validateMergedContextConfiguration(WebMergedContextConfiguration)
to allow subclasses to validate the supplied configuration before proceeding.MergeXmlWebApplicationContext instance.MergeXmlWebApplicationContext references a
parent configuration,
the corresponding ApplicationContext will be retrieved and
set as the parent
for the context created by this method.MergeXmlWebApplicationContext.setPatchLocation(String)MergeXmlWebApplicationContext#setStandardLocationTypes(String)
to the StandardConfigLocations.TESTCONTEXTTYPE for integration tests.configureWebResources(org.broadleafcommerce.common.web.extensibility.MergeXmlWebApplicationContext, org.springframework.test.context.web.WebMergedContextConfiguration) to create the MockServletContext and
set it in the MergeXmlWebApplicationContext.AbstractContextLoader.prepareContext(org.springframework.context.ConfigurableApplicationContext, org.springframework.test.context.MergedContextConfiguration) to allow for customizing the context before bean
definitions are loaded.Refreshes the context and registers
a JVM shutdown hook for it.AbstractGenericWebContextLoader.loadContext(MergedContextConfiguration)ExceptionSmartContextLoader.loadContext(MergedContextConfiguration),
MergeXmlWebApplicationContextprotected void configureWebResources(org.broadleafcommerce.common.web.extensibility.MergeXmlWebApplicationContext context,
org.springframework.test.context.web.WebMergedContextConfiguration webMergedConfig)
If the supplied WAC has no parent or its parent is not a WAC, the supplied WAC will be configured as the Root WAC (see "Root WAC Configuration" below).
Otherwise the context hierarchy of the supplied WAC will be traversed
to find the top-most WAC (i.e., the root); and the ServletContext
of the Root WAC will be set as the ServletContext for the supplied
WAC.
WebMergedContextConfiguration.ResourceLoader is instantiated for the MockServletContext:
if the resource base path is prefixed with "classpath:/", a
DefaultResourceLoader will be used; otherwise, a
FileSystemResourceLoader will be used.MockServletContext will be created using the resource base
path and resource loader.MergeXmlWebApplicationContext is then stored in
the MockServletContext under the
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE key.MockServletContext is set in the
MergeXmlWebApplicationContext.context - the merge xml web application context for which to configure the web
resourceswebMergedConfig - the merged context configuration to use to load the
merge xml web application contextCopyright © 2020. All rights reserved.