25
25
import org .springframework .boot .test .context .FilteredClassLoader ;
26
26
import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
27
27
import org .springframework .boot .test .context .runner .ReactiveWebApplicationContextRunner ;
28
+ import org .springframework .boot .test .context .runner .WebApplicationContextRunner ;
28
29
import org .springframework .boot .web .client .RestTemplateBuilder ;
29
30
import org .springframework .context .annotation .Bean ;
30
31
import org .springframework .context .annotation .Configuration ;
@@ -46,6 +47,9 @@ class ZipkinConfigurationsSenderConfigurationTests {
46
47
private final ReactiveWebApplicationContextRunner reactiveContextRunner = new ReactiveWebApplicationContextRunner ()
47
48
.withConfiguration (AutoConfigurations .of (SenderConfiguration .class ));
48
49
50
+ private final WebApplicationContextRunner servletContextRunner = new WebApplicationContextRunner ()
51
+ .withConfiguration (AutoConfigurations .of (SenderConfiguration .class ));
52
+
49
53
@ Test
50
54
void shouldSupplyBeans () {
51
55
this .contextRunner .run ((context ) -> {
@@ -56,8 +60,8 @@ void shouldSupplyBeans() {
56
60
}
57
61
58
62
@ Test
59
- void shouldUseWebClientSenderIfWebApplicationIsReactive () {
60
- this .reactiveContextRunner .withUserConfiguration (WebClientConfiguration .class )
63
+ void shouldPreferWebClientSenderIfWebApplicationIsReactiveAndUrlSenderIsNotAvailable () {
64
+ this .reactiveContextRunner .withUserConfiguration (RestTemplateConfiguration . class , WebClientConfiguration .class )
61
65
.withClassLoader (new FilteredClassLoader ("zipkin2.reporter.urlconnection" )).run ((context ) -> {
62
66
assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
63
67
assertThat (context ).hasSingleBean (Sender .class );
@@ -66,26 +70,64 @@ void shouldUseWebClientSenderIfWebApplicationIsReactive() {
66
70
}
67
71
68
72
@ Test
69
- void shouldNotUseWebClientSenderIfNoBuilderIsAvailable () {
70
- this .reactiveContextRunner .run ((context ) -> {
71
- assertThat (context ).doesNotHaveBean (ZipkinWebClientSender .class );
72
- assertThat (context ).hasSingleBean (Sender .class );
73
- assertThat (context ).hasSingleBean (URLConnectionSender .class );
74
- });
73
+ void shouldPreferWebClientSenderIfWebApplicationIsServletAndUrlSenderIsNotAvailable () {
74
+ this .servletContextRunner .withUserConfiguration (RestTemplateConfiguration .class , WebClientConfiguration .class )
75
+ .withClassLoader (new FilteredClassLoader ("zipkin2.reporter.urlconnection" )).run ((context ) -> {
76
+ assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
77
+ assertThat (context ).hasSingleBean (Sender .class );
78
+ assertThat (context ).hasSingleBean (ZipkinWebClientSender .class );
79
+ });
80
+ }
81
+
82
+ @ Test
83
+ void shouldPreferWebClientInNonWebApplicationAndUrlConnectionSenderIsNotAvailable () {
84
+ this .contextRunner .withUserConfiguration (RestTemplateConfiguration .class , WebClientConfiguration .class )
85
+ .withClassLoader (new FilteredClassLoader ("zipkin2.reporter.urlconnection" )).run ((context ) -> {
86
+ assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
87
+ assertThat (context ).hasSingleBean (Sender .class );
88
+ assertThat (context ).hasSingleBean (ZipkinWebClientSender .class );
89
+ });
75
90
}
76
91
77
92
@ Test
78
- void shouldUseRestTemplateSenderIfUrlConnectionSenderIsNotAvailableAndWebAppIsNotReactive () {
93
+ void willUseRestTemplateInNonWebApplicationIfUrlConnectionSenderIsNotAvailable () {
79
94
this .contextRunner .withUserConfiguration (RestTemplateConfiguration .class )
80
- .withClassLoader (
81
- new FilteredClassLoader ("zipkin2.reporter.urlconnection" , "org.springframework.web.reactive" ))
82
- .run ((context ) -> {
95
+ .withClassLoader (new FilteredClassLoader ("zipkin2.reporter.urlconnection" )).run ((context ) -> {
83
96
assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
84
97
assertThat (context ).hasSingleBean (Sender .class );
85
98
assertThat (context ).hasSingleBean (ZipkinRestTemplateSender .class );
86
99
});
87
100
}
88
101
102
+ @ Test
103
+ void willUseRestTemplateInServletWebApplicationIfUrlConnectionSenderIsNotAvailable () {
104
+ this .servletContextRunner .withUserConfiguration (RestTemplateConfiguration .class )
105
+ .withClassLoader (new FilteredClassLoader ("zipkin2.reporter.urlconnection" )).run ((context ) -> {
106
+ assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
107
+ assertThat (context ).hasSingleBean (Sender .class );
108
+ assertThat (context ).hasSingleBean (ZipkinRestTemplateSender .class );
109
+ });
110
+ }
111
+
112
+ @ Test
113
+ void willUseRestTemplateInReactiveWebApplicationIfUrlConnectionSenderIsNotAvailable () {
114
+ this .reactiveContextRunner .withUserConfiguration (RestTemplateConfiguration .class )
115
+ .withClassLoader (new FilteredClassLoader ("zipkin2.reporter.urlconnection" )).run ((context ) -> {
116
+ assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
117
+ assertThat (context ).hasSingleBean (Sender .class );
118
+ assertThat (context ).hasSingleBean (ZipkinRestTemplateSender .class );
119
+ });
120
+ }
121
+
122
+ @ Test
123
+ void shouldNotUseWebClientSenderIfNoBuilderIsAvailable () {
124
+ this .reactiveContextRunner .run ((context ) -> {
125
+ assertThat (context ).doesNotHaveBean (ZipkinWebClientSender .class );
126
+ assertThat (context ).hasSingleBean (Sender .class );
127
+ assertThat (context ).hasSingleBean (URLConnectionSender .class );
128
+ });
129
+ }
130
+
89
131
@ Test
90
132
void shouldBackOffOnCustomBeans () {
91
133
this .contextRunner .withUserConfiguration (CustomConfiguration .class ).run ((context ) -> {
0 commit comments