2222import org .springframework .boot .autoconfigure .AutoConfigurations ;
2323import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
2424import org .springframework .cloud .kubernetes .fabric8 .leader .Fabric8LeaderAutoConfiguration ;
25- import org .springframework .cloud .kubernetes .fabric8 .leader .Fabric8PodReadinessWatcher ;
2625
2726/**
2827 * tests that ensure 'spring.cloud.kubernetes.leader.election' enabled correct
@@ -38,7 +37,7 @@ class Fabric8LeaderAutoConfigurationTests {
3837 *
3938 * As such:
4039 *
41- * - Fabric8LeaderAutoConfiguration must be picked up
40+ * - Fabric8LeaderAutoConfiguration must be picked up
4241 * - Fabric8LeaderElectionAutoConfiguration must not be picked up
4342 * </pre>
4443 */
@@ -49,12 +48,8 @@ void leaderElectionAnnotationMissing() {
4948 Fabric8LeaderElectionAutoConfiguration .class ,
5049 Fabric8LeaderElectionCallbacksAutoConfiguration .class ))
5150 .run (context -> {
52-
53- // this one comes from Fabric8LeaderElectionAutoConfiguration
54- Assertions .assertThat (context ).doesNotHaveBean (Fabric8LeaderElectionInitiator .class );
55-
56- // this one comes from Fabric8LeaderAutoConfiguration
57- Assertions .assertThat (context ).hasSingleBean (Fabric8PodReadinessWatcher .class );
51+ Assertions .assertThat (context ).hasSingleBean (Fabric8LeaderAutoConfiguration .class );
52+ Assertions .assertThat (context ).doesNotHaveBean (Fabric8LeaderElectionAutoConfiguration .class );
5853 });
5954 }
6055
@@ -64,7 +59,7 @@ void leaderElectionAnnotationMissing() {
6459 *
6560 * As such:
6661 *
67- * - Fabric8LeaderAutoConfiguration must be picked up
62+ * - Fabric8LeaderAutoConfiguration must be picked up
6863 * - Fabric8LeaderElectionAutoConfiguration must not be picked up
6964 * </pre>
7065 */
@@ -76,22 +71,18 @@ void leaderElectionAnnotationPresentEqualToFalse() {
7671 Fabric8LeaderElectionCallbacksAutoConfiguration .class ))
7772 .withPropertyValues ("spring.cloud.kubernetes.leader.election.enabled=false" )
7873 .run (context -> {
79-
80- // this one comes from Fabric8LeaderElectionAutoConfiguration
81- Assertions .assertThat (context ).doesNotHaveBean (Fabric8LeaderElectionInitiator .class );
82-
83- // this one comes from Fabric8LeaderAutoConfiguration
84- Assertions .assertThat (context ).hasSingleBean (Fabric8PodReadinessWatcher .class );
74+ Assertions .assertThat (context ).hasSingleBean (Fabric8LeaderAutoConfiguration .class );
75+ Assertions .assertThat (context ).doesNotHaveBean (Fabric8LeaderElectionAutoConfiguration .class );
8576 });
8677 }
8778
8879 /**
8980 * <pre>
90- * - spring.cloud.kubernetes.leader.election = false
81+ * - spring.cloud.kubernetes.leader.election = true
9182 *
9283 * As such:
9384 *
94- * - Fabric8LeaderAutoConfiguration must not be picked up
85+ * - Fabric8LeaderAutoConfiguration must not be picked up
9586 * - Fabric8LeaderElectionAutoConfiguration must be picked up
9687 * </pre>
9788 */
@@ -104,12 +95,63 @@ void leaderElectionAnnotationPresentEqualToTrue() {
10495 .withPropertyValues ("spring.cloud.kubernetes.leader.election.enabled=true" ,
10596 "spring.main.cloud-platform=kubernetes" )
10697 .run (context -> {
98+ Assertions .assertThat (context ).doesNotHaveBean (Fabric8LeaderAutoConfiguration .class );
99+ Assertions .assertThat (context ).hasSingleBean (Fabric8LeaderElectionAutoConfiguration .class );
100+ });
101+ }
107102
108- // this one comes from Fabric8LeaderElectionAutoConfiguration
109- Assertions .assertThat (context ).hasSingleBean (Fabric8LeaderElectionInitiator .class );
103+ /**
104+ * <pre>
105+ * - spring.cloud.kubernetes.leader.election = true
106+ * - management.info.leader.election.enabled = true
107+ *
108+ * As such:
109+ *
110+ * - Fabric8LeaderAutoConfiguration must not be picked up
111+ * - Fabric8LeaderElectionAutoConfiguration must be picked up
112+ * - Fabric8LeaderElectionInfoContributor must be picked up
113+ * </pre>
114+ */
115+ @ Test
116+ void leaderInfoContributorPresent () {
117+ new ApplicationContextRunner ().withUserConfiguration (Fabric8LeaderApp .class )
118+ .withConfiguration (AutoConfigurations .of (Fabric8LeaderAutoConfiguration .class ,
119+ Fabric8LeaderElectionAutoConfiguration .class ,
120+ Fabric8LeaderElectionCallbacksAutoConfiguration .class ))
121+ .withPropertyValues ("spring.main.cloud-platform=kubernetes" , "management.info.leader.election.enabled=true" ,
122+ "spring.cloud.kubernetes.leader.election.enabled=true" )
123+ .run (context -> {
124+ Assertions .assertThat (context ).doesNotHaveBean (Fabric8LeaderAutoConfiguration .class );
125+ Assertions .assertThat (context ).hasSingleBean (Fabric8LeaderElectionAutoConfiguration .class );
126+ Assertions .assertThat (context ).hasSingleBean (Fabric8LeaderElectionInfoContributor .class );
127+ });
128+ }
110129
111- // this one comes from Fabric8LeaderAutoConfiguration
112- Assertions .assertThat (context ).doesNotHaveBean (Fabric8PodReadinessWatcher .class );
130+ /**
131+ * <pre>
132+ * - spring.cloud.kubernetes.leader.election = true
133+ * - management.info.leader.election.enabled = false
134+ *
135+ * As such:
136+ *
137+ * - Fabric8LeaderAutoConfiguration must not be picked up
138+ * - Fabric8LeaderElectionAutoConfiguration must be picked up
139+ * - Fabric8LeaderElectionInfoContributor must not be picked up
140+ * </pre>
141+ */
142+ @ Test
143+ void leaderInfoContributorMissing () {
144+ new ApplicationContextRunner ().withUserConfiguration (Fabric8LeaderApp .class )
145+ .withConfiguration (AutoConfigurations .of (Fabric8LeaderAutoConfiguration .class ,
146+ Fabric8LeaderElectionAutoConfiguration .class ,
147+ Fabric8LeaderElectionCallbacksAutoConfiguration .class ))
148+ .withPropertyValues ("spring.main.cloud-platform=kubernetes" ,
149+ "management.info.leader.election.enabled=false" ,
150+ "spring.cloud.kubernetes.leader.election.enabled=true" )
151+ .run (context -> {
152+ Assertions .assertThat (context ).doesNotHaveBean (Fabric8LeaderAutoConfiguration .class );
153+ Assertions .assertThat (context ).hasSingleBean (Fabric8LeaderElectionAutoConfiguration .class );
154+ Assertions .assertThat (context ).doesNotHaveBean (Fabric8LeaderElectionInfoContributor .class );
113155 });
114156 }
115157
0 commit comments