|
16 | 16 |
|
17 | 17 | package org.springframework.grpc.autoconfigure.server; |
18 | 18 |
|
19 | | -import java.util.concurrent.atomic.AtomicBoolean; |
20 | | - |
21 | 19 | import io.grpc.BindableService; |
22 | 20 | import io.grpc.ServerServiceDefinition; |
23 | 21 | import io.grpc.internal.GrpcUtil; |
24 | | -import io.grpc.servlet.jakarta.GrpcServlet; |
25 | | -import io.grpc.servlet.jakarta.ServletAdapter; |
26 | 22 | import io.grpc.servlet.jakarta.ServletServerBuilder; |
27 | 23 | import org.junit.jupiter.api.Test; |
28 | 24 |
|
|
35 | 31 | import org.springframework.util.unit.DataSize; |
36 | 32 |
|
37 | 33 | import static org.assertj.core.api.Assertions.assertThat; |
| 34 | +import static org.mockito.ArgumentMatchers.any; |
38 | 35 | import static org.mockito.Mockito.mock; |
| 36 | +import static org.mockito.Mockito.verify; |
39 | 37 | import static org.mockito.Mockito.when; |
40 | 38 |
|
41 | 39 | /** |
@@ -74,40 +72,32 @@ void whenNoBindableServicesRegisteredAutoConfigurationIsSkipped() { |
74 | 72 |
|
75 | 73 | @Test |
76 | 74 | void whenWebApplicationServletIsAutoConfigured() { |
77 | | - this.contextRunner().run((context) -> { |
78 | | - assertThat(context).getBean(ServletRegistrationBean.class) |
79 | | - .isNotNull() |
80 | | - .extracting("servlet") |
81 | | - .isInstanceOf(GrpcServlet.class) |
82 | | - .extracting("servletAdapter") |
83 | | - .isInstanceOf(ServletAdapter.class) |
84 | | - .extracting("maxInboundMessageSize") |
85 | | - .isEqualTo(GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE); |
86 | | - }); |
| 75 | + this.contextRunner().run((context) -> assertThat(context).getBean(ServletRegistrationBean.class).isNotNull()); |
87 | 76 | } |
88 | 77 |
|
89 | 78 | @Test |
90 | 79 | void whenCustomizerIsRegistered() { |
91 | | - AtomicBoolean invoked = new AtomicBoolean(false); |
92 | | - ServerBuilderCustomizer<ServletServerBuilder> customizer = serverBuilder -> invoked.set(true); |
93 | | - this.contextRunner().withBean(ServerBuilderCustomizer.class, () -> customizer).run(context -> { |
94 | | - assertThat(context).getBean(ServletRegistrationBean.class).isNotNull(); |
95 | | - assertThat(invoked.get()).isTrue(); |
96 | | - }); |
| 80 | + ServerBuilderCustomizer<ServletServerBuilder> customizer = mock(); |
| 81 | + this.contextRunner() |
| 82 | + .withBean(ServerBuilderCustomizer.class, () -> customizer) |
| 83 | + .run(context -> verify(customizer).customize(any(ServletServerBuilder.class))); |
97 | 84 | } |
98 | 85 |
|
99 | 86 | @Test |
100 | | - void whenMaxInboundMessageSizeIsConfigured() { |
101 | | - this.contextRunner().withPropertyValues("spring.grpc.server.max-inbound-message-size=10KB").run(context -> { |
102 | | - assertThat(context).getBean(ServletRegistrationBean.class) |
103 | | - .isNotNull() |
104 | | - .extracting("servlet") |
105 | | - .isInstanceOf(GrpcServlet.class) |
106 | | - .extracting("servletAdapter") |
107 | | - .isInstanceOf(ServletAdapter.class) |
108 | | - .extracting("maxInboundMessageSize") |
109 | | - .isEqualTo((int) DataSize.ofKilobytes(10).toBytes()); |
110 | | - }); |
| 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)); |
111 | 101 | } |
112 | 102 |
|
113 | 103 | } |
0 commit comments