GH-1106 Fix RoutingFunction fail when "spring.cloud.function.definition" header contains a List value instead of a String value (GCP-specific)

Resolves #1106
Resolves #1146
This commit is contained in:
akenra
2024-05-12 21:23:52 +05:00
committed by Oleg Zhurakousky
parent 812c39eccb
commit faeb0f77ad
2 changed files with 79 additions and 5 deletions

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.function.context.config;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
@@ -98,7 +99,7 @@ public class RoutingFunctionTests {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testInvocationWithMessageAndHeader() {
public void testInvocationWithMessageAndStringHeader() {
FunctionCatalog functionCatalog = this.configureCatalog();
Function function = functionCatalog.lookup(RoutingFunction.FUNCTION_NAME);
assertThat(function).isNotNull();
@@ -107,6 +108,57 @@ public class RoutingFunctionTests {
assertThat(function.apply(message)).isEqualTo("olleh");
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testInvocationWithMessageAndListOfSingleElementHeader() {
FunctionCatalog functionCatalog = this.configureCatalog();
Function function = functionCatalog.lookup(RoutingFunction.FUNCTION_NAME);
assertThat(function).isNotNull();
Message<String> message = MessageBuilder.withPayload("hello")
.setHeader(FunctionProperties.PREFIX + ".definition", List.of("reverse"))
.build();
assertThat(function.apply(message)).isEqualTo("olleh");
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testCompositionWithMessageAndListOfMultipleElementsHeader() {
FunctionCatalog functionCatalog = this.configureCatalog();
Function function = functionCatalog.lookup(RoutingFunction.FUNCTION_NAME);
assertThat(function).isNotNull();
Message<String> message = MessageBuilder.withPayload("hello")
.setHeader(FunctionProperties.PREFIX + ".definition",
List.of("reverse", "uppercase"))
.build();
assertThat(function.apply(message)).isEqualTo("OLLEH");
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testInvocationWithMessageAndListOfSingleRoutingExpression() {
FunctionCatalog functionCatalog = this.configureCatalog();
Function function = functionCatalog.lookup(RoutingFunction.FUNCTION_NAME);
assertThat(function).isNotNull();
Message<String> message = MessageBuilder.withPayload("hello")
.setHeader(FunctionProperties.PREFIX + ".routing-expression",
List.of("'reverse'"))
.build();
assertThat(function.apply(message)).isEqualTo("olleh");
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testInvocationWithMessageAndListOfMultipleRoutingExpressions() {
FunctionCatalog functionCatalog = this.configureCatalog();
Function function = functionCatalog.lookup(RoutingFunction.FUNCTION_NAME);
assertThat(function).isNotNull();
Message<String> message = MessageBuilder.withPayload("hello")
.setHeader(FunctionProperties.PREFIX + ".routing-expression",
List.of("'uppercase'", "'reverse'"))
.build();
assertThat(function.apply(message)).isEqualTo("HELLO");
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testRoutingSimpleInputWithReactiveFunctionWithMessageHeader() {