Allow pipe as well as comma in function composition

This commit is contained in:
Dave Syer
2018-03-16 07:59:01 -04:00
parent 8ab4d61bb4
commit 47f86671ca
2 changed files with 15 additions and 2 deletions

View File

@@ -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) {

View File

@@ -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