How to use PayloadTemplateMessageBuilder method of com.consol.citrus.actions.ReceiveMessageAction class

Best Citrus code snippet using com.consol.citrus.actions.ReceiveMessageAction.PayloadTemplateMessageBuilder

Source:ReceiveMessageTestDesignerTest.java Github

copy

Full Screen

...26import com.consol.citrus.report.TestActionListeners;27import com.consol.citrus.script.ScriptTypes;28import com.consol.citrus.testng.AbstractTestNGUnitTest;29import com.consol.citrus.validation.MessageValidator;30import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;31import com.consol.citrus.validation.builder.StaticMessageContentBuilder;32import com.consol.citrus.validation.callback.ValidationCallback;33import com.consol.citrus.validation.context.HeaderValidationContext;34import com.consol.citrus.validation.json.*;35import com.consol.citrus.validation.script.GroovyJsonMessageValidator;36import com.consol.citrus.validation.script.ScriptValidationContext;37import com.consol.citrus.validation.text.PlainTextMessageValidator;38import com.consol.citrus.validation.xml.*;39import com.consol.citrus.variable.MessageHeaderVariableExtractor;40import com.consol.citrus.variable.dictionary.DataDictionary;41import com.consol.citrus.variable.dictionary.xml.NodeMappingDataDictionary;42import org.hamcrest.core.StringContains;43import org.mockito.Mockito;44import org.springframework.context.ApplicationContext;45import org.springframework.core.io.ClassPathResource;46import org.springframework.core.io.Resource;47import org.springframework.oxm.Marshaller;48import org.springframework.oxm.xstream.XStreamMarshaller;49import org.testng.Assert;50import org.testng.annotations.BeforeClass;51import org.testng.annotations.Test;52import java.io.ByteArrayInputStream;53import java.io.IOException;54import java.util.*;55import static org.hamcrest.Matchers.containsString;56import static org.mockito.Mockito.reset;57import static org.mockito.Mockito.when;58/**59 * @author Christoph Deppisch60 */61public class ReceiveMessageTestDesignerTest extends AbstractTestNGUnitTest {62 63 private Endpoint messageEndpoint = Mockito.mock(Endpoint.class);64 private Resource resource = Mockito.mock(Resource.class);65 private ApplicationContext applicationContextMock = Mockito.mock(ApplicationContext.class);66 private XStreamMarshaller marshaller = new XStreamMarshaller();67 @BeforeClass68 public void prepareMarshaller() {69 marshaller.getXStream().processAnnotations(TestRequest.class);70 }71 @Test72 public void testReceiveEmpty() {73 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {74 @Override75 public void configure() {76 receive(messageEndpoint);77 }78 };79 builder.configure();80 TestCase test = builder.getTestCase();81 Assert.assertEquals(test.getActionCount(), 1);82 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);83 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);84 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();85 Assert.assertEquals(action.getName(), "receive");86 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());87 Assert.assertEquals(action.getEndpoint(), messageEndpoint);88 Assert.assertEquals(action.getValidationContexts().size(), 3);89 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);90 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);91 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);92 }93 @Test94 public void testReceiveBuilder() {95 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {96 @Override97 public void configure() {98 receive(messageEndpoint)99 .message(new DefaultMessage("Foo").setHeader("operation", "foo"));100 }101 };102 builder.configure();103 TestCase test = builder.getTestCase();104 Assert.assertEquals(test.getActionCount(), 1);105 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);106 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);107 108 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();109 Assert.assertEquals(action.getName(), "receive");110 111 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());112 Assert.assertEquals(action.getEndpoint(), messageEndpoint);113 Assert.assertEquals(action.getValidationContexts().size(), 3);114 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);115 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);116 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);117 118 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);119 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "Foo");120 Assert.assertNotNull(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getHeader("operation"));121 }122 @Test123 public void testReceiveBuilderWithPayloadModel() {124 reset(applicationContextMock);125 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());126 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());127 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());128 when(applicationContextMock.getBeansOfType(Marshaller.class)).thenReturn(Collections.<String, Marshaller>singletonMap("marshaller", marshaller));129 when(applicationContextMock.getBean(Marshaller.class)).thenReturn(marshaller);130 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {131 @Override132 public void configure() {133 receive(messageEndpoint)134 .payloadModel(new TestRequest("Hello Citrus!"));135 }136 };137 builder.configure();138 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(), ReceiveMessageAction.class);142 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();143 Assert.assertEquals(action.getName(), "receive");144 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());145 Assert.assertEquals(action.getEndpoint(), messageEndpoint);146 Assert.assertEquals(action.getValidationContexts().size(), 3);147 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);148 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);149 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);150 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);151 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");152 }153 @Test154 public void testReceiveBuilderWithPayloadModelExplicitMarshaller() {155 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {156 @Override157 public void configure() {158 receive(messageEndpoint)159 .payload(new TestRequest("Hello Citrus!"), marshaller);160 }161 };162 builder.configure();163 TestCase test = builder.getTestCase();164 Assert.assertEquals(test.getActionCount(), 1);165 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);166 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);167 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();168 Assert.assertEquals(action.getName(), "receive");169 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());170 Assert.assertEquals(action.getEndpoint(), messageEndpoint);171 Assert.assertEquals(action.getValidationContexts().size(), 3);172 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);173 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);174 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);175 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);176 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");177 }178 @Test179 public void testReceiveBuilderWithPayloadModelExplicitMarshallerName() {180 reset(applicationContextMock);181 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());182 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());183 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());184 when(applicationContextMock.containsBean("myMarshaller")).thenReturn(true);185 when(applicationContextMock.getBean("myMarshaller")).thenReturn(marshaller);186 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {187 @Override188 public void configure() {189 receive(messageEndpoint)190 .payload(new TestRequest("Hello Citrus!"), "myMarshaller");191 }192 };193 builder.configure();194 TestCase test = builder.getTestCase();195 Assert.assertEquals(test.getActionCount(), 1);196 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);197 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);198 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();199 Assert.assertEquals(action.getName(), "receive");200 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());201 Assert.assertEquals(action.getEndpoint(), messageEndpoint);202 Assert.assertEquals(action.getValidationContexts().size(), 3);203 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);204 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);205 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);206 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);207 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");208 }209 210 @Test211 public void testReceiveBuilderWithPayloadString() {212 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {213 @Override214 public void configure() {215 receive(messageEndpoint)216 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");217 }218 };219 builder.configure();220 TestCase test = builder.getTestCase();221 Assert.assertEquals(test.getActionCount(), 1);222 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);223 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);224 225 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();226 Assert.assertEquals(action.getName(), "receive");227 228 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());229 Assert.assertEquals(action.getEndpoint(), messageEndpoint);230 Assert.assertEquals(action.getValidationContexts().size(), 3);231 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);232 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);233 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);234 235 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);236 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");237 }238 239 @Test240 public void testReceiveBuilderWithPayloadResource() throws IOException {241 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {242 @Override243 public void configure() {244 receive(messageEndpoint)245 .payload(resource);246 }247 };248 249 reset(resource);250 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("somePayload".getBytes()));251 builder.configure();252 TestCase test = builder.getTestCase();253 Assert.assertEquals(test.getActionCount(), 1);254 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);255 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);256 257 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();258 Assert.assertEquals(action.getName(), "receive");259 260 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());261 Assert.assertEquals(action.getEndpoint(), messageEndpoint);262 Assert.assertEquals(action.getValidationContexts().size(), 3);263 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);264 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);265 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);266 267 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);268 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "somePayload");269 }270 271 @Test272 public void testReceiveBuilderWithEndpointName() {273 reset(applicationContextMock);274 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());275 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());276 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());277 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {278 @Override279 public void configure() {280 receive("fooMessageEndpoint")281 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");282 }283 };284 builder.configure();285 TestCase test = builder.getTestCase();286 Assert.assertEquals(test.getActionCount(), 1);287 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);288 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);289 290 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();291 Assert.assertEquals(action.getName(), "receive");292 Assert.assertEquals(action.getEndpointUri(), "fooMessageEndpoint");293 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());294 }295 296 @Test297 public void testReceiveBuilderWithTimeout() {298 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {299 @Override300 public void configure() {301 receive(messageEndpoint)302 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")303 .timeout(1000L);304 }305 };306 builder.configure();307 TestCase test = builder.getTestCase();308 Assert.assertEquals(test.getActionCount(), 1);309 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);310 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);311 312 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();313 Assert.assertEquals(action.getName(), "receive");314 315 Assert.assertEquals(action.getEndpoint(), messageEndpoint);316 Assert.assertEquals(action.getReceiveTimeout(), 1000L);317 }318 319 @Test320 public void testReceiveBuilderWithHeaders() {321 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {322 @Override323 public void configure() {324 receive(messageEndpoint)325 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")326 .headers(Collections.singletonMap("some", "value"))327 .header("operation", "sayHello")328 .header("foo", "bar");329 330 receive(messageEndpoint)331 .header("operation", "sayHello")332 .header("foo", "bar")333 .headers(Collections.singletonMap("some", "value"))334 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");335 }336 };337 builder.configure();338 TestCase test = builder.getTestCase();339 Assert.assertEquals(test.getActionCount(), 2);340 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);341 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);342 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);343 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), ReceiveMessageAction.class);344 345 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();346 Assert.assertEquals(action.getName(), "receive");347 348 Assert.assertEquals(action.getEndpoint(), messageEndpoint);349 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());350 351 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);352 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");353 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("some"));354 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));355 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("foo"));356 357 action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();358 Assert.assertEquals(action.getName(), "receive");359 360 Assert.assertEquals(action.getEndpoint(), messageEndpoint);361 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());362 363 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);364 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");365 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("some"));366 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));367 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("foo"));368 }369 370 @Test371 public void testReceiveBuilderWithHeaderData() {372 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {373 @Override374 public void configure() {375 receive(messageEndpoint)376 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")377 .header("<Header><Name>operation</Name><Value>foo</Value></Header>");378 379 receive(messageEndpoint)380 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))381 .header("<Header><Name>operation</Name><Value>foo</Value></Header>");382 }383 };384 builder.configure();385 TestCase test = builder.getTestCase();386 Assert.assertEquals(test.getActionCount(), 2);387 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);388 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);389 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);390 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), ReceiveMessageAction.class);391 392 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();393 Assert.assertEquals(action.getName(), "receive");394 395 Assert.assertEquals(action.getEndpoint(), messageEndpoint);396 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());397 398 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);399 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");400 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().size(), 1L);401 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");402 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderResources().size(), 0L);403 404 action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();405 Assert.assertEquals(action.getName(), "receive");406 407 Assert.assertEquals(action.getEndpoint(), messageEndpoint);408 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());409 410 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);411 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");412 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().size(), 1L);413 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");414 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderResources().size(), 0L);415 }416 @Test417 public void testReceiveBuilderWithMultipleHeaderData() {418 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {419 @Override420 public void configure() {421 receive(messageEndpoint)422 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")423 .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")424 .header("<Header><Name>operation</Name><Value>foo2</Value></Header>");425 receive(messageEndpoint)426 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))427 .header("<Header><Name>operation</Name><Value>foo1</Value></Header>")428 .header("<Header><Name>operation</Name><Value>foo2</Value></Header>");429 }430 };431 builder.configure();432 TestCase test = builder.getTestCase();433 Assert.assertEquals(test.getActionCount(), 2);434 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);435 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);436 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);437 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), ReceiveMessageAction.class);438 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();439 Assert.assertEquals(action.getName(), "receive");440 Assert.assertEquals(action.getEndpoint(), messageEndpoint);441 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());442 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);443 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");444 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().size(), 2L);445 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");446 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");447 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderResources().size(), 0L);448 action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();449 Assert.assertEquals(action.getName(), "receive");450 Assert.assertEquals(action.getEndpoint(), messageEndpoint);451 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());452 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);453 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");454 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().size(), 2L);455 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo1</Value></Header>");456 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().get(1), "<Header><Name>operation</Name><Value>foo2</Value></Header>");457 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderResources().size(), 0L);458 }459 @Test460 public void testReceiveBuilderWithHeaderFragment() {461 reset(applicationContextMock);462 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());463 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());464 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());465 when(applicationContextMock.getBeansOfType(Marshaller.class)).thenReturn(Collections.<String, Marshaller>singletonMap("marshaller", marshaller));466 when(applicationContextMock.getBean(Marshaller.class)).thenReturn(marshaller);467 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {468 @Override469 public void configure() {470 receive(messageEndpoint)471 .headerFragment(new TestRequest("Hello Citrus!"));472 }473 };474 builder.configure();475 TestCase test = builder.getTestCase();476 Assert.assertEquals(test.getActionCount(), 1);477 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);478 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);479 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();480 Assert.assertEquals(action.getName(), "receive");481 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());482 Assert.assertEquals(action.getEndpoint(), messageEndpoint);483 Assert.assertEquals(action.getValidationContexts().size(), 3);484 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);485 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);486 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);487 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);488 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().size(), 1L);489 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");490 }491 @Test492 public void testReceiveBuilderWithHeaderFragmentExplicitMarshaller() {493 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {494 @Override495 public void configure() {496 receive(messageEndpoint)497 .headerFragment(new TestRequest("Hello Citrus!"), marshaller);498 }499 };500 builder.configure();501 TestCase test = builder.getTestCase();502 Assert.assertEquals(test.getActionCount(), 1);503 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);504 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);505 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();506 Assert.assertEquals(action.getName(), "receive");507 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());508 Assert.assertEquals(action.getEndpoint(), messageEndpoint);509 Assert.assertEquals(action.getValidationContexts().size(), 3);510 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);511 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);512 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);513 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);514 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().size(), 1L);515 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");516 }517 @Test518 public void testReceiveBuilderWithHeaderFragmentExplicitMarshallerName() {519 reset(applicationContextMock);520 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());521 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());522 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());523 when(applicationContextMock.containsBean("myMarshaller")).thenReturn(true);524 when(applicationContextMock.getBean("myMarshaller")).thenReturn(marshaller);525 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {526 @Override527 public void configure() {528 receive(messageEndpoint)529 .headerFragment(new TestRequest("Hello Citrus!"), "myMarshaller");530 }531 };532 builder.configure();533 TestCase test = builder.getTestCase();534 Assert.assertEquals(test.getActionCount(), 1);535 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);536 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);537 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();538 Assert.assertEquals(action.getName(), "receive");539 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());540 Assert.assertEquals(action.getEndpoint(), messageEndpoint);541 Assert.assertEquals(action.getValidationContexts().size(), 3);542 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);543 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);544 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);545 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);546 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().size(), 1L);547 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<TestRequest><Message>Hello Citrus!</Message></TestRequest>");548 }549 550 @Test551 public void testReceiveBuilderWithHeaderResource() throws IOException {552 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {553 @Override554 public void configure() {555 receive(messageEndpoint)556 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")557 .header(resource);558 559 receive(messageEndpoint)560 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))561 .header(resource);562 }563 };564 565 reset(resource);566 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("someHeaderData".getBytes()))567 .thenReturn(new ByteArrayInputStream("otherHeaderData".getBytes()));568 builder.configure();569 TestCase test = builder.getTestCase();570 Assert.assertEquals(test.getActionCount(), 2);571 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);572 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);573 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);574 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), ReceiveMessageAction.class);575 576 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();577 Assert.assertEquals(action.getName(), "receive");578 579 Assert.assertEquals(action.getEndpoint(), messageEndpoint);580 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());581 582 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);583 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");584 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().size(), 1L);585 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(0), "someHeaderData");586 587 action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();588 Assert.assertEquals(action.getName(), "receive");589 590 Assert.assertEquals(action.getEndpoint(), messageEndpoint);591 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());592 593 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);594 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");595 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().size(), 1L);596 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().get(0), "otherHeaderData");597 }598 @Test599 public void testReceiveBuilderWithMultipleHeaderResource() throws IOException {600 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {601 @Override602 public void configure() {603 receive(messageEndpoint)604 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")605 .header("<Header><Name>operation</Name><Value>foo</Value></Header>")606 .header(resource);607 receive(messageEndpoint)608 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>"))609 .header("<Header><Name>operation</Name><Value>foo</Value></Header>")610 .header(resource);611 }612 };613 reset(resource);614 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("someHeaderData".getBytes()))615 .thenReturn(new ByteArrayInputStream("otherHeaderData".getBytes()));616 builder.configure();617 TestCase test = builder.getTestCase();618 Assert.assertEquals(test.getActionCount(), 2);619 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);620 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);621 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);622 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), ReceiveMessageAction.class);623 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();624 Assert.assertEquals(action.getName(), "receive");625 Assert.assertEquals(action.getEndpoint(), messageEndpoint);626 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());627 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);628 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>Hello World!</Message></TestRequest>");629 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().size(), 2L);630 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");631 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getHeaderData().get(1), "someHeaderData");632 action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();633 Assert.assertEquals(action.getName(), "receive");634 Assert.assertEquals(action.getEndpoint(), messageEndpoint);635 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());636 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);637 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");638 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().size(), 2L);639 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().get(0), "<Header><Name>operation</Name><Value>foo</Value></Header>");640 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getHeaderData().get(1), "otherHeaderData");641 }642 643 @Test644 public void testReceiveBuilderWithValidator() {645 final PlainTextMessageValidator validator = new PlainTextMessageValidator();646 647 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {648 @Override649 public void configure() {650 receive(messageEndpoint)651 .messageType(MessageType.PLAINTEXT)652 .payload("TestMessage")653 .header("operation", "sayHello")654 .validator(validator);655 }656 };657 builder.configure();658 TestCase test = builder.getTestCase();659 Assert.assertEquals(test.getActionCount(), 1);660 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);661 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);662 663 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();664 Assert.assertEquals(action.getName(), "receive");665 666 Assert.assertEquals(action.getEndpoint(), messageEndpoint);667 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());668 Assert.assertEquals(action.getValidators().size(), 1L);669 Assert.assertEquals(action.getValidators().get(0), validator);670 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);671 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");672 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));673 }674 675 @Test676 public void testReceiveBuilderWithValidatorName() {677 final PlainTextMessageValidator validator = new PlainTextMessageValidator();678 679 reset(applicationContextMock);680 when(applicationContextMock.getBean("plainTextValidator", MessageValidator.class)).thenReturn(validator);681 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());682 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());683 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());684 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {685 @Override686 public void configure() {687 receive(messageEndpoint)688 .messageType(MessageType.PLAINTEXT)689 .payload("TestMessage")690 .header("operation", "sayHello")691 .validator("plainTextValidator");692 }693 };694 builder.configure();695 TestCase test = builder.getTestCase();696 Assert.assertEquals(test.getActionCount(), 1);697 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);698 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);699 700 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();701 Assert.assertEquals(action.getName(), "receive");702 703 Assert.assertEquals(action.getEndpoint(), messageEndpoint);704 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());705 Assert.assertEquals(action.getValidators().size(), 1L);706 Assert.assertEquals(action.getValidators().get(0), validator);707 708 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);709 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");710 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));711 }712 @Test713 public void testReceiveBuilderWithDictionary() {714 final DataDictionary dictionary = new NodeMappingDataDictionary();715 reset(applicationContextMock);716 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());717 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());718 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());719 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {720 @Override721 public void configure() {722 receive(messageEndpoint)723 .messageType(MessageType.PLAINTEXT)724 .payload("TestMessage")725 .header("operation", "sayHello")726 .dictionary(dictionary);727 }728 };729 builder.configure();730 TestCase test = builder.getTestCase();731 Assert.assertEquals(test.getActionCount(), 1);732 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);733 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);734 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();735 Assert.assertEquals(action.getName(), "receive");736 Assert.assertEquals(action.getEndpoint(), messageEndpoint);737 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());738 Assert.assertEquals(action.getDataDictionary(), dictionary);739 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);740 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");741 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));742 }743 @Test744 public void testReceiveBuilderWithDictionaryName() {745 final DataDictionary dictionary = new NodeMappingDataDictionary();746 reset(applicationContextMock);747 when(applicationContextMock.getBean("customDictionary", DataDictionary.class)).thenReturn(dictionary);748 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());749 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());750 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());751 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {752 @Override753 public void configure() {754 receive(messageEndpoint)755 .messageType(MessageType.PLAINTEXT)756 .payload("TestMessage")757 .header("operation", "sayHello")758 .dictionary("customDictionary");759 }760 };761 builder.configure();762 TestCase test = builder.getTestCase();763 Assert.assertEquals(test.getActionCount(), 1);764 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);765 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);766 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();767 Assert.assertEquals(action.getName(), "receive");768 Assert.assertEquals(action.getEndpoint(), messageEndpoint);769 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());770 Assert.assertEquals(action.getDataDictionary(), dictionary);771 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);772 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");773 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));774 }775 776 @Test777 public void testReceiveBuilderWithSelector() {778 final Map<String, String> messageSelector = new HashMap<String, String>();779 messageSelector.put("operation", "sayHello");780 781 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {782 @Override783 public void configure() {784 receive(messageEndpoint)785 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")786 .selector(messageSelector);787 }788 };789 builder.configure();790 TestCase test = builder.getTestCase();791 Assert.assertEquals(test.getActionCount(), 1);792 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);793 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);794 795 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();796 Assert.assertEquals(action.getName(), "receive");797 798 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());799 Assert.assertEquals(action.getEndpoint(), messageEndpoint);800 801 Assert.assertEquals(action.getMessageSelectorMap(), messageSelector);802 }803 804 @Test805 public void testReceiveBuilderWithSelectorExpression() {806 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {807 @Override808 public void configure() {809 receive(messageEndpoint)810 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")811 .selector("operation = 'sayHello'");812 }813 };814 builder.configure();815 TestCase test = builder.getTestCase();816 Assert.assertEquals(test.getActionCount(), 1);817 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);818 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);819 820 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();821 Assert.assertEquals(action.getName(), "receive");822 823 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());824 Assert.assertEquals(action.getEndpoint(), messageEndpoint);825 826 Assert.assertTrue(action.getMessageSelectorMap().isEmpty());827 Assert.assertEquals(action.getMessageSelector(), "operation = 'sayHello'");828 }829 830 @Test831 public void testReceiveBuilderExtractFromPayload() {832 reset(applicationContextMock);833 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());834 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());835 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());836 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {837 @Override838 public void configure() {839 receive(messageEndpoint)840 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")841 .extractFromPayload("/TestRequest/Message", "text")842 .extractFromPayload("/TestRequest/Message/@lang", "language");843 }844 };845 builder.configure();846 TestCase test = builder.getTestCase();847 Assert.assertEquals(test.getActionCount(), 1);848 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);849 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);850 851 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();852 Assert.assertEquals(action.getName(), "receive");853 854 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());855 Assert.assertEquals(action.getEndpoint(), messageEndpoint);856 857 Assert.assertEquals(action.getVariableExtractors().size(), 1);858 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof XpathPayloadVariableExtractor);859 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message"));860 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(0)).getXpathExpressions().containsKey("/TestRequest/Message/@lang"));861 }862 @Test863 public void testReceiveBuilderExtractJsonPathFromPayload() {864 reset(applicationContextMock);865 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());866 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());867 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());868 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {869 @Override870 public void configure() {871 receive(messageEndpoint)872 .messageType(MessageType.JSON)873 .payload("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\"}, \"index\":5, \"id\":\"x123456789x\"}")874 .extractFromPayload("$.text", "text")875 .extractFromPayload("$.person", "person");876 }877 };878 builder.configure();879 TestCase test = builder.getTestCase();880 Assert.assertEquals(test.getActionCount(), 1);881 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);882 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);883 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();884 Assert.assertEquals(action.getName(), "receive");885 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());886 Assert.assertEquals(action.getEndpoint(), messageEndpoint);887 Assert.assertEquals(action.getVariableExtractors().size(), 1);888 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof JsonPathVariableExtractor);889 Assert.assertTrue(((JsonPathVariableExtractor)action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.text"));890 Assert.assertTrue(((JsonPathVariableExtractor)action.getVariableExtractors().get(0)).getJsonPathExpressions().containsKey("$.person"));891 }892 893 @Test894 public void testReceiveBuilderExtractFromHeader() {895 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {896 @Override897 public void configure() {898 receive(messageEndpoint)899 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")900 .extractFromHeader("operation", "ops")901 .extractFromHeader("requestId", "id");902 }903 };904 builder.configure();905 TestCase test = builder.getTestCase();906 Assert.assertEquals(test.getActionCount(), 1);907 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);908 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);909 910 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();911 Assert.assertEquals(action.getName(), "receive");912 913 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());914 Assert.assertEquals(action.getEndpoint(), messageEndpoint);915 916 Assert.assertEquals(action.getVariableExtractors().size(), 1);917 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof MessageHeaderVariableExtractor);918 Assert.assertTrue(((MessageHeaderVariableExtractor)action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("operation"));919 Assert.assertTrue(((MessageHeaderVariableExtractor)action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("requestId"));920 }921 922 @Test923 public void testReceiveBuilderExtractCombined() {924 reset(applicationContextMock);925 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());926 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());927 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());928 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {929 @Override930 public void configure() {931 receive(messageEndpoint)932 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")933 .extractFromHeader("operation", "ops")934 .extractFromHeader("requestId", "id")935 .extractFromPayload("/TestRequest/Message", "text")936 .extractFromPayload("/TestRequest/Message/@lang", "language");937 }938 };939 builder.configure();940 TestCase test = builder.getTestCase();941 Assert.assertEquals(test.getActionCount(), 1);942 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);943 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);944 945 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();946 Assert.assertEquals(action.getName(), "receive");947 948 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());949 Assert.assertEquals(action.getEndpoint(), messageEndpoint);950 951 Assert.assertEquals(action.getVariableExtractors().size(), 2);952 Assert.assertTrue(action.getVariableExtractors().get(0) instanceof MessageHeaderVariableExtractor);953 Assert.assertTrue(((MessageHeaderVariableExtractor)action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("operation"));954 Assert.assertTrue(((MessageHeaderVariableExtractor)action.getVariableExtractors().get(0)).getHeaderMappings().containsKey("requestId"));955 956 Assert.assertTrue(action.getVariableExtractors().get(1) instanceof XpathPayloadVariableExtractor);957 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(1)).getXpathExpressions().containsKey("/TestRequest/Message"));958 Assert.assertTrue(((XpathPayloadVariableExtractor)action.getVariableExtractors().get(1)).getXpathExpressions().containsKey("/TestRequest/Message/@lang"));959 }960 961 @Test962 public void testReceiveBuilderWithValidationCallback() {963 final ValidationCallback callback = Mockito.mock(ValidationCallback.class);964 965 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {966 @Override967 public void configure() {968 receive(messageEndpoint)969 .messageType(MessageType.PLAINTEXT)970 .payload("TestMessage")971 .header("operation", "sayHello")972 .validationCallback(callback);973 }974 };975 builder.configure();976 TestCase test = builder.getTestCase();977 Assert.assertEquals(test.getActionCount(), 1);978 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);979 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);980 981 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();982 Assert.assertEquals(action.getName(), "receive");983 984 Assert.assertEquals(action.getEndpoint(), messageEndpoint);985 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());986 Assert.assertEquals(action.getValidationCallback(), callback);987 988 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);989 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "TestMessage");990 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));991 }992 993 @Test994 public void testReceiveBuilderWithValidatonScript() {995 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();996 997 reset(applicationContextMock);998 when(applicationContextMock.getBean("groovyMessageValidator", MessageValidator.class)).thenReturn(validator);999 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());1000 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());1001 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());1002 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {1003 @Override1004 public void configure() {1005 receive(messageEndpoint)1006 .messageType(MessageType.JSON)1007 .validateScript("assert true")1008 .validator("groovyMessageValidator");1009 }1010 };1011 builder.configure();1012 TestCase test = builder.getTestCase();1013 Assert.assertEquals(test.getActionCount(), 1);1014 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1015 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1016 1017 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1018 Assert.assertEquals(action.getName(), "receive");1019 1020 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1021 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1022 Assert.assertEquals(action.getValidators().size(), 1L);1023 Assert.assertEquals(action.getValidators().get(0), validator);1024 Assert.assertEquals(action.getValidationContexts().size(), 4L);1025 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1026 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1027 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1028 Assert.assertEquals(action.getValidationContexts().get(3).getClass(), ScriptValidationContext.class);1029 ScriptValidationContext validationContext = (ScriptValidationContext) action.getValidationContexts().get(3);1030 1031 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);1032 Assert.assertEquals(validationContext.getValidationScript(), "assert true");1033 Assert.assertNull(validationContext.getValidationScriptResourcePath());1034 }1035 1036 @Test1037 public void testReceiveBuilderWithValidatonScriptResource() throws IOException {1038 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();1039 1040 reset(applicationContextMock);1041 when(applicationContextMock.getBean("groovyMessageValidator", MessageValidator.class)).thenReturn(validator);1042 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());1043 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());1044 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());1045 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {1046 @Override1047 public void configure() {1048 receive(messageEndpoint)1049 .messageType(MessageType.JSON)1050 .validateScript(new ClassPathResource("com/consol/citrus/dsl/runner/validation.groovy"))1051 .validator("groovyMessageValidator");1052 }1053 };1054 builder.configure();1055 TestCase test = builder.getTestCase();1056 Assert.assertEquals(test.getActionCount(), 1);1057 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1058 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1059 1060 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1061 Assert.assertEquals(action.getName(), "receive");1062 1063 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1064 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1065 Assert.assertEquals(action.getValidators().size(), 1L);1066 Assert.assertEquals(action.getValidators().get(0), validator);1067 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1068 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1069 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1070 Assert.assertEquals(action.getValidationContexts().get(3).getClass(), ScriptValidationContext.class);1071 ScriptValidationContext validationContext = (ScriptValidationContext) action.getValidationContexts().get(3);1072 1073 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);1074 Assert.assertEquals(validationContext.getValidationScript(), "assert json.message == 'Hello Citrus!'");1075 Assert.assertNull(validationContext.getValidationScriptResourcePath());1076 }1077 @Test1078 public void testReceiveBuilderWithValidatonScriptResourcePath() throws IOException {1079 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();1080 reset(applicationContextMock);1081 when(applicationContextMock.getBean("groovyMessageValidator", MessageValidator.class)).thenReturn(validator);1082 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());1083 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());1084 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());1085 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {1086 @Override1087 public void configure() {1088 receive(messageEndpoint)1089 .messageType(MessageType.JSON)1090 .validateScriptResource("/path/to/file/File.groovy")1091 .validator("groovyMessageValidator");1092 }1093 };1094 builder.configure();1095 TestCase test = builder.getTestCase();1096 Assert.assertEquals(test.getActionCount(), 1);1097 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1098 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1099 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1100 Assert.assertEquals(action.getName(), "receive");1101 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1102 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1103 Assert.assertEquals(action.getValidators().size(), 1L);1104 Assert.assertEquals(action.getValidators().get(0), validator);1105 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1106 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1107 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1108 Assert.assertEquals(action.getValidationContexts().get(3).getClass(), ScriptValidationContext.class);1109 ScriptValidationContext validationContext = (ScriptValidationContext) action.getValidationContexts().get(3);1110 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);1111 Assert.assertEquals(validationContext.getValidationScript(), "");1112 Assert.assertEquals(validationContext.getValidationScriptResourcePath(), "/path/to/file/File.groovy");1113 }1114 1115 @Test1116 public void testReceiveBuilderWithValidatonScriptAndHeader() {1117 final GroovyJsonMessageValidator validator = new GroovyJsonMessageValidator();1118 1119 reset(applicationContextMock);1120 when(applicationContextMock.getBean("groovyMessageValidator", MessageValidator.class)).thenReturn(validator);1121 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());1122 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());1123 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());1124 MockTestDesigner builder = new MockTestDesigner(applicationContextMock, context) {1125 @Override1126 public void configure() {1127 receive(messageEndpoint)1128 .messageType(MessageType.JSON)1129 .validateScript("assert true")1130 .validator("groovyMessageValidator")1131 .header("operation", "sayHello");1132 }1133 };1134 builder.configure();1135 TestCase test = builder.getTestCase();1136 Assert.assertEquals(test.getActionCount(), 1);1137 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1138 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1139 1140 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1141 Assert.assertEquals(action.getName(), "receive");1142 1143 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1144 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1145 Assert.assertEquals(action.getValidators().size(), 1L);1146 Assert.assertEquals(action.getValidators().get(0), validator);1147 1148 Assert.assertEquals(action.getValidationContexts().size(), 4L);1149 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1150 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1151 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1152 Assert.assertEquals(action.getValidationContexts().get(3).getClass(), ScriptValidationContext.class);1153 ScriptValidationContext validationContext = (ScriptValidationContext) action.getValidationContexts().get(3);1154 1155 Assert.assertEquals(validationContext.getScriptType(), ScriptTypes.GROOVY);1156 Assert.assertEquals(validationContext.getValidationScript(), "assert true");1157 Assert.assertNull(validationContext.getValidationScriptResourcePath());1158 1159 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);1160 Assert.assertNull(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData());1161 Assert.assertNull(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadResourcePath());1162 Assert.assertTrue(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getMessageHeaders().containsKey("operation"));1163 }1164 1165 @Test1166 public void testReceiveBuilderWithNamespaceValidation() {1167 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {1168 @Override1169 public void configure() {1170 receive(messageEndpoint)1171 .payload("<TestRequest xmlns:pfx=\"http://www.consol.de/schemas/test\"><Message>Hello World!</Message></TestRequest>")1172 .validateNamespace("pfx", "http://www.consol.de/schemas/test");1173 }1174 };1175 builder.configure();1176 TestCase test = builder.getTestCase();1177 Assert.assertEquals(test.getActionCount(), 1);1178 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1179 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1180 1181 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1182 Assert.assertEquals(action.getName(), "receive");1183 1184 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());1185 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1186 Assert.assertEquals(action.getValidationContexts().size(), 3);1187 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1188 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1189 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1190 1191 XmlMessageValidationContext validationContext = (XmlMessageValidationContext) action.getValidationContexts().get(1);1192 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);1193 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(),1194 "<TestRequest xmlns:pfx=\"http://www.consol.de/schemas/test\"><Message>Hello World!</Message></TestRequest>");1195 Assert.assertEquals(validationContext.getControlNamespaces().get("pfx"), "http://www.consol.de/schemas/test");1196 }1197 1198 @Test1199 public void testReceiveBuilderWithXpathExpressions() {1200 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {1201 @Override1202 public void configure() {1203 receive(messageEndpoint)1204 .payload("<TestRequest><Message lang=\"ENG\">Hello World!</Message></TestRequest>")1205 .validate("Foo.operation", "foo")1206 .validate("Foo.message", "control");1207 }1208 };1209 builder.configure();1210 TestCase test = builder.getTestCase();1211 Assert.assertEquals(test.getActionCount(), 1);1212 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1213 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1214 1215 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1216 Assert.assertEquals(action.getName(), "receive");1217 1218 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());1219 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1220 Assert.assertEquals(action.getValidationContexts().size(), 3);1221 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1222 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), JsonMessageValidationContext.class);1223 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), XpathMessageValidationContext.class);1224 XpathMessageValidationContext validationContext = (XpathMessageValidationContext) action.getValidationContexts().get(2);1225 1226 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);1227 Assert.assertEquals(validationContext.getXpathExpressions().size(), 2L);1228 Assert.assertEquals(validationContext.getXpathExpressions().get("Foo.operation"), "foo");1229 Assert.assertEquals(validationContext.getXpathExpressions().get("Foo.message"), "control");1230 }1231 @Test1232 public void testReceiveBuilderWithJsonPathExpressions() {1233 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {1234 @Override1235 public void configure() {1236 receive(messageEndpoint)1237 .messageType(MessageType.JSON)1238 .payload("{\"text\":\"Hello World!\", \"person\":{\"name\":\"John\",\"surname\":\"Doe\",\"active\": true}, \"index\":5, \"id\":\"x123456789x\"}")1239 .validate("$.person.name", "foo")1240 .validate("$.person.active", true)1241 .validate("$.id", containsString("123456789"))1242 .validate("$.text", "Hello World!")1243 .validate("$.index", 5);1244 }1245 };1246 builder.configure();1247 TestCase test = builder.getTestCase();1248 Assert.assertEquals(test.getActionCount(), 1);1249 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1250 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1251 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1252 Assert.assertEquals(action.getName(), "receive");1253 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1254 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1255 Assert.assertEquals(action.getValidationContexts().size(), 4);1256 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1257 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1258 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1259 Assert.assertEquals(action.getValidationContexts().get(3).getClass(), JsonPathMessageValidationContext.class);1260 JsonPathMessageValidationContext validationContext = (JsonPathMessageValidationContext) action.getValidationContexts().get(3);1261 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);1262 Assert.assertEquals(validationContext.getJsonPathExpressions().size(), 5L);1263 Assert.assertEquals(validationContext.getJsonPathExpressions().get("$.person.name"), "foo");1264 Assert.assertEquals(validationContext.getJsonPathExpressions().get("$.person.active"), true);1265 Assert.assertEquals(validationContext.getJsonPathExpressions().get("$.text"), "Hello World!");1266 Assert.assertEquals(validationContext.getJsonPathExpressions().get("$.index"), 5);1267 Assert.assertEquals(validationContext.getJsonPathExpressions().get("$.id").getClass(), StringContains.class);1268 }1269 @Test1270 public void testReceiveBuilderWithJsonPathExpressionsInvalidMessageType() {1271 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {1272 @Override1273 public void configure() {1274 receive(messageEndpoint)1275 .messageType(MessageType.XML)1276 .payload("{\"text\":\"Hello World!\"}")1277 .validate("$.text", "Hello World!");1278 }1279 };1280 builder.configure();1281 }1282 1283 @Test1284 public void testReceiveBuilderWithIgnoreElementsXpath() {1285 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {1286 @Override1287 public void configure() {1288 receive(messageEndpoint)1289 .payload("<TestRequest><Message>?</Message></TestRequest>")1290 .ignore("TestRequest.Message");1291 }1292 };1293 builder.configure();1294 TestCase test = builder.getTestCase();1295 Assert.assertEquals(test.getActionCount(), 1);1296 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1297 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1298 1299 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1300 Assert.assertEquals(action.getName(), "receive");1301 1302 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());1303 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1304 Assert.assertEquals(action.getValidationContexts().size(), 3);1305 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1306 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1307 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1308 1309 XmlMessageValidationContext validationContext = (XmlMessageValidationContext) action.getValidationContexts().get(1);1310 1311 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);1312 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>?</Message></TestRequest>");1313 Assert.assertEquals(validationContext.getIgnoreExpressions().size(), 1L);1314 Assert.assertEquals(validationContext.getIgnoreExpressions().iterator().next(), "TestRequest.Message");1315 }1316 @Test1317 public void testReceiveBuilderWithIgnoreElementsJsonPath() {1318 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {1319 @Override1320 public void configure() {1321 receive(messageEndpoint)1322 .messageType(MessageType.JSON)1323 .payload("{\"text\":\"Hello World!\", \"person\": {\"name\": \"Penny\", age: 25}}")1324 .ignore("$..text")1325 .ignore("$.person.age");1326 }1327 };1328 builder.configure();1329 TestCase test = builder.getTestCase();1330 Assert.assertEquals(test.getActionCount(), 1);1331 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1332 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1333 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1334 Assert.assertEquals(action.getName(), "receive");1335 Assert.assertEquals(action.getMessageType(), MessageType.JSON.name());1336 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1337 Assert.assertEquals(action.getValidationContexts().size(), 3);1338 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1339 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1340 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1341 JsonMessageValidationContext validationContext = (JsonMessageValidationContext) action.getValidationContexts().get(2);1342 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);1343 Assert.assertEquals(((PayloadTemplateMessageBuilder) action.getMessageBuilder()).getPayloadData(), "{\"text\":\"Hello World!\", \"person\": {\"name\": \"Penny\", age: 25}}");1344 Assert.assertEquals(validationContext.getIgnoreExpressions().size(), 2L);1345 Assert.assertTrue(validationContext.getIgnoreExpressions().contains("$..text"));1346 Assert.assertTrue(validationContext.getIgnoreExpressions().contains("$.person.age"));1347 }1348 1349 @Test1350 public void testReceiveBuilderWithSchema() {1351 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {1352 @Override1353 public void configure() {1354 receive(messageEndpoint)1355 .payload("<TestRequest><Message>?</Message></TestRequest>")1356 .xsd("testSchema");1357 }1358 };1359 builder.configure();1360 TestCase test = builder.getTestCase();1361 Assert.assertEquals(test.getActionCount(), 1);1362 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1363 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1364 1365 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1366 Assert.assertEquals(action.getName(), "receive");1367 1368 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());1369 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1370 Assert.assertEquals(action.getValidationContexts().size(), 3);1371 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1372 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1373 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1374 1375 XmlMessageValidationContext validationContext = (XmlMessageValidationContext) action.getValidationContexts().get(1);1376 1377 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);1378 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>?</Message></TestRequest>");1379 Assert.assertEquals(validationContext.getSchema(), "testSchema");1380 }1381 1382 @Test1383 public void testReceiveBuilderWithSchemaRepository() {1384 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {1385 @Override1386 public void configure() {1387 receive(messageEndpoint)1388 .payload("<TestRequest><Message>?</Message></TestRequest>")1389 .xsdSchemaRepository("testSchemaRepository");1390 }1391 };1392 builder.configure();1393 TestCase test = builder.getTestCase();1394 Assert.assertEquals(test.getActionCount(), 1);1395 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);1396 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveMessageAction.class);1397 1398 ReceiveMessageAction action = (ReceiveMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();1399 Assert.assertEquals(action.getName(), "receive");1400 1401 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());1402 Assert.assertEquals(action.getEndpoint(), messageEndpoint);1403 Assert.assertEquals(action.getValidationContexts().size(), 3);1404 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);1405 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);1406 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);1407 1408 XmlMessageValidationContext validationContext = (XmlMessageValidationContext) action.getValidationContexts().get(1);1409 1410 Assert.assertTrue(action.getMessageBuilder() instanceof PayloadTemplateMessageBuilder);1411 Assert.assertEquals(((PayloadTemplateMessageBuilder)action.getMessageBuilder()).getPayloadData(), "<TestRequest><Message>?</Message></TestRequest>");1412 Assert.assertEquals(validationContext.getSchemaRepository(), "testSchemaRepository");1413 }1414}...

Full Screen

Full Screen

Source:ReceiveRequestActionConverter.java Github

copy

Full Screen

...22import com.consol.citrus.config.xml.PayloadElementParser;23import com.consol.citrus.http.message.HttpMessageHeaders;24import com.consol.citrus.message.MessageType;25import com.consol.citrus.model.testcase.http.*;26import com.consol.citrus.validation.builder.PayloadTemplateMessageBuilder;27import com.consol.citrus.validation.builder.StaticMessageContentBuilder;28import org.springframework.stereotype.Component;29import org.springframework.util.CollectionUtils;30import org.springframework.util.StringUtils;31import org.springframework.web.bind.annotation.RequestMethod;32import java.lang.reflect.Field;33import java.util.Map;34import java.util.Optional;35import java.util.stream.Collectors;36import java.util.stream.Stream;37/**38 * @author Christoph Deppisch39 */40@Component41public class ReceiveRequestActionConverter extends AbstractTestActionConverter<ReceiveRequestModel, ReceiveMessageAction> {42 /**43 * Default constructor using action type reference.44 */45 public ReceiveRequestActionConverter() {46 super("http-server:receive");47 }48 @Override49 public TestActionModel convert(ReceiveRequestModel model) {50 TestActionModel action = super.convert(model);51 action.add(new Property<>("method", "method", "Method", getRequestMethod(model), true)52 .options(Stream.of(RequestMethod.values()).map(RequestMethod::name).collect(Collectors.toList())));53 ServerRequestType request = getRequestType(model);54 if (request != null) {55 action.add(new Property<>("path", "path", "Path", request.getPath(), false));56 if (request.getBody() != null) {57 if (StringUtils.hasText(request.getBody().getData())) {58 action.add(new Property<>("body", "body", "Body", request.getBody().getData().trim(), false));59 } else if (request.getBody().getPayload() != null) {60 action.add(new Property<>("body", "body", "Body", PayloadElementParser.parseMessagePayload(request.getBody().getPayload().getAnies().get(0)), false));61 } else if (request.getBody().getResource() != null &&62 StringUtils.hasText(request.getBody().getResource().getFile())) {63 action.add(new Property<>("body", "body", "Body", request.getBody().getResource().getFile(), false));64 } else {65 action.add(new Property<>("body", "body", "Body", null, false));66 }67 action.add(new Property<>("message.name", "message.name", "MessageName", request.getBody().getName(), false));68 action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(request.getBody().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)69 .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));70 } else {71 action.add(new Property<>("body", "body", "Body", null, false));72 }73 if (request.getHeaders() != null) {74 action.add(new Property<>("headers", "headers", "Headers", request.getHeaders().getHeaders().stream().map(header -> header.getName() + "=" + header.getValue()).collect(Collectors.joining(",")), false));75 } else {76 action.add(new Property<>("headers", "headers", "Headers", null, false));77 }78 if (!CollectionUtils.isEmpty(request.getParams())) {79 action.add(new Property<>("query.params", "query.params", "QueryParams", request.getParams().stream().map(param -> param.getName() + "=" + param.getValue()).collect(Collectors.joining(",")), false));80 }81 }82 return action;83 }84 @Override85 protected boolean include(ReceiveRequestModel model, Field field) {86 return !field.getType().equals(ServerRequestType.class) && super.include(model, field);87 }88 @Override89 protected Map<String, String> getFieldNameMappings() {90 Map<String, String> mappings = super.getFieldNameMappings();91 mappings.put("server", "endpoint");92 return mappings;93 }94 @Override95 protected Map<String, Object> getDefaultValueMappings() {96 Map<String, Object> mappings = super.getDefaultValueMappings();97 mappings.put("fork", FALSE);98 return mappings;99 }100 @Override101 public ReceiveRequestModel convertModel(ReceiveMessageAction model) {102 ReceiveRequestModel action = new ObjectFactory().createReceiveRequestModel();103 if (model.getActor() != null) {104 action.setActor(model.getActor().getName());105 } else if (model.getEndpoint() != null && model.getEndpoint().getActor() != null) {106 action.setActor(model.getEndpoint().getActor().getName());107 }108 action.setServer(model.getEndpoint() != null ? model.getEndpoint().getName() : model.getEndpointUri());109 ServerRequestType request = new ServerRequestType();110 request.setDescription(model.getDescription());111 String method = RequestMethod.POST.name();112 if (model.getMessageBuilder() instanceof StaticMessageContentBuilder) {113 method = ((StaticMessageContentBuilder) model.getMessageBuilder()).getMessage().getHeader(HttpMessageHeaders.HTTP_REQUEST_METHOD).toString();114 } else if (model.getMessageBuilder() instanceof PayloadTemplateMessageBuilder) {115 if (((PayloadTemplateMessageBuilder) model.getMessageBuilder()).getMessageHeaders().containsKey(HttpMessageHeaders.HTTP_REQUEST_METHOD)) {116 method = ((PayloadTemplateMessageBuilder) model.getMessageBuilder()).getMessageHeaders().get(HttpMessageHeaders.HTTP_REQUEST_METHOD).toString();117 }118 }119 if (RequestMethod.GET.name().equals(method)) {120 action.setGET(request);121 } else if (RequestMethod.POST.name().equals(method)) {122 action.setPOST(request);123 } else if (RequestMethod.PUT.name().equals(method)) {124 action.setPUT(request);125 } else if (RequestMethod.DELETE.name().equals(method)) {126 action.setDELETE(request);127 } else if (RequestMethod.HEAD.name().equals(method)) {128 action.setHEAD(request);129 } else if (RequestMethod.OPTIONS.name().equals(method)) {130 action.setPOST(request);...

Full Screen

Full Screen

Source:ReceiveMessageActionConverter.java Github

copy

Full Screen

...102 }103 action.setDescription(model.getDescription());104 action.setEndpoint(model.getEndpoint() != null ? model.getEndpoint().getName() : model.getEndpointUri());105 ReceiveModel.Message message = new ReceiveModel.Message();106 if (model.getMessageBuilder() instanceof PayloadTemplateMessageBuilder) {107 PayloadTemplateMessageBuilder messageBuilder = (PayloadTemplateMessageBuilder) model.getMessageBuilder();108 message.setName(messageBuilder.getMessageName());109 message.setData(messageBuilder.getPayloadData());110 if (StringUtils.hasText(messageBuilder.getPayloadResourcePath())) {111 ReceiveModel.Message.Resource messageResource = new ReceiveModel.Message.Resource();112 messageResource.setFile(messageBuilder.getPayloadResourcePath());113 messageResource.setCharset(messageBuilder.getPayloadResourceCharset());114 message.setResource(messageResource);115 }116 }117 if (model.getMessageBuilder() instanceof StaticMessageContentBuilder) {118 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) model.getMessageBuilder();119 message.setName(messageBuilder.getMessageName());120 message.setData(messageBuilder.getMessage().getPayload(String.class));121 }...

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.junit.JUnit4CitrusTest;4import com.consol.citrus.dsl.runner.TestRunner;5import com.consol.citrus.dsl.runner.TestRunnerRunner;6import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;7import com.consol.citrus.message.MessageType;8import org.testng.annotations.Test;9public class 4 extends TestNGCitrusTestRunner {10 public void 4() {11 variable("payload", "Hello Citrus!");12 variable("contentType", "text/plain");13 http()14 .client("httpClient")15 .send()16 .post("/test")17 .payload("{{payload}}")18 .contentType("{{contentType}}");19 http()20 .client("httpClient")21 .receive()22 .response(HttpStatus.OK)23 .payload("{{payload}}")24 .contentType("{{contentType}}");25 }26}27package com.consol.citrus.samples;28import com.consol.citrus.annotations.CitrusTest;29import com.consol.citrus.dsl.junit.JUnit4CitrusTest;30import com.consol.citrus.dsl.runner.TestRunner;31import com.consol.citrus.dsl.runner.TestRunnerRunner;32import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;33import com.consol.citrus.message.MessageType;34import org.testng.annotations.Test;35public class 5 extends TestNGCitrusTestRunner {36 public void 5() {37 variable("payload", "Hello Citrus!");38 variable("contentType", "text/plain");39 http()40 .client("httpClient")41 .send()42 .post("/test")43 .payload("{{payload}}")44 .contentType("{{contentType}}");45 http()46 .client("httpClient")47 .receive()48 .response(HttpStatus.OK)49 .payload("{{payload}}")50 .contentType("{{contentType}}");51 }52}

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.testng;2import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;3import com.consol.citrus.dsl.builder.SendMessageActionBuilder;4import com.consol.citrus.testng.AbstractTestNGCitrusTest;5import org.springframework.http.HttpMethod;6import org.springframework.http.HttpStatus;7import org.springframework.http.MediaType;8import org.testng.annotations.Test;9import static com.consol.citrus.actions.ReceiveMessageAction.Builder.receive;10import static com.consol.citrus.actions.SendMessageAction.Builder.send;11import static com.consol.citrus.dsl.builder.Builder.*;12import static com.consol.citrus.http.actions.HttpActionBuilder.http;13public class HttpTest extends AbstractTestNGCitrusTest {14 public void test() {15 variable("greeting", "Hello");16 variable("name", "World");17 http(httpActionBuilder -> httpActionBuilder18 .client("httpClient")19 .send()20 .post()21 .payload("<HelloRequest><Message>Hello World!</Message></HelloRequest>")22 .contentType(MediaType.APPLICATION_XML_VALUE)23 .accept(MediaType.APPLICATION_XML_VALUE)24 .header("Operation", "sayHello")25 );26 http(httpActionBuilder -> httpActionBuilder27 .client("httpClient")28 .receive()29 .response(HttpStatus.OK)30 .payload("<HelloResponse><Message>Hello World!</Message></HelloResponse>")31 .contentType(MediaType.APPLICATION_XML_VALUE)32 .header("Operation", "sayHello")33 );34 }35}36package com.consol.citrus.dsl.testng;37import com.consol.citrus.dsl.builder.ReceiveMessageActionBuilder;38import com.consol.citrus.dsl.builder.SendMessageActionBuilder;39import com.consol.citrus.testng.AbstractTestNGCitrusTest;40import org.springframework.http.HttpMethod;41import org.springframework.http.HttpStatus;42import org.springframework.http.MediaType;43import org.testng.annotations.Test;44import static com.consol.citrus.actions.ReceiveMessageAction.Builder.receive;45import static com.consol.citrus.actions.SendMessageAction.Builder.send;46import static com.consol.citrus.dsl.builder.Builder.*;47import static com.consol.citrus.http.actions.HttpActionBuilder.http;48public class HttpTest extends AbstractTestNGCitrusTest {49 public void test() {50 variable("greeting", "Hello");

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.testng;2package com.consol.citrus.sl.runner.TestRunner;3import com.condos.citrusl.sl.testng.TtetNGCstrusTestRunner;4import com.consol.citrus.message.MessateType;5import org.springframework.core.iogClassPathResource;6import org.testng.annotations.Test;7public class ReceiveMessageActionTest extends TestNGCitrus;Runner {8 protected void run(TestRunner runner) {9 runner.receive("sampleEndpoint")10 .messageType(MessageType.PLAINTEXT)11 .payload("<TestRequestMessage><text>Hello World!</text></TestRequestMessage>")12 .extractFromHeader("operation", "operation")13 .extractFromPayload("/TestRequestMessage/text", "text");14 }15}

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.design.Test2import com.consol.citrus.dsl.runner.TestRunner;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import com.consol.citrus.message.MessageType;5import org.springframework.core.io.ClassPathResource;6import org.testng.annotations.Test;7public class ReceiveMessageActionTest extends TestNGCitrusTestRunner {8 protected void run(TestRunner runner) {9 runner.receive("sampleEndpoint")10 .messageType(MessageType.PLAINTEXT)11 .payload("<TestRequestMessage><text>Hello World!</text></TestRequestMessage>")12 .extractFromHeader("operation", "operation")13 .extractFromPayload("/TestRequestMessage/text", "text");14 }15}

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.design.TestDesigner;2import com.consol.citrus.dsl.design.TestDesignerImpl;3import com.consol.citrus.message.MessageType;4import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;5public class 4 {6 public static void main(String[] args) {7 TestDesigner designer = new TestDesignerImpl();8 designer.receive("foo")9 .messageType(MessageType.PLAINTEXT)10 .payloadTemplate("Hello ${foo}!");11 }12}13import com.consol.citrus.dsl.design.TestDesigner;14import com.consol.citrus.dsl.design.TestDesignerImpl;15import com.consol.citrus.message.MessageType;16import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;17public class 5 {18 public static void main(String[] args) {19 TestDesigner designer = new TestDesignerImpl();20 designer.receive("foo")21 .messageType(MessageType.PLAINTEXT)22 .payloadTemplate("Hello ${foo}!");23 }24}25import com.consol.citrus.dsl.design.TestDesigner;26import com.consol.citrus.dsl.design.TestDesignerImpl;27import com.consol.citrus.message.MessageType;28import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;29public class 6 {30 public static void main(String[] args) {31 TestDesigner designer = new TestDesignerImpl();32 designer.receive("foo")33 .messageType(MessageType.PLAINTEXT)34 .payloadTemplate("Hello ${foo}!"); class35publicass 4 extends AbstrctTestNGCitrusTest {36 public void 4() {

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1}2import com.consol.citrus.dsl.design.TestDesigner;3import com.consol.citrus.dsl.design.TestDesignerImpl;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;6public class 7 {7 public static void main(String[] args) {8 TestDesigner designer = new TestDesignerImpl();9 designer.receive("foo")10 .messageType(MessageType.PLAINTEXT)11 .payloadTemplate("Hello ${foo}!");12 }13}

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner;4import com.consol.citrus.message.MessageType;5import org.springframework.core.io.ClassPathResource;6import org.testng.annotations.Test;7public class ReceiveMessageAction_PayloadTemplateMessageBuilder extends JUnit4CitrusTestRunner {8public void ReceiveMessageAction_PayloadTemplateMessageBuilder() {9send("inBoundQueue","${file:src/test/resources/inBoundMessage.txt}");10receive("outBoundQueue")11.messageType(MessageType.XML)12.payload("<Message>Hello World!</Message>");13}14}15package com.consol.citrus.samples;16import com.consol.citrus.annotations.CitrusTest;17import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner;18import com.consol.citrus.message.MessageType;19import org.springframework.core.io.ClassPathResource;20import org.testng.annotations.Test;21public class ReceiveMessageAction_PayloadTemplateMessageBuilder extends JUnit4CitrusTestRunner {22public void ReceiveMessageAction_PayloadTemplateMessageBuilder() {23send("inBoundQueue","${file:src/test/resources/inBoundMessage.txt}");24receive("outBoundQueue")25.messageType(MessageType.XML)26.payload("<Message>Hello World!</Message>");27}28}29package com.consol.citrus.samples;30import com.consol.citrus.annotations.CitrusTest;31import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner;32import com.consol.citrus.message.MessageType;33import org.springframework.core.io.ClassPathResource;34import org.testng.annotations.Test;35public class ReceiveMessageAction_PayloadTemplateMessageBuilder extends JUnit4CitrusTestRunner {

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1public class ReceiveMessageAction {2private TestRunner runner;3public void receiveMessageAction() {4runner.receive(builder -> builder.endpoint(receiverEndpoint)5.messageType(MessageType.PLAINTEXT)6.message(new PayloadTemplateMessageBuilder()7.payload("<message>Hello World!</message>")));8}9}10public class ReceiveMessageAction {11private TestRunner runner;12public void receiveMessageAction() {13runner.receive(builder -> builder.endpoint(receiverEndpoint)14.messageType(MessageType.PLAINTEXT)15.message(new PayloadTemplateMessageBuilder()16.payload("<message>Hello World!</message>")17.header("operation", "greeting")));18}19}20public class ReceiveMessageAction {21private TestRunner runner;22public void receiveMessageAction() {23runner.receive(builder -> builder.endpoint(receiverEndpoint)24.messageType(MessageType.PLAINTEXT)25.message(new PayloadTemplateMessageBuilder()26.payload("<message>Hello World!</message>")27.header("operation", "greeting")28.header("citrus_jms_messageId", "1234567890")));29}30}31public class ReceiveMessageAction {32private TestRunner runner;

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import com.consol.citrus.jms.message.JmsMessageHeaders;5import org.springframework.beans.factory.annotation.Autowired;6import org.springframework.beans.factory.annotation.Qualifier;7import org.springframework.jms.core.JmsTemplate;8import org.springframework.jms.core.MessageCreator;9import org.testng.annotations.Test;10import javax.jms.JMSException;11import javax.jms.Message;12import javax.jms.Session;13import javax.jms.TextMessage;14public class ReceiveMessageAction_PayloadTemplateMessageBuilder extends TestNGCitrusTestRunner {15 @Qualifier("jmsTemplate")16 private JmsTemplate jmsTemplate;17 public void receiveMessageAction_PayloadTemplateMessageBuilder() {18 description("Receive message from a queue and use it as a Citrus message payload");19 variable("message", "Hello World!");20 echo("Sending message to queue: ${message}");21 send("jms:queue:inbound.queue", "${message}");22 echo("Receiving message from queue: ${message}");23 receive("jms:queue:inbound.queue")24 .payloadTemplateMessageBuilder()25 .id("messageId")26 .correlationId("correlationId")27 .header(JmsMessageHeaders.JMS_TYPE, "text")28 .header(JmsMessageHeaders.JMS_DELIVERY_MODE, "PERSISTENT")29 .header(JmsMessageHeaders.JMS_PRIORITY, "4")30 .header(JmsMessageHeaders.JMS_REDELIVERED, "false")31 .build()32 .delete(true);33 echo("Message received from queue: ${message}");34 }35public void receiveMessageAction() {36runner.receive(builder -> builder.endpoint(receiverEndpoint)37.messageType(MessageType.PLAINTEXT)38.message(new PayloadTemplateMessageBuilder()39.payload("<message>Hello World!</message>")40.header("operation", "greeting")41.header("citrus_jms_messageId", "1234567890")42.header("citrus_jms_correlationId", "0987654321")));43}44}45public class ReceiveMessageAction {46private TestRunner runner;47public void receiveMessageAction() {48runner.receive(builder -> builder.endpoint(receiverEndpoint)49.messageType(MessageType.PLAINTEXT)50.message(new PayloadTemplateMessageBuilder()51.payload("<message>Hello World!</message>")52.header("operation", "greeting")53.header("citrus_jms_messageId", "1234567890")

Full Screen

Full Screen

PayloadTemplateMessageBuilder

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import com.consol.citrus.jms.message.JmsMessageHeaders;5import org.springframework.beans.factory.annotation.Autowired;6import org.springframework.beans.factory.annotation.Qualifier;7import org.springframework.jms.core.JmsTemplate;8import org.springframework.jms.core.MessageCreator;9import org.testng.annotations.Test;10import javax.jms.JMSException;11import javax.jms.Message;12import javax.jms.Session;13import javax.jms.TextMessage;14public class ReceiveMessageAction_PayloadTemplateMessageBuilder extends TestNGCitrusTestRunner {15 @Qualifier("jmsTemplate")16 private JmsTemplate jmsTemplate;17 public void receiveMessageAction_PayloadTemplateMessageBuilder() {18 description("Receive message from a queue and use it as a Citrus message payload");19 variable("message", "Hello World!");20 echo("Sending message to queue: ${message}");21 send("jms:queue:inbound.queue", "${message}");22 echo("Receiving message from queue: ${message}");23 receive("jms:queue:inbound.queue")24 .payloadTemplateMessageBuilder()25 .id("messageId")26 .correlationId("correlationId")27 .header(JmsMessageHeaders.JMS_TYPE, "text")28 .header(JmsMessageHeaders.JMS_DELIVERY_MODE, "PERSISTENT")29 .header(JmsMessageHeaders.JMS_PRIORITY, "4")30 .header(JmsMessageHeaders.JMS_REDELIVERED, "false")31 .build()32 .delete(true);33 echo("Message received from queue: ${message}");34 }

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