1616
1717package org .springframework .cloud .client .loadbalancer ;
1818
19+ import java .net .URI ;
20+
1921import org .junit .jupiter .api .Test ;
2022
2123import org .springframework .beans .factory .annotation .Autowired ;
2224import org .springframework .boot .SpringBootConfiguration ;
2325import org .springframework .boot .test .context .SpringBootTest ;
2426import org .springframework .boot .web .client .RestTemplateBuilder ;
25- import org .springframework .context . ApplicationContext ;
27+ import org .springframework .cloud . client . ServiceInstance ;
2628import org .springframework .context .annotation .Bean ;
2729import org .springframework .web .client .RestTemplate ;
2830
@@ -39,9 +41,6 @@ public class LoadBalancedRestTemplateBuilderIntegrationTests {
3941
4042 private final RestTemplateBuilder restTemplateBuilder ;
4143
42- @ Autowired
43- ApplicationContext context ;
44-
4544 public LoadBalancedRestTemplateBuilderIntegrationTests (@ Autowired RestTemplateBuilder restTemplateBuilder ) {
4645 this .restTemplateBuilder = restTemplateBuilder ;
4746 }
@@ -51,7 +50,12 @@ void shouldBuildLoadBalancedRestTemplate() {
5150 RestTemplate restTemplate = restTemplateBuilder .build ();
5251
5352 assertThat (restTemplate .getInterceptors ()).hasSize (1 );
54- assertThat (restTemplate .getInterceptors ().get (0 )).isInstanceOf (BlockingLoadBalancerInterceptor .class );
53+ assertThat (restTemplate .getInterceptors ()
54+ .get (0 )).isInstanceOf (DeferringLoadBalancerInterceptor .class );
55+ assertThat (((DeferringLoadBalancerInterceptor ) restTemplate .getInterceptors ()
56+ .get (0 ))
57+ .getLoadBalancerInterceptorProvider ()
58+ .getObject ()).isInstanceOf (BlockingLoadBalancerInterceptor .class );
5559 }
5660
5761 @ SpringBootConfiguration
@@ -63,6 +67,38 @@ RestTemplateBuilder restTemplateBuilder() {
6367 return new RestTemplateBuilder ();
6468 }
6569
70+ @ Bean
71+ LoadBalancerClient testLoadBalancerClient () {
72+ return new LoadBalancerClient () {
73+ @ Override
74+ public <T > T execute (String serviceId , LoadBalancerRequest <T > request ) {
75+ throw new UnsupportedOperationException ("LoadBalancerInterceptor invoked." );
76+ }
77+
78+ @ Override
79+ public <T > T execute (String serviceId , ServiceInstance serviceInstance ,
80+ LoadBalancerRequest <T > request ) {
81+ throw new UnsupportedOperationException ("LoadBalancerInterceptor invoked." );
82+ }
83+
84+ @ Override
85+ public URI reconstructURI (ServiceInstance instance , URI original ) {
86+ throw new UnsupportedOperationException ("LoadBalancerInterceptor invoked." );
87+ }
88+
89+ @ Override
90+ public ServiceInstance choose (String serviceId ) {
91+ throw new UnsupportedOperationException ("LoadBalancerInterceptor invoked." );
92+ }
93+
94+ @ Override
95+ public <T > ServiceInstance choose (String serviceId , Request <T > request ) {
96+ throw new UnsupportedOperationException ("LoadBalancerInterceptor invoked." );
97+ }
98+ };
99+ }
100+
101+ }
102+
66103 }
67104
68- }
0 commit comments