Allow pipe as well as comma in function composition
This commit is contained in:
@@ -234,10 +234,11 @@ public class ContextFunctionCatalogAutoConfiguration {
|
||||
|
||||
private Object compose(String name, Map<String, Object> lookup,
|
||||
boolean hasInput) {
|
||||
name = name.replaceAll(",", "|");
|
||||
if (lookup.containsKey(name)) {
|
||||
return lookup.get(name);
|
||||
}
|
||||
String[] stages = StringUtils.tokenizeToStringArray(name, ",");
|
||||
String[] stages = StringUtils.delimitedListToStringArray(name, "|");
|
||||
Map<String, Object> source = !hasInput || stages.length <= 1 ? lookup
|
||||
: this.functions;
|
||||
if (stages.length == 0 && source.size() == 1) {
|
||||
|
||||
@@ -91,13 +91,25 @@ public class ContextFunctionPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compose() {
|
||||
public void composeWithComma() {
|
||||
processor.register(new FunctionRegistration<>(new Foos()).names("foos"));
|
||||
processor.register(new FunctionRegistration<>(new Bars()).names("bars"));
|
||||
@SuppressWarnings("unchecked")
|
||||
Function<Flux<Integer>, Flux<String>> foos = (Function<Flux<Integer>, Flux<String>>) processor
|
||||
.lookupFunction("foos,bars");
|
||||
assertThat(foos.apply(Flux.just(2)).blockFirst()).isEqualTo("Hello 4");
|
||||
assertThat(processor.getRegistration(foos).getNames()).containsExactly("foos|bars");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compose() {
|
||||
processor.register(new FunctionRegistration<>(new Foos()).names("foos"));
|
||||
processor.register(new FunctionRegistration<>(new Bars()).names("bars"));
|
||||
@SuppressWarnings("unchecked")
|
||||
Function<Flux<Integer>, Flux<String>> foos = (Function<Flux<Integer>, Flux<String>>) processor
|
||||
.lookupFunction("foos|bars");
|
||||
assertThat(foos.apply(Flux.just(2)).blockFirst()).isEqualTo("Hello 4");
|
||||
assertThat(processor.getRegistration(foos).getNames()).containsExactly("foos|bars");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user