Skip to content

Commit

Permalink
Update AbstractGrailsTagTests
Browse files Browse the repository at this point in the history
Make the initialization process of ApplicationContext correct
  • Loading branch information
rainboyan committed May 18, 2023
1 parent 7828140 commit 4fb6bf5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
11 changes: 9 additions & 2 deletions grails-plugin-gsp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ task isolatedTestsTwo(type:Test) {
]
}

task isolatedTestsThree(type:Test) {
includes = [
"**/PageRendererSpec.class"
]
}

test {
dependsOn isolatedTestsOne, isolatedTestsTwo
dependsOn isolatedTestsOne, isolatedTestsTwo, isolatedTestsThree
excludes = [
"**/FormTagLibResourceTests.class",
"**/RestfulReverseUrlRenderingTests.class"
"**/RestfulReverseUrlRenderingTests.class",
"**/PageRendererSpec.class"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,15 @@ import org.grails.plugins.web.GroovyPagesAutoConfiguration
import org.grails.plugins.web.controllers.ControllersPluginConfiguration
import org.grails.plugins.web.mapping.UrlMappingsPluginConfiguration
import org.grails.plugins.web.mime.MimeTypesConfiguration
import org.grails.spring.DefaultRuntimeSpringConfiguration
import org.grails.taglib.GroovyPageAttributes
import org.grails.taglib.TagOutput
import org.grails.taglib.encoder.OutputContextLookupHelper
import org.grails.taglib.encoder.OutputEncodingStack
import org.grails.taglib.encoder.WithCodecHelper
import org.grails.web.context.ServletEnvironmentGrailsApplicationDiscoveryStrategy
import org.grails.web.mapping.DefaultLinkGenerator
import org.grails.web.pages.DefaultGroovyPagesUriService
import org.grails.web.pages.GSPResponseWriter
import org.grails.web.servlet.context.support.WebRuntimeSpringConfiguration
import org.grails.web.servlet.mvc.GrailsWebRequest
import org.grails.web.sitemesh.GSPSitemeshPage
import org.grails.web.sitemesh.GrailsHTMLPageParser
Expand Down Expand Up @@ -301,13 +300,8 @@ info.app.name: ${getClass().name}
ctx.beanFactory.registerSingleton("conversionService", new DefaultConversionService())
ctx.beanFactory.registerSingleton(GroovyPagesUriService.BEAN_ID, new DefaultGroovyPagesUriService())
ctx.register(DEFAULT_AUTO_CONFIGURATIONS)
ctx.refresh()
ctx.servletContext.setAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT, ctx)

grailsApplication.setApplicationContext(ctx)

messageSource = ctx.getBean("messageSource", MessageSource)

onInitMockBeans()

List<Class> dependantPluginClasses = []
Expand All @@ -327,21 +321,8 @@ info.app.name: ${getClass().name}
mockManager.registerProvidedArtefacts(grailsApplication)
mockManager.setApplicationContext(ctx)

def springConfig = new WebRuntimeSpringConfiguration(ctx)

webRequest = GrailsWebMockUtil.bindMockWebRequest(ctx)
onInit()
try {
JstlUtils.exposeLocalizationContext webRequest.getRequest(), null
}
catch (Throwable ignore) {
}

servletContext = webRequest.servletContext
Holders.servletContext = servletContext
Holders.addApplicationDiscoveryStrategy(new ServletEnvironmentGrailsApplicationDiscoveryStrategy(servletContext));
def springConfig = new DefaultRuntimeSpringConfiguration()

springConfig.servletContext = servletContext
springConfig.registerPostProcessor(new BeanFactoryPostProcessor() {

@Override
Expand All @@ -351,18 +332,24 @@ info.app.name: ${getClass().name}
}
})

dependentPlugins*.doWithRuntimeConfiguration(springConfig)

grailsApplication.mainContext = springConfig.getUnrefreshedApplicationContext()
appCtx = springConfig.getApplicationContext()
mockManager.doRuntimeConfiguration(springConfig)
springConfig.registerBeansWithRegistry(ctx)
ctx.refresh()

ctx.servletContext.setAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT, appCtx)
grailsApplication.setApplicationContext(ctx)
grailsApplication.mainContext = ctx
appCtx = ctx
messageSource = ctx.getBean("messageSource", MessageSource)

servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx)
mockManager.applicationContext = appCtx
webRequest = GrailsWebMockUtil.bindMockWebRequest(ctx)
onInit()
try {
JstlUtils.exposeLocalizationContext webRequest.getRequest(), null
}
catch (Throwable ignore) {
}

//GroovySystem.metaClassRegistry.removeMetaClass(String)
//GroovySystem.metaClassRegistry.removeMetaClass(Object)
servletContext = webRequest.servletContext

mockManager.doDynamicMethods()
initRequestAndResponse()
Expand Down

0 comments on commit 4fb6bf5

Please sign in to comment.