Skip to content

Commit e21dce1

Browse files
committed
Add integration test.
Signed-off-by: Olga Maciaszek-Sharma <olga.maciaszek-sharma@broadcom.com>
1 parent a16309e commit e21dce1

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2013-2025 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.gateway.server.mvc;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.boot.autoconfigure.SpringBootApplication;
23+
import org.springframework.boot.test.context.SpringBootTest;
24+
import org.springframework.boot.test.web.server.LocalServerPort;
25+
import org.springframework.cloud.gateway.server.mvc.filter.FilterAutoConfiguration;
26+
import org.springframework.cloud.gateway.server.mvc.test.HttpbinTestcontainers;
27+
import org.springframework.cloud.gateway.server.mvc.test.TestLoadBalancerConfig;
28+
import org.springframework.cloud.gateway.server.mvc.test.client.TestRestClient;
29+
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
30+
import org.springframework.test.context.ActiveProfiles;
31+
import org.springframework.test.context.ContextConfiguration;
32+
33+
/**
34+
* Integration tests for {@link FilterAutoConfiguration.LoadBalancerHandlerConfiguration}.
35+
*
36+
* @author Olga Maciaszek-Sharma
37+
*
38+
*/
39+
@SpringBootTest(classes = {ServerMvcLoadBalancerIntegrationTests.Config.class, FilterAutoConfiguration.class},
40+
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
41+
@ContextConfiguration(initializers = HttpbinTestcontainers.class)
42+
@ActiveProfiles("lb")
43+
public class ServerMvcLoadBalancerIntegrationTests {
44+
45+
@LocalServerPort
46+
int port;
47+
48+
@Autowired
49+
TestRestClient testRestClient;
50+
51+
@Test
52+
void shouldUseLbHandlerFunctionDefinitionToResolveHost() {
53+
testRestClient.get()
54+
.uri("http://localhost:" + port + "/test")
55+
.exchange().expectStatus().isOk();
56+
}
57+
58+
@SpringBootApplication
59+
@LoadBalancerClient(name = "httpbin", configuration = TestLoadBalancerConfig.Httpbin.class)
60+
static class Config {
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
spring:
2+
cloud:
3+
gateway:
4+
mvc:
5+
routes:
6+
- id: test
7+
uri: lb://httpbin
8+
predicates:
9+
- Path=/test/**
10+
filters:
11+
- StripPrefix=1

0 commit comments

Comments
 (0)