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

Commit 34329be

Browse files
committed
Extract Framework and Security test hints from SpringBootTestHints
Over time SpringBootTestHints has grown to configure more than it should. This commit extracts SpringTestHints and SpringSecurityTestHints from the existing SpringBootTestHints and collapses the existing SqlScriptsTestExecutionListenerHints into SpringTestHints. This commit also adds missing entries for spring-test annotations and corresponding JDK proxy configuration for synthesized annotations where appropriate. Closes gh-1249 Results of building all key sample applications: GraalVM: GraalVM 21.3.0 Java 11 CE (Java Version 11.0.13+7-jvmci-21.3-b05) Date Sample Build Time (s) Build Mem (GB) RSS Mem (M) Image Size (M) Startup Time (s) JVM Uptime (s) ReflectConfig (lines) 20211110-1919 commandlinerunner 41.3 5.02 21.3 23.4 0.017 0.023 583 20211110-1921 webflux-netty 92.1 6.52 42.9 56.9 0.042 0.044 2141 20211110-1923 webmvc-tomcat 89.9 5.04 47.5 53.6 0.054 0.057 2194 20211110-1925 webflux-thymeleaf 99.9 6.67 51.1 60.9 0.055 0.057 2456 20211110-1926 grpc 47.0 5.40 26.5 26.1 362 20211110-1929 jdbc-tx 100.5 7.09 61.6 64.6 0.069 0.07 2713 20211110-1930 class-proxies-aop 90.2 6.35 64.6 62.3 0.089 0.092 2336 20211110-1932 batch 82.3 6.36 62.5 52.0 0.058 0.06 1581
1 parent 683e315 commit 34329be

File tree

5 files changed

+173
-68
lines changed

5 files changed

+173
-68
lines changed

spring-native-configuration/src/main/java/org/springframework/boot/test/SpringBootTestHints.java

+32-54
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22-
import org.springframework.boot.SpringBootConfiguration;
23-
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
24-
import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration;
25-
import org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters;
26-
import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration;
27-
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
28-
import org.springframework.boot.test.context.SpringBootTest;
2922
import org.springframework.nativex.hint.AccessBits;
30-
import org.springframework.nativex.hint.FieldHint;
3123
import org.springframework.nativex.hint.JdkProxyHint;
3224
import org.springframework.nativex.hint.NativeHint;
3325
import org.springframework.nativex.hint.TypeHint;
@@ -36,60 +28,46 @@
3628
import org.springframework.nativex.type.NativeConfiguration;
3729
import org.springframework.nativex.type.Type;
3830
import org.springframework.nativex.type.TypeSystem;
39-
import org.springframework.security.test.context.support.WithSecurityContext;
40-
import org.springframework.security.web.FilterChainProxy;
41-
import org.springframework.security.web.context.SecurityContextPersistenceFilter;
42-
import org.springframework.test.context.ActiveProfiles;
43-
import org.springframework.test.context.TestPropertySource;
4431

45-
@NativeHint(trigger = org.junit.jupiter.api.Test.class, types = {
46-
@TypeHint(types = {
47-
SpringBootTest.WebEnvironment.class,
48-
org.springframework.test.context.junit.jupiter.SpringExtension.class,
49-
org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.class,
50-
org.springframework.test.context.support.DefaultBootstrapContext.class,
51-
org.springframework.boot.test.context.SpringBootTestContextBootstrapper.class,
52-
org.springframework.boot.test.context.SpringBootContextLoader.class,
53-
org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.class,
54-
org.springframework.boot.test.mock.mockito.MockitoPostProcessor.class,
55-
ImportAutoConfiguration.class,
56-
OverrideAutoConfiguration.class,
57-
TypeExcludeFilters.class,
58-
org.springframework.aot.test.AotCacheAwareContextLoaderDelegate.class
32+
/**
33+
* Native hints for Spring Boot's testing support.
34+
*
35+
* @see org.springframework.test.SpringTestHints
36+
*/
37+
@NativeHint(trigger = org.junit.jupiter.api.Test.class,
38+
types = {
39+
@TypeHint(types = {
40+
org.springframework.aot.test.AotCacheAwareContextLoaderDelegate.class,
41+
org.springframework.boot.autoconfigure.ImportAutoConfiguration.class,
42+
org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration.class,
43+
org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.class,
44+
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters.class,
45+
org.springframework.boot.test.context.SpringBootContextLoader.class,
46+
org.springframework.boot.test.context.SpringBootTest.WebEnvironment.class,
47+
org.springframework.boot.test.context.SpringBootTestContextBootstrapper.class,
48+
org.springframework.boot.test.mock.mockito.MockitoPostProcessor.class
5949
}, typeNames = {
60-
"org.springframework.boot.autoconfigure.test.ImportAutoConfiguration",
61-
"org.springframework.boot.test.mock.mockito.MockitoPostProcessor$SpyPostProcessor",
62-
"org.springframework.boot.test.context.ImportsContextCustomizer$ImportsCleanupPostProcessor"
50+
"org.springframework.boot.autoconfigure.test.ImportAutoConfiguration",
51+
"org.springframework.boot.test.mock.mockito.MockitoPostProcessor$SpyPostProcessor",
52+
"org.springframework.boot.test.context.ImportsContextCustomizer$ImportsCleanupPostProcessor"
6353
}),
6454
@TypeHint(types = {
65-
org.springframework.boot.test.context.SpringBootTest.class,
66-
ActiveProfiles.class,
67-
org.springframework.test.context.web.WebAppConfiguration.class,
68-
org.springframework.test.context.BootstrapWith.class,
69-
AutoConfigureMockMvc.class,
70-
SpringBootConfiguration.class,
71-
TestPropertySource.class
55+
org.springframework.boot.SpringBootConfiguration.class,
56+
org.springframework.boot.test.context.SpringBootTest.class,
57+
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc.class,
7258
}, access = AccessBits.ANNOTATION)
73-
}, jdkProxies = {
74-
@JdkProxyHint(types = { org.springframework.test.context.BootstrapWith.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
75-
@JdkProxyHint(types = { org.springframework.boot.test.context.SpringBootTest.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
59+
},
60+
jdkProxies = {
7661
@JdkProxyHint(types = { org.springframework.context.annotation.Import.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
62+
@JdkProxyHint(types = { org.springframework.boot.test.context.SpringBootTest.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
7763
@JdkProxyHint(types = { org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
7864
@JdkProxyHint(types = { org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
79-
@JdkProxyHint(typeNames = { "org.springframework.context.annotation.ComponentScan$Filter", "org.springframework.core.annotation.SynthesizedAnnotation" })
80-
})
81-
@NativeHint(trigger = TestDatabaseAutoConfiguration.class, types = @TypeHint(typeNames = "org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration$EmbeddedDataSourceFactoryBean"))
82-
// TODO Move to Spring Security (test) hint
83-
@NativeHint(trigger = WithSecurityContext.class, types = {
84-
@TypeHint(types = {
85-
SecurityContextPersistenceFilter.class
86-
}, access = AccessBits.FULL_REFLECTION),
87-
@TypeHint(types = org.springframework.security.web.csrf.CsrfFilter.class, access = AccessBits.FULL_REFLECTION, fields = @FieldHint(name = "tokenRepository", allowWrite = true)),
88-
@TypeHint(types = FilterChainProxy.class, access = AccessBits.LOAD_AND_CONSTRUCT | AccessBits.DECLARED_METHODS),
89-
@TypeHint(types = WithSecurityContext.class, access = AccessBits.CLASS | AccessBits.DECLARED_METHODS),
90-
@TypeHint(typeNames = "org.springframework.security.test.context.support.WithMockUserSecurityContextFactory")
91-
}, jdkProxies = {@JdkProxyHint(types = { WithSecurityContext.class, org.springframework.core.annotation.SynthesizedAnnotation.class })
92-
})
65+
}
66+
)
67+
68+
@NativeHint(trigger = org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration.class,
69+
types = @TypeHint(typeNames = "org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration$EmbeddedDataSourceFactoryBean"))
70+
9371
public class SpringBootTestHints implements NativeConfiguration {
9472

9573
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2019-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.test;
18+
19+
import org.springframework.nativex.hint.AccessBits;
20+
import org.springframework.nativex.hint.FieldHint;
21+
import org.springframework.nativex.hint.JdkProxyHint;
22+
import org.springframework.nativex.hint.NativeHint;
23+
import org.springframework.nativex.hint.TypeHint;
24+
import org.springframework.nativex.type.NativeConfiguration;
25+
26+
/**
27+
* Native hints for Spring Security's testing support.
28+
*
29+
* @see org.springframework.test.SpringTestHints
30+
* @see org.springframework.boot.test.SpringBootTestHints
31+
*/
32+
@NativeHint(trigger = org.springframework.security.test.context.support.WithSecurityContext.class,
33+
types = {
34+
@TypeHint(types = org.springframework.security.web.FilterChainProxy.class, access = AccessBits.LOAD_AND_CONSTRUCT | AccessBits.DECLARED_METHODS),
35+
@TypeHint(types = org.springframework.security.web.context.SecurityContextPersistenceFilter.class, access = AccessBits.FULL_REFLECTION),
36+
@TypeHint(types = org.springframework.security.web.csrf.CsrfFilter.class, access = AccessBits.FULL_REFLECTION, fields = @FieldHint(name = "tokenRepository", allowWrite = true)),
37+
@TypeHint(types = org.springframework.security.test.context.support.WithSecurityContext.class, access = AccessBits.ANNOTATION),
38+
@TypeHint(typeNames = "org.springframework.security.test.context.support.WithMockUserSecurityContextFactory")
39+
},
40+
jdkProxies = {
41+
@JdkProxyHint(types = { org.springframework.security.test.context.support.WithSecurityContext.class, org.springframework.core.annotation.SynthesizedAnnotation.class })
42+
}
43+
)
44+
public class SpringSecurityTestHints implements NativeConfiguration {
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright 2019-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.test;
18+
19+
import org.springframework.nativex.hint.AccessBits;
20+
import org.springframework.nativex.hint.JdkProxyHint;
21+
import org.springframework.nativex.hint.NativeHint;
22+
import org.springframework.nativex.hint.TypeHint;
23+
import org.springframework.nativex.type.NativeConfiguration;
24+
25+
/**
26+
* Native hints for Spring Framework's testing support.
27+
*
28+
* @author Sam Brannen
29+
* @see org.springframework.boot.test.SpringBootTestHints
30+
*/
31+
@NativeHint(trigger = org.junit.jupiter.api.Test.class,
32+
types = {
33+
@TypeHint(types = {
34+
org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.class,
35+
org.springframework.test.context.junit.jupiter.SpringExtension.class,
36+
org.springframework.test.context.support.DefaultBootstrapContext.class,
37+
org.springframework.test.context.support.DefaultTestContextBootstrapper.class,
38+
org.springframework.test.context.web.WebTestContextBootstrapper.class
39+
}),
40+
@TypeHint(types = {
41+
org.springframework.test.context.ActiveProfiles.class,
42+
org.springframework.test.context.BootstrapWith.class,
43+
org.springframework.test.context.ContextConfiguration.class,
44+
org.springframework.test.context.ContextHierarchy.class,
45+
org.springframework.test.context.DynamicPropertySource.class,
46+
org.springframework.test.context.NestedTestConfiguration.class,
47+
org.springframework.test.context.TestConstructor.class,
48+
org.springframework.test.context.TestExecutionListeners.class,
49+
org.springframework.test.context.TestPropertySource.class,
50+
org.springframework.test.context.event.RecordApplicationEvents.class,
51+
org.springframework.test.context.junit.jupiter.EnabledIf.class,
52+
org.springframework.test.context.junit.jupiter.DisabledIf.class,
53+
org.springframework.test.context.junit.jupiter.SpringJUnitConfig.class,
54+
org.springframework.test.context.transaction.AfterTransaction.class,
55+
org.springframework.test.context.transaction.BeforeTransaction.class,
56+
org.springframework.test.context.web.WebAppConfiguration.class
57+
}, access = AccessBits.ANNOTATION)
58+
},
59+
jdkProxies = {
60+
@JdkProxyHint(types = { org.springframework.test.context.ActiveProfiles.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
61+
@JdkProxyHint(types = { org.springframework.test.context.BootstrapWith.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
62+
@JdkProxyHint(types = { org.springframework.test.context.ContextConfiguration.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
63+
@JdkProxyHint(types = { org.springframework.test.context.ContextHierarchy.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
64+
@JdkProxyHint(types = { org.springframework.test.context.NestedTestConfiguration.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
65+
@JdkProxyHint(types = { org.springframework.test.context.TestConstructor.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
66+
@JdkProxyHint(types = { org.springframework.test.context.TestExecutionListeners.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
67+
@JdkProxyHint(types = { org.springframework.test.context.TestPropertySource.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
68+
@JdkProxyHint(types = { org.springframework.test.context.event.RecordApplicationEvents.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
69+
@JdkProxyHint(types = { org.springframework.test.context.junit.jupiter.EnabledIf.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
70+
@JdkProxyHint(types = { org.springframework.test.context.junit.jupiter.DisabledIf.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
71+
@JdkProxyHint(types = { org.springframework.test.context.web.WebAppConfiguration.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
72+
// TODO Determine if we still need to add a JDK proxy hint for @ComponentScan.Fiter when testing with AOT support.
73+
@JdkProxyHint(typeNames = { "org.springframework.context.annotation.ComponentScan$Filter", "org.springframework.core.annotation.SynthesizedAnnotation" })
74+
}
75+
)
76+
77+
@NativeHint(trigger = org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener.class,
78+
types = {
79+
@TypeHint(types = {
80+
org.springframework.test.context.jdbc.Sql.class,
81+
org.springframework.test.context.jdbc.SqlConfig.class,
82+
org.springframework.test.context.jdbc.SqlGroup.class,
83+
org.springframework.test.context.jdbc.SqlMergeMode.class
84+
}, access = AccessBits.ANNOTATION)
85+
},
86+
jdkProxies = {
87+
@JdkProxyHint(types = { org.springframework.test.context.jdbc.Sql.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
88+
@JdkProxyHint(types = { org.springframework.test.context.jdbc.SqlConfig.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
89+
@JdkProxyHint(types = { org.springframework.test.context.jdbc.SqlGroup.class, org.springframework.core.annotation.SynthesizedAnnotation.class }),
90+
@JdkProxyHint(types = { org.springframework.test.context.jdbc.SqlMergeMode.class, org.springframework.core.annotation.SynthesizedAnnotation.class })
91+
}
92+
)
93+
public class SpringTestHints implements NativeConfiguration {
94+
}

spring-native-configuration/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListenerHints.java

-13
This file was deleted.

spring-native-configuration/src/main/resources/META-INF/services/org.springframework.nativex.type.NativeConfiguration

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ org.springframework.security.config.annotation.method.configuration.GlobalMethod
112112
org.springframework.security.config.annotation.web.configuration.WebMvcSecurityHints
113113
org.springframework.security.ldap.LdapSecurityHints
114114
org.springframework.security.thymeleaf.ThymeleafSpringSecurity5Hints
115+
org.springframework.security.test.SpringSecurityTestHints
115116
org.springframework.session.servlet.HttpSessionHints
116117
org.springframework.session.server.WebSessionHints
117118
org.springframework.stereotype.ComponentHints
118-
org.springframework.test.context.jdbc.SqlScriptsTestExecutionListenerHints
119+
org.springframework.test.SpringTestHints
119120
org.springframework.test.web.reactive.server.DefaultWebTestClientBuilderHints
120121
org.springframework.transaction.annotation.TransactionManagementHints
121122
org.springframework.web.bind.annotation.WebAnnotationHints

0 commit comments

Comments
 (0)