Added test for the previously fixed NPE

This commit is contained in:
Oleg Zhurakousky
2019-09-16 10:14:43 +02:00
parent 0f635c32f7
commit 1723a40786
3 changed files with 31 additions and 12 deletions

View File

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

View File

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

View File

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