Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Wrong test context can be inferred in a native mage leading to a ClassCastException #1353

Closed
sdeleuze opened this issue Dec 6, 2021 · 0 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@sdeleuze
Copy link
Contributor

sdeleuze commented Dec 6, 2021

When executing ./build.sh -t on the petclinic-jdbc sample, we got this error.

Failures (1):
  JUnit Jupiter:PetclinicIntegrationTests:testFindAll()
    MethodSource [className = 'org.springframework.samples.petclinic.PetclinicIntegrationTests', methodName = 'testFindAll', methodParameterTypes = '']
    => java.lang.IllegalStateException: Failed to load ApplicationContext
       org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
       org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124)
       org.springframework.aot.test.AotDependencyInjectionTestExecutionListener.injectDependenciesInAotMode(AotDependencyInjectionTestExecutionListener.java:84)
       org.springframework.aot.test.AotDependencyInjectionTestExecutionListener.prepareTestInstance(AotDependencyInjectionTestExecutionListener.java:58)
       org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:248)
       [...]
     Caused by: java.lang.ClassCastException: org.springframework.boot.test.context.ReactiveWebMergedContextConfiguration cannot be cast to org.springframework.test.context.web.WebMergedContextConfiguration
       org.springframework.aot.test.boot.AotSpringBootConfigContextLoader$WebConfigurer.configure(AotSpringBootConfigContextLoader.java:135)
       org.springframework.aot.test.boot.AotSpringBootConfigContextLoader.loadContext(AotSpringBootConfigContextLoader.java:103)
       org.springframework.aot.test.boot.AotSpringBootConfigContextLoader.loadContext(AotSpringBootConfigContextLoader.java:50)
       org.springframework.aot.test.AotCacheAwareContextLoaderDelegate.loadContextInternal(AotCacheAwareContextLoaderDelegate.java:54)
       org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
       [...]

I am wondering if here we are sure to always have a WebMergedContextConfiguration and never a ReactiveWebMergedContextConfiguration given the fact that ReactiveWebMergedContextConfiguration does not inherit from WebMergedContextConfiguration (could be given the name).

I don't understand yet why this happen in native and likely not in JVM + AOT mode (worth to double check by debugging potentially). The only reason I can think about would be that we miss some reflection config that impact classpath detection on native, leading to providing a ReactiveWebMergedContextConfiguration instead of a WebMergedContextConfiguration like on the JVM.

@sdeleuze sdeleuze added the type: bug A general bug label Dec 6, 2021
@sdeleuze sdeleuze added this to the 0.11.0 milestone Dec 6, 2021
@sdeleuze sdeleuze assigned snicoll and sdeleuze and unassigned snicoll Dec 6, 2021
@snicoll snicoll changed the title Fix petclinic-jdbc sample tests Wrong test context can be inferred in a native mage leading to a ClassCastException Dec 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A general bug
Development

No branches or pull requests

2 participants