@Test
  public void testSendBuilderWithHeaders() {
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(messageEndpoint)
                .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")
                .header("operation", "foo")
                .header("language", "eng");
          }
        };

    builder.configure();

    TestCase test = builder.getTestCase();
    Assert.assertEquals(test.getActionCount(), 1);
    Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);

    SendMessageAction action = ((SendMessageAction) test.getActions().get(0));
    Assert.assertEquals(action.getName(), "send");

    Assert.assertEquals(action.getEndpoint(), messageEndpoint);
    Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);

    PayloadTemplateMessageBuilder messageBuilder =
        (PayloadTemplateMessageBuilder) action.getMessageBuilder();
    Assert.assertEquals(
        messageBuilder.getPayloadData(),
        "<TestRequest><Message>Hello World!</Message></TestRequest>");
    Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 2L);
    Assert.assertEquals(messageBuilder.getMessageHeaders().get("operation"), "foo");
    Assert.assertEquals(messageBuilder.getMessageHeaders().get("language"), "eng");
  }
  @Test
  public void testSendBuilderWithPayloadResource() throws IOException {
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(messageEndpoint).payload(resource);
          }
        };

    reset(resource);
    when(resource.getInputStream())
        .thenReturn(new ByteArrayInputStream("somePayloadData".getBytes()));
    builder.configure();

    TestCase test = builder.getTestCase();
    Assert.assertEquals(test.getActionCount(), 1);
    Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);

    SendMessageAction action = ((SendMessageAction) test.getActions().get(0));
    Assert.assertEquals(action.getName(), "send");

    Assert.assertEquals(action.getEndpoint(), messageEndpoint);
    Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);

    PayloadTemplateMessageBuilder messageBuilder =
        (PayloadTemplateMessageBuilder) action.getMessageBuilder();
    Assert.assertEquals(messageBuilder.getPayloadData(), "somePayloadData");
    Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);
  }
  @Test
  public void testSendBuilderWithPayloadModelExplicitMarshaller() {
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(messageEndpoint).payload(new TestRequest("Hello Citrus!"), marshaller);
          }
        };

    builder.configure();

    TestCase test = builder.getTestCase();
    Assert.assertEquals(test.getActionCount(), 1);
    Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);

    SendMessageAction action = ((SendMessageAction) test.getActions().get(0));
    Assert.assertEquals(action.getName(), "send");

    Assert.assertEquals(action.getEndpoint(), messageEndpoint);
    Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);

    PayloadTemplateMessageBuilder messageBuilder =
        (PayloadTemplateMessageBuilder) action.getMessageBuilder();
    Assert.assertEquals(
        messageBuilder.getPayloadData(),
        "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");
    Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);
  }
  @Test
  public void testSendBuilderWithPayloadModelExplicitMarshallerName() {
    reset(applicationContextMock);
    when(applicationContextMock.getBean(TestActionListeners.class))
        .thenReturn(new TestActionListeners());
    when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class))
        .thenReturn(new HashMap<String, SequenceBeforeTest>());
    when(applicationContextMock.getBeansOfType(SequenceAfterTest.class))
        .thenReturn(new HashMap<String, SequenceAfterTest>());
    when(applicationContextMock.getBean("myMarshaller", Marshaller.class)).thenReturn(marshaller);
    MockTestDesigner builder =
        new MockTestDesigner(applicationContextMock) {
          @Override
          public void configure() {
            send(messageEndpoint).payload(new TestRequest("Hello Citrus!"), "myMarshaller");
          }
        };

    builder.configure();

    TestCase test = builder.getTestCase();
    Assert.assertEquals(test.getActionCount(), 1);
    Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);

    SendMessageAction action = ((SendMessageAction) test.getActions().get(0));
    Assert.assertEquals(action.getName(), "send");

    Assert.assertEquals(action.getEndpoint(), messageEndpoint);
    Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);

    PayloadTemplateMessageBuilder messageBuilder =
        (PayloadTemplateMessageBuilder) action.getMessageBuilder();
    Assert.assertEquals(
        messageBuilder.getPayloadData(),
        "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");
    Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);
  }
  @Test
  public void testSendBuilderWithHeaderDataResource() throws IOException {
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(messageEndpoint)
                .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")
                .header(resource);

            send(messageEndpoint)
                .message(
                    new DefaultMessage(
                        "<TestRequest><Message>Hello World!</Message></TestRequest>"))
                .header(resource);
          }
        };

    reset(resource);
    when(resource.getInputStream())
        .thenReturn(new ByteArrayInputStream("someHeaderData".getBytes()))
        .thenReturn(new ByteArrayInputStream("otherHeaderData".getBytes()));
    builder.configure();

    TestCase test = builder.getTestCase();
    Assert.assertEquals(test.getActionCount(), 2);
    Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);
    Assert.assertEquals(test.getActions().get(1).getClass(), SendMessageAction.class);

    SendMessageAction action = ((SendMessageAction) test.getActions().get(0));
    Assert.assertEquals(action.getName(), "send");

    Assert.assertEquals(action.getEndpoint(), messageEndpoint);
    Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);

    PayloadTemplateMessageBuilder messageBuilder =
        (PayloadTemplateMessageBuilder) action.getMessageBuilder();
    Assert.assertEquals(
        messageBuilder.getPayloadData(),
        "<TestRequest><Message>Hello World!</Message></TestRequest>");
    Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);
    Assert.assertEquals(messageBuilder.getHeaderData().size(), 1L);
    Assert.assertEquals(messageBuilder.getHeaderData().get(0), "someHeaderData");
    Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);

    action = ((SendMessageAction) test.getActions().get(1));
    Assert.assertEquals(action.getName(), "send");

    Assert.assertEquals(action.getEndpoint(), messageEndpoint);
    Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);

    StaticMessageContentBuilder staticMessageBuilder =
        (StaticMessageContentBuilder) action.getMessageBuilder();
    Assert.assertEquals(
        staticMessageBuilder.getMessage().getPayload(String.class),
        "<TestRequest><Message>Hello World!</Message></TestRequest>");
    Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);
    Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 1L);
    Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "otherHeaderData");
    Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);
  }
  @Test
  public void testSendBuilderWithMultipleHeaderData() {
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(messageEndpoint)
                .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")
                .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")
                .header("<Header><Name>operation</Name><Value>foo2</Value></Header>");

            send(messageEndpoint)
                .message(
                    new DefaultMessage(
                        "<TestRequest><Message>Hello World!</Message></TestRequest>"))
                .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")
                .header("<Header><Name>operation</Name><Value>foo2</Value></Header>");
          }
        };

    builder.configure();

    TestCase test = builder.getTestCase();
    Assert.assertEquals(test.getActionCount(), 2);
    Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);
    Assert.assertEquals(test.getActions().get(1).getClass(), SendMessageAction.class);

    SendMessageAction action = ((SendMessageAction) test.getActions().get(0));
    Assert.assertEquals(action.getName(), "send");

    Assert.assertEquals(action.getEndpoint(), messageEndpoint);
    Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);

    PayloadTemplateMessageBuilder messageBuilder =
        (PayloadTemplateMessageBuilder) action.getMessageBuilder();
    Assert.assertEquals(
        messageBuilder.getPayloadData(),
        "<TestRequest><Message>Hello World!</Message></TestRequest>");
    Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);
    Assert.assertEquals(messageBuilder.getHeaderData().size(), 2L);
    Assert.assertEquals(
        messageBuilder.getHeaderData().get(0),
        "<Header><Name>operation</Name><Value>foo1</Value></Header>");
    Assert.assertEquals(
        messageBuilder.getHeaderData().get(1),
        "<Header><Name>operation</Name><Value>foo2</Value></Header>");
    Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);

    action = ((SendMessageAction) test.getActions().get(1));
    Assert.assertEquals(action.getName(), "send");

    Assert.assertEquals(action.getEndpoint(), messageEndpoint);
    Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);

    StaticMessageContentBuilder staticMessageBuilder =
        (StaticMessageContentBuilder) action.getMessageBuilder();
    Assert.assertEquals(
        staticMessageBuilder.getMessage().getPayload(String.class),
        "<TestRequest><Message>Hello World!</Message></TestRequest>");
    Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);
    Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 2L);
    Assert.assertEquals(
        staticMessageBuilder.getHeaderData().get(0),
        "<Header><Name>operation</Name><Value>foo1</Value></Header>");
    Assert.assertEquals(
        staticMessageBuilder.getHeaderData().get(1),
        "<Header><Name>operation</Name><Value>foo2</Value></Header>");
    Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);
  }