17
17
package org .springframework .boot .actuate .endpoint .annotation ;
18
18
19
19
import org .junit .jupiter .api .Test ;
20
+
20
21
import org .springframework .aot .context .bootstrap .generator .infrastructure .nativex .NativeConfigurationRegistry ;
21
- import org .springframework .aot .context .bootstrap .generator .infrastructure .nativex .NativeReflectionEntry ;
22
22
import org .springframework .beans .factory .support .BeanDefinitionBuilder ;
23
23
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
24
- import org .springframework .boot .actuate .health .Health ;
25
- import org .springframework .boot .actuate .health .HealthIndicator ;
24
+ import org .springframework .boot .actuate .health .HealthContributor ;
25
+ import org .springframework .boot .actuate .health .PingHealthIndicator ;
26
26
import org .springframework .nativex .hint .Flag ;
27
27
28
- import java .util .List ;
29
-
30
28
import static org .assertj .core .api .Assertions .assertThat ;
31
29
32
30
/**
@@ -40,14 +38,24 @@ class HealthContributorNativeConfigurationProcessorTests {
40
38
void registerHealthIndicator () {
41
39
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory ();
42
40
beanFactory .registerBeanDefinition ("noise" , BeanDefinitionBuilder .rootBeanDefinition (String .class ).getBeanDefinition ());
43
- beanFactory .registerBeanDefinition ("healthIndicator" , BeanDefinitionBuilder .rootBeanDefinition (TestHealthIndicator .class ).getBeanDefinition ());
41
+ beanFactory .registerBeanDefinition ("healthIndicator" , BeanDefinitionBuilder .rootBeanDefinition (PingHealthIndicator .class ).getBeanDefinition ());
44
42
NativeConfigurationRegistry registry = process (beanFactory );
45
- List <NativeReflectionEntry > entries = registry .reflection ().getEntries ();
46
- assertThat (entries ).anySatisfy ((entry ) -> {
47
- assertThat (entry .getType ()).isEqualTo (TestHealthIndicator .class );
43
+ assertThat (registry .reflection ().getEntries ()).singleElement ().satisfies ((entry ) -> {
44
+ assertThat (entry .getType ()).isEqualTo (PingHealthIndicator .class );
45
+ assertThat (entry .getFlags ()).contains (Flag .allDeclaredConstructors );
46
+ });
47
+ }
48
+
49
+ @ Test
50
+ void registerHealthContributor () {
51
+ DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory ();
52
+ beanFactory .registerBeanDefinition ("noise" , BeanDefinitionBuilder .rootBeanDefinition (String .class ).getBeanDefinition ());
53
+ beanFactory .registerBeanDefinition ("healthContributor" , BeanDefinitionBuilder .rootBeanDefinition (HealthContributor .class ).getBeanDefinition ());
54
+ NativeConfigurationRegistry registry = process (beanFactory );
55
+ assertThat (registry .reflection ().getEntries ()).singleElement ().satisfies ((entry ) -> {
56
+ assertThat (entry .getType ()).isEqualTo (HealthContributor .class );
48
57
assertThat (entry .getFlags ()).contains (Flag .allDeclaredConstructors );
49
58
});
50
- assertThat (entries ).hasSize (1 );
51
59
}
52
60
53
61
private NativeConfigurationRegistry process (DefaultListableBeanFactory beanFactory ) {
@@ -56,13 +64,4 @@ private NativeConfigurationRegistry process(DefaultListableBeanFactory beanFacto
56
64
return registry ;
57
65
}
58
66
59
- @ SuppressWarnings ("unused" )
60
- static class TestHealthIndicator implements HealthIndicator {
61
-
62
- @ Override
63
- public Health health () {
64
- return Health .up ().build ();
65
- }
66
- }
67
-
68
67
}
0 commit comments