Best Citrus code snippet using com.consol.citrus.dsl.design.ReceiveMessageTestDesignerTest.configure
Source:ReceiveMessageTestDesignerTest.java
...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);...
configure
Using AI Code Generation
1package com.consol.citrus.dsl.design;2import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;3import org.junit.Test;4public class ReceiveMessageTestDesignerTest extends JUnit4CitrusTestDesigner {5 public void receiveMessage() {6 receive(builder -> builder.endpoint("myEndpoint")7 .messageType("text/plain")8 .payload("Hello Citrus!"));9 }10}11package com.consol.citrus.dsl.design;12import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;13import org.testng.annotations.Test;14public class ReceiveMessageTestDesignerTest extends TestNGCitrusTestDesigner {15 public void receiveMessage() {16 receive(builder -> builder.endpoint("myEndpoint")17 .messageType("text/plain")18 .payload("Hello Citrus!"));19 }20}21package com.consol.citrus.dsl.design;22import com.consol.citrus.dsl.testng.TestNGCitrusTest;23import org.testng.annotations.Test;24public class ReceiveMessageTestDesignerTest extends TestNGCitrusTest {25 public void receiveMessage() {26 receive(builder -> builder.endpoint("myEndpoint")27 .messageType("text/plain")28 .payload("Hello Citrus!"));29 }30}31package com.consol.citrus.dsl.design;32import com.consol.citrus.dsl.testng.TestNGCitrusTestBuilder;33import org.testng.annotations.Test;34public class ReceiveMessageTestDesignerTest extends TestNGCitrusTestBuilder {35 public void receiveMessage() {36 receive(builder -> builder.endpoint("myEndpoint")37 .messageType("text/plain")38 .payload("Hello Citrus!"));39 }40}41package com.consol.citrus.dsl.design;42import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;43import org.testng.annotations.Test;44public class ReceiveMessageTestDesignerTest extends TestNGCitrusTestRunner {45 public void receiveMessage() {
configure
Using AI Code Generation
1public void testReceiveMessage() {2 run(new ReceiveMessageTestDesigner() {3 public void configure() {4 receive(builder -> builder.endpoint("testEndpoint")5 .payload("<TestRequestMessage><text>Hello World!</text></TestRequestMessage>"));6 }7 });8}9public void testSendReceiveMessage() {10 run(new SendReceiveMessageTestDesigner() {11 public void configure() {12 send(builder -> builder.endpoint("testEndpoint")13 .payload("<TestRequestMessage><text>Hello World!</text></TestRequestMessage>"));14 receive(builder -> builder.endpoint("testEndpoint")15 .payload("<TestResponseMessage><text>Hello World!</text></TestResponseMessage>"));16 }17 });18}19public void testSendMessage() {20 run(new SendMessageTestDesigner() {21 public void configure() {22 send(builder -> builder.endpoint("testEndpoint")23 .payload("<TestRequestMessage><text>Hello World!</text></TestRequestMessage>"));24 }25 });26}27public void testStartServer() {28 run(new StartServerTestDesigner() {29 public void configure() {30 start(builder -> builder.endpoint("testEndpoint"));31 }32 });33}34public void testStopServer() {35 run(new StopServerTestDesigner() {36 public void configure() {37 stop(builder -> builder.endpoint("testEndpoint"));38 }39 });40}41public void testTestDesigner() {42 run(new TestDesigner() {43 public void configure() {44 echo("Hello World!");45 }46 });47}48public void testWait() {49 run(new WaitTestDesigner() {50 public void configure() {51 wait(builder -> builder
configure
Using AI Code Generation
1public void testReceiveMessage() {2 run(new ReceiveMessageTestDesigner() {3 public void configure() {4 receive()5 .message(new DefaultMessage("Hello Citrus!"))6 .endpoint("testEndpoint");7 }8 });9}10public void testSendMessage() {11 run(new SendMessageTestDesigner() {12 public void configure() {13 send()14 .message(new DefaultMessage("Hello Citrus!"))15 .endpoint("testEndpoint");16 }17 });18}19public void testSendEmptyMessage() {20 run(new SendEmptyMessageTestDesigner() {21 public void configure() {22 send()23 .message(new DefaultMessage())24 .endpoint("testEndpoint");25 }26 });27}28public void testSendTimeoutMessage() {29 run(new SendTimeoutMessageTestDesigner() {30 public void configure() {31 send()32 .message(new DefaultMessage())33 .endpoint("testEndpoint");34 }35 });36}37public void testSendFaultMessage() {38 run(new SendFaultMessageTestDesigner() {39 public void configure() {40 send()41 .message(new DefaultMessage())42 .endpoint("testEndpoint");43 }44 });45}46public void testSendSoapFaultMessage() {47 run(new SendSoapFaultMessageTestDesigner() {48 public void configure() {49 send()50 .message(new DefaultMessage())51 .endpoint("testEndpoint");52 }53 });54}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!