@Test(
      expectedExceptions = CitrusRuntimeException.class,
      expectedExceptionsMessageRegExp = "Invalid use of http and soap action builder")
  public void testSendBuilderWithSoapAndHttpMixed() {
    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>());
    MockTestDesigner builder =
        new MockTestDesigner(applicationContextMock) {
          @Override
          public void configure() {
            send("httpClient")
                .http()
                .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")
                .header("operation", "soapOperation")
                .soap();
          }
        };

    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.getEndpointUri(), "httpClient");
    Assert.assertEquals(action.getMessageType(), MessageType.XML.name());
  }
  @Test
  public void testSendBuilderWithEndpointName() {
    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>());
    MockTestDesigner builder =
        new MockTestDesigner(applicationContextMock) {
          @Override
          public void configure() {
            send("fooMessageEndpoint")
                .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");
          }
        };

    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.getEndpointUri(), "fooMessageEndpoint");
  }
  @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 testSendBuilderWithDictionary() {
    final DataDictionary dictionary = new NodeMappingDataDictionary();

    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>());

    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(messageEndpoint)
                .payload("{ \"TestRequest\": { \"Message\": \"?\" }}")
                .dictionary(dictionary);
          }
        };

    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.getDataDictionary(), dictionary);
  }
  @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 testHttpMethod() {
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(httpClient)
                .http()
                .method(HttpMethod.GET)
                .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");
          }
        };

    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(), httpClient);
    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(), 1L);
    Assert.assertEquals(
        messageBuilder.getMessageHeaders().get(HttpMessageHeaders.HTTP_REQUEST_METHOD),
        HttpMethod.GET.name());
  }
  @Test
  public void testSendBuilderWithMessageInstance() {
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(messageEndpoint)
                .message(new DefaultMessage("Foo").setHeader("operation", "foo"))
                .header("additional", "additionalValue");
          }
        };

    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(), StaticMessageContentBuilder.class);

    StaticMessageContentBuilder messageBuilder =
        (StaticMessageContentBuilder) action.getMessageBuilder();
    Assert.assertEquals(messageBuilder.getMessage().getPayload(String.class), "Foo");
    Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");
    Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "additionalValue");
  }
  @Test
  public void testFork() {
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(httpClient)
                .message(new DefaultMessage("Foo").setHeader("operation", "foo"))
                .header("additional", "additionalValue");

            send(httpClient)
                .message(new DefaultMessage("Foo").setHeader("operation", "foo"))
                .fork(true);
          }
        };

    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(), httpClient);
    Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);

    StaticMessageContentBuilder messageBuilder =
        (StaticMessageContentBuilder) action.getMessageBuilder();
    Assert.assertEquals(messageBuilder.getMessage().getPayload(String.class), "Foo");
    Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");
    Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 1L);
    Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "additionalValue");

    Assert.assertFalse(action.isForkMode());

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

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

    Assert.assertTrue(action.isForkMode());
  }
  @Test
  public void testXpathSupport() {
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(messageEndpoint)
                .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")
                .xpath("/TestRequest/Message", "Hello World!");
          }
        };

    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.assertTrue(action.getMessageBuilder() instanceof AbstractMessageContentBuilder);
    Assert.assertEquals(
        ((AbstractMessageContentBuilder) action.getMessageBuilder())
            .getMessageInterceptors()
            .size(),
        1);
    Assert.assertTrue(
        ((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0)
            instanceof XpathMessageConstructionInterceptor);
    Assert.assertEquals(
        ((XpathMessageConstructionInterceptor)
                ((AbstractMessageContentBuilder) action.getMessageBuilder())
                    .getMessageInterceptors()
                    .get(0))
            .getXPathExpressions()
            .get("/TestRequest/Message"),
        "Hello World!");
  }
  @Test
  public void testJsonPathSupport() {
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(messageEndpoint)
                .payload("{ \"TestRequest\": { \"Message\": \"?\" }}")
                .jsonPath("$.TestRequest.Message", "Hello World!");
          }
        };

    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.assertTrue(action.getMessageBuilder() instanceof AbstractMessageContentBuilder);
    Assert.assertEquals(
        ((AbstractMessageContentBuilder) action.getMessageBuilder())
            .getMessageInterceptors()
            .size(),
        1);
    Assert.assertTrue(
        ((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0)
            instanceof JsonPathMessageConstructionInterceptor);
    Assert.assertEquals(
        ((JsonPathMessageConstructionInterceptor)
                ((AbstractMessageContentBuilder) action.getMessageBuilder())
                    .getMessageInterceptors()
                    .get(0))
            .getJsonPathExpressions()
            .get("$.TestRequest.Message"),
        "Hello World!");
  }
  @Test
  public void testSendBuilderWithObjectMessageInstance() {
    final Message message = new DefaultMessage(new Integer(10)).setHeader("operation", "foo");
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(messageEndpoint).message(message);
          }
        };

    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(), StaticMessageContentBuilder.class);

    StaticMessageContentBuilder messageBuilder =
        (StaticMessageContentBuilder) action.getMessageBuilder();
    Assert.assertEquals(messageBuilder.getMessage().getPayload(), 10);
    Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);
    Assert.assertEquals(
        messageBuilder.getMessage().copyHeaders().size(), message.copyHeaders().size());
    Assert.assertEquals(
        messageBuilder.getMessage().getHeader(MessageHeaders.ID),
        message.getHeader(MessageHeaders.ID));
    Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");

    Message constructed =
        messageBuilder.buildMessageContent(new TestContext(), MessageType.PLAINTEXT.name());
    Assert.assertEquals(constructed.copyHeaders().size(), message.copyHeaders().size());
    Assert.assertEquals(constructed.getHeader("operation"), "foo");
    Assert.assertEquals(
        constructed.getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));
  }
  @Test
  public void testHttpRequestUriAndQueryParams() {
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(httpClient)
                .http()
                .uri("http://localhost:8080/")
                .queryParam("param1", "value1")
                .queryParam("param2", "value2")
                .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");
          }
        };

    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(), httpClient);
    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(DynamicEndpointUriResolver.ENDPOINT_URI_HEADER_NAME),
        "http://localhost:8080/");
    Assert.assertEquals(
        messageBuilder.getMessageHeaders().get(DynamicEndpointUriResolver.QUERY_PARAM_HEADER_NAME),
        "param1=value1,param2=value2");
  }
  @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 testSendBuilderExtractJsonPathFromPayload() {
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(messageEndpoint)
                .messageType(MessageType.JSON)
                .payload(
                    "{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}")
                .extractFromPayload("$.text", "text")
                .extractFromPayload("$.person", "language");
          }
        };

    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.getVariableExtractors().size(), 1);
    Assert.assertTrue(action.getVariableExtractors().get(0) instanceof JsonPathVariableExtractor);
    Assert.assertTrue(
        ((JsonPathVariableExtractor) action.getVariableExtractors().get(0))
            .getJsonPathExpressions()
            .containsKey("$.text"));
    Assert.assertTrue(
        ((JsonPathVariableExtractor) action.getVariableExtractors().get(0))
            .getJsonPathExpressions()
            .containsKey("$.person"));
  }
  @Test
  public void testSendBuilderExtractFromPayload() {
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(messageEndpoint)
                .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")
                .extractFromPayload("/TestRequest/Message", "text")
                .extractFromPayload("/TestRequest/Message/@lang", "language");
          }
        };

    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.getVariableExtractors().size(), 1);
    Assert.assertTrue(
        action.getVariableExtractors().get(0) instanceof XpathPayloadVariableExtractor);
    Assert.assertTrue(
        ((XpathPayloadVariableExtractor) action.getVariableExtractors().get(0))
            .getXpathExpressions()
            .containsKey("/TestRequest/Message"));
    Assert.assertTrue(
        ((XpathPayloadVariableExtractor) action.getVariableExtractors().get(0))
            .getXpathExpressions()
            .containsKey("/TestRequest/Message/@lang"));
  }
  @Test
  public void testSendBuilderExtractFromHeader() {
    MockTestDesigner builder =
        new MockTestDesigner(applicationContext) {
          @Override
          public void configure() {
            send(messageEndpoint)
                .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")
                .extractFromHeader("operation", "ops")
                .extractFromHeader("requestId", "id");
          }
        };

    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.getVariableExtractors().size(), 1);
    Assert.assertTrue(
        action.getVariableExtractors().get(0) instanceof MessageHeaderVariableExtractor);
    Assert.assertTrue(
        ((MessageHeaderVariableExtractor) action.getVariableExtractors().get(0))
            .getHeaderMappings()
            .containsKey("operation"));
    Assert.assertTrue(
        ((MessageHeaderVariableExtractor) action.getVariableExtractors().get(0))
            .getHeaderMappings()
            .containsKey("requestId"));
  }
  @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);
  }
  @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);
  }