Skip to content

Commit be6318f

Browse files
committed
Polish "Register health / reflection only if BindableService beans exist"
Adjusts the previous commit autoconfig tests: - renames test methods for consistency - check for default beans created Signed-off-by: Chris Bono <[email protected]>
1 parent fdb7129 commit be6318f

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/GrpcServerReflectionAutoConfigurationTests.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @author Chris Bono
3232
* @author Andrey Litvitski
3333
*/
34-
public class GrpcServerReflectionAutoConfigurationTests {
34+
class GrpcServerReflectionAutoConfigurationTests {
3535

3636
private ApplicationContextRunner contextRunner() {
3737
return new ApplicationContextRunner()
@@ -41,38 +41,37 @@ private ApplicationContextRunner contextRunner() {
4141
}
4242

4343
@Test
44-
void whenNoBindableServiceDefinedDoesNotAutoConfigureBean() {
44+
void whenAutoConfigurationIsNotSkippedThenCreatesReflectionServiceBean() {
45+
this.contextRunner().run((context -> assertThat(context).hasBean("serverReflection")));
46+
}
47+
48+
@Test
49+
void whenNoBindableServiceDefinedThenAutoConfigurationIsSkipped() {
4550
new ApplicationContextRunner()
4651
.withConfiguration(AutoConfigurations.of(GrpcServerReflectionAutoConfiguration.class))
4752
.run((context) -> assertThat(context).doesNotHaveBean(GrpcServerReflectionAutoConfiguration.class));
4853
}
4954

5055
@Test
51-
void whenReflectionEnabledFlagNotPresentThenCreateDefaultBean() {
52-
this.contextRunner().run((context -> assertThat(context).hasBean("serverReflection")));
56+
void whenReflectionEnabledPropertyNotSetThenAutoConfigurationIsNotSkipped() {
57+
this.contextRunner()
58+
.run((context) -> assertThat(context).hasSingleBean(GrpcServerReflectionAutoConfiguration.class));
5359
}
5460

5561
@Test
56-
void whenReflectionEnabledThenCreateBean() {
62+
void whenReflectionEnabledPropertySetTrueThenAutoConfigurationIsNotSkipped() {
5763
this.contextRunner()
5864
.withPropertyValues("spring.grpc.server.reflection.enabled=true")
5965
.run((context) -> assertThat(context).hasSingleBean(GrpcServerReflectionAutoConfiguration.class));
6066
}
6167

6268
@Test
63-
void whenReflectionDisabledThenSkipBeanCreation() {
69+
void whenReflectionEnabledPropertySetFalseThenAutoConfigurationIsSkipped() {
6470
this.contextRunner()
6571
.withPropertyValues("spring.grpc.server.reflection.enabled=false")
6672
.run((context) -> assertThat(context).doesNotHaveBean(GrpcServerReflectionAutoConfiguration.class));
6773
}
6874

69-
@Test
70-
void whenServerEnabledPropertySetFalseThenAutoConfigurationIsSkipped() {
71-
this.contextRunner()
72-
.withPropertyValues("spring.grpc.server.enabled=false")
73-
.run((context) -> assertThat(context).doesNotHaveBean(GrpcServerReflectionAutoConfiguration.class));
74-
}
75-
7675
@Test
7776
void whenServerEnabledPropertyNotSetThenAutoConfigurationIsNotSkipped() {
7877
this.contextRunner()
@@ -86,4 +85,11 @@ void whenServerEnabledPropertySetTrueThenAutoConfigurationIsNotSkipped() {
8685
.run((context) -> assertThat(context).hasSingleBean(GrpcServerReflectionAutoConfiguration.class));
8786
}
8887

88+
@Test
89+
void whenServerEnabledPropertySetFalseThenAutoConfigurationIsSkipped() {
90+
this.contextRunner()
91+
.withPropertyValues("spring.grpc.server.enabled=false")
92+
.run((context) -> assertThat(context).doesNotHaveBean(GrpcServerReflectionAutoConfiguration.class));
93+
}
94+
8995
}

spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/health/GrpcServerHealthAutoConfigurationTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ private ApplicationContextRunner contextRunner() {
6060
.withBean(BindableService.class, Mockito::mock);
6161
}
6262

63+
@Test
64+
void whenAutoConfigurationIsNotSkippedThenCreatesDefaultBeans() {
65+
this.contextRunner()
66+
.run((context -> assertThat(context).hasSingleBean(HealthStatusManager.class)
67+
.hasBean("grpcHealthService")));
68+
}
69+
6370
@Test
6471
void whenNoBindableServiceDefinedDoesNotAutoConfigureBean() {
6572
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GrpcServerHealthAutoConfiguration.class))

0 commit comments

Comments
 (0)