GH-467 Added initial support for GET method to FunctionEndpointInitializer
At the moment support is rudimentary as it does not include any type conversion, but neither does POST so it is consistent. Given that BeanFactoryAwareFunctionRegistry provides all that functionality already perhaps the proper fix with regard to converter would be to use it or part of it in place of InMemoryFunctionCatalog currently used. Resolves #467
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.cloud.function.web.function;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -90,11 +91,37 @@ public class FunctionEndpointInitializerTests {
|
||||
assertThat(response.getBody()).isEqualTo("desserts");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWithtFunction() throws Exception {
|
||||
FunctionalSpringApplication.run(ApplicationConfiguration.class);
|
||||
TestRestTemplate testRestTemplate = new TestRestTemplate();
|
||||
String port = System.getProperty("server.port");
|
||||
Thread.sleep(200);
|
||||
ResponseEntity<String> response = testRestTemplate
|
||||
.getForEntity(new URI("http://localhost:" + port + "/reverse/stressed"), String.class);
|
||||
assertThat(response.getBody()).isEqualTo("desserts");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWithtSupplier() throws Exception {
|
||||
FunctionalSpringApplication.run(ApplicationConfiguration.class);
|
||||
TestRestTemplate testRestTemplate = new TestRestTemplate();
|
||||
String port = System.getProperty("server.port");
|
||||
Thread.sleep(200);
|
||||
ResponseEntity<String> response = testRestTemplate
|
||||
.getForEntity(new URI("http://localhost:" + port + "/supplier"), String.class);
|
||||
assertThat(response.getBody()).isEqualTo("Jim Lahey");
|
||||
}
|
||||
|
||||
|
||||
@SpringBootConfiguration
|
||||
protected static class ApplicationConfiguration
|
||||
implements ApplicationContextInitializer<GenericApplicationContext> {
|
||||
|
||||
public Supplier<String> supplier() {
|
||||
return () -> "Jim Lahey";
|
||||
}
|
||||
|
||||
public Function<String, String> uppercase() {
|
||||
return s -> s.toUpperCase();
|
||||
}
|
||||
@@ -118,6 +145,9 @@ public class FunctionEndpointInitializerTests {
|
||||
applicationContext.registerBean("lowercase", FunctionRegistration.class,
|
||||
() -> new FunctionRegistration<>(lowercase())
|
||||
.type(FunctionType.from(String.class).to(String.class)));
|
||||
applicationContext.registerBean("supplier", FunctionRegistration.class,
|
||||
() -> new FunctionRegistration<>(supplier())
|
||||
.type(FunctionType.supplier(String.class)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user