HttpMessageContentBuilder extends AbstractMessageContentBuilder { @Override public Message buildMessageContent(final TestContext context, final String messageType) { final HttpMessage message = new HttpMessage(template); delegate.getMessageHeaders().putAll(template.getHeaders()); final Message constructed = delegate.buildMessageContent(context, messageType); message.setName(delegate.getMessageName()); message.setType(constructed.getType()); message.setPayload(constructed.getPayload()); message.setCookies(constructCookies(context)); replaceHeaders(constructed, message); return message; } HttpMessageContentBuilder(final HttpMessage httpMessage,
                                     final AbstractMessageContentBuilder delegate);   HttpMessageContentBuilder(final HttpMessage template,
                              final AbstractMessageContentBuilder delegate,
                              final CookieEnricher cookieEnricher); @Override Message buildMessageContent(final TestContext context, final String messageType); @Override String getMessageName(); @Override void setMessageName(final String messageName); @Override void setMessageHeaders(final Map<String, Object> messageHeaders); @Override List<String> getHeaderResources(); @Override void setHeaderResources(final List<String> headerResources); @Override List<String> getHeaderData(); @Override void setHeaderData(final List<String> headerData); @Override Map<String, Object> getMessageHeaders(); @Override Object buildMessagePayload(final TestContext context, final String messageType); AbstractMessageContentBuilder getDelegate(); HttpMessage getMessage();  }
@Test public void testDefaultMessageHeader() { final HttpMessageContentBuilder builder = getBuilder(); final Message builtMessage = builder.buildMessageContent(new TestContext(), MessageType.XML.name()); assertEquals(builtMessage.getHeaders().entrySet().size(), 3); assertEquals(message.getHeader(MessageHeaders.ID), builtMessage.getHeader(MessageHeaders.ID)); assertEquals(message.getHeader(MessageHeaders.TIMESTAMP), builtMessage.getHeader(MessageHeaders.TIMESTAMP)); assertEquals(builtMessage.getType(), MessageType.XML.toString()); }
@Test public void testHeaderVariableSubstitution() { final HttpMessageContentBuilder builder = getBuilder(); final TestContext testContext = new TestContext(); testContext.setVariable("testHeader", "foo"); testContext.setVariable("testValue", "bar"); message.setHeader("${testHeader}", "${testValue}"); final Message builtMessage = builder.buildMessageContent(testContext, String.valueOf(MessageType.XML)); assertEquals(builtMessage.getHeader("foo"), "bar"); }
@Test public void testTemplateHeadersArePreserved(){ final HttpMessageContentBuilder builder = getBuilder(); message.setHeader("foo", "bar"); final HttpMessage builtMessage = (HttpMessage) builder.buildMessageContent( new TestContext(), String.valueOf(MessageType.XML)); assertEquals(builtMessage.getHeader("foo"), "bar"); }
@Test public void testCookieEnricherIsCalledForTemplateCookies(){ final CookieEnricher cookieEnricherMock = mock(CookieEnricher.class); final TestContext testContextMock = mock(TestContext.class); final Cookie templateCookie = mock(Cookie.class); message.setCookies(new Cookie[]{templateCookie}); final Cookie enrichedCookie = mock(Cookie.class); when(cookieEnricherMock.enrich( eq(Collections.singletonList(templateCookie)), eq(testContextMock))) .thenReturn(Collections.singletonList(enrichedCookie)); final HttpMessageContentBuilder builder = new HttpMessageContentBuilder( message, new StaticMessageContentBuilder(message), cookieEnricherMock); final HttpMessage message = (HttpMessage) builder.buildMessageContent( testContextMock, String.valueOf(MessageType.XML)); assertEquals(message.getCookies().size(), 1); assertTrue(message.getCookies().contains(enrichedCookie)); }