コード例 #1
0
 @Test
 public void testFromMessageExtractStringPayload() throws Exception {
   Message<String> testMessage = MessageBuilder.withPayload("myPayloadStuff").build();
   String expected = "\"myPayloadStuff\"";
   OutboundJsonMessageMapper mapper = new OutboundJsonMessageMapper();
   mapper.setShouldExtractPayload(true);
   String result = mapper.fromMessage(testMessage);
   assertEquals(expected, result);
 }
コード例 #2
0
 @Test
 public void testFromMessageWithHeadersAndStringPayload() throws Exception {
   Message<String> testMessage = MessageBuilder.withPayload("myPayloadStuff").build();
   OutboundJsonMessageMapper mapper = new OutboundJsonMessageMapper();
   String result = mapper.fromMessage(testMessage);
   assertTrue(result.contains("\"headers\":{"));
   assertTrue(result.contains("\"$timestamp\":" + testMessage.getHeaders().getTimestamp()));
   assertTrue(result.contains("\"$id\":\"" + testMessage.getHeaders().getId() + "\""));
   assertTrue(result.contains("\"payload\":\"myPayloadStuff\""));
 }
コード例 #3
0
 @Test
 public void testFromMessageExtractBeanPayload() throws Exception {
   TestBean payload = new TestBean();
   Message<TestBean> testMessage = MessageBuilder.withPayload(payload).build();
   OutboundJsonMessageMapper mapper = new OutboundJsonMessageMapper();
   mapper.setShouldExtractPayload(true);
   String result = mapper.fromMessage(testMessage);
   assertTrue(!result.contains("headers"));
   TestBean parsedPayload = objectMapper.readValue(result, TestBean.class);
   assertEquals(payload, parsedPayload);
 }
コード例 #4
0
 @Test
 public void testFromMessageWithHeadersAndBeanPayload() throws Exception {
   TestBean payload = new TestBean();
   Message<TestBean> testMessage = MessageBuilder.withPayload(payload).build();
   OutboundJsonMessageMapper mapper = new OutboundJsonMessageMapper();
   String result = mapper.fromMessage(testMessage);
   assertTrue(result.contains("\"headers\":{"));
   assertTrue(result.contains("\"$timestamp\":" + testMessage.getHeaders().getTimestamp()));
   assertTrue(result.contains("\"$id\":\"" + testMessage.getHeaders().getId() + "\""));
   TestBean parsedPayload = extractJsonPayloadToTestBean(result);
   assertEquals(payload, parsedPayload);
 }