Enhance test to validate HTTP header propagation
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.function.test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
@@ -44,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@FunctionalSpringBootTest(classes = ApplicationConfiguration.class, webEnvironment = WebEnvironment.NONE, properties = {
|
||||
@@ -63,8 +65,11 @@ public class FunctionalExporterTests {
|
||||
|
||||
private static ConfigurableApplicationContext context;
|
||||
|
||||
private static Map<String, Object> headers = new HashMap<>();
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
headers.clear();
|
||||
String port = "" + SocketUtils.findAvailableTcpPort();
|
||||
System.setProperty("server.port", port);
|
||||
System.setProperty("my.port", port);
|
||||
@@ -77,6 +82,7 @@ public class FunctionalExporterTests {
|
||||
|
||||
@AfterClass
|
||||
public static void close() {
|
||||
headers.clear();
|
||||
System.clearProperty("server.port");
|
||||
if (context != null) {
|
||||
context.close();
|
||||
@@ -92,6 +98,8 @@ public class FunctionalExporterTests {
|
||||
// It completed
|
||||
assertThat(FunctionalExporterTests.app.inputs).contains("HELLO");
|
||||
assertThat(this.forwarder.isOk()).isTrue();
|
||||
assertThat(headers.containsKey("scf-sink-url"));
|
||||
assertThat(headers.containsKey("scf-func-name"));
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@@ -99,8 +107,11 @@ public class FunctionalExporterTests {
|
||||
implements ApplicationContextInitializer<GenericApplicationContext> {
|
||||
|
||||
Function<Message<Person>, Message<String>> uppercase() {
|
||||
return value -> MessageBuilder.withPayload(value.getPayload().getName().toUpperCase())
|
||||
return value -> {
|
||||
headers.putAll(value.getHeaders());
|
||||
return MessageBuilder.withPayload(value.getPayload().getName().toUpperCase())
|
||||
.copyHeaders(value.getHeaders()).build();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user