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