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

@@ -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;
}
}
}