|
16 | 16 |
|
17 | 17 | package org.springframework.grpc.autoconfigure.server; |
18 | 18 |
|
19 | | -import static org.assertj.core.api.Assertions.assertThat; |
20 | | -import static org.mockito.ArgumentMatchers.any; |
21 | | -import static org.mockito.ArgumentMatchers.anyInt; |
22 | | -import static org.mockito.Mockito.inOrder; |
23 | | -import static org.mockito.Mockito.mock; |
24 | | -import static org.mockito.Mockito.when; |
25 | | - |
26 | | -import java.time.Duration; |
27 | | -import java.util.List; |
28 | | -import java.util.concurrent.TimeUnit; |
29 | | - |
30 | | -import org.assertj.core.api.InstanceOfAssertFactories; |
| 19 | +import io.grpc.BindableService; |
| 20 | +import io.grpc.ServerServiceDefinition; |
| 21 | +import io.grpc.internal.GrpcUtil; |
| 22 | +import io.grpc.servlet.jakarta.ServletServerBuilder; |
31 | 23 | import org.junit.jupiter.api.Test; |
32 | | -import org.mockito.InOrder; |
33 | | -import org.mockito.MockedStatic; |
34 | | -import org.mockito.Mockito; |
35 | | -import org.mockito.stubbing.Answer; |
| 24 | + |
36 | 25 | import org.springframework.boot.autoconfigure.AutoConfigurations; |
37 | | -import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration; |
38 | 26 | import org.springframework.boot.test.context.FilteredClassLoader; |
39 | 27 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
40 | 28 | import org.springframework.boot.test.context.runner.WebApplicationContextRunner; |
41 | 29 | import org.springframework.boot.web.servlet.ServletRegistrationBean; |
42 | | -import org.springframework.context.annotation.Bean; |
43 | | -import org.springframework.context.annotation.Configuration; |
44 | | -import org.springframework.core.annotation.Order; |
45 | | -import org.springframework.grpc.server.GrpcServerFactory; |
46 | | -import org.springframework.grpc.server.NettyGrpcServerFactory; |
47 | 30 | import org.springframework.grpc.server.ServerBuilderCustomizer; |
48 | | -import org.springframework.grpc.server.ShadedNettyGrpcServerFactory; |
49 | | -import org.springframework.grpc.server.lifecycle.GrpcServerLifecycle; |
| 31 | +import org.springframework.util.unit.DataSize; |
50 | 32 |
|
51 | | -import io.grpc.BindableService; |
52 | | -import io.grpc.Grpc; |
53 | | -import io.grpc.ServerBuilder; |
54 | | -import io.grpc.ServerServiceDefinition; |
55 | | -import io.grpc.ServiceDescriptor; |
56 | | -import io.grpc.netty.NettyServerBuilder; |
| 33 | +import static org.assertj.core.api.Assertions.assertThat; |
| 34 | +import static org.mockito.ArgumentMatchers.any; |
| 35 | +import static org.mockito.Mockito.mock; |
| 36 | +import static org.mockito.Mockito.verify; |
| 37 | +import static org.mockito.Mockito.when; |
57 | 38 |
|
58 | 39 | /** |
59 | 40 | * Tests for {@link GrpcServerAutoConfiguration}. |
60 | 41 | * |
61 | 42 | * @author Chris Bono |
| 43 | + * @author Toshiaki Maki |
62 | 44 | */ |
63 | 45 | class GrpcServletAutoConfigurationTests { |
64 | 46 |
|
@@ -93,4 +75,29 @@ void whenWebApplicationServletIsAutoConfigured() { |
93 | 75 | this.contextRunner().run((context) -> assertThat(context).getBean(ServletRegistrationBean.class).isNotNull()); |
94 | 76 | } |
95 | 77 |
|
| 78 | + @Test |
| 79 | + void whenCustomizerIsRegistered() { |
| 80 | + ServerBuilderCustomizer<ServletServerBuilder> customizer = mock(); |
| 81 | + this.contextRunner() |
| 82 | + .withBean(ServerBuilderCustomizer.class, () -> customizer) |
| 83 | + .run(context -> verify(customizer).customize(any(ServletServerBuilder.class))); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + void whenMaxInboundMessageSizeIsSetThenItIsUsed() { |
| 88 | + this.contextRunner() |
| 89 | + .withPropertyValues("spring.grpc.server.max-inbound-message-size=10KB") |
| 90 | + .run(context -> assertThat(context).getBean(ServletRegistrationBean.class) |
| 91 | + .hasFieldOrPropertyWithValue("servlet.servletAdapter.maxInboundMessageSize", |
| 92 | + Math.toIntExact(DataSize.ofKilobytes(10).toBytes()))); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + void whenMaxInboundMessageSizeIsNotSetThenDefaultIsUsed() { |
| 97 | + this.contextRunner() |
| 98 | + .run((context) -> assertThat(context).getBean(ServletRegistrationBean.class) |
| 99 | + .hasFieldOrPropertyWithValue("servlet.servletAdapter.maxInboundMessageSize", |
| 100 | + GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE)); |
| 101 | + } |
| 102 | + |
96 | 103 | } |
0 commit comments