GH-429 Fixed logic behind 'composed' flag
Fixed and simplified logic behind 'composed' flag in FunctionInvocationWrapper and added additional test Resolves #429
This commit is contained in:
@@ -449,11 +449,7 @@ public class BeanFactoryAwareFunctionRegistry
|
||||
|
||||
FunctionInvocationWrapper(Object target, Type functionType, String functionDefinition, String... acceptedOutputMimeTypes) {
|
||||
this.target = target;
|
||||
this.composed = target instanceof RoutingFunction ||
|
||||
(!target.getClass().getName().contains("$$EnhancerBySpringCGLIB")
|
||||
&& !AopUtils.isAopProxy(target) && !AopUtils.isJdkDynamicProxy(target)
|
||||
&& target.getClass().getDeclaredFields().length > 1
|
||||
&& target.getClass().isSynthetic());
|
||||
this.composed = functionDefinition.contains("|") || target instanceof RoutingFunction;
|
||||
this.functionType = functionType;
|
||||
this.acceptedOutputMimeTypes = acceptedOutputMimeTypes;
|
||||
this.functionDefinition = functionDefinition;
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.cloud.function.context.catalog;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -36,6 +37,7 @@ import reactor.util.function.Tuples;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
import org.springframework.cloud.function.context.catalog.BeanFactoryAwareFunctionRegistry.FunctionInvocationWrapper;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -43,6 +45,8 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -289,9 +293,18 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
|
||||
Person person = uppercasePerson.apply("{\"name\":\"bill\",\"id\":2}");
|
||||
assertThat(person.getName()).isEqualTo("BILL");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SCF_GH_429ConfigurationTests() throws Exception {
|
||||
FunctionCatalog catalog = this.configureCatalog(MyFunction.class);
|
||||
FunctionInvocationWrapper function = catalog.lookup("beanFactoryAwareFunctionRegistryTests.MyFunction");
|
||||
assertThat(function).isNotNull();
|
||||
Field f = ReflectionUtils.findField(FunctionInvocationWrapper.class, "composed");
|
||||
f.setAccessible(true);
|
||||
boolean composed = (boolean) f.get(function);
|
||||
assertThat(composed).isFalse();
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
@@ -521,4 +534,16 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
return "Person: " + name + "/" + id;
|
||||
}
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
@Component
|
||||
public static class MyFunction implements Function<String, String> {
|
||||
|
||||
@Override
|
||||
public String apply(String t) {
|
||||
return t;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user