Added POJO test for 'lite' server scenario

polishing
This commit is contained in:
Oleg Zhurakousky
2018-10-22 18:34:49 +02:00
parent 263fe1c632
commit 9e2cbf49dd
3 changed files with 46 additions and 6 deletions

View File

@@ -252,7 +252,7 @@ public class RequestProcessor {
private final Supplier<Publisher<?>> supplier;
private MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
private final MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
private HttpHeaders headers = new HttpHeaders();

View File

@@ -47,6 +47,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.web.reactive.function.server.HandlerStrategies;
import org.springframework.web.reactive.function.server.RouterFunction;
@@ -179,6 +180,7 @@ class FunctionEndpointInitializer
System.err.println("JVM running for " + uptime + "ms");
}
catch (Throwable e) {
// ignore
}
}
@@ -218,9 +220,7 @@ class FunctionEndpointFactory {
logger.info("Found functions: " + names);
if (handler != null) {
logger.info("Configured function: " + handler);
if (!names.contains(handler)) {
throw new IllegalStateException("Cannot locate function: " + handler);
}
Assert.isTrue(names.contains(handler), "Cannot locate function: " + handler);
return catalog.lookup(Function.class, handler);
}
return catalog.lookup(Function.class, names.iterator().next());

View File

@@ -40,6 +40,7 @@ import static org.junit.Assert.assertTrue;
/**
*
* @author Dave Syer
* @author Oleg Zhurakousky
*
*/
@@ -55,6 +56,7 @@ public class HeadersToMessageTests {
@Test
public void testBodyAndCustomHeaderFromMessagePropagation() throws Exception {
// test POJO paylod
ResponseEntity<String> postForEntity = rest.postForEntity(
new URI("/functions/employee"), "{\"name\":\"Bob\",\"age\":25}",
String.class);
@@ -63,13 +65,23 @@ public class HeadersToMessageTests {
assertEquals("application/xml",
postForEntity.getHeaders().get("x-content-type").get(0));
assertEquals("bar", postForEntity.getHeaders().get("foo").get(0));
// test simple type payload
postForEntity = rest.postForEntity(
new URI("/functions/string"), "{\"name\":\"Bob\",\"age\":25}",
String.class);
assertEquals("{\"name\":\"Bob\",\"age\":25}", postForEntity.getBody());
assertTrue(postForEntity.getHeaders().containsKey("x-content-type"));
assertEquals("application/xml",
postForEntity.getHeaders().get("x-content-type").get(0));
assertEquals("bar", postForEntity.getHeaders().get("foo").get(0));
}
@EnableAutoConfiguration
@org.springframework.boot.test.context.TestConfiguration
protected static class TestConfiguration {
@Bean({ "employee" })
public Function<Message<String>, Message<String>> function() {
@Bean({ "string" })
public Function<Message<String>, Message<String>> functiono() {
return request -> {
Message<String> message = MessageBuilder.withPayload(request.getPayload())
.setHeader("X-Content-Type", "application/xml")
@@ -77,5 +89,33 @@ public class HeadersToMessageTests {
return message;
};
}
@Bean({ "employee" })
public Function<Message<Employee>, Message<Employee>> function1() {
return request -> {
Message<Employee> message = MessageBuilder.withPayload(request.getPayload())
.setHeader("X-Content-Type", "application/xml")
.setHeader("foo", "bar").build();
return message;
};
}
}
@SuppressWarnings("unused") // used by json converter
private static class Employee {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
}