Cleanup and additional test
This commit is contained in:
@@ -26,6 +26,8 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
|||||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||||
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration;
|
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@@ -37,6 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
public class HybridFunctionalRegistrationTests {
|
public class HybridFunctionalRegistrationTests {
|
||||||
|
|
||||||
// see https://github.com/spring-cloud/spring-cloud-function/issues/258
|
// see https://github.com/spring-cloud/spring-cloud-function/issues/258
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
@Test
|
@Test
|
||||||
public void testNoDoubleRegistrationInHybridMode() {
|
public void testNoDoubleRegistrationInHybridMode() {
|
||||||
ConfigurableApplicationContext context = FunctionalSpringApplication
|
ConfigurableApplicationContext context = FunctionalSpringApplication
|
||||||
@@ -46,9 +49,26 @@ public class HybridFunctionalRegistrationTests {
|
|||||||
|
|
||||||
assertThat(context.containsBean("function")).isTrue();
|
assertThat(context.containsBean("function")).isTrue();
|
||||||
assertThat(context.getBeansOfType(UppercaseFunction.class).size()).isEqualTo(1);
|
assertThat(context.getBeansOfType(UppercaseFunction.class).size()).isEqualTo(1);
|
||||||
assertThat((Object) catalog.lookup(Function.class, "hybridFunctionalRegistrationTests.UppercaseFunction")).isNotNull();
|
assertThat((Function) catalog.lookup("hybridFunctionalRegistrationTests.UppercaseFunction")).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
@Test
|
||||||
|
public void testMessageHeaderPropagationInFunctionalBeanRegistration() {
|
||||||
|
ConfigurableApplicationContext context = FunctionalSpringApplication
|
||||||
|
.run(UppercaseMessageFunction.class, "--spring.functional.enabled=false");
|
||||||
|
|
||||||
|
FunctionCatalog catalog = context.getBean(FunctionCatalog.class);
|
||||||
|
|
||||||
|
assertThat(context.containsBean("function")).isTrue();
|
||||||
|
assertThat(context.getBeansOfType(UppercaseMessageFunction.class).size()).isEqualTo(1);
|
||||||
|
Function f = catalog.lookup(Function.class, "hybridFunctionalRegistrationTests.UppercaseMessageFunction");
|
||||||
|
assertThat(f).isNotNull();
|
||||||
|
String result = (String) f.apply(MessageBuilder.withPayload("hello").setHeader("foo", "foo").setHeader("blah", "blah").build());
|
||||||
|
assertThat(result).isEqualTo("HELLO");
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
@Test
|
@Test
|
||||||
public void testNoDoubleRegistrationInHybridModeFluxedFunction() {
|
public void testNoDoubleRegistrationInHybridModeFluxedFunction() {
|
||||||
ConfigurableApplicationContext context = FunctionalSpringApplication
|
ConfigurableApplicationContext context = FunctionalSpringApplication
|
||||||
@@ -58,7 +78,7 @@ public class HybridFunctionalRegistrationTests {
|
|||||||
|
|
||||||
assertThat(context.containsBean("function")).isTrue();
|
assertThat(context.containsBean("function")).isTrue();
|
||||||
assertThat(context.getBeansOfType(UppercaseFluxFunction.class).size()).isEqualTo(1);
|
assertThat(context.getBeansOfType(UppercaseFluxFunction.class).size()).isEqualTo(1);
|
||||||
assertThat((Object) catalog.lookup(Function.class, "hybridFunctionalRegistrationTests.UppercaseFluxFunction")).isNotNull();
|
assertThat((Function) catalog.lookup(Function.class, "hybridFunctionalRegistrationTests.UppercaseFluxFunction")).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SpringBootConfiguration
|
@SpringBootConfiguration
|
||||||
@@ -74,6 +94,21 @@ public class HybridFunctionalRegistrationTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SpringBootConfiguration
|
||||||
|
@ImportAutoConfiguration({
|
||||||
|
ContextFunctionCatalogAutoConfiguration.class,
|
||||||
|
JacksonAutoConfiguration.class }
|
||||||
|
)
|
||||||
|
public static class UppercaseMessageFunction implements Function<Message<String>, String> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apply(Message<String> message) {
|
||||||
|
assertThat(message.getHeaders().get("foo")).isEqualTo("foo");
|
||||||
|
assertThat(message.getHeaders().get("blah")).isEqualTo("blah");
|
||||||
|
return message.getPayload().toUpperCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SpringBootConfiguration
|
@SpringBootConfiguration
|
||||||
@ImportAutoConfiguration({
|
@ImportAutoConfiguration({
|
||||||
ContextFunctionCatalogAutoConfiguration.class,
|
ContextFunctionCatalogAutoConfiguration.class,
|
||||||
|
|||||||
@@ -290,29 +290,11 @@ public class HttpPostIntegrationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void uppercaseSSE() throws Exception {
|
public void uppercaseSSE() throws Exception {
|
||||||
String s = this.rest.exchange(RequestEntity.post(new URI("/uppercase")).contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.body("[\"foo\",\"bar\"]"), String.class).getBody();
|
|
||||||
assertThat(this.rest.exchange(RequestEntity.post(new URI("/uppercase")).contentType(MediaType.APPLICATION_JSON)
|
assertThat(this.rest.exchange(RequestEntity.post(new URI("/uppercase")).contentType(MediaType.APPLICATION_JSON)
|
||||||
.body("[\"foo\",\"bar\"]"), String.class).getBody())
|
.body("[\"foo\",\"bar\"]"), String.class).getBody())
|
||||||
.isEqualTo(sse("(FOO)", "(BAR)"));
|
.isEqualTo(sse("(FOO)", "(BAR)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void uppercaseSSE() throws Exception {
|
|
||||||
// assertThat(this.rest.exchange(RequestEntity.post(new URI("/uppercase"))
|
|
||||||
// .accept(EVENT_STREAM).contentType(MediaType.APPLICATION_JSON)
|
|
||||||
// .body("[\"foo\",\"bar\"]"), String.class).getBody())
|
|
||||||
// .isEqualTo(sse("(FOO)", "(BAR)"));
|
|
||||||
//
|
|
||||||
//// String body = this.rest.exchange(RequestEntity.post(new URI("/uppercase")).contentType(MediaType.APPLICATION_JSON)
|
|
||||||
//// .body("[\"foo\",\"bar\"]"), String.class).getBody();
|
|
||||||
//
|
|
||||||
//// System.out.println(body);
|
|
||||||
//
|
|
||||||
//// assertThat(body)
|
|
||||||
//// .isEqualTo(sse("(FOO)", "(BAR)"));
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sum() throws Exception {
|
public void sum() throws Exception {
|
||||||
|
|
||||||
@@ -351,7 +333,6 @@ public class HttpPostIntegrationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String sse(String... values) {
|
private String sse(String... values) {
|
||||||
//return "data:" + StringUtils.arrayToDelimitedString(values, "\n\ndata:") + "\n\n";
|
|
||||||
return "[\"" + StringUtils.arrayToDelimitedString(values, "\",\"") + "\"]";
|
return "[\"" + StringUtils.arrayToDelimitedString(values, "\",\"") + "\"]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user