Added test for the previously fixed NPE
This commit is contained in:
@@ -423,12 +423,11 @@ public class FunctionConfiguration {
|
||||
.filter(clazz -> AnnotationUtils.findAnnotation(clazz, BindingProvider.class) != null)
|
||||
.findFirst().isPresent();
|
||||
if (!bindingProvider
|
||||
&& ObjectUtils.isEmpty(applicationContext.getBeanNamesForAnnotation(EnableBinding.class))) {
|
||||
this.determineFunctionName(functionCatalog, environment);
|
||||
&& ObjectUtils.isEmpty(applicationContext.getBeanNamesForAnnotation(EnableBinding.class))
|
||||
&& this.determineFunctionName(functionCatalog, environment)) {
|
||||
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) applicationContext.getBeanFactory();
|
||||
RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(BindableFunctionProxyFactory.class);
|
||||
FunctionInvocationWrapper function = functionCatalog
|
||||
.lookup(streamFunctionProperties.getDefinition());
|
||||
FunctionInvocationWrapper function = functionCatalog.lookup(streamFunctionProperties.getDefinition());
|
||||
if (function != null) {
|
||||
if (function.isSupplier()) {
|
||||
this.inputCount = 0;
|
||||
@@ -447,7 +446,6 @@ public class FunctionConfiguration {
|
||||
registry.registerBeanDefinition(streamFunctionProperties.getDefinition() + "_binding",
|
||||
rootBeanDefinition);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,7 +457,7 @@ public class FunctionConfiguration {
|
||||
return this.outputCount;
|
||||
}
|
||||
|
||||
private void determineFunctionName(FunctionCatalog catalog, Environment environment) {
|
||||
private boolean determineFunctionName(FunctionCatalog catalog, Environment environment) {
|
||||
String definition = streamFunctionProperties.getDefinition();
|
||||
if (!StringUtils.hasText(definition)) {
|
||||
definition = environment.getProperty("spring.cloud.function.definition");
|
||||
@@ -474,6 +472,7 @@ public class FunctionConfiguration {
|
||||
else {
|
||||
streamFunctionProperties.setDefinition(((FunctionInspector) functionCatalog).getName(functionCatalog.lookup("")));
|
||||
}
|
||||
return StringUtils.hasText(streamFunctionProperties.getDefinition());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -73,13 +73,12 @@ public class StreamFunctionProperties {
|
||||
}
|
||||
|
||||
public void setDefinition(String definition) {
|
||||
if (definition == null) {
|
||||
return;
|
||||
if (StringUtils.hasText(definition)) {
|
||||
this.composeFrom = definition.startsWith("|");
|
||||
this.composeTo = definition.endsWith("|");
|
||||
this.definition = this.composeFrom ? definition.substring(1)
|
||||
: (this.composeTo ? definition.substring(0, definition.length() - 1) : definition);
|
||||
}
|
||||
this.composeFrom = definition.startsWith("|");
|
||||
this.composeTo = definition.endsWith("|");
|
||||
this.definition = this.composeFrom ? definition.substring(1)
|
||||
: (this.composeTo ? definition.substring(0, definition.length() - 1) : definition);
|
||||
}
|
||||
|
||||
BindingServiceProperties getBindingServiceProperties() {
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -53,6 +54,21 @@ public class ImplicitFunctionBindingTests {
|
||||
System.clearProperty("spring.cloud.function.definition");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyConfiguration() {
|
||||
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(
|
||||
EmptyConfiguration.class))
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.jmx.enabled=false")) {
|
||||
context.getBean(InputDestination.class);
|
||||
}
|
||||
catch (Exception e) { // should not fail
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleFunctionWithStreamProperty() {
|
||||
|
||||
@@ -291,4 +307,9 @@ public class ImplicitFunctionBindingTests {
|
||||
}
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
public static class EmptyConfiguration {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user