GH-409 Fix default discovery of functions
Fixed discovery of functions to ensure that even in cases where default function is found but it's type can not be determined such function is discarded. This effectively ensures that if the actual instance does not match the declared type such function is not treated as function. Resolves #409
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.function.context.catalog;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -53,7 +54,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class BeanFactoryAwareFunctionRegistryTests {
|
||||
|
||||
private FunctionCatalog configureCatalog() {
|
||||
ApplicationContext context = new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
return this.configureCatalog(SampleFunctionConfiguration.class);
|
||||
}
|
||||
|
||||
private FunctionCatalog configureCatalog(Class<?>... configClass) {
|
||||
ApplicationContext context = new SpringApplicationBuilder(configClass)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.main.lazy-initialization=true");
|
||||
FunctionCatalog catalog = context.getBean(FunctionCatalog.class);
|
||||
@@ -268,6 +273,15 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
result.getT3().subscribe(v -> System.out.println("=> 3: " + v));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SCF_GH_409ConfigurationTests() {
|
||||
FunctionCatalog catalog = this.configureCatalog(SCF_GH_409ConfigurationAsSupplier.class);
|
||||
assertThat((Object) catalog.lookup("")).isNull();
|
||||
|
||||
catalog = this.configureCatalog(SCF_GH_409ConfigurationAsFunction.class);
|
||||
assertThat((Object) catalog.lookup("")).isNull();
|
||||
}
|
||||
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
@@ -431,6 +445,46 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
}
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
public static class SCF_GH_409ConfigurationAsSupplier {
|
||||
|
||||
@Bean
|
||||
public Serializable blah() {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
private static class Foo implements Supplier<Object>, Serializable {
|
||||
|
||||
@Override
|
||||
public Object get() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
public static class SCF_GH_409ConfigurationAsFunction {
|
||||
|
||||
@Bean
|
||||
public Serializable blah() {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
private static class Foo implements Function<Object, Object>, Serializable {
|
||||
|
||||
@Override
|
||||
public Object apply(Object t) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class Person {
|
||||
private String name;
|
||||
private int id;
|
||||
|
||||
Reference in New Issue
Block a user