Adds test for Supplier functions via config in server-webmvc

See gh-3646
This commit is contained in:
spencergibb
2025-02-05 11:39:57 -05:00
parent 6e6ceb5dff
commit f469733d9f
2 changed files with 23 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.gateway.server.mvc.config;
import java.util.Locale;
import java.util.function.Function;
import java.util.function.Supplier;
import org.junit.jupiter.api.Test;
@@ -63,6 +64,18 @@ public class FunctionHandlerConfigTests {
.isEqualTo("HELLO");
}
@Test
public void testSupplierFunctionWorks() {
restClient.get()
.uri("/supplierfunction")
.accept(MediaType.TEXT_PLAIN)
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.isEqualTo("hello");
}
@SpringBootConfiguration
@EnableAutoConfiguration
protected static class TestConfiguration {
@@ -72,6 +85,11 @@ public class FunctionHandlerConfigTests {
return s -> s.toUpperCase(Locale.ROOT);
}
@Bean
Supplier<String> hello() {
return () -> "hello";
}
}
}

View File

@@ -10,7 +10,11 @@ spring.cloud.gateway.mvc:
predicates:
- Path=/templatedfunction/{fnName}
- Method=POST
testsupplierfunction:
uri: fn:hello
predicates:
- Path=/supplierfunction
- Method=GET
logging:
level:
org.springframework.cloud.gateway.server.mvc: TRACE