GH-550 Add support for wrapping value into Message if necessary

Resolves #550
This commit is contained in:
Oleg Zhurakousky
2020-06-19 15:26:28 +02:00
parent 62e8132fce
commit 98fd8ca9cd
3 changed files with 39 additions and 1 deletions

View File

@@ -471,6 +471,40 @@ public class BeanFactoryAwareFunctionRegistryTests {
registry.register(e);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testValueWrappedInMessageIfNecessary() {
FunctionCatalog catalog = this.configureCatalog(PojoToMessageFunctionCompositionConfiguration.class);
Function f = catalog.lookup("uppercase|echo");
assertThat(f.apply("hello")).isEqualTo("HELLO");
f = catalog.lookup("toJson|uppercasePerson");
assertThat(f.apply("Bubbles")).isEqualTo("BUBBLES");
}
@EnableAutoConfiguration
public static class PojoToMessageFunctionCompositionConfiguration {
@Bean
public Function<String, String> uppercase() {
return v -> v.toUpperCase();
}
@Bean
public Function<Message<String>, String> echo() {
return v -> v.getPayload();
}
@Bean
public Function<String, String> toJson() {
return v -> "{\"id\":1, \"name\":\"" + v + "\"}";
}
@Bean
public Function<Message<Person>, String> uppercasePerson() {
return v -> v.getPayload().getName().toUpperCase();
}
}
@EnableAutoConfiguration
public static class EmptyConfiguration {

View File

@@ -91,7 +91,7 @@ public class SimpleFunctionRegistryTests {
catalog.register(registration);
FunctionInvocationWrapper lookedUpFunction = catalog.lookup("hello");
assertThat(lookedUpFunction).isNotNull(); // becouse we only have one and can look it up with any name
assertThat(lookedUpFunction).isNotNull(); // because we only have one and can look it up with any name
FunctionRegistration<TestFunction> registration2 = new FunctionRegistration<>(
function, "foo2").type(FunctionType.of(TestFunction.class));
catalog.register(registration2);