How to use SendMessageAction method of com.consol.citrus.actions.SendMessageAction class

Best Citrus code snippet using com.consol.citrus.actions.SendMessageAction.SendMessageAction

Source:SendMessageTestRunnerTest.java Github

copy

Full Screen

...14 * limitations under the License.15 */16package com.consol.citrus.dsl.runner;17import com.consol.citrus.TestCase;18import com.consol.citrus.actions.SendMessageAction;19import com.consol.citrus.container.SequenceAfterTest;20import com.consol.citrus.container.SequenceBeforeTest;21import com.consol.citrus.context.TestContext;22import com.consol.citrus.dsl.TestRequest;23import com.consol.citrus.endpoint.Endpoint;24import com.consol.citrus.message.DefaultMessage;25import com.consol.citrus.message.Message;26import com.consol.citrus.message.MessageHeaders;27import com.consol.citrus.message.MessageType;28import com.consol.citrus.messaging.Producer;29import com.consol.citrus.report.TestActionListeners;30import com.consol.citrus.testng.AbstractTestNGUnitTest;31import com.consol.citrus.validation.builder.AbstractMessageContentBuilder;32import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;33import com.consol.citrus.validation.builder.StaticMessageContentBuilder;34import com.consol.citrus.validation.json.JsonPathMessageConstructionInterceptor;35import com.consol.citrus.validation.json.JsonPathVariableExtractor;36import com.consol.citrus.validation.xml.XpathMessageConstructionInterceptor;37import com.consol.citrus.validation.xml.XpathPayloadVariableExtractor;38import com.consol.citrus.variable.MessageHeaderVariableExtractor;39import com.consol.citrus.variable.dictionary.DataDictionary;40import com.consol.citrus.variable.dictionary.json.JsonMappingDataDictionary;41import org.mockito.Mockito;42import org.springframework.context.ApplicationContext;43import org.springframework.core.io.Resource;44import org.springframework.oxm.Marshaller;45import org.springframework.oxm.xstream.XStreamMarshaller;46import org.springframework.util.StringUtils;47import org.testng.Assert;48import org.testng.annotations.BeforeClass;49import org.testng.annotations.Test;50import java.io.ByteArrayInputStream;51import java.io.IOException;52import java.util.Collections;53import java.util.HashMap;54import static org.mockito.Mockito.any;55import static org.mockito.Mockito.doAnswer;56import static org.mockito.Mockito.reset;57import static org.mockito.Mockito.when;58/**59 * @author Christoph Deppisch60 * @since 2.361 */62public class SendMessageTestRunnerTest extends AbstractTestNGUnitTest {63 64 private Endpoint messageEndpoint = Mockito.mock(Endpoint.class);65 private Producer messageProducer = Mockito.mock(Producer.class);66 private ApplicationContext applicationContextMock = Mockito.mock(ApplicationContext.class);67 private Resource resource = Mockito.mock(Resource.class);68 private XStreamMarshaller marshaller = new XStreamMarshaller();69 @BeforeClass70 public void prepareMarshaller() {71 marshaller.getXStream().processAnnotations(TestRequest.class);72 }73 @Test74 public void testSendBuilderWithMessageInstance() {75 reset(messageEndpoint, messageProducer);76 when(messageEndpoint.createProducer()).thenReturn(messageProducer);77 when(messageEndpoint.getActor()).thenReturn(null);78 doAnswer(invocation -> {79 Message message = (Message) invocation.getArguments()[0];80 Assert.assertEquals(message.getPayload(String.class), "Foo");81 Assert.assertNotNull(message.getHeader("operation"));82 Assert.assertEquals(message.getHeader("operation"), "foo");83 return null;84 }).when(messageProducer).send(any(Message.class), any(TestContext.class));85 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {86 @Override87 public void execute() {88 send(builder -> builder.endpoint(messageEndpoint)89 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))90 .header("additional", "additionalValue"));91 }92 };93 final TestCase test = builder.getTestCase();94 Assert.assertEquals(test.getActionCount(), 1);95 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);96 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));97 Assert.assertEquals(action.getName(), "send");98 Assert.assertEquals(action.getEndpoint(), messageEndpoint);99 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);100 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();101 Assert.assertEquals(messageBuilder.getMessage().getPayload(String.class), "Foo");102 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");103 Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "additionalValue");104 }105 @Test106 public void testSendBuilderWithObjectMessageInstance() {107 reset(messageEndpoint, messageProducer);108 when(messageEndpoint.createProducer()).thenReturn(messageProducer);109 when(messageEndpoint.getActor()).thenReturn(null);110 doAnswer(invocation -> {111 Message message = (Message) invocation.getArguments()[0];112 Assert.assertEquals(message.getPayload(Integer.class), new Integer(10));113 Assert.assertNotNull(message.getHeader("operation"));114 Assert.assertEquals(message.getHeader("operation"), "foo");115 return null;116 }).when(messageProducer).send(any(Message.class), any(TestContext.class));117 final Message message = new DefaultMessage(10).setHeader("operation", "foo");118 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {119 @Override120 public void execute() {121 send(builder -> builder.endpoint(messageEndpoint)122 .message(message));123 }124 };125 final TestCase test = builder.getTestCase();126 Assert.assertEquals(test.getActionCount(), 1);127 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);128 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));129 Assert.assertEquals(action.getName(), "send");130 Assert.assertEquals(action.getEndpoint(), messageEndpoint);131 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);132 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();133 Assert.assertEquals(messageBuilder.getMessage().getPayload(), 10);134 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);135 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), message.getHeaders().size());136 Assert.assertEquals(messageBuilder.getMessage().getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));137 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");138 final Message constructed = messageBuilder.buildMessageContent(new TestContext(), MessageType.PLAINTEXT.name());139 Assert.assertEquals(constructed.getHeaders().size(), message.getHeaders().size() + 1);140 Assert.assertEquals(constructed.getHeader("operation"), "foo");141 Assert.assertNotEquals(constructed.getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));142 }143 @Test144 public void testSendBuilderWithObjectMessageInstanceAdditionalHeader() {145 reset(messageEndpoint, messageProducer);146 when(messageEndpoint.createProducer()).thenReturn(messageProducer);147 when(messageEndpoint.getActor()).thenReturn(null);148 doAnswer(invocation -> {149 Message message = (Message) invocation.getArguments()[0];150 Assert.assertEquals(message.getPayload(Integer.class), new Integer(10));151 Assert.assertNotNull(message.getHeader("operation"));152 Assert.assertEquals(message.getHeader("operation"), "foo");153 Assert.assertNotNull(message.getHeader("additional"));154 Assert.assertEquals(message.getHeader("additional"), "new");155 return null;156 }).when(messageProducer).send(any(Message.class), any(TestContext.class));157 final Message message = new DefaultMessage(10).setHeader("operation", "foo");158 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {159 @Override160 public void execute() {161 send(builder -> builder.endpoint(messageEndpoint)162 .message(message)163 .header("additional", "new"));164 }165 };166 final TestCase test = builder.getTestCase();167 Assert.assertEquals(test.getActionCount(), 1);168 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);169 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));170 Assert.assertEquals(action.getName(), "send");171 Assert.assertEquals(action.getEndpoint(), messageEndpoint);172 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);173 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();174 Assert.assertEquals(messageBuilder.getMessage().getPayload(), 10);175 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 1L);176 Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "new");177 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), message.getHeaders().size());178 Assert.assertEquals(messageBuilder.getMessage().getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));179 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");180 final Message constructed = messageBuilder.buildMessageContent(new TestContext(), MessageType.PLAINTEXT.name());181 Assert.assertEquals(constructed.getHeaders().size(), message.getHeaders().size() + 2);182 Assert.assertEquals(constructed.getHeader("operation"), "foo");183 Assert.assertEquals(constructed.getHeader("additional"), "new");184 }185 @Test186 public void testSendBuilderWithPayloadModel() {187 reset(applicationContextMock, messageEndpoint, messageProducer);188 when(messageEndpoint.createProducer()).thenReturn(messageProducer);189 when(messageEndpoint.getActor()).thenReturn(null);190 doAnswer(invocation -> {191 Message message = (Message) invocation.getArguments()[0];192 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");193 return null;194 }).when(messageProducer).send(any(Message.class), any(TestContext.class));195 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));196 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());197 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());198 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());199 when(applicationContextMock.getBeansOfType(Marshaller.class)).thenReturn(Collections.singletonMap("marshaller", marshaller));200 when(applicationContextMock.getBean(Marshaller.class)).thenReturn(marshaller);201 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {202 @Override203 public void execute() {204 send(builder -> builder.endpoint(messageEndpoint)205 .payloadModel(new TestRequest("Hello Citrus!")));206 }207 };208 final TestCase test = builder.getTestCase();209 Assert.assertEquals(test.getActionCount(), 1);210 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);211 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));212 Assert.assertEquals(action.getName(), "send");213 Assert.assertEquals(action.getEndpoint(), messageEndpoint);214 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);215 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();216 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");217 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);218 }219 @Test220 public void testSendBuilderWithPayloadModelExplicitMarshaller() {221 reset(messageEndpoint, messageProducer);222 when(messageEndpoint.createProducer()).thenReturn(messageProducer);223 when(messageEndpoint.getActor()).thenReturn(null);224 doAnswer(invocation -> {225 Message message = (Message) invocation.getArguments()[0];226 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");227 return null;228 }).when(messageProducer).send(any(Message.class), any(TestContext.class));229 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {230 @Override231 public void execute() {232 send(builder -> builder.endpoint(messageEndpoint)233 .payload(new TestRequest("Hello Citrus!"), marshaller));234 }235 };236 final TestCase test = builder.getTestCase();237 Assert.assertEquals(test.getActionCount(), 1);238 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);239 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));240 Assert.assertEquals(action.getName(), "send");241 Assert.assertEquals(action.getEndpoint(), messageEndpoint);242 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);243 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();244 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");245 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);246 }247 @Test248 public void testSendBuilderWithPayloadModelExplicitMarshallerName() {249 reset(applicationContextMock, messageEndpoint, messageProducer);250 when(messageEndpoint.createProducer()).thenReturn(messageProducer);251 when(messageEndpoint.getActor()).thenReturn(null);252 doAnswer(invocation -> {253 Message message = (Message) invocation.getArguments()[0];254 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");255 return null;256 }).when(messageProducer).send(any(Message.class), any(TestContext.class));257 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));258 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());259 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());260 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());261 when(applicationContextMock.containsBean("myMarshaller")).thenReturn(true);262 when(applicationContextMock.getBean("myMarshaller")).thenReturn(marshaller);263 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {264 @Override265 public void execute() {266 send(builder -> builder.endpoint(messageEndpoint)267 .payload(new TestRequest("Hello Citrus!"), "myMarshaller"));268 }269 };270 final TestCase test = builder.getTestCase();271 Assert.assertEquals(test.getActionCount(), 1);272 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);273 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));274 Assert.assertEquals(action.getName(), "send");275 Assert.assertEquals(action.getEndpoint(), messageEndpoint);276 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);277 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();278 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");279 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);280 }281 282 @Test283 public void testSendBuilderWithPayloadData() {284 reset(messageEndpoint, messageProducer);285 when(messageEndpoint.createProducer()).thenReturn(messageProducer);286 when(messageEndpoint.getActor()).thenReturn(null);287 doAnswer(invocation -> {288 Message message = (Message) invocation.getArguments()[0];289 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");290 return null;291 }).when(messageProducer).send(any(Message.class), any(TestContext.class));292 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {293 @Override294 public void execute() {295 send(builder -> builder.endpoint(messageEndpoint)296 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>"));297 }298 };299 final TestCase test = builder.getTestCase();300 Assert.assertEquals(test.getActionCount(), 1);301 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);302 303 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));304 Assert.assertEquals(action.getName(), "send");305 306 Assert.assertEquals(action.getEndpoint(), messageEndpoint);307 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);308 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();309 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");310 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);311 }312 @Test313 public void testSendBuilderWithPayloadResource() throws IOException {314 reset(resource, messageEndpoint, messageProducer);315 when(messageEndpoint.createProducer()).thenReturn(messageProducer);316 when(messageEndpoint.getActor()).thenReturn(null);317 doAnswer(invocation -> {318 Message message = (Message) invocation.getArguments()[0];319 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");320 return null;321 }).when(messageProducer).send(any(Message.class), any(TestContext.class));322 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("<TestRequest><Message>Hello World!</Message></TestRequest>".getBytes()));323 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {324 @Override325 public void execute() {326 send(builder -> builder.endpoint(messageEndpoint)327 .payload(resource));328 }329 };330 final TestCase test = builder.getTestCase();331 Assert.assertEquals(test.getActionCount(), 1);332 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);333 334 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));335 Assert.assertEquals(action.getName(), "send");336 337 Assert.assertEquals(action.getEndpoint(), messageEndpoint);338 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);339 340 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();341 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");342 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);343 }344 345 @Test346 public void testSendBuilderWithEndpointName() {347 final TestContext context = applicationContext.getBean(TestContext.class);348 context.setApplicationContext(applicationContextMock);349 reset(applicationContextMock, messageEndpoint, messageProducer);350 when(messageEndpoint.createProducer()).thenReturn(messageProducer);351 when(messageEndpoint.getActor()).thenReturn(null);352 doAnswer(invocation -> {353 Message message = (Message) invocation.getArguments()[0];354 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");355 return null;356 }).when(messageProducer).send(any(Message.class), any(TestContext.class));357 when(applicationContextMock.getBean(TestContext.class)).thenReturn(context);358 when(applicationContextMock.getBean("fooMessageEndpoint", Endpoint.class)).thenReturn(messageEndpoint);359 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());360 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());361 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());362 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {363 @Override364 public void execute() {365 send(builder -> builder.endpoint("fooMessageEndpoint")366 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>"));367 }368 };369 final TestCase test = builder.getTestCase();370 Assert.assertEquals(test.getActionCount(), 1);371 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);372 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));373 Assert.assertEquals(action.getName(), "send");374 Assert.assertEquals(action.getEndpointUri(), "fooMessageEndpoint");375 }376 377 @Test378 public void testSendBuilderWithHeaders() {379 reset(messageEndpoint, messageProducer);380 when(messageEndpoint.createProducer()).thenReturn(messageProducer);381 when(messageEndpoint.getActor()).thenReturn(null);382 doAnswer(invocation -> {383 Message message = (Message) invocation.getArguments()[0];384 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");385 Assert.assertNotNull(message.getHeader("operation"));386 Assert.assertEquals(message.getHeader("operation"), "foo");387 Assert.assertNotNull(message.getHeader("language"));388 Assert.assertEquals(message.getHeader("language"), "eng");389 return null;390 }).when(messageProducer).send(any(Message.class), any(TestContext.class));391 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {392 @Override393 public void execute() {394 send(builder -> builder.endpoint(messageEndpoint)395 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")396 .headers(Collections.singletonMap("some", "value"))397 .header("operation", "foo")398 .header("language", "eng"));399 }400 };401 final TestCase test = builder.getTestCase();402 Assert.assertEquals(test.getActionCount(), 1);403 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);404 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));405 Assert.assertEquals(action.getName(), "send");406 Assert.assertEquals(action.getEndpoint(), messageEndpoint);407 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);408 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();409 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");410 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 3L);411 Assert.assertEquals(messageBuilder.getMessageHeaders().get("some"), "value");412 Assert.assertEquals(messageBuilder.getMessageHeaders().get("operation"), "foo");413 Assert.assertEquals(messageBuilder.getMessageHeaders().get("language"), "eng");414 }415 416 @Test417 public void testSendBuilderWithHeaderData() {418 reset(messageEndpoint, messageProducer);419 when(messageEndpoint.createProducer()).thenReturn(messageProducer);420 when(messageEndpoint.getActor()).thenReturn(null);421 doAnswer(invocation -> {422 Message message = (Message) invocation.getArguments()[0];423 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");424 Assert.assertNotNull(message.getHeaderData());425 Assert.assertEquals(message.getHeaderData().size(), 1L);426 Assert.assertEquals(message.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");427 return null;428 }).when(messageProducer).send(any(Message.class), any(TestContext.class));429 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {430 @Override431 public void execute() {432 send(builder -> builder.endpoint(messageEndpoint)433 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")434 .header("<Header><Name>operation</Name><Value>foo</Value></Header>"));435 436 send(builder -> builder.endpoint(messageEndpoint)437 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))438 .header("<Header><Name>operation</Name><Value>foo</Value></Header>"));439 }440 };441 final TestCase test = builder.getTestCase();442 Assert.assertEquals(test.getActionCount(), 2);443 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);444 Assert.assertEquals(test.getActions().get(1).getClass(), SendMessageAction.class);445 446 SendMessageAction action = ((SendMessageAction)test.getActions().get(0));447 Assert.assertEquals(action.getName(), "send");448 449 Assert.assertEquals(action.getEndpoint(), messageEndpoint);450 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);451 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();452 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");453 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);454 Assert.assertEquals(messageBuilder.getHeaderData().size(), 1L);455 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");456 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);457 action = ((SendMessageAction)test.getActions().get(1));458 Assert.assertEquals(action.getName(), "send");459 Assert.assertEquals(action.getEndpoint(), messageEndpoint);460 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);461 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();462 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");463 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);464 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 1L);465 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");466 Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);467 }468 @Test469 public void testSendBuilderWithMultipleHeaderData() {470 reset(messageEndpoint, messageProducer);471 when(messageEndpoint.createProducer()).thenReturn(messageProducer);472 when(messageEndpoint.getActor()).thenReturn(null);473 doAnswer(invocation -> {474 Message message = (Message) invocation.getArguments()[0];475 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");476 Assert.assertNotNull(message.getHeaderData());477 Assert.assertEquals(message.getHeaderData().size(), 2L);478 Assert.assertEquals(message.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");479 Assert.assertEquals(message.getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");480 return null;481 }).when(messageProducer).send(any(Message.class), any(TestContext.class));482 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {483 @Override484 public void execute() {485 send(builder -> builder.endpoint(messageEndpoint)486 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")487 .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")488 .header("<Header><Name>operation</Name><Value>foo2</Value></Header>"));489 send(builder -> builder.endpoint(messageEndpoint)490 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))491 .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")492 .header("<Header><Name>operation</Name><Value>foo2</Value></Header>"));493 }494 };495 final TestCase test = builder.getTestCase();496 Assert.assertEquals(test.getActionCount(), 2);497 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);498 Assert.assertEquals(test.getActions().get(1).getClass(), SendMessageAction.class);499 SendMessageAction action = ((SendMessageAction)test.getActions().get(0));500 Assert.assertEquals(action.getName(), "send");501 Assert.assertEquals(action.getEndpoint(), messageEndpoint);502 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);503 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();504 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");505 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);506 Assert.assertEquals(messageBuilder.getHeaderData().size(), 2L);507 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");508 Assert.assertEquals(messageBuilder.getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");509 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);510 action = ((SendMessageAction)test.getActions().get(1));511 Assert.assertEquals(action.getName(), "send");512 Assert.assertEquals(action.getEndpoint(), messageEndpoint);513 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);514 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();515 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");516 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);517 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 2L);518 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");519 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");520 Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);521 }522 523 @Test524 public void testSendBuilderWithHeaderDataResource() throws IOException {525 reset(resource, messageEndpoint, messageProducer);526 when(messageEndpoint.createProducer()).thenReturn(messageProducer);527 when(messageEndpoint.getActor()).thenReturn(null);528 doAnswer(invocation -> {529 Message message = (Message) invocation.getArguments()[0];530 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");531 Assert.assertNotNull(message.getHeaderData());532 Assert.assertEquals(message.getHeaderData().size(), 1L);533 Assert.assertEquals(message.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");534 return null;535 }).doAnswer(invocation -> {536 Message message = (Message) invocation.getArguments()[0];537 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");538 Assert.assertNotNull(message.getHeaderData());539 Assert.assertEquals(message.getHeaderData().size(), 1L);540 Assert.assertEquals(message.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo2</Value></Header>");541 return null;542 }).when(messageProducer).send(any(Message.class), any(TestContext.class));543 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("<Header><Name>operation</Name><Value>foo1</Value></Header>".getBytes()))544 .thenReturn(new ByteArrayInputStream("<Header><Name>operation</Name><Value>foo2</Value></Header>".getBytes()));545 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {546 @Override547 public void execute() {548 send(builder -> builder.endpoint(messageEndpoint)549 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")550 .header(resource));551 send(builder -> builder.endpoint(messageEndpoint)552 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))553 .header(resource));554 }555 };556 final TestCase test = builder.getTestCase();557 Assert.assertEquals(test.getActionCount(), 2);558 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);559 Assert.assertEquals(test.getActions().get(1).getClass(), SendMessageAction.class);560 561 SendMessageAction action = ((SendMessageAction)test.getActions().get(0));562 Assert.assertEquals(action.getName(), "send");563 564 Assert.assertEquals(action.getEndpoint(), messageEndpoint);565 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);566 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();567 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");568 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);569 Assert.assertEquals(messageBuilder.getHeaderData().size(), 1L);570 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");571 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);572 action = ((SendMessageAction)test.getActions().get(1));573 Assert.assertEquals(action.getName(), "send");574 Assert.assertEquals(action.getEndpoint(), messageEndpoint);575 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);576 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();577 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");578 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);579 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 1L);580 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo2</Value></Header>");581 Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);582 }583 584 @Test585 public void testSendBuilderExtractFromPayload() {586 reset(messageEndpoint, messageProducer);587 when(messageEndpoint.createProducer()).thenReturn(messageProducer);588 when(messageEndpoint.getActor()).thenReturn(null);589 doAnswer(invocation -> {590 Message message = (Message) invocation.getArguments()[0];591 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>");592 return null;593 }).when(messageProducer).send(any(Message.class), any(TestContext.class));594 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {595 @Override596 public void execute() {597 send(builder -> builder.endpoint(messageEndpoint)598 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")599 .extractFromPayload("/TestRequest/Message", "text")600 .extractFromPayload("/TestRequest/Message/@lang", "language"));601 }602 };603 final TestContext context = builder.getTestContext();604 Assert.assertNotNull(context.getVariable("text"));605 Assert.assertNotNull(context.getVariable("language"));606 Assert.assertEquals(context.getVariable("text"), "Hello World!");607 Assert.assertEquals(context.getVariable("language"), "ENG");608 final TestCase test = builder.getTestCase();609 Assert.assertEquals(test.getActionCount(), 1);610 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);611 612 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));613 Assert.assertEquals(action.getName(), "send");614 615 Assert.assertEquals(action.getEndpoint(), messageEndpoint);616 617 Assert.assertEquals(action.getVariableExtractors().size(), 1);618 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof XpathPayloadVariableExtractor);619 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message"));620 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message/@lang"));621 }622 @Test623 public void testSendBuilderExtractJsonPathFromPayload() {624 reset(messageEndpoint, messageProducer);625 when(messageEndpoint.createProducer()).thenReturn(messageProducer);626 when(messageEndpoint.getActor()).thenReturn(null);627 doAnswer(invocation -> {628 Message message = (Message) invocation.getArguments()[0];629 Assert.assertEquals(message.getPayload(String.class), "{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}");630 return null;631 }).when(messageProducer).send(any(Message.class), any(TestContext.class));632 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {633 @Override634 public void execute() {635 send(builder -> builder.endpoint(messageEndpoint)636 .messageType(MessageType.JSON)637 .payload("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}")638 .extractFromPayload("$.text", "text")639 .extractFromPayload("$.person", "person"));640 }641 };642 final TestContext context = builder.getTestContext();643 Assert.assertNotNull(context.getVariable("text"));644 Assert.assertNotNull(context.getVariable("person"));645 Assert.assertEquals(context.getVariable("text"), "Hello World!");646 Assert.assertTrue(context.getVariable("person").contains("\"John\""));647 final TestCase test = builder.getTestCase();648 Assert.assertEquals(test.getActionCount(), 1);649 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);650 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));651 Assert.assertEquals(action.getName(), "send");652 Assert.assertEquals(action.getEndpoint(), messageEndpoint);653 Assert.assertEquals(action.getVariableExtractors().size(), 1);654 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof JsonPathVariableExtractor);655 Assert.assertTrue(((JsonPathVariableExtractor)action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.text"));656 Assert.assertTrue(((JsonPathVariableExtractor)action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.person"));657 }658 659 @Test660 public void testSendBuilderExtractFromHeader() {661 reset(messageEndpoint, messageProducer);662 when(messageEndpoint.createProducer()).thenReturn(messageProducer);663 when(messageEndpoint.getActor()).thenReturn(null);664 doAnswer(invocation -> {665 Message message = (Message) invocation.getArguments()[0];666 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>");667 return null;668 }).when(messageProducer).send(any(Message.class), any(TestContext.class));669 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {670 @Override671 public void execute() {672 send(builder -> builder.endpoint(messageEndpoint)673 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")674 .header("operation", "sayHello")675 .header("requestId", "123456")676 .extractFromHeader("operation", "operationHeader")677 .extractFromHeader("requestId", "id"));678 }679 };680 final TestContext context = builder.getTestContext();681 Assert.assertNotNull(context.getVariable("operationHeader"));682 Assert.assertNotNull(context.getVariable("id"));683 Assert.assertEquals(context.getVariable("operationHeader"), "sayHello");684 Assert.assertEquals(context.getVariable("id"), "123456");685 final TestCase test = builder.getTestCase();686 Assert.assertEquals(test.getActionCount(), 1);687 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);688 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));689 Assert.assertEquals(action.getName(), "send");690 Assert.assertEquals(action.getEndpoint(), messageEndpoint);691 Assert.assertEquals(action.getVariableExtractors().size(), 1);692 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof MessageHeaderVariableExtractor);693 Assert.assertTrue(((MessageHeaderVariableExtractor) action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("operation"));694 Assert.assertTrue(((MessageHeaderVariableExtractor) action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("requestId"));695 }696 @Test697 public void testXpathSupport() {698 reset(messageEndpoint, messageProducer);699 when(messageEndpoint.createProducer()).thenReturn(messageProducer);700 when(messageEndpoint.getActor()).thenReturn(null);701 doAnswer(invocation -> {702 Message message = (Message) invocation.getArguments()[0];703 Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),704 "<?xmlversion=\"1.0\"encoding=\"UTF-8\"?><TestRequest><Messagelang=\"ENG\">HelloWorld!</Message></TestRequest>");705 return null;706 }).when(messageProducer).send(any(Message.class), any(TestContext.class));707 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {708 @Override709 public void execute() {710 send(builder -> builder.endpoint(messageEndpoint)711 .payload("<TestRequest><Message lang=\"ENG\">?</Message></TestRequest>")712 .xpath("/TestRequest/Message", "Hello World!"));713 }714 };715 final TestCase test = builder.getTestCase();716 Assert.assertEquals(test.getActionCount(), 1);717 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);718 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));719 Assert.assertEquals(action.getName(), "send");720 Assert.assertEquals(action.getEndpoint(), messageEndpoint);721 Assert.assertTrue(action.getMessageBuilder() instanceof AbstractMessageContentBuilder);722 Assert.assertEquals(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().size(), 1);723 Assert.assertTrue(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0) instanceof XpathMessageConstructionInterceptor);724 Assert.assertEquals(((XpathMessageConstructionInterceptor)((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0)).getXPathExpressions().get("/TestRequest/Message"), "Hello World!");725 }726 @Test727 public void testJsonPathSupport() {728 reset(messageEndpoint, messageProducer);729 when(messageEndpoint.createProducer()).thenReturn(messageProducer);730 when(messageEndpoint.getActor()).thenReturn(null);731 doAnswer(invocation -> {732 Message message = (Message) invocation.getArguments()[0];733 Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),734 "{\"TestRequest\":{\"Message\":\"HelloWorld!\"}}");735 return null;736 }).when(messageProducer).send(any(Message.class), any(TestContext.class));737 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {738 @Override739 public void execute() {740 send(builder -> builder.endpoint(messageEndpoint)741 .messageType(MessageType.JSON)742 .payload("{ \"TestRequest\": { \"Message\": \"?\" }}")743 .jsonPath("$.TestRequest.Message", "Hello World!"));744 }745 };746 final TestCase test = builder.getTestCase();747 Assert.assertEquals(test.getActionCount(), 1);748 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);749 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));750 Assert.assertEquals(action.getName(), "send");751 Assert.assertEquals(action.getEndpoint(), messageEndpoint);752 Assert.assertTrue(action.getMessageBuilder() instanceof AbstractMessageContentBuilder);753 Assert.assertEquals(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().size(), 1);754 Assert.assertTrue(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0) instanceof JsonPathMessageConstructionInterceptor);755 Assert.assertEquals(((JsonPathMessageConstructionInterceptor)((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0)).getJsonPathExpressions().get("$.TestRequest.Message"), "Hello World!");756 }757 @Test758 public void testSendBuilderWithDictionary() {759 final JsonMappingDataDictionary dictionary = new JsonMappingDataDictionary();760 dictionary.getMappings().put("TestRequest.Message", "Hello World!");761 reset(messageEndpoint, messageProducer);762 when(messageEndpoint.createProducer()).thenReturn(messageProducer);763 when(messageEndpoint.getActor()).thenReturn(null);764 doAnswer(invocation -> {765 Message message = (Message) invocation.getArguments()[0];766 Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),767 "{\"TestRequest\":{\"Message\":\"HelloWorld!\"}}");768 return null;769 }).when(messageProducer).send(any(Message.class), any(TestContext.class));770 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {771 @Override772 public void execute() {773 send(builder -> builder.endpoint(messageEndpoint)774 .messageType(MessageType.JSON)775 .payload("{ \"TestRequest\": { \"Message\": \"?\" }}")776 .dictionary(dictionary));777 }778 };779 final TestCase test = builder.getTestCase();780 Assert.assertEquals(test.getActionCount(), 1);781 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);782 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));783 Assert.assertEquals(action.getName(), "send");784 Assert.assertEquals(action.getEndpoint(), messageEndpoint);785 Assert.assertEquals(action.getDataDictionary(), dictionary);786 }787 @Test788 public void testSendBuilderWithDictionaryName() {789 final JsonMappingDataDictionary dictionary = new JsonMappingDataDictionary();790 dictionary.getMappings().put("TestRequest.Message", "Hello World!");791 reset(applicationContextMock, messageEndpoint, messageProducer);792 when(messageEndpoint.createProducer()).thenReturn(messageProducer);793 when(messageEndpoint.getActor()).thenReturn(null);794 doAnswer(invocation -> {795 Message message = (Message) invocation.getArguments()[0];796 Assert.assertEquals(StringUtils.trimAllWhitespace(message.getPayload(String.class)),797 "{\"TestRequest\":{\"Message\":\"HelloWorld!\"}}");798 return null;799 }).when(messageProducer).send(any(Message.class), any(TestContext.class));800 when(applicationContextMock.getBean(TestContext.class)).thenReturn(applicationContext.getBean(TestContext.class));801 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());802 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());803 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());804 when(applicationContextMock.getBean("customDictionary", DataDictionary.class)).thenReturn(dictionary);805 final MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {806 @Override807 public void execute() {808 send(builder -> builder.endpoint(messageEndpoint)809 .messageType(MessageType.JSON)810 .payload("{ \"TestRequest\": { \"Message\": \"?\" }}")811 .dictionary("customDictionary"));812 }813 };814 final TestCase test = builder.getTestCase();815 Assert.assertEquals(test.getActionCount(), 1);816 Assert.assertEquals(test.getActions().get(0).getClass(), SendMessageAction.class);817 final SendMessageAction action = ((SendMessageAction)test.getActions().get(0));818 Assert.assertEquals(action.getName(), "send");819 Assert.assertEquals(action.getEndpoint(), messageEndpoint);820 Assert.assertEquals(action.getDataDictionary(), dictionary);821 }822}...

Full Screen

Full Screen

Source:SendMessageTestDesignerTest.java Github

copy

Full Screen

...14 * limitations under the License.15 */16package com.consol.citrus.dsl.design;17import com.consol.citrus.TestCase;18import com.consol.citrus.actions.SendMessageAction;19import com.consol.citrus.container.SequenceAfterTest;20import com.consol.citrus.container.SequenceBeforeTest;21import com.consol.citrus.context.TestContext;22import com.consol.citrus.dsl.TestRequest;23import com.consol.citrus.dsl.actions.DelegatingTestAction;24import com.consol.citrus.endpoint.Endpoint;25import com.consol.citrus.message.DefaultMessage;26import com.consol.citrus.message.Message;27import com.consol.citrus.message.MessageHeaders;28import com.consol.citrus.message.MessageType;29import com.consol.citrus.report.TestActionListeners;30import com.consol.citrus.testng.AbstractTestNGUnitTest;31import com.consol.citrus.validation.builder.AbstractMessageContentBuilder;32import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;33import com.consol.citrus.validation.builder.StaticMessageContentBuilder;34import com.consol.citrus.validation.json.JsonPathMessageConstructionInterceptor;35import com.consol.citrus.validation.json.JsonPathVariableExtractor;36import com.consol.citrus.validation.xml.XpathMessageConstructionInterceptor;37import com.consol.citrus.validation.xml.XpathPayloadVariableExtractor;38import com.consol.citrus.variable.MessageHeaderVariableExtractor;39import com.consol.citrus.variable.dictionary.DataDictionary;40import com.consol.citrus.variable.dictionary.xml.NodeMappingDataDictionary;41import org.mockito.Mockito;42import org.springframework.context.ApplicationContext;43import org.springframework.core.io.Resource;44import org.springframework.oxm.Marshaller;45import org.springframework.oxm.xstream.XStreamMarshaller;46import org.testng.Assert;47import org.testng.annotations.BeforeClass;48import org.testng.annotations.Test;49import java.io.ByteArrayInputStream;50import java.io.IOException;51import java.util.Collections;52import java.util.HashMap;53import static org.mockito.Mockito.reset;54import static org.mockito.Mockito.when;55/**56 * @author Christoph Deppisch57 */58public class SendMessageTestDesignerTest extends AbstractTestNGUnitTest {59 60 private Endpoint messageEndpoint = Mockito.mock(Endpoint.class);61 private ApplicationContext applicationContextMock = Mockito.mock(ApplicationContext.class);62 private Resource resource = Mockito.mock(Resource.class);63 private XStreamMarshaller marshaller = new XStreamMarshaller();64 @BeforeClass65 public void prepareMarshaller() {66 marshaller.getXStream().processAnnotations(TestRequest.class);67 }68 @Test69 public void testSendBuilderWithMessageInstance() {70 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {71 @Override72 public void configure() {73 send(messageEndpoint)74 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))75 .header("additional", "additionalValue");76 }77 };78 builder.configure();79 final TestCase test = builder.getTestCase();80 Assert.assertEquals(test.getActionCount(), 1);81 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);82 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);83 84 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();85 Assert.assertEquals(action.getName(), "send");86 87 Assert.assertEquals(action.getEndpoint(), messageEndpoint);88 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);89 90 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();91 Assert.assertEquals(messageBuilder.getMessage().getPayload(String.class), "Foo");92 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");93 Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "additionalValue");94 }95 @Test96 public void testSendBuilderWithObjectMessageInstance() {97 final Message message = new DefaultMessage(10).setHeader("operation", "foo");98 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {99 @Override100 public void configure() {101 send(messageEndpoint)102 .message(message);103 }104 };105 builder.configure();106 final TestCase test = builder.getTestCase();107 Assert.assertEquals(test.getActionCount(), 1);108 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);109 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);110 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();111 Assert.assertEquals(action.getName(), "send");112 Assert.assertEquals(action.getEndpoint(), messageEndpoint);113 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);114 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();115 Assert.assertEquals(messageBuilder.getMessage().getPayload(), 10);116 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);117 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), message.getHeaders().size());118 Assert.assertEquals(messageBuilder.getMessage().getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));119 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");120 final Message constructed = messageBuilder.buildMessageContent(new TestContext(), MessageType.PLAINTEXT.name());121 Assert.assertEquals(constructed.getHeaders().size(), message.getHeaders().size() + 1);122 Assert.assertEquals(constructed.getHeader("operation"), "foo");123 Assert.assertEquals(constructed.getHeader(MessageHeaders.MESSAGE_TYPE), MessageType.PLAINTEXT.name());124 Assert.assertNotEquals(constructed.getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));125 }126 @Test127 public void testSendBuilderWithObjectMessageInstanceAdditionalHeader() {128 final Message message = new DefaultMessage(10).setHeader("operation", "foo");129 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {130 @Override131 public void configure() {132 send(messageEndpoint)133 .message(message)134 .header("additional", "new");135 }136 };137 builder.configure();138 final TestCase test = builder.getTestCase();139 Assert.assertEquals(test.getActionCount(), 1);140 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);141 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);142 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();143 Assert.assertEquals(action.getName(), "send");144 Assert.assertEquals(action.getEndpoint(), messageEndpoint);145 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);146 final StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();147 Assert.assertEquals(messageBuilder.getMessage().getPayload(), 10);148 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 1L);149 Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "new");150 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), message.getHeaders().size());151 Assert.assertEquals(messageBuilder.getMessage().getHeader(MessageHeaders.ID), message.getHeader(MessageHeaders.ID));152 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");153 final Message constructed = messageBuilder.buildMessageContent(new TestContext(), MessageType.PLAINTEXT.name());154 Assert.assertEquals(constructed.getHeaders().size(), message.getHeaders().size() + 2);155 Assert.assertEquals(constructed.getHeader("operation"), "foo");156 Assert.assertEquals(constructed.getHeader("additional"), "new");157 Assert.assertEquals(constructed.getHeader(MessageHeaders.MESSAGE_TYPE), MessageType.PLAINTEXT.name());158 }159 @Test160 public void testSendBuilderWithPayloadModel() {161 reset(applicationContextMock);162 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());163 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());164 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());165 when(applicationContextMock.getBeansOfType(Marshaller.class)).thenReturn(Collections.singletonMap("marshaller", marshaller));166 when(applicationContextMock.getBean(Marshaller.class)).thenReturn(marshaller);167 final MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {168 @Override169 public void configure() {170 send(messageEndpoint)171 .payloadModel(new TestRequest("Hello Citrus!"));172 }173 };174 builder.configure();175 final TestCase test = builder.getTestCase();176 Assert.assertEquals(test.getActionCount(), 1);177 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);178 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);179 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();180 Assert.assertEquals(action.getName(), "send");181 Assert.assertEquals(action.getEndpoint(), messageEndpoint);182 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);183 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();184 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");185 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);186 }187 @Test188 public void testSendBuilderWithPayloadModelExplicitMarshaller() {189 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {190 @Override191 public void configure() {192 send(messageEndpoint)193 .payload(new TestRequest("Hello Citrus!"), marshaller);194 }195 };196 builder.configure();197 final TestCase test = builder.getTestCase();198 Assert.assertEquals(test.getActionCount(), 1);199 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);200 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);201 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();202 Assert.assertEquals(action.getName(), "send");203 Assert.assertEquals(action.getEndpoint(), messageEndpoint);204 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);205 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();206 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");207 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);208 }209 @Test210 public void testSendBuilderWithPayloadModelExplicitMarshallerName() {211 reset(applicationContextMock);212 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());213 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());214 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());215 when(applicationContextMock.containsBean("myMarshaller")).thenReturn(true);216 when(applicationContextMock.getBean("myMarshaller")).thenReturn(marshaller);217 final MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {218 @Override219 public void configure() {220 send(messageEndpoint)221 .payload(new TestRequest("Hello Citrus!"), "myMarshaller");222 }223 };224 builder.configure();225 final TestCase test = builder.getTestCase();226 Assert.assertEquals(test.getActionCount(), 1);227 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);228 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);229 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();230 Assert.assertEquals(action.getName(), "send");231 Assert.assertEquals(action.getEndpoint(), messageEndpoint);232 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);233 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();234 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");235 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);236 }237 238 @Test239 public void testSendBuilderWithPayloadData() {240 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {241 @Override242 public void configure() {243 send(messageEndpoint)244 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");245 }246 };247 builder.configure();248 final TestCase test = builder.getTestCase();249 Assert.assertEquals(test.getActionCount(), 1);250 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);251 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);252 253 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();254 Assert.assertEquals(action.getName(), "send");255 256 Assert.assertEquals(action.getEndpoint(), messageEndpoint);257 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);258 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();259 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");260 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);261 }262 @Test263 public void testSendBuilderWithPayloadResource() throws IOException {264 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {265 @Override266 public void configure() {267 send(messageEndpoint)268 .payload(resource);269 }270 };271 272 reset(resource);273 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("somePayloadData".getBytes()));274 builder.configure();275 final TestCase test = builder.getTestCase();276 Assert.assertEquals(test.getActionCount(), 1);277 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);278 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);279 280 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();281 Assert.assertEquals(action.getName(), "send");282 283 Assert.assertEquals(action.getEndpoint(), messageEndpoint);284 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);285 286 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();287 Assert.assertEquals(messageBuilder.getPayloadData(), "somePayloadData");288 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);289 }290 291 @Test292 public void testSendBuilderWithEndpointName() {293 reset(applicationContextMock);294 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());295 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());296 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());297 final MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {298 @Override299 public void configure() {300 send("fooMessageEndpoint")301 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");302 }303 };304 builder.configure();305 final TestCase test = builder.getTestCase();306 Assert.assertEquals(test.getActionCount(), 1);307 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);308 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);309 310 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();311 Assert.assertEquals(action.getName(), "send");312 Assert.assertEquals(action.getEndpointUri(), "fooMessageEndpoint");313 }314 315 @Test316 public void testSendBuilderWithHeaders() {317 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {318 @Override319 public void configure() {320 send(messageEndpoint)321 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")322 .headers(Collections.singletonMap("some", "value"))323 .header("operation", "foo")324 .header("language", "eng");325 }326 };327 builder.configure();328 final TestCase test = builder.getTestCase();329 Assert.assertEquals(test.getActionCount(), 1);330 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);331 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);332 333 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();334 Assert.assertEquals(action.getName(), "send");335 336 Assert.assertEquals(action.getEndpoint(), messageEndpoint);337 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);338 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();339 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");340 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 3L);341 Assert.assertEquals(messageBuilder.getMessageHeaders().get("some"), "value");342 Assert.assertEquals(messageBuilder.getMessageHeaders().get("operation"), "foo");343 Assert.assertEquals(messageBuilder.getMessageHeaders().get("language"), "eng");344 }345 346 @Test347 public void testSendBuilderWithHeaderData() {348 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {349 @Override350 public void configure() {351 send(messageEndpoint)352 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")353 .header("<Header><Name>operation</Name><Value>foo</Value></Header>");354 355 send(messageEndpoint)356 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))357 .header("<Header><Name>operation</Name><Value>foo</Value></Header>");358 }359 };360 builder.configure();361 final TestCase test = builder.getTestCase();362 Assert.assertEquals(test.getActionCount(), 2);363 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);364 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);365 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);366 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), SendMessageAction.class);367 368 SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();369 Assert.assertEquals(action.getName(), "send");370 371 Assert.assertEquals(action.getEndpoint(), messageEndpoint);372 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);373 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();374 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");375 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);376 Assert.assertEquals(messageBuilder.getHeaderData().size(), 1L);377 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");378 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);379 action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();380 Assert.assertEquals(action.getName(), "send");381 Assert.assertEquals(action.getEndpoint(), messageEndpoint);382 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);383 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();384 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");385 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);386 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 1L);387 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");388 Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);389 }390 @Test391 public void testSendBuilderWithMultipleHeaderData() {392 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {393 @Override394 public void configure() {395 send(messageEndpoint)396 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")397 .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")398 .header("<Header><Name>operation</Name><Value>foo2</Value></Header>");399 send(messageEndpoint)400 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))401 .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")402 .header("<Header><Name>operation</Name><Value>foo2</Value></Header>");403 }404 };405 builder.configure();406 final TestCase test = builder.getTestCase();407 Assert.assertEquals(test.getActionCount(), 2);408 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);409 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);410 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);411 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), SendMessageAction.class);412 SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();413 Assert.assertEquals(action.getName(), "send");414 Assert.assertEquals(action.getEndpoint(), messageEndpoint);415 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);416 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();417 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");418 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);419 Assert.assertEquals(messageBuilder.getHeaderData().size(), 2L);420 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");421 Assert.assertEquals(messageBuilder.getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");422 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);423 action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();424 Assert.assertEquals(action.getName(), "send");425 Assert.assertEquals(action.getEndpoint(), messageEndpoint);426 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);427 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();428 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");429 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);430 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 2L);431 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");432 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");433 Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);434 }435 436 @Test437 public void testSendBuilderWithHeaderDataResource() throws IOException {438 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {439 @Override440 public void configure() {441 send(messageEndpoint)442 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")443 .header(resource);444 445 send(messageEndpoint)446 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))447 .header(resource);448 }449 };450 451 reset(resource);452 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("someHeaderData".getBytes()))453 .thenReturn(new ByteArrayInputStream("otherHeaderData".getBytes()));454 builder.configure();455 final TestCase test = builder.getTestCase();456 Assert.assertEquals(test.getActionCount(), 2);457 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);458 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);459 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);460 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), SendMessageAction.class);461 462 SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();463 Assert.assertEquals(action.getName(), "send");464 465 Assert.assertEquals(action.getEndpoint(), messageEndpoint);466 Assert.assertEquals(action.getMessageBuilder().getClass(), PayloadTemplateMessageBuilder.class);467 final PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) action.getMessageBuilder();468 Assert.assertEquals(messageBuilder.getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");469 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);470 Assert.assertEquals(messageBuilder.getHeaderData().size(), 1L);471 Assert.assertEquals(messageBuilder.getHeaderData().get(0), "someHeaderData");472 Assert.assertEquals(messageBuilder.getHeaderResources().size(), 0L);473 action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();474 Assert.assertEquals(action.getName(), "send");475 Assert.assertEquals(action.getEndpoint(), messageEndpoint);476 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);477 final StaticMessageContentBuilder staticMessageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();478 Assert.assertEquals(staticMessageBuilder.getMessage().getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");479 Assert.assertEquals(staticMessageBuilder.getMessageHeaders().size(), 0L);480 Assert.assertEquals(staticMessageBuilder.getHeaderData().size(), 1L);481 Assert.assertEquals(staticMessageBuilder.getHeaderData().get(0), "otherHeaderData");482 Assert.assertEquals(staticMessageBuilder.getHeaderResources().size(), 0L);483 }484 485 @Test486 public void testSendBuilderExtractFromPayload() {487 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {488 @Override489 public void configure() {490 send(messageEndpoint)491 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")492 .extractFromPayload("/TestRequest/Message", "text")493 .extractFromPayload("/TestRequest/Message/@lang", "language");494 }495 };496 builder.configure();497 final TestCase test = builder.getTestCase();498 Assert.assertEquals(test.getActionCount(), 1);499 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);500 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);501 502 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();503 Assert.assertEquals(action.getName(), "send");504 505 Assert.assertEquals(action.getEndpoint(), messageEndpoint);506 507 Assert.assertEquals(action.getVariableExtractors().size(), 1);508 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof XpathPayloadVariableExtractor);509 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message"));510 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message/@lang"));511 }512 @Test513 public void testSendBuilderExtractJsonPathFromPayload() {514 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {515 @Override516 public void configure() {517 send(messageEndpoint)518 .messageType(MessageType.JSON)519 .payload("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}")520 .extractFromPayload("$.text", "text")521 .extractFromPayload("$.person", "language");522 }523 };524 builder.configure();525 final TestCase test = builder.getTestCase();526 Assert.assertEquals(test.getActionCount(), 1);527 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);528 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);529 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();530 Assert.assertEquals(action.getName(), "send");531 Assert.assertEquals(action.getEndpoint(), messageEndpoint);532 Assert.assertEquals(action.getVariableExtractors().size(), 1);533 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof JsonPathVariableExtractor);534 Assert.assertTrue(((JsonPathVariableExtractor)action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.text"));535 Assert.assertTrue(((JsonPathVariableExtractor)action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.person"));536 }537 538 @Test539 public void testSendBuilderExtractFromHeader() {540 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {541 @Override542 public void configure() {543 send(messageEndpoint)544 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")545 .extractFromHeader("operation", "ops")546 .extractFromHeader("requestId", "id");547 }548 };549 builder.configure();550 final TestCase test = builder.getTestCase();551 Assert.assertEquals(test.getActionCount(), 1);552 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);553 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);554 555 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();556 Assert.assertEquals(action.getName(), "send");557 558 Assert.assertEquals(action.getEndpoint(), messageEndpoint);559 560 Assert.assertEquals(action.getVariableExtractors().size(), 1);561 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof MessageHeaderVariableExtractor);562 Assert.assertTrue(((MessageHeaderVariableExtractor)action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("operation"));563 Assert.assertTrue(((MessageHeaderVariableExtractor)action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("requestId"));564 }565 @Test566 public void testXpathSupport() {567 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {568 @Override569 public void configure() {570 send(messageEndpoint)571 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")572 .xpath("/TestRequest/Message", "Hello World!");573 }574 };575 builder.configure();576 final TestCase test = builder.getTestCase();577 Assert.assertEquals(test.getActionCount(), 1);578 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);579 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);580 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();581 Assert.assertEquals(action.getName(), "send");582 Assert.assertEquals(action.getEndpoint(), messageEndpoint);583 Assert.assertTrue(action.getMessageBuilder() instanceof AbstractMessageContentBuilder);584 Assert.assertEquals(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().size(), 1);585 Assert.assertTrue(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0) instanceof XpathMessageConstructionInterceptor);586 Assert.assertEquals(((XpathMessageConstructionInterceptor)((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0)).getXPathExpressions().get("/TestRequest/Message"), "Hello World!");587 }588 @Test589 public void testJsonPathSupport() {590 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {591 @Override592 public void configure() {593 send(messageEndpoint)594 .payload("{ \"TestRequest\": { \"Message\": \"?\" }}")595 .jsonPath("$.TestRequest.Message", "Hello World!");596 }597 };598 builder.configure();599 final TestCase test = builder.getTestCase();600 Assert.assertEquals(test.getActionCount(), 1);601 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);602 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);603 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();604 Assert.assertEquals(action.getName(), "send");605 Assert.assertEquals(action.getEndpoint(), messageEndpoint);606 Assert.assertTrue(action.getMessageBuilder() instanceof AbstractMessageContentBuilder);607 Assert.assertEquals(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().size(), 1);608 Assert.assertTrue(((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0) instanceof JsonPathMessageConstructionInterceptor);609 Assert.assertEquals(((JsonPathMessageConstructionInterceptor)((AbstractMessageContentBuilder) action.getMessageBuilder()).getMessageInterceptors().get(0)).getJsonPathExpressions().get("$.TestRequest.Message"), "Hello World!");610 }611 @Test612 public void testSendBuilderWithDictionary() {613 final DataDictionary dictionary = new NodeMappingDataDictionary();614 reset(applicationContextMock);615 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());616 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());617 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());618 final MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {619 @Override620 public void configure() {621 send(messageEndpoint)622 .payload("{ \"TestRequest\": { \"Message\": \"?\" }}")623 .dictionary(dictionary);624 }625 };626 builder.configure();627 final TestCase test = builder.getTestCase();628 Assert.assertEquals(test.getActionCount(), 1);629 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);630 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);631 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();632 Assert.assertEquals(action.getName(), "send");633 Assert.assertEquals(action.getEndpoint(), messageEndpoint);634 Assert.assertEquals(action.getDataDictionary(), dictionary);635 }636 @Test637 public void testSendBuilderWithDictionaryName() {638 final DataDictionary dictionary = new NodeMappingDataDictionary();639 reset(applicationContextMock);640 when(applicationContextMock.getBean("customDictionary", DataDictionary.class)).thenReturn(dictionary);641 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());642 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<>());643 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<>());644 final MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {645 @Override646 public void configure() {647 send(messageEndpoint)648 .payload("TestMessage")649 .header("operation", "sayHello")650 .dictionary("customDictionary");651 }652 };653 builder.configure();654 final TestCase test = builder.getTestCase();655 Assert.assertEquals(test.getActionCount(), 1);656 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);657 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);658 final SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();659 Assert.assertEquals(action.getName(), "send");660 Assert.assertEquals(action.getEndpoint(), messageEndpoint);661 Assert.assertEquals(action.getDataDictionary(), dictionary);662 }663}...

Full Screen

Full Screen

Source:SendHttpMessageTestDesignerTest.java Github

copy

Full Screen

...14 * limitations under the License.15 */16package com.consol.citrus.dsl.design;17import com.consol.citrus.TestCase;18import com.consol.citrus.actions.SendMessageAction;19import com.consol.citrus.dsl.actions.DelegatingTestAction;20import com.consol.citrus.endpoint.resolver.DynamicEndpointUriResolver;21import com.consol.citrus.http.client.HttpClient;22import com.consol.citrus.http.message.HttpMessageContentBuilder;23import com.consol.citrus.http.message.HttpMessageHeaders;24import com.consol.citrus.message.DefaultMessage;25import com.consol.citrus.testng.AbstractTestNGUnitTest;26import com.consol.citrus.validation.builder.StaticMessageContentBuilder;27import org.mockito.Mockito;28import org.springframework.context.ApplicationContext;29import org.springframework.http.HttpMethod;30import org.testng.Assert;31import org.testng.annotations.Test;32/**33 * @author Christoph Deppisch34 */35public class SendHttpMessageTestDesignerTest extends AbstractTestNGUnitTest {36 private HttpClient httpClient = Mockito.mock(HttpClient.class);37 private ApplicationContext applicationContextMock = Mockito.mock(ApplicationContext.class);38 @Test39 public void testFork() {40 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {41 @Override42 public void configure() {43 send(httpClient)44 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))45 .header("additional", "additionalValue");46 send(httpClient)47 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))48 .fork(true);49 }50 };51 builder.configure();52 TestCase test = builder.getTestCase();53 Assert.assertEquals(test.getActionCount(), 2);54 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);55 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);56 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);57 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), SendMessageAction.class);58 SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();59 Assert.assertEquals(action.getName(), "send");60 Assert.assertEquals(action.getEndpoint(), httpClient);61 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);62 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();63 Assert.assertEquals(messageBuilder.getMessage().getPayload(String.class), "Foo");64 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");65 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 1L);66 Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "additionalValue");67 Assert.assertFalse(action.isForkMode());68 action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();69 Assert.assertEquals(action.getName(), "send");70 Assert.assertEquals(action.getEndpoint(), httpClient);71 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);72 Assert.assertTrue(action.isForkMode());73 }74 @Test75 public void testHttpMethod() {76 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {77 @Override78 public void configure() {79 http().client(httpClient)80 .send()81 .get()82 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");83 }84 };85 builder.configure();86 TestCase test = builder.getTestCase();87 Assert.assertEquals(test.getActionCount(), 1);88 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);89 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);90 SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();91 Assert.assertEquals(action.getName(), "send");92 Assert.assertEquals(action.getEndpoint(), httpClient);93 Assert.assertEquals(action.getMessageBuilder().getClass(), HttpMessageContentBuilder.class);94 HttpMessageContentBuilder messageBuilder = (HttpMessageContentBuilder) action.getMessageBuilder();95 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");96 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), 3L);97 Assert.assertEquals(messageBuilder.getMessage().getHeaders().get(HttpMessageHeaders.HTTP_REQUEST_METHOD), HttpMethod.GET.name());98 }99 @Test100 public void testHttpRequestUriAndPath() {101 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {102 @Override103 public void configure() {104 http().client(httpClient)105 .send()106 .get("/test")107 .uri("http://localhost:8080/")108 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");109 }110 };111 builder.configure();112 TestCase test = builder.getTestCase();113 Assert.assertEquals(test.getActionCount(), 1);114 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);115 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);116 SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();117 Assert.assertEquals(action.getName(), "send");118 Assert.assertEquals(action.getEndpoint(), httpClient);119 Assert.assertEquals(action.getMessageBuilder().getClass(), HttpMessageContentBuilder.class);120 HttpMessageContentBuilder messageBuilder = (HttpMessageContentBuilder) action.getMessageBuilder();121 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");122 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), 6L);123 Assert.assertEquals(messageBuilder.getMessage().getHeaders().get(HttpMessageHeaders.HTTP_REQUEST_URI), "http://localhost:8080/");124 Assert.assertEquals(messageBuilder.getMessage().getHeaders().get(DynamicEndpointUriResolver.ENDPOINT_URI_HEADER_NAME), "http://localhost:8080/");125 Assert.assertEquals(messageBuilder.getMessage().getHeaders().get(DynamicEndpointUriResolver.REQUEST_PATH_HEADER_NAME), "/test");126 }127 @Test128 public void testHttpRequestUriAndQueryParams() {129 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {130 @Override131 public void configure() {132 http().client(httpClient)133 .send()134 .get()135 .uri("http://localhost:8080/")136 .queryParam("param1", "value1")137 .queryParam("param2", "value2")138 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");139 }140 };141 builder.configure();142 TestCase test = builder.getTestCase();143 Assert.assertEquals(test.getActionCount(), 1);144 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);145 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);146 SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();147 Assert.assertEquals(action.getName(), "send");148 Assert.assertEquals(action.getEndpoint(), httpClient);149 Assert.assertEquals(action.getMessageBuilder().getClass(), HttpMessageContentBuilder.class);150 HttpMessageContentBuilder messageBuilder = (HttpMessageContentBuilder) action.getMessageBuilder();151 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");152 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), 7L);153 Assert.assertEquals(messageBuilder.getMessage().getHeaders().get(HttpMessageHeaders.HTTP_REQUEST_URI), "http://localhost:8080/");154 Assert.assertEquals(messageBuilder.getMessage().getHeaders().get(DynamicEndpointUriResolver.ENDPOINT_URI_HEADER_NAME), "http://localhost:8080/");155 Assert.assertEquals(messageBuilder.getMessage().getHeaders().get(DynamicEndpointUriResolver.QUERY_PARAM_HEADER_NAME), "param1=value1,param2=value2");156 }157}...

Full Screen

Full Screen

SendMessageAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.builder;2import com.consol.citrus.actions.SendMessageAction;3import com.consol.citrus.dsl.runner.TestRunner;4import com.consol.citrus.message.MessageType;5public class SendMessageActionBuilder extends AbstractTestActionBuilder<SendMessageAction> {6 public SendMessageActionBuilder(TestRunner testRunner, SendMessageAction action) {7 super(testRunner, action);8 }9 public SendMessageActionBuilder message(String payload) {10 action.setMessage(payload);11 return this;12 }13 public SendMessageActionBuilder message(byte[] payload) {14 action.setMessage(payload);15 return this;16 }17 public SendMessageActionBuilder message(Object payload) {18 action.setMessage(payload);19 return this;20 }21 public SendMessageActionBuilder message(Object payload, MessageType messageType) {22 action.setMessage(payload, messageType);23 return this;24 }25 public SendMessageActionBuilder messageName(String name) {26 action.setMessageName(name);27 return this;28 }29 public SendMessageActionBuilder endpoint(String uri) {30 action.setEndpointUri(uri);31 return this;32 }33 public SendMessageActionBuilder messageType(MessageType messageType) {34 action.setMessageType(messageType);35 return this;36 }37 public SendMessageActionBuilder headers(String headers) {38 action.setMessageHeaders(headers);39 return this;40 }

Full Screen

Full Screen

SendMessageAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.design;2import com.consol.citrus.dsl.builder.SendMessageBuilder;3import com.consol.citrus.message.MessageType;4import com.consol.citrus.testng.AbstractTestNGCitrusTest;5import org.springframework.core.io.ClassPathResource;6import org.testng.annotations.Test;7public class SendMessageActionJavaITest extends AbstractTestNGCitrusTest {8 public void sendMessageActionJavaITest() {9 variable("messageId", "1234567890");10 variable("messageType", "TestMessage");11 variable("correlationId", "0987654321");12 variable("contentType", "text/xml");13 variable("data", "Hello Citrus!");14 parallel(15 sequential(16 send("sendMessageActionJavaITestClient")17 .endpoint("sendMessageActionJavaITestEndpoint")18 .payload("<TestMessage>" +19 .header("operation", "greetMe")20 .header("messageId", "${messageId}")21 .header("messageType", "${messageType}")22 .header("correlationId", "${correlationId}")23 .header("contentType", "${contentType}")24 .header("data", "${data}")25 .header("endpointUri", "${endpointUri}")26 sequential(27 receive("sendMessageActionJavaITestClient")28 .endpoint("sendMessageActionJavaITestEndpoint")29 .payload("<TestMessage>" +30 .header("operation", "greetMe")31 .header("messageId", "${messageId}")32 .header("messageType", "${messageType}")33 .header("correlationId", "${correlationId}")34 .header("contentType", "${contentType}")35 .header("data", "${data}")36 .header("endpointUri", "${endpointUri}")37 );38 }39}40package com.consol.citrus.dsl.design;41import com.consol.citrus.dsl.builder.SendMessageBuilder;42import com.consol.citrus.message.MessageType;43import com.consol.citrus.testng.AbstractTestNGCitrusTest;44import org.springframework.core.io

Full Screen

Full Screen

SendMessageAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.design;2import com.consol.citrus.dsl.builder.SendMessageActionBuilder;3import com.consol.citrus.dsl.builder.SendSoapMessageActionBuilder;4import com.consol.citrus.dsl.builder.SendSoapMessageBuilder;5import com.consol.citrus.dsl.builder.SendSoapMessageBuilderSupport;6import com.consol.citrus.message.MessageType;7import com.consol.citrus.testng.AbstractTestNGCitrusTest;8import com.consol.citrus.ws.actions.SendMessageAction;9import org.springframework.http.HttpStatus;10import org.springframework.http.MediaType;11import org.testng.annotations.Test;12import static com.consol.citrus.actions.SendMessageAction.Builder.send;13import static com.consol.citrus.dsl.builder.SendMessageActionBuilder.send;14import static com.consol.citrus.dsl.builder.SendSoapMessageActionBuilder.soap;15import static com.consol.citrus.dsl.builder.SendSoapMessageBuilder.soap;16import static com.consol.citrus.dsl.builder.SendSoapMessageBuilderSupport.soap;17public class SendMessageActionTest extends AbstractTestNGCitrusTest {18 public void send() {19 send(sendMessageActionBuilder -> sendMessageActionBuilder.message("Hello World!"));20 }21 public void sendWithMessageName() {22 send(sendMessageActionBuilder -> sendMessageActionBuilder.messageName("HelloMessage"));23 }24 public void sendWithEndpoint() {25 send(sendMessageActionBuilder -> sendMessageActionBuilder.endpoint("helloEndpoint"));26 }27 public void sendWithEndpointName() {28 send(sendMessageActionBuilder -> sendMessageActionBuilder.endpointName("helloEndpoint"));29 }30 public void sendWithMessage() {31 send(sendMessageActionBuilder -> sendMessageActionBuilder.message("Hello World!"));32 }33 public void sendWithMessageBuilder() {34 send(sendMessageActionBuilder -> sendMessageActionBuilder.message(sendSoapMessageBuilder -> sendSoapMessageBuilder.soap().client("helloClient")));35 }36 public void sendWithMessageBuilderSupport() {37 send(sendMessageActionBuilder -> sendMessageActionBuilder.message(sendSoapMessageBuilderSupport -> sendSoapMessageBuilderSupport.soap().client("helloClient")));38 }39 public void sendWithMessageActionBuilder() {40 send(sendMessageActionBuilder -> sendMessageActionBuilder.message(sendSoapMessageActionBuilder -> sendSoapMessageActionBuilder.soap().client("hello

Full Screen

Full Screen

SendMessageAction

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.design;2import com.consol.citrus.dsl.builder.SendMessageActionBuilder;3import com.consol.citrus.dsl.design.TestDesigner;4import com.consol.citrus.dsl.design.TestDesignerBeforeTestSupport;5import com.consol.citrus.message.MessageType;6import org.testng.annotations.Test;7public class SendMessageActionJavaITest extends TestDesignerBeforeTestSupport {8 public void sendMessageActionJavaITest() {9 variable("message", "Hello Citrus!");10 variable("contentType", "text/plain");11 variable("correlationId", "1234567890");12 variable("charset", "UTF-8");13 variable("headerName", "operation");14 variable("headerValue", "greet");15 variable("headerName2", "citrus:testCaseName");16 variable("headerValue2", "Citrus:Java:sendMessageAction");17 variable("headerName3", "citrus:testCaseName");18 variable("headerValue3", "Citrus:Java:sendMessageAction");19 variable("headerName4", "citrus:testCaseName");20 variable("headerValue4", "Citrus:Java:sendMessageAction");21 variable("headerName5", "citrus:testCaseName");22 variable("headerValue5", "Citrus:Java:sendMessageAction");23 variable("headerName6", "citrus:testCaseName");24 variable("headerValue6", "Citrus:Java:sendMessageAction");25 variable("headerName7", "citrus:testCaseName");26 variable("headerValue7", "Citrus:Java:sendMessageAction");27 variable("headerName8", "citrus:testCaseName");28 variable("headerValue8", "Citrus:Java:sendMessageAction");29 variable("headerName9", "citrus:testCaseName");30 variable("headerValue9", "Citrus:Java:sendMessageAction");31 variable("headerName10", "citrus:testCaseName");32 variable("headerValue10", "Citrus:Java:sendMessageAction");33 variable("headerName11", "citrus:testCaseName");34 variable("headerValue11", "Citrus:Java:sendMessageAction");35 variable("headerName12", "citrus:testCaseName");36 variable("headerValue12", "Citrus:Java:sendMessageAction");37 variable("headerName13", "citrus:testCase

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful