Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure messageSource type is StaticMessageSource for tests #431

Closed
wants to merge 1 commit into from

Conversation

jamesfredley
Copy link
Contributor

StaticMessageSource incudes addMessage() methods, required by tests

after removing micronaut, the messageSource type was PluginAwareResourceBundleMessageSource instead of StaticMessageSource when the tests execute

org.grails.plugins.i18n.I18nGrailsPlugin doWithSpring() sets messageSource to type PluginAwareResourceBundleMessageSource

org.grails.testing.GrailsApplicationBuilder.build() sets messageSource to type StaticMessageSource in doWithSpringClosure{} which calls registerBeans()

On grails/grails-core#13702

This fixes 22 tests that require StaticMessageSource

It also fixes 6 tests in DataBindingConfigurationSpec with ValueConverters using @Order

…udes addMessage() methods

after removing micronaut, the messageSource type was PluginAwareResourceBundleMessageSource instead of StaticMessageSource when the tests execute

org.grails.plugins.i18n.I18nGrailsPlugin doWithSpring() sets messageSource to type PluginAwareResourceBundleMessageSource

org.grails.testing.GrailsApplicationBuilder.build() sets messageSource to type StaticMessageSource in doWithSpringClosure which calls registerBeans()
@jamesfredley
Copy link
Contributor Author

So far my guess is order of execution with org.grails.plugins.i18n.I18nGrailsPlugin doWithSpring() running earlier before Micronaut removal and later after Micronaut removal.

I experimented with setting it to StaticMessageSource in few locations and if it is set too early it gets overridden by org.grails.plugins.i18n.I18nGrailsPlugin doWithSpring() setting it to type PluginAwareResourceBundleMessageSource. The location in this PR is later in the process and after org.grails.plugins.i18n.I18nGrailsPlugin doWithSpring() runs.

@jamesfredley jamesfredley mentioned this pull request Sep 29, 2024
@codeconsole
Copy link
Contributor

codeconsole commented Sep 29, 2024

@codeconsole
Copy link
Contributor

codeconsole commented Sep 29, 2024

Disabling the i18n plugin results in no messageSource being registered.

@jamesfredley I think the real issue here is the TestRuntimeGrailsApplicationPostProcessor (grailsApplicationPostProcessor) never executes and registers the StaticMessageSource

protected void registerGrailsAppPostProcessorBean(ConfigurableBeanFactory beanFactory) {
GrailsApplication grailsApp
Closure doWithSpringClosure = {
registerBeans(grailsApp)
executeDoWithSpringCallback(grailsApp)
}
Closure customizeGrailsApplicationClosure = { GrailsApplication grailsApplication ->
grailsApp = grailsApplication
if (doWithConfig) {
doWithConfig.call(grailsApplication.config)
// reset flatConfig
grailsApplication.configChanged()
}
Holders.config = grailsApplication.config
}
def constructorArgumentValues = new ConstructorArgumentValues()
constructorArgumentValues.addIndexedArgumentValue(0, doWithSpringClosure)
constructorArgumentValues.addIndexedArgumentValue(1, includePlugins ?: DEFAULT_INCLUDED_PLUGINS)
def values = new MutablePropertyValues()
values.add('localOverride', localOverride)
values.add('loadExternalBeans', loadExternalBeans)
values.add('customizeGrailsApplicationClosure', customizeGrailsApplicationClosure)
def beanDef = new RootBeanDefinition(TestRuntimeGrailsApplicationPostProcessor, constructorArgumentValues, values)
beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE)
(beanFactory as BeanDefinitionRegistry).registerBeanDefinition('grailsApplicationPostProcessor', beanDef)
}

@jamesfredley
Copy link
Contributor Author

@codeconsole You are correct that org.grails.testing.GrailsApplicationBuilder.registerGrailsAppPostProcessorBean() runs but the constructor on TestRuntimeGrailsApplicationPostProcessor is not being called later.

@codeconsole
Copy link
Contributor

#435

@jamesfredley jamesfredley deleted the fix-message-source-for-tests branch September 29, 2024 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants