Skip to content

Commit 3589ed6

Browse files
committed
test: type integration spec field as ConfigurableApplicationContext
Per Copilot PR #1215 review feedback (comments 3142335908 and 3142335915): - `ApplicationContext.getBeanFactory()` is not part of the `ApplicationContext` API; the previous code relied on Groovy dynamic dispatch / a specific context implementation. - Switch the autowired field type to `ConfigurableApplicationContext` and call `getBeanDefinition(...)` / `containsBeanDefinition(...)` on the returned `ConfigurableListableBeanFactory`. This makes the required Spring API explicit at the source level. Verified locally: `./gradlew :core-examples-integration-test-app:compileIntegrationTestGroovy` BUILD SUCCESSFUL. Assisted-by: claude-code:claude-4.6-opus
1 parent 1282c5c commit 3589ed6

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

plugin-core/examples/integration-test-app/src/integration-test/groovy/grails/plugin/springsecurity/SecurityAutoConfigurationExcluderIntegrationSpec.groovy

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ package grails.plugin.springsecurity
2121
import spock.lang.Specification
2222

2323
import org.springframework.beans.factory.annotation.Autowired
24-
import org.springframework.context.ApplicationContext
24+
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory
25+
import org.springframework.context.ConfigurableApplicationContext
2526
import org.springframework.security.core.userdetails.UserDetailsService
2627
import org.springframework.security.web.SecurityFilterChain
2728

@@ -31,7 +32,7 @@ import grails.testing.mixin.integration.Integration
3132
class SecurityAutoConfigurationExcluderIntegrationSpec extends Specification {
3233

3334
@Autowired
34-
ApplicationContext applicationContext
35+
ConfigurableApplicationContext applicationContext
3536

3637
void "SecurityAutoConfigurationExcluder class is on the classpath"() {
3738
expect:
@@ -41,33 +42,37 @@ class SecurityAutoConfigurationExcluderIntegrationSpec extends Specification {
4142
}
4243

4344
void "no Spring Boot SecurityFilterChain bean is registered alongside the plugin"() {
44-
given: 'all SecurityFilterChain beans visible to the application context'
45+
given: 'the application context bean factory'
46+
ConfigurableListableBeanFactory beanFactory = applicationContext.beanFactory
47+
48+
and: 'all SecurityFilterChain beans visible to the application context'
4549
def filterChainBeans = applicationContext.getBeanNamesForType(SecurityFilterChain)
4650

4751
expect: 'none come from Spring Boot security auto-configurations'
4852
filterChainBeans.every { name ->
49-
def def_ = applicationContext.getBeanFactory().getBeanDefinition(name)
50-
!def_.beanClassName?.startsWith('org.springframework.boot.security.')
53+
!beanFactory.getBeanDefinition(name).beanClassName?.startsWith('org.springframework.boot.security.')
5154
}
5255

5356
and: 'none of the excluded auto-configuration class names are registered as beans'
5457
SecurityAutoConfigurationExcluder.excludedAutoConfigurations.each { className ->
55-
assert !applicationContext.containsBeanDefinition(className) :
58+
assert !beanFactory.containsBeanDefinition(className) :
5659
"Spring Boot auto-configuration ${className} should be excluded by SecurityAutoConfigurationExcluder"
5760
}
5861
}
5962

6063
void "no Spring Boot in-memory UserDetailsService is registered alongside the plugin"() {
61-
given: 'all UserDetailsService beans visible to the application context'
64+
given: 'the application context bean factory'
65+
ConfigurableListableBeanFactory beanFactory = applicationContext.beanFactory
66+
67+
and: 'all UserDetailsService beans visible to the application context'
6268
def udsBeans = applicationContext.getBeanNamesForType(UserDetailsService)
6369

6470
expect: 'at least one (the plugin one) exists'
6571
udsBeans.length >= 1
6672

6773
and: 'none come from Spring Boot security auto-configurations'
6874
udsBeans.every { name ->
69-
def def_ = applicationContext.getBeanFactory().getBeanDefinition(name)
70-
!def_.beanClassName?.startsWith('org.springframework.boot.security.')
75+
!beanFactory.getBeanDefinition(name).beanClassName?.startsWith('org.springframework.boot.security.')
7176
}
7277

7378
and: "Boot's in-memory UserDetailsService is not present"

0 commit comments

Comments
 (0)