From b28c7c5cfc6f9570f6f3943c75e586f73f6b251d Mon Sep 17 00:00:00 2001 From: Eric Bottard Date: Wed, 18 Mar 2020 16:03:00 +0100 Subject: [PATCH] Add a test for accept being multi-valued and tested in order --- ...BeanFactoryAwareFunctionRegistryTests.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spring-cloud-function-context/src/test/java/org/springframework/cloud/function/context/catalog/BeanFactoryAwareFunctionRegistryTests.java b/spring-cloud-function-context/src/test/java/org/springframework/cloud/function/context/catalog/BeanFactoryAwareFunctionRegistryTests.java index f18d92837..1d7e630b7 100644 --- a/spring-cloud-function-context/src/test/java/org/springframework/cloud/function/context/catalog/BeanFactoryAwareFunctionRegistryTests.java +++ b/spring-cloud-function-context/src/test/java/org/springframework/cloud/function/context/catalog/BeanFactoryAwareFunctionRegistryTests.java @@ -363,6 +363,21 @@ public class BeanFactoryAwareFunctionRegistryTests { assertThat(result instanceof Message).isFalse(); } + /** + * This test tests the fallback mechanism when an accept header has several values. + * The function produces Integer, which cannot be serialized by the default converter supporting text/plain + * (StringMessageConverter) but can by the one supporting application/json, which comes second. + */ + @Test + public void testMultipleOrderedAcceptValues() throws Exception { + FunctionCatalog catalog = this.configureCatalog(MultipleOrderedAcceptValuesConfiguration.class); + Function> function = catalog.lookup("beanFactoryAwareFunctionRegistryTests.MultipleOrderedAcceptValuesConfiguration", "text/plain,application/json"); + assertThat(function).isNotNull(); + Message result = function.apply("hello"); + assertThat(result.getPayload()).isEqualTo("5".getBytes("UTF-8")); + } + + @SuppressWarnings("unchecked") @Test public void testSerializationWithCompatibleWildcardSubtypeAcceptHeader() { @@ -749,4 +764,15 @@ public class BeanFactoryAwareFunctionRegistryTests { return result; } } + + @EnableAutoConfiguration + @Configuration + @Component + public static class MultipleOrderedAcceptValuesConfiguration implements Function { + + @Override + public Integer apply(String t) { + return t.length(); + } + } }