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