Add a test for accept being multi-valued and tested in order

This commit is contained in:
Eric Bottard
2020-03-18 16:03:00 +01:00
committed by Oleg Zhurakousky
parent fb095f7ac3
commit b28c7c5cfc

View File

@@ -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<String, Message<byte[]>> function = catalog.lookup("beanFactoryAwareFunctionRegistryTests.MultipleOrderedAcceptValuesConfiguration", "text/plain,application/json");
assertThat(function).isNotNull();
Message<byte[]> 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<String, Integer> {
@Override
public Integer apply(String t) {
return t.length();
}
}
}