GH-444 Fixed support for default function lookup
Given that function can be looked up with no definition, the fallback alternative should be 'spring.cloud.function.definition' property Resolves #444
This commit is contained in:
@@ -125,6 +125,9 @@ public class BeanFactoryAwareFunctionRegistry
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T lookup(String definition, String... acceptedOutputTypes) {
|
||||
if (!StringUtils.hasText(definition)) {
|
||||
definition = this.applicationContext.getEnvironment().getProperty("spring.cloud.function.definition");
|
||||
}
|
||||
Object function = this.proxyInvokerIfNecessary((FunctionInvocationWrapper) this.compose(null, definition, acceptedOutputTypes));
|
||||
return (T) function;
|
||||
}
|
||||
|
||||
@@ -69,6 +69,27 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
return catalog;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultLookup() throws Exception {
|
||||
FunctionCatalog catalog = this.configureCatalog();
|
||||
Object function = catalog.lookup("");
|
||||
assertThat(function).isNull();
|
||||
//==
|
||||
System.setProperty("spring.cloud.function.definition", "uppercase");
|
||||
function = catalog.lookup("");
|
||||
assertThat(function).isNotNull();
|
||||
Field field = ReflectionUtils.findField(FunctionInvocationWrapper.class, "composed");
|
||||
field.setAccessible(true);
|
||||
assertThat(((boolean) field.get(function))).isFalse();
|
||||
//==
|
||||
System.setProperty("spring.cloud.function.definition", "uppercase|uppercaseFlux");
|
||||
function = catalog.lookup("");
|
||||
assertThat(function).isNotNull();
|
||||
field = ReflectionUtils.findField(FunctionInvocationWrapper.class, "composed");
|
||||
field.setAccessible(true);
|
||||
assertThat(((boolean) field.get(function))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImperativeFunction() {
|
||||
FunctionCatalog catalog = this.configureCatalog();
|
||||
@@ -530,6 +551,7 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person: " + name + "/" + id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user