Fixed README generation and polished few tests
This commit is contained in:
@@ -430,6 +430,7 @@ public class BeanFactoryAwareFunctionRegistry
|
||||
}
|
||||
}
|
||||
|
||||
// Outputs will be converted only if we're told how (via acceptedOutputMimeTypes), otherwise output returned as is.
|
||||
if (!ObjectUtils.isEmpty(this.acceptedOutputMimeTypes)) {
|
||||
result = result instanceof Publisher
|
||||
? this.convertOutputPublisherIfNecessary((Publisher<?>) result, this.acceptedOutputMimeTypes)
|
||||
@@ -462,7 +463,7 @@ public class BeanFactoryAwareFunctionRegistry
|
||||
}
|
||||
convertedValue = Tuples.fromArray(convertedInputArray);
|
||||
}
|
||||
else {
|
||||
else if (value != null) {
|
||||
List<MimeType> acceptedContentTypes = MimeTypeUtils.parseMimeTypes(acceptedOutputMimeTypes[0].toString());
|
||||
|
||||
convertedValue = acceptedContentTypes.stream()
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -78,6 +79,28 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
assertThat(messageResult.get(1).getPayload()).isEqualTo("\"UPPERCASEFLUX2\"".getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConsumerFunction() { // function that returns Void, effectively a Consumer
|
||||
FunctionCatalog catalog = this.configureCatalog();
|
||||
|
||||
Function<String, Void> consumerFunction = catalog.lookup("consumerFunction");
|
||||
assertThat(consumerFunction.apply("hello")).isNull();
|
||||
|
||||
Function<Message<byte[]>, Void> consumerFunctionAsMessageA = catalog.lookup("consumerFunction");
|
||||
assertThat(consumerFunctionAsMessageA.apply(new GenericMessage<byte[]>("\"hello\"".getBytes()))).isNull();
|
||||
|
||||
Function<Message<byte[]>, Void> consumerFunctionAsMessageB = catalog.lookup("consumerFunction", "application/json");
|
||||
assertThat(consumerFunctionAsMessageB.apply(new GenericMessage<byte[]>("\"hello\"".getBytes()))).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageToPojoConversion() {
|
||||
FunctionCatalog catalog = this.configureCatalog();
|
||||
Function<Message<String>, Person> uppercasePerson = catalog.lookup("uppercasePerson");
|
||||
Person person = uppercasePerson.apply(MessageBuilder.withPayload("{\"name\":\"bill\",\"id\":2}").build());
|
||||
assertThat(person.getName()).isEqualTo("BILL");
|
||||
}
|
||||
|
||||
/*
|
||||
* When invoking imperative function as reactive the rules are
|
||||
* - the input wrapper must match the output wrapper (e.g., <Flux, Flux> or <Mono, Mono>)
|
||||
@@ -249,6 +272,13 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
@Configuration
|
||||
protected static class SampleFunctionConfiguration {
|
||||
|
||||
@Bean
|
||||
public Function<Person, Person> uppercasePerson() {
|
||||
return person -> {
|
||||
return new Person(person.getName().toUpperCase(), person.getId());
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Supplier<String> numberword() {
|
||||
return () -> "one";
|
||||
@@ -267,6 +297,14 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
return v -> v.toUpperCase();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<String, Void> consumerFunction() {
|
||||
return v -> {
|
||||
System.out.println("Value: " + v);
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<Flux<String>, Flux<String>> uppercaseFlux() {
|
||||
return flux -> flux.map(v -> v.toUpperCase());
|
||||
@@ -392,10 +430,13 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
}
|
||||
}
|
||||
|
||||
private static class Person {
|
||||
public static class Person {
|
||||
private String name;
|
||||
private int id;
|
||||
Person(String name, int id) {
|
||||
public Person() {
|
||||
|
||||
}
|
||||
public Person(String name, int id) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user