GH-550 Add support for wrapping value into Message if necessary
Resolves #550
This commit is contained in:
@@ -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 {
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user