17
17
package org .springframework .boot .actuate .autoconfigure .tracing .zipkin ;
18
18
19
19
import org .junit .jupiter .api .Test ;
20
+ import org .mockito .ArgumentMatchers ;
20
21
import zipkin2 .reporter .Sender ;
21
22
import zipkin2 .reporter .urlconnection .URLConnectionSender ;
22
23
26
27
import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
27
28
import org .springframework .boot .test .context .runner .ReactiveWebApplicationContextRunner ;
28
29
import org .springframework .boot .test .context .runner .WebApplicationContextRunner ;
29
- import org .springframework .boot .web .client .RestTemplateBuilder ;
30
30
import org .springframework .context .annotation .Bean ;
31
31
import org .springframework .context .annotation .Configuration ;
32
32
import org .springframework .web .reactive .function .client .WebClient ;
33
33
34
34
import static org .assertj .core .api .Assertions .assertThat ;
35
+ import static org .mockito .BDDMockito .then ;
35
36
import static org .mockito .Mockito .mock ;
36
37
37
38
/**
@@ -66,6 +67,8 @@ void shouldPreferWebClientSenderIfWebApplicationIsReactiveAndUrlSenderIsNotAvail
66
67
assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
67
68
assertThat (context ).hasSingleBean (Sender .class );
68
69
assertThat (context ).hasSingleBean (ZipkinWebClientSender .class );
70
+ then (context .getBean (ZipkinWebClientBuilderCustomizer .class )).should ()
71
+ .customize (ArgumentMatchers .any ());
69
72
});
70
73
}
71
74
@@ -90,29 +93,29 @@ void shouldPreferWebClientInNonWebApplicationAndUrlConnectionSenderIsNotAvailabl
90
93
}
91
94
92
95
@ Test
93
- void willUseRestTemplateInNonWebApplicationIfUrlConnectionSenderIsNotAvailable () {
96
+ void willUseRestTemplateInNonWebApplicationIfUrlConnectionSenderAndWebclientAreNotAvailable () {
94
97
this .contextRunner .withUserConfiguration (RestTemplateConfiguration .class )
95
- .withClassLoader (new FilteredClassLoader ("zipkin2.reporter.urlconnection" )).run ((context ) -> {
98
+ .withClassLoader (new FilteredClassLoader (URLConnectionSender . class , WebClient . class )).run ((context ) -> {
96
99
assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
97
100
assertThat (context ).hasSingleBean (Sender .class );
98
101
assertThat (context ).hasSingleBean (ZipkinRestTemplateSender .class );
99
102
});
100
103
}
101
104
102
105
@ Test
103
- void willUseRestTemplateInServletWebApplicationIfUrlConnectionSenderIsNotAvailable () {
106
+ void willUseRestTemplateInServletWebApplicationIfUrlConnectionSenderAndWebClientNotAvailable () {
104
107
this .servletContextRunner .withUserConfiguration (RestTemplateConfiguration .class )
105
- .withClassLoader (new FilteredClassLoader ("zipkin2.reporter.urlconnection" )).run ((context ) -> {
108
+ .withClassLoader (new FilteredClassLoader (URLConnectionSender . class , WebClient . class )).run ((context ) -> {
106
109
assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
107
110
assertThat (context ).hasSingleBean (Sender .class );
108
111
assertThat (context ).hasSingleBean (ZipkinRestTemplateSender .class );
109
112
});
110
113
}
111
114
112
115
@ Test
113
- void willUseRestTemplateInReactiveWebApplicationIfUrlConnectionSenderIsNotAvailable () {
116
+ void willUseRestTemplateInReactiveWebApplicationIfUrlConnectionSenderAndWebClientAreNotAvailable () {
114
117
this .reactiveContextRunner .withUserConfiguration (RestTemplateConfiguration .class )
115
- .withClassLoader (new FilteredClassLoader ("zipkin2.reporter.urlconnection" )).run ((context ) -> {
118
+ .withClassLoader (new FilteredClassLoader (URLConnectionSender . class , WebClient . class )).run ((context ) -> {
116
119
assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
117
120
assertThat (context ).hasSingleBean (Sender .class );
118
121
assertThat (context ).hasSingleBean (ZipkinRestTemplateSender .class );
@@ -140,8 +143,8 @@ void shouldBackOffOnCustomBeans() {
140
143
private static class RestTemplateConfiguration {
141
144
142
145
@ Bean
143
- RestTemplateBuilder restTemplateBuilder () {
144
- return new RestTemplateBuilder ( );
146
+ ZipkinRestTemplateBuilderCustomizer restTemplateBuilder () {
147
+ return mock ( ZipkinRestTemplateBuilderCustomizer . class );
145
148
}
146
149
147
150
}
@@ -150,8 +153,8 @@ RestTemplateBuilder restTemplateBuilder() {
150
153
private static class WebClientConfiguration {
151
154
152
155
@ Bean
153
- WebClient . Builder webClientBuilder () {
154
- return WebClient . builder ( );
156
+ ZipkinWebClientBuilderCustomizer webClientBuilder () {
157
+ return mock ( ZipkinWebClientBuilderCustomizer . class );
155
158
}
156
159
157
160
}
0 commit comments