Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
spring.application.name=grpc-server
grpc.server.reflection.enabled=false
6 changes: 5 additions & 1 deletion spring-grpc-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-services</artifactId>
</dependency>

</dependencies>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.springframework.grpc.autoconfigure.server;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.grpc.BindableService;
import io.grpc.protobuf.services.ProtoReflectionService;

/**
* {@link EnableAutoConfiguration Auto-configuration} for gRPC Reflection service
* <p>
* grpc.reflection.enabled=true must be present in configuration in order for the
* auto-configuration to execute
*
* @author Haris Zujo
*/
@Configuration
@ConditionalOnClass(ProtoReflectionService.class)
public class GrpcServerReflectionAutoConfiguration {

@Bean
@ConditionalOnProperty(name = "grpc.server.reflection.enabled", havingValue = "true")
public BindableService serverReflection() {
return ProtoReflectionService.newInstance();
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
org.springframework.grpc.autoconfigure.server.GrpcServerFactoryAutoConfiguration
org.springframework.grpc.autoconfigure.server.GrpcServerAutoConfiguration
org.springframework.grpc.autoconfigure.client.GrpcClientAutoConfiguration
org.springframework.grpc.autoconfigure.server.GrpcServerReflectionAutoConfiguration

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.springframework.grpc.autoconfigure.server;

import io.grpc.BindableService;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.grpc.server.lifecycle.GrpcServerLifecycle;

import static org.assertj.core.api.Assertions.assertThat;

public class GrpcServerReflectionAutoConfigurationTests {

private ApplicationContextRunner contextRunner() {
return new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(GrpcServerReflectionAutoConfiguration.class))
.withBean("noopServerLifecylcle", GrpcServerLifecycle.class, Mockito::mock);
}

@Test
void whenReflectionEnabledThenCreateBean() {
this.contextRunner()
.withPropertyValues("grpc.server.reflection.enabled=true")
.run((context) -> assertThat(context).hasSingleBean(BindableService.class));
}

@Test
void whenReflectionDisabledThenSkipBeanCreation() {
this.contextRunner()
.withPropertyValues("grpc.server.reflection.enabled=false")
.run((context) -> assertThat(context).doesNotHaveBean(BindableService.class));
}

}