Skip to content

Commit 84babc1

Browse files
committed
Add Integration tests.
1 parent ba93e7b commit 84babc1

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed

spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/LoadBalancedRestClientIntegrationTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.cloud.client.loadbalancer;
1818

19-
import java.io.IOException;
2019
import java.net.URI;
2120

2221
import org.junit.jupiter.api.Test;
@@ -70,13 +69,13 @@ RestClient.Builder restClientBuilder() {
7069
LoadBalancerClient testLoadBalancerClient() {
7170
return new LoadBalancerClient() {
7271
@Override
73-
public <T> T execute(String serviceId, LoadBalancerRequest<T> request) throws IOException {
72+
public <T> T execute(String serviceId, LoadBalancerRequest<T> request) {
7473
throw new UnsupportedOperationException("LoadBalancerInterceptor invoked.");
7574
}
7675

7776
@Override
78-
public <T> T execute(String serviceId, ServiceInstance serviceInstance, LoadBalancerRequest<T> request)
79-
throws IOException {
77+
public <T> T execute(String serviceId, ServiceInstance serviceInstance,
78+
LoadBalancerRequest<T> request) {
8079
throw new UnsupportedOperationException("LoadBalancerInterceptor invoked.");
8180
}
8281

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.client.loadbalancer;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.boot.SpringBootConfiguration;
23+
import org.springframework.boot.test.context.SpringBootTest;
24+
import org.springframework.boot.web.client.RestTemplateBuilder;
25+
import org.springframework.context.ApplicationContext;
26+
import org.springframework.context.annotation.Bean;
27+
import org.springframework.web.client.RestTemplate;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
/**
32+
* Integration tests for load-balanced {@link RestTemplateBuilder}.
33+
*
34+
* @author Olga Maciaszek-Sharma
35+
*/
36+
@SpringBootTest(classes = { LoadBalancedRestTemplateBuilderIntegrationTests.TestConfig.class,
37+
LoadBalancerAutoConfiguration.class }, properties = "spring.cloud.loadbalancer.retry.enabled=false")
38+
public class LoadBalancedRestTemplateBuilderIntegrationTests {
39+
40+
private final RestTemplateBuilder restTemplateBuilder;
41+
42+
@Autowired
43+
ApplicationContext context;
44+
45+
public LoadBalancedRestTemplateBuilderIntegrationTests(@Autowired RestTemplateBuilder restTemplateBuilder) {
46+
this.restTemplateBuilder = restTemplateBuilder;
47+
}
48+
49+
@Test
50+
void shouldBuildLoadBalancedRestTemplate() {
51+
RestTemplate restTemplate = restTemplateBuilder.build();
52+
53+
assertThat(restTemplate.getInterceptors()).hasSize(1);
54+
assertThat(restTemplate.getInterceptors().get(0)).isInstanceOf(BlockingLoadBalancerInterceptor.class);
55+
}
56+
57+
@SpringBootConfiguration
58+
static class TestConfig {
59+
60+
@LoadBalanced
61+
@Bean
62+
RestTemplateBuilder restTemplateBuilder() {
63+
return new RestTemplateBuilder();
64+
}
65+
66+
}
67+
68+
}

0 commit comments

Comments
 (0)