Skip to content

Commit

Permalink
Add Integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaMaciaszek committed Oct 14, 2024
1 parent ba93e7b commit 84babc1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.springframework.cloud.client.loadbalancer;

import java.io.IOException;
import java.net.URI;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -70,13 +69,13 @@ RestClient.Builder restClientBuilder() {
LoadBalancerClient testLoadBalancerClient() {
return new LoadBalancerClient() {
@Override
public <T> T execute(String serviceId, LoadBalancerRequest<T> request) throws IOException {
public <T> T execute(String serviceId, LoadBalancerRequest<T> request) {
throw new UnsupportedOperationException("LoadBalancerInterceptor invoked.");
}

@Override
public <T> T execute(String serviceId, ServiceInstance serviceInstance, LoadBalancerRequest<T> request)
throws IOException {
public <T> T execute(String serviceId, ServiceInstance serviceInstance,
LoadBalancerRequest<T> request) {
throw new UnsupportedOperationException("LoadBalancerInterceptor invoked.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.cloud.client.loadbalancer;

import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Integration tests for load-balanced {@link RestTemplateBuilder}.
*
* @author Olga Maciaszek-Sharma
*/
@SpringBootTest(classes = { LoadBalancedRestTemplateBuilderIntegrationTests.TestConfig.class,
LoadBalancerAutoConfiguration.class }, properties = "spring.cloud.loadbalancer.retry.enabled=false")
public class LoadBalancedRestTemplateBuilderIntegrationTests {

private final RestTemplateBuilder restTemplateBuilder;

@Autowired
ApplicationContext context;

public LoadBalancedRestTemplateBuilderIntegrationTests(@Autowired RestTemplateBuilder restTemplateBuilder) {
this.restTemplateBuilder = restTemplateBuilder;
}

@Test
void shouldBuildLoadBalancedRestTemplate() {
RestTemplate restTemplate = restTemplateBuilder.build();

assertThat(restTemplate.getInterceptors()).hasSize(1);

Check failure on line 53 in spring-cloud-commons/src/test/java/org/springframework/cloud/client/loadbalancer/LoadBalancedRestTemplateBuilderIntegrationTests.java

View workflow job for this annotation

GitHub Actions / JUnit Test Report

LoadBalancedRestTemplateBuilderIntegrationTests.shouldBuildLoadBalancedRestTemplate

Expected size: 1 but was: 0 in: []
Raw output
java.lang.AssertionError: 

Expected size: 1 but was: 0 in:
[]
	at org.springframework.cloud.client.loadbalancer.LoadBalancedRestTemplateBuilderIntegrationTests.shouldBuildLoadBalancedRestTemplate(LoadBalancedRestTemplateBuilderIntegrationTests.java:53)
assertThat(restTemplate.getInterceptors().get(0)).isInstanceOf(BlockingLoadBalancerInterceptor.class);
}

@SpringBootConfiguration
static class TestConfig {

@LoadBalanced
@Bean
RestTemplateBuilder restTemplateBuilder() {
return new RestTemplateBuilder();
}

}

}

0 comments on commit 84babc1

Please sign in to comment.