How to use getCorrelationManager method of com.consol.citrus.channel.ChannelSyncConsumer class

Best Citrus code snippet using com.consol.citrus.channel.ChannelSyncConsumer.getCorrelationManager

Source:ChannelEndpointSyncConsumerTest.java Github

copy

Full Screen

...64 Message receivedMessage = channelSyncConsumer.receive(context);65 Assert.assertEquals(receivedMessage.getPayload(), message.getPayload());66 Assert.assertEquals(receivedMessage.getHeader(org.springframework.messaging.MessageHeaders.ID), message.getHeaders().getId());67 Assert.assertEquals(receivedMessage.getHeader(org.springframework.messaging.MessageHeaders.REPLY_CHANNEL), message.getHeaders().getReplyChannel());68 MessageChannel savedReplyChannel = channelSyncConsumer.getCorrelationManager().find(endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKey(receivedMessage),69 endpoint.getEndpointConfiguration().getTimeout());70 Assert.assertNotNull(savedReplyChannel);71 Assert.assertEquals(savedReplyChannel, replyChannel);72 verify(messagingTemplate).setReceiveTimeout(5000L);73 }74 75 @Test76 @SuppressWarnings({ "unchecked", "rawtypes" })77 public void testReceiveMessageChannelNameResolver() {78 ChannelSyncEndpoint endpoint = new ChannelSyncEndpoint();79 endpoint.getEndpointConfiguration().setMessagingTemplate(messagingTemplate);80 endpoint.getEndpointConfiguration().setChannelName("testChannel");81 endpoint.getEndpointConfiguration().setChannelResolver(channelResolver);82 83 Map<String, Object> headers = new HashMap<String, Object>();84 final org.springframework.messaging.Message message = MessageBuilder.withPayload("<TestResponse>Hello World!</TestResponse>")85 .copyHeaders(headers)86 .setReplyChannel(replyChannel)87 .build();88 reset(messagingTemplate, channel, replyChannel, channelResolver);89 90 when(channelResolver.resolveDestination("testChannel")).thenReturn(channel);91 when(messagingTemplate.receive(channel)).thenReturn(message);92 ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();93 Message receivedMessage = channelSyncConsumer.receive(context);94 Assert.assertEquals(receivedMessage.getPayload(), message.getPayload());95 Assert.assertEquals(receivedMessage.getHeader(org.springframework.messaging.MessageHeaders.ID), message.getHeaders().getId());96 Assert.assertEquals(receivedMessage.getHeader(org.springframework.messaging.MessageHeaders.REPLY_CHANNEL), message.getHeaders().getReplyChannel());97 MessageChannel savedReplyChannel = channelSyncConsumer.getCorrelationManager().find(endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKey(receivedMessage),98 endpoint.getEndpointConfiguration().getTimeout());99 Assert.assertNotNull(savedReplyChannel);100 Assert.assertEquals(savedReplyChannel, replyChannel);101 verify(messagingTemplate).setReceiveTimeout(5000L);102 }103 104 @Test105 @SuppressWarnings({ "unchecked", "rawtypes" })106 public void testReceiveMessageWithReplyChannelName() {107 ChannelSyncEndpoint endpoint = new ChannelSyncEndpoint();108 endpoint.getEndpointConfiguration().setMessagingTemplate(messagingTemplate);109 endpoint.getEndpointConfiguration().setChannel(channel);110 111 BeanFactory factory = Mockito.mock(BeanFactory.class);112 endpoint.getEndpointConfiguration().setBeanFactory(factory);113 114 Map<String, Object> headers = new HashMap<String, Object>();115 final org.springframework.messaging.Message message = MessageBuilder.withPayload("<TestResponse>Hello World!</TestResponse>")116 .copyHeaders(headers)117 .setReplyChannelName("replyChannel")118 .build();119 reset(messagingTemplate, channel, replyChannel, factory);120 121 when(messagingTemplate.receive(channel)).thenReturn(message);122 when(factory.getBean("replyChannel", MessageChannel.class)).thenReturn(replyChannel);123 ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();124 Message receivedMessage = channelSyncConsumer.receive(context);125 Assert.assertEquals(receivedMessage.getPayload(), message.getPayload());126 Assert.assertEquals(receivedMessage.getHeader(org.springframework.messaging.MessageHeaders.ID), message.getHeaders().getId());127 Assert.assertEquals(receivedMessage.getHeader(org.springframework.messaging.MessageHeaders.REPLY_CHANNEL), "replyChannel");128 MessageChannel savedReplyChannel = channelSyncConsumer.getCorrelationManager().find(endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKey(receivedMessage),129 endpoint.getEndpointConfiguration().getTimeout());130 Assert.assertNotNull(savedReplyChannel);131 Assert.assertEquals(savedReplyChannel, replyChannel);132 verify(messagingTemplate).setReceiveTimeout(5000L);133 }134 135 @Test136 @SuppressWarnings({ "unchecked", "rawtypes" })137 public void testReceiveMessageWithCustomTimeout() {138 ChannelSyncEndpoint endpoint = new ChannelSyncEndpoint();139 endpoint.getEndpointConfiguration().setMessagingTemplate(messagingTemplate);140 endpoint.getEndpointConfiguration().setChannel(channel);141 endpoint.getEndpointConfiguration().setTimeout(10000L);142 143 Map<String, Object> headers = new HashMap<String, Object>();144 final org.springframework.messaging.Message message = MessageBuilder.withPayload("<TestResponse>Hello World!</TestResponse>")145 .copyHeaders(headers)146 .setReplyChannel(replyChannel)147 .build();148 reset(messagingTemplate, channel, replyChannel);149 when(messagingTemplate.receive(channel)).thenReturn(message);150 ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();151 Message receivedMessage = channelSyncConsumer.receive(context);152 Assert.assertEquals(receivedMessage.getPayload(), message.getPayload());153 Assert.assertEquals(receivedMessage.getHeader(org.springframework.messaging.MessageHeaders.ID), message.getHeaders().getId());154 MessageChannel savedReplyChannel = channelSyncConsumer.getCorrelationManager().find(endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKey(receivedMessage),155 endpoint.getEndpointConfiguration().getTimeout());156 Assert.assertNotNull(savedReplyChannel);157 Assert.assertEquals(savedReplyChannel, replyChannel);158 verify(messagingTemplate).setReceiveTimeout(10000L);159 }160 161 @Test162 @SuppressWarnings({ "unchecked", "rawtypes" })163 public void testReceiveMessageWithReplyMessageCorrelator() {164 ChannelSyncEndpoint endpoint = new ChannelSyncEndpoint();165 endpoint.getEndpointConfiguration().setMessagingTemplate(messagingTemplate);166 endpoint.getEndpointConfiguration().setChannel(channel);167 endpoint.getEndpointConfiguration().setCorrelator(messageCorrelator);168 endpoint.getEndpointConfiguration().setTimeout(500L);169 endpoint.getEndpointConfiguration().setPollingInterval(100);170 171 Map<String, Object> headers = new HashMap<String, Object>();172 final org.springframework.messaging.Message message = MessageBuilder.withPayload("<TestResponse>Hello World!</TestResponse>")173 .copyHeaders(headers)174 .setReplyChannel(replyChannel)175 .build();176 reset(messagingTemplate, channel, replyChannel, messageCorrelator);177 178 when(messagingTemplate.receive(channel)).thenReturn(message);179 when(messageCorrelator.getCorrelationKey(any(Message.class))).thenReturn(MessageHeaders.ID + " = '123456789'");180 when(messageCorrelator.getCorrelationKeyName(any(String.class))).thenReturn("correlationKeyName");181 ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();182 Message receivedMessage = channelSyncConsumer.receive(context);183 Assert.assertEquals(receivedMessage.getPayload(), message.getPayload());184 Assert.assertEquals(receivedMessage.getHeader(org.springframework.messaging.MessageHeaders.ID), message.getHeaders().getId());185 Assert.assertNull(channelSyncConsumer.getCorrelationManager().find("", endpoint.getEndpointConfiguration().getTimeout()));186 Assert.assertNull(channelSyncConsumer.getCorrelationManager().find(MessageHeaders.ID + " = 'totally_wrong'",187 endpoint.getEndpointConfiguration().getTimeout()));188 MessageChannel savedReplyChannel = channelSyncConsumer.getCorrelationManager().find(MessageHeaders.ID + " = '123456789'",189 endpoint.getEndpointConfiguration().getTimeout());190 Assert.assertNotNull(savedReplyChannel);191 Assert.assertEquals(savedReplyChannel, replyChannel);192 verify(messagingTemplate).setReceiveTimeout(500L);193 }194 195 @Test196 public void testReceiveNoMessage() {197 ChannelSyncEndpoint endpoint = new ChannelSyncEndpoint();198 endpoint.getEndpointConfiguration().setMessagingTemplate(messagingTemplate);199 endpoint.getEndpointConfiguration().setChannel(channel);200 201 reset(messagingTemplate, channel, replyChannel);202 203 when(messagingTemplate.receive(channel)).thenReturn(null);204 try {205 ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();206 channelSyncConsumer.receive(context);207 } catch(ActionTimeoutException e) {208 Assert.assertTrue(e.getLocalizedMessage().startsWith("Action timeout while receiving message from channel"));209 return;210 }211 Assert.fail("Missing " + ActionTimeoutException.class + " because no message was received");212 verify(messagingTemplate).setReceiveTimeout(5000L);213 }214 215 @Test216 @SuppressWarnings({ "unchecked", "rawtypes" })217 public void testReceiveMessageNoReplyChannel() {218 ChannelSyncEndpoint endpoint = new ChannelSyncEndpoint();219 endpoint.getEndpointConfiguration().setMessagingTemplate(messagingTemplate);220 endpoint.getEndpointConfiguration().setChannel(channel);221 endpoint.getEndpointConfiguration().setTimeout(500L);222 endpoint.getEndpointConfiguration().setPollingInterval(150L);223 224 Map<String, Object> headers = new HashMap<String, Object>();225 final org.springframework.messaging.Message message = MessageBuilder.withPayload("<TestResponse>Hello World!</TestResponse>")226 .copyHeaders(headers)227 .build();228 reset(messagingTemplate, channel, replyChannel);229 when(messagingTemplate.receive(channel)).thenReturn(message);230 ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();231 Message receivedMessage = channelSyncConsumer.receive(context);232 Assert.assertEquals(receivedMessage.getPayload(), message.getPayload());233 Assert.assertEquals(receivedMessage.getHeader(org.springframework.messaging.MessageHeaders.ID), message.getHeaders().getId());234 MessageChannel savedReplyChannel = channelSyncConsumer.getCorrelationManager().find("", endpoint.getEndpointConfiguration().getTimeout());235 Assert.assertNull(savedReplyChannel);236 verify(messagingTemplate).setReceiveTimeout(500L);237 }238 @Test239 public void testSendReplyMessage() {240 ChannelSyncEndpoint endpoint = new ChannelSyncEndpoint();241 endpoint.getEndpointConfiguration().setMessagingTemplate(messagingTemplate);242 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");243 reset(messagingTemplate, replyChannel);244 ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();245 channelSyncConsumer.saveReplyMessageChannel(new DefaultMessage("").setHeader(org.springframework.messaging.MessageHeaders.REPLY_CHANNEL, replyChannel), context);246 channelSyncConsumer.send(message, context);247 verify(messagingTemplate).send(eq(replyChannel), any(org.springframework.messaging.Message.class));248 }249 @Test250 public void testSendReplyMessageWithReplyMessageCorrelator() {251 ChannelSyncEndpoint endpoint = new ChannelSyncEndpoint();252 endpoint.getEndpointConfiguration().setMessagingTemplate(messagingTemplate);253 MessageCorrelator correlator = new DefaultMessageCorrelator();254 endpoint.getEndpointConfiguration().setCorrelator(correlator);255 Message request = new DefaultMessage("").setHeader(org.springframework.messaging.MessageHeaders.REPLY_CHANNEL, replyChannel);256 ((ChannelSyncConsumer)endpoint.createConsumer()).getCorrelationManager().saveCorrelationKey(257 endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKeyName(endpoint.createConsumer().getName()),258 request.getId(), context);259 Map<String, Object> headers = new HashMap<String, Object>();260 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", headers);261 reset(messagingTemplate, replyChannel);262 doAnswer(new Answer() {263 @Override264 public Object answer(InvocationOnMock invocation) throws Throwable {265 Assert.assertEquals(((GenericMessage)invocation.getArguments()[1]).getPayload(), message.getPayload());266 return null;267 }268 }).when(messagingTemplate).send(eq(replyChannel), any(org.springframework.messaging.Message.class));269 ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();270 channelSyncConsumer.saveReplyMessageChannel(request, context);271 channelSyncConsumer.send(message, context);272 }273 @Test274 public void testSendReplyMessageWithMissingCorrelatorKey() {275 ChannelSyncEndpoint endpoint = new ChannelSyncEndpoint();276 endpoint.getEndpointConfiguration().setMessagingTemplate(messagingTemplate);277 MessageCorrelator correlator = new DefaultMessageCorrelator();278 endpoint.getEndpointConfiguration().setCorrelator(correlator);279 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");280 try {281 ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();282 channelSyncConsumer.send(message, context);283 } catch(CitrusRuntimeException e) {284 Assert.assertTrue(e.getMessage().startsWith("Failed to get correlation key for"), e.getMessage());285 return;286 }287 Assert.fail("Missing " + IllegalArgumentException.class + " because of missing correlation key");288 }289 @Test290 public void testNoCorrelationKeyFound() {291 ChannelSyncEndpoint endpoint = new ChannelSyncEndpoint();292 endpoint.getEndpointConfiguration().setMessagingTemplate(messagingTemplate);293 MessageCorrelator correlator = new DefaultMessageCorrelator();294 endpoint.getEndpointConfiguration().setCorrelator(correlator);295 ChannelSyncEndpoint dummyEndpoint = new ChannelSyncEndpoint();296 dummyEndpoint.setName("dummyEndpoint");297 ((ChannelSyncConsumer)dummyEndpoint.createConsumer()).getCorrelationManager().saveCorrelationKey(298 dummyEndpoint.getEndpointConfiguration().getCorrelator().getCorrelationKeyName(dummyEndpoint.createConsumer().getName()),299 "123456789", context);300 Map<String, Object> headers = new HashMap<String, Object>();301 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", headers);302 try {303 ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();304 channelSyncConsumer.send(message, context);305 } catch(CitrusRuntimeException e) {306 Assert.assertTrue(e.getMessage().startsWith("Failed to get correlation key"));307 return;308 }309 Assert.fail("Missing " + IllegalArgumentException.class + " because no reply destination found");310 }311 @Test312 public void testNoReplyDestinationFound() {313 ChannelSyncEndpoint endpoint = new ChannelSyncEndpoint();314 endpoint.getEndpointConfiguration().setMessagingTemplate(messagingTemplate);315 endpoint.getEndpointConfiguration().setTimeout(1000L);316 MessageCorrelator correlator = new DefaultMessageCorrelator();317 endpoint.getEndpointConfiguration().setCorrelator(correlator);318 ((ChannelSyncConsumer)endpoint.createConsumer()).getCorrelationManager().saveCorrelationKey(319 endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKeyName(endpoint.createConsumer().getName()),320 "123456789", context);321 Map<String, Object> headers = new HashMap<String, Object>();322 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", headers);323 try {324 ChannelSyncConsumer channelSyncConsumer = (ChannelSyncConsumer) endpoint.createConsumer();325 channelSyncConsumer.send(message, context);326 } catch(IllegalArgumentException e) {327 Assert.assertTrue(e.getMessage().startsWith("Failed to find reply channel"));328 return;329 }330 Assert.fail("Missing " + IllegalArgumentException.class + " because no reply destination found");331 }332 @Test...

Full Screen

Full Screen

Source:DirectEndpointSyncConsumerTest.java Github

copy

Full Screen

...62 Message receivedMessage = channelSyncConsumer.receive(context);63 Assert.assertEquals(receivedMessage.getPayload(), message.getPayload());64 Assert.assertEquals(receivedMessage.getHeader(MessageHeaders.ID), message.getId());65 Assert.assertEquals(receivedMessage.getHeader(DirectMessageHeaders.REPLY_QUEUE), message.getHeader(DirectMessageHeaders.REPLY_QUEUE));66 MessageQueue savedReplyQueue = channelSyncConsumer.getCorrelationManager().find(endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKey(receivedMessage),67 endpoint.getEndpointConfiguration().getTimeout());68 Assert.assertNotNull(savedReplyQueue);69 Assert.assertEquals(savedReplyQueue, replyQueue);70 }71 @Test72 public void testReceiveMessageQueueNameResolver() {73 DirectSyncEndpoint endpoint = new DirectSyncEndpoint();74 endpoint.getEndpointConfiguration().setQueueName("testQueue");75 context.setReferenceResolver(resolver);76 Map<String, Object> headers = new HashMap<>();77 final Message message = new DefaultMessage("<TestResponse>Hello World!</TestResponse>", headers)78 .setHeader(DirectMessageHeaders.REPLY_QUEUE, replyQueue);79 reset(queue, replyQueue, resolver);80 when(resolver.resolve("testQueue", MessageQueue.class)).thenReturn(queue);81 when(queue.receive(5000L)).thenReturn(message);82 DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();83 Message receivedMessage = channelSyncConsumer.receive(context);84 Assert.assertEquals(receivedMessage.getPayload(), message.getPayload());85 Assert.assertEquals(receivedMessage.getHeader(MessageHeaders.ID), message.getId());86 Assert.assertEquals(receivedMessage.getHeader(DirectMessageHeaders.REPLY_QUEUE), message.getHeader(DirectMessageHeaders.REPLY_QUEUE));87 MessageQueue savedReplyQueue = channelSyncConsumer.getCorrelationManager().find(endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKey(receivedMessage),88 endpoint.getEndpointConfiguration().getTimeout());89 Assert.assertNotNull(savedReplyQueue);90 Assert.assertEquals(savedReplyQueue, replyQueue);91 }92 @Test93 public void testReceiveMessageWithReplyQueueName() {94 DirectSyncEndpoint endpoint = new DirectSyncEndpoint();95 endpoint.getEndpointConfiguration().setQueue(queue);96 Map<String, Object> headers = new HashMap<>();97 final Message message = new DefaultMessage("<TestResponse>Hello World!</TestResponse>", headers)98 .setHeader(DirectMessageHeaders.REPLY_QUEUE, "replyQueue");99 context.setReferenceResolver(resolver);100 reset(queue, replyQueue, resolver);101 when(queue.receive(5000L)).thenReturn(message);102 when(resolver.resolve("replyQueue", MessageQueue.class)).thenReturn(replyQueue);103 DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();104 Message receivedMessage = channelSyncConsumer.receive(context);105 Assert.assertEquals(receivedMessage.getPayload(), message.getPayload());106 Assert.assertEquals(receivedMessage.getHeader(MessageHeaders.ID), message.getId());107 Assert.assertEquals(receivedMessage.getHeader(DirectMessageHeaders.REPLY_QUEUE), "replyQueue");108 MessageQueue savedReplyQueue = channelSyncConsumer.getCorrelationManager().find(endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKey(receivedMessage),109 endpoint.getEndpointConfiguration().getTimeout());110 Assert.assertNotNull(savedReplyQueue);111 Assert.assertEquals(savedReplyQueue, replyQueue);112 }113 @Test114 public void testReceiveMessageWithCustomTimeout() {115 DirectSyncEndpoint endpoint = new DirectSyncEndpoint();116 endpoint.getEndpointConfiguration().setQueue(queue);117 endpoint.getEndpointConfiguration().setTimeout(10000L);118 Map<String, Object> headers = new HashMap<>();119 final Message message = new DefaultMessage("<TestResponse>Hello World!</TestResponse>", headers)120 .setHeader(DirectMessageHeaders.REPLY_QUEUE, replyQueue);121 reset(queue, replyQueue);122 when(queue.receive(10000L)).thenReturn(message);123 DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();124 Message receivedMessage = channelSyncConsumer.receive(context);125 Assert.assertEquals(receivedMessage.getPayload(), message.getPayload());126 Assert.assertEquals(receivedMessage.getHeader(MessageHeaders.ID), message.getId());127 MessageQueue savedReplyQueue = channelSyncConsumer.getCorrelationManager().find(endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKey(receivedMessage),128 endpoint.getEndpointConfiguration().getTimeout());129 Assert.assertNotNull(savedReplyQueue);130 Assert.assertEquals(savedReplyQueue, replyQueue);131 }132 @Test133 public void testReceiveMessageWithReplyMessageCorrelator() {134 DirectSyncEndpoint endpoint = new DirectSyncEndpoint();135 endpoint.getEndpointConfiguration().setQueue(queue);136 endpoint.getEndpointConfiguration().setCorrelator(messageCorrelator);137 endpoint.getEndpointConfiguration().setTimeout(500L);138 endpoint.getEndpointConfiguration().setPollingInterval(100);139 Map<String, Object> headers = new HashMap<>();140 final Message message = new DefaultMessage("<TestResponse>Hello World!</TestResponse>", headers)141 .setHeader(DirectMessageHeaders.REPLY_QUEUE, replyQueue);142 reset(queue, replyQueue, messageCorrelator);143 when(queue.receive(500L)).thenReturn(message);144 when(messageCorrelator.getCorrelationKey(any(Message.class))).thenReturn(MessageHeaders.ID + " = '123456789'");145 when(messageCorrelator.getCorrelationKeyName(any(String.class))).thenReturn("correlationKeyName");146 DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();147 Message receivedMessage = channelSyncConsumer.receive(context);148 Assert.assertEquals(receivedMessage.getPayload(), message.getPayload());149 Assert.assertEquals(receivedMessage.getHeader(MessageHeaders.ID), message.getId());150 Assert.assertNull(channelSyncConsumer.getCorrelationManager().find("", endpoint.getEndpointConfiguration().getTimeout()));151 Assert.assertNull(channelSyncConsumer.getCorrelationManager().find(MessageHeaders.ID + " = 'totally_wrong'",152 endpoint.getEndpointConfiguration().getTimeout()));153 MessageQueue savedReplyQueue = channelSyncConsumer.getCorrelationManager().find(MessageHeaders.ID + " = '123456789'",154 endpoint.getEndpointConfiguration().getTimeout());155 Assert.assertNotNull(savedReplyQueue);156 Assert.assertEquals(savedReplyQueue, replyQueue);157 }158 @Test159 public void testReceiveNoMessage() {160 DirectSyncEndpoint endpoint = new DirectSyncEndpoint();161 endpoint.getEndpointConfiguration().setQueue(queue);162 reset(queue, replyQueue);163 when(queue.receive(5000L)).thenReturn(null);164 try {165 DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();166 channelSyncConsumer.receive(context);167 } catch(ActionTimeoutException e) {168 Assert.assertTrue(e.getLocalizedMessage().startsWith("Action timeout after 5000 milliseconds. Failed to receive message on endpoint"));169 return;170 }171 Assert.fail("Missing " + ActionTimeoutException.class + " because no message was received");172 }173 @Test174 public void testReceiveMessageNoReplyQueue() {175 DirectSyncEndpoint endpoint = new DirectSyncEndpoint();176 endpoint.getEndpointConfiguration().setQueue(queue);177 endpoint.getEndpointConfiguration().setTimeout(500L);178 endpoint.getEndpointConfiguration().setPollingInterval(150L);179 Map<String, Object> headers = new HashMap<>();180 final Message message = new DefaultMessage("<TestResponse>Hello World!</TestResponse>", headers);181 reset(queue, replyQueue);182 when(queue.receive(500L)).thenReturn(message);183 DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();184 Message receivedMessage = channelSyncConsumer.receive(context);185 Assert.assertEquals(receivedMessage.getPayload(), message.getPayload());186 Assert.assertEquals(receivedMessage.getHeader(MessageHeaders.ID), message.getId());187 MessageQueue savedReplyQueue = channelSyncConsumer.getCorrelationManager().find("", endpoint.getEndpointConfiguration().getTimeout());188 Assert.assertNull(savedReplyQueue);189 }190 @Test191 public void testSendReplyMessage() {192 DirectSyncEndpoint endpoint = new DirectSyncEndpoint();193 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");194 reset(replyQueue);195 DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();196 channelSyncConsumer.saveReplyMessageQueue(new DefaultMessage("").setHeader(DirectMessageHeaders.REPLY_QUEUE, replyQueue), context);197 channelSyncConsumer.send(message, context);198 verify(replyQueue).send(any(Message.class));199 }200 @Test201 public void testSendReplyMessageWithReplyMessageCorrelator() {202 DirectSyncEndpoint endpoint = new DirectSyncEndpoint();203 MessageCorrelator correlator = new DefaultMessageCorrelator();204 endpoint.getEndpointConfiguration().setCorrelator(correlator);205 Message request = new DefaultMessage("").setHeader(DirectMessageHeaders.REPLY_QUEUE, replyQueue);206 ((DirectSyncConsumer)endpoint.createConsumer()).getCorrelationManager().saveCorrelationKey(207 endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKeyName(endpoint.createConsumer().getName()),208 request.getId(), context);209 Map<String, Object> headers = new HashMap<>();210 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", headers);211 reset(replyQueue);212 doAnswer(invocation -> {213 Assert.assertEquals(((DefaultMessage)invocation.getArguments()[0]).getPayload(), message.getPayload());214 return null;215 }).when(replyQueue).send(any(Message.class));216 DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();217 channelSyncConsumer.saveReplyMessageQueue(request, context);218 channelSyncConsumer.send(message, context);219 }220 @Test221 public void testSendReplyMessageWithMissingCorrelatorKey() {222 DirectSyncEndpoint endpoint = new DirectSyncEndpoint();223 MessageCorrelator correlator = new DefaultMessageCorrelator();224 endpoint.getEndpointConfiguration().setCorrelator(correlator);225 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");226 try {227 DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();228 channelSyncConsumer.send(message, context);229 } catch(CitrusRuntimeException e) {230 Assert.assertTrue(e.getMessage().startsWith("Failed to get correlation key for"), e.getMessage());231 return;232 }233 Assert.fail("Missing " + IllegalArgumentException.class + " because of missing correlation key");234 }235 @Test236 public void testNoCorrelationKeyFound() {237 DirectSyncEndpoint endpoint = new DirectSyncEndpoint();238 MessageCorrelator correlator = new DefaultMessageCorrelator();239 endpoint.getEndpointConfiguration().setCorrelator(correlator);240 DirectSyncEndpoint dummyEndpoint = new DirectSyncEndpoint();241 dummyEndpoint.setName("dummyEndpoint");242 ((DirectSyncConsumer)dummyEndpoint.createConsumer()).getCorrelationManager().saveCorrelationKey(243 dummyEndpoint.getEndpointConfiguration().getCorrelator().getCorrelationKeyName(dummyEndpoint.createConsumer().getName()),244 "123456789", context);245 Map<String, Object> headers = new HashMap<>();246 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", headers);247 try {248 DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();249 channelSyncConsumer.send(message, context);250 } catch(CitrusRuntimeException e) {251 Assert.assertTrue(e.getMessage().startsWith("Failed to get correlation key"));252 return;253 }254 Assert.fail("Missing " + IllegalArgumentException.class + " because no reply destination found");255 }256 @Test257 public void testNoReplyDestinationFound() {258 DirectSyncEndpoint endpoint = new DirectSyncEndpoint();259 endpoint.getEndpointConfiguration().setTimeout(1000L);260 MessageCorrelator correlator = new DefaultMessageCorrelator();261 endpoint.getEndpointConfiguration().setCorrelator(correlator);262 ((DirectSyncConsumer)endpoint.createConsumer()).getCorrelationManager().saveCorrelationKey(263 endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKeyName(endpoint.createConsumer().getName()),264 "123456789", context);265 Map<String, Object> headers = new HashMap<>();266 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", headers);267 try {268 DirectSyncConsumer channelSyncConsumer = (DirectSyncConsumer) endpoint.createConsumer();269 channelSyncConsumer.send(message, context);270 } catch(IllegalArgumentException e) {271 Assert.assertTrue(e.getMessage().startsWith("Failed to find reply channel"));272 return;273 }274 Assert.fail("Missing " + IllegalArgumentException.class + " because no reply destination found");275 }276 @Test...

Full Screen

Full Screen

getCorrelationManager

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.channel;2import org.springframework.context.support.ClassPathXmlApplicationContext;3public class CitrusTest {4 public static void main(String[] args) {5 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");6 ChannelSyncConsumer channel = context.getBean("channel", ChannelSyncConsumer.class);7 System.out.println(channel.getCorrelationManager());8 }9}

Full Screen

Full Screen

getCorrelationManager

Using AI Code Generation

copy

Full Screen

1public class 4 {2 public static void main(String[] args) {3 ChannelSyncConsumer channelSyncConsumer = new ChannelSyncConsumer();4 MessageChannel channel = new DirectChannel();5 channelSyncConsumer.setChannel(channel);6 channelSyncConsumer.setCorrelationManager(new DefaultCorrelationManager());7 Message message = new DefaultMessage("Test");8 channelSyncConsumer.send(message);9 Message reply = channelSyncConsumer.receive("Test", 10000);10 System.out.println(reply.getPayload());11 }12}13public class 5 {14 public static void main(String[] args) {15 ChannelSyncConsumer channelSyncConsumer = new ChannelSyncConsumer();16 MessageChannel channel = new DirectChannel();17 channelSyncConsumer.setChannel(channel);18 channelSyncConsumer.setCorrelationManager(new DefaultCorrelationManager());19 Message message = new DefaultMessage("Test");20 channelSyncConsumer.send(message);21 Message reply = channelSyncConsumer.receive("Test", 10000);22 System.out.println(reply.getPayload());23 }24}25public class 6 {26 public static void main(String[] args) {27 ChannelSyncConsumer channelSyncConsumer = new ChannelSyncConsumer();28 MessageChannel channel = new DirectChannel();29 channelSyncConsumer.setChannel(channel);30 channelSyncConsumer.setCorrelationManager(new DefaultCorrelationManager());31 Message message = new DefaultMessage("Test");32 channelSyncConsumer.send(message);33 Message reply = channelSyncConsumer.receive("Test", 10000);34 System.out.println(reply.getPayload());35 }36}37public class 7 {38 public static void main(String[] args) {39 ChannelSyncConsumer channelSyncConsumer = new ChannelSyncConsumer();40 MessageChannel channel = new DirectChannel();41 channelSyncConsumer.setChannel(channel);42 channelSyncConsumer.setCorrelationManager(new DefaultCorrelationManager());43 Message message = new DefaultMessage("Test");44 channelSyncConsumer.send(message);45 Message reply = channelSyncConsumer.receive("Test", 10000);46 System.out.println(reply.getPayload());47 }48}

Full Screen

Full Screen

getCorrelationManager

Using AI Code Generation

copy

Full Screen

1import org.springframework.integration.Message;2import org.springframework.integration.MessageChannel;3import org.springframework.integration.support.MessageBuilder;4import org.springframework.integration.channel.QueueChannel;5import org.springframework.integration.channel.DirectChannel;6import org.springframework.integration.channel.ChannelInterceptor;7import org.springframework.integration.channel.ChannelInterceptorAdapter;8import org.springframework.integration.MessageChannel;9import org.springframework.integration.Message;10import org.springframework.integration.MessageHeaders;11import org.springframework.integration.support.MessageBuilder;12import org.springframework.integration.channel.QueueChannel;13import org.springframework.integration.channel.DirectChannel;14import org.springframework.integration.channel.ChannelInterceptor;15import org.springframework.integration.channel.ChannelInterceptorAdapter;16import org.springframework.integration.MessageChannel;17import org.springframework.integration.Message;18import org.springframework.integration.MessageHeaders;19import org.springframework.integration.support.MessageBuilder;20import org.springframework.integration.channel.QueueChannel;21import org.springframework.integration.channel.DirectChannel;22import org.springframework.integration.channel.ChannelInterceptor;23import org.springframework.integration.channel.ChannelInterceptorAdapter;24import org.springframework.integration.MessageChannel;25import org.springframework.integration.Message;26import org.springframework.integration.MessageHeaders;27import org.springframework.integration.support.MessageBuilder;28import org.springframework.integration.channel.QueueChannel;29import org.springframework.integration.channel.DirectChannel;30import org.springframework.integration.channel.ChannelInterceptor;31import org.springframework.integration.channel.ChannelInterceptorAdapter;32import org.springframework.integration.MessageChannel;33import org.springframework.integration.Message;34import org.springframework.integration.MessageHeaders;35import org.springframework.integration.support.MessageBuilder;36import org.springframework.integration.channel.QueueChannel;37import org.springframework.integration.channel.DirectChannel;38import org.springframework.integration.channel.ChannelInterceptor;39import org.springframework.integration.channel.ChannelInterceptorAdapter;40import org.springframework.integration.MessageChannel;41import org.springframework.integration.Message;42import org.springframework.integration.MessageHeaders;43import org.springframework.integration.support.MessageBuilder;44import org.springframework.integration.channel.QueueChannel;45import org.springframework.integration.channel.DirectChannel;46import org.springframework.integration.channel.ChannelInterceptor;47import org.springframework.integration.channel.ChannelInterceptorAdapter;48import org.springframework.integration.MessageChannel;49import org.springframework.integration.Message;50import org.springframework.integration.MessageHeaders;51import org.springframework.integration.support.MessageBuilder;52import org.springframework.integration.channel.QueueChannel;53import org.springframework.integration.channel.DirectChannel;54import org.springframework.integration.channel.ChannelInterceptor;55import org.springframework.integration.channel.ChannelInterceptorAdapter;56import org.springframework.integration.MessageChannel;57import org.springframework.integration.Message;58import org.springframework.integration.MessageHeaders;59import org.springframework.integration.support.MessageBuilder;60import org.springframework.integration.channel.QueueChannel;61import org.springframework.integration.channel.DirectChannel;62import org.springframework.integration.channel.ChannelInterceptor;63import org.springframework.integration.channel.ChannelInterceptorAdapter;64import org.springframework.integration.MessageChannel;65import org.springframework.integration.Message;66import org.springframework.integration

Full Screen

Full Screen

getCorrelationManager

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import org.springframework.context.support.ClassPathXmlApplicationContext;3import com.consol.citrus.message.Message;4import com.consol.citrus.samples.channelsyncconsumer.ChannelSyncConsumer;5public class ChannelSyncConsumerTest {6 public static void main(String[] args) {7 ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:channelsyncconsumer/spring-context.xml");8 ChannelSyncConsumer channelSyncConsumer = ctx.getBean("channelSyncConsumer", ChannelSyncConsumer.class);9 Message message = channelSyncConsumer.getMessage();10 System.out.println("Message received: " + message.getPayload());11 ctx.close();12 }13}14package com.consol.citrus.samples.channelsyncconsumer;15import org.springframework.beans.factory.annotation.Autowired;16import org.springframework.integration.annotation.ServiceActivator;17import org.springframework.integration.channel.QueueChannel;18import org.springframework.messaging.Message;19import org.springframework.messaging.MessageHandler;20import org.springframework.messaging.MessagingException;21import org.springframework.stereotype.Component;22import com.consol.citrus.message.CitrusMessageHeaders;23import com.consol.citrus.message.MessageCorrelator;24import com.consol.citrus.message.MessageCorrelatorRegistry;25import com.consol.citrus.message.MessageHeaderType;26import com.consol.citrus.message.MessageHeaders;27import com.consol.citrus.message.MessageType;28public class ChannelSyncConsumer {29 private QueueChannel channel;30 private MessageCorrelatorRegistry correlatorRegistry;31 public Message getMessage() {32 return channel.receive();33 }34 public Message getMessage(String correlationKey) {35 return channel.receive(10000L, correlationKey);36 }37 public Message getMessage(MessageCorrelator correlator) {38 return channel.receive(10000L, correlator);39 }40 @ServiceActivator(inputChannel = "channel")41 public void handle(Message<?> message) throws Exception {42 System.out.println("Message received: " + message.getPayload());43 if (message.getHeaders().containsKey(CitrusMessageHeaders.CORRELATION_KEY)) {44 String correlationKey = message.getHeaders().get(CitrusMessageHeaders.CORRELATION_KEY, String.class);45 MessageCorrelator correlator = correlatorRegistry.getCorrelator(correlationKey);

Full Screen

Full Screen

getCorrelationManager

Using AI Code Generation

copy

Full Screen

1ChannelSyncConsumer channelSyncConsumer = new ChannelSyncConsumer();2channelSyncConsumer.getCorrelationManager();3ChannelSyncConsumer channelSyncConsumer = new ChannelSyncConsumer();4channelSyncConsumer.setCorrelationManager(correlationManager);5ChannelSyncConsumer channelSyncConsumer = new ChannelSyncConsumer();6channelSyncConsumer.getCorrelationKey();7ChannelSyncConsumer channelSyncConsumer = new ChannelSyncConsumer();8channelSyncConsumer.setCorrelationKey(correlationKey);9ChannelSyncConsumer channelSyncConsumer = new ChannelSyncConsumer();10channelSyncConsumer.getCorrelationData();11ChannelSyncConsumer channelSyncConsumer = new ChannelSyncConsumer();12channelSyncConsumer.setCorrelationData(correlationData);13ChannelSyncConsumer channelSyncConsumer = new ChannelSyncConsumer();14channelSyncConsumer.getCorrelationExpression();15ChannelSyncConsumer channelSyncConsumer = new ChannelSyncConsumer();16channelSyncConsumer.setCorrelationExpression(correlationExpression);

Full Screen

Full Screen

getCorrelationManager

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.channel.ChannelSyncConsumer;2import com.consol.citrus.message.CorrelationManager;3import com.consol.citrus.message.MessageCorrelator;4import com.consol.citrus.message.MessageCorrelatorBuilder;5import com.consol.citrus.message.MessageCorrelatorBuilderImpl;6import com.consol.citrus.message.MessageCorrelatorImpl;7import com.consol.citrus.message.MessageDirection;8import com.consol.citrus.message.MessageHeaders;9import com.consol.citrus.message.MessageType;10import com.consol.citrus.message.ReplyMessageCorrelator;11import com.consol.citrus.message.ReplyMessageCorrelatorBuilder;12import com.consol.citrus.message.ReplyMessageCorrelatorBuilderImpl;13import com.consol.citrus.message.ReplyMessageCorrelatorImpl;14import com.consol.citrus.message.SelectiveConsumer;15import com.consol.citrus.message.SelectiveConsumerImpl;16import com.consol.citrus.message.builder.DefaultMessageBuilder;17import com.consol.citrus.message.builder.ScriptMessageBuilder;18import com.consol.citrus.message.builder.StaticMessageContentBuilder;19import com.consol.citrus.message.builder.TemplateMessageBuilder;20import com.consol.citrus.message.builder.TemplateMessageBuilderSupport;21import com.consol.citrus.message.builder.TemplateMessageDataDictionary;22import com.consol.citrus.message.builder.TemplateMessageDataDictionaryBuilder;23import com.consol.citrus.message.builder.TemplateMessageDataDictionaryBuilderImpl;24import com.consol.citrus.message.builder.TemplateMessageDataDictionaryImpl;25import com.consol.citrus.message.builder.TemplateMessageProcessor;26import com.consol.citrus.message.builder.TemplateMessageProcessorImpl;27import com.consol.citrus.message.builder.TemplateMessageProcessorSupport;28import com.consol.citrus.message.correlation.DefaultCorrelationManager;29import com.consol.citrus.message.correlation.ReplyMessageCorrelator;30import com.consol.citrus.message.correlation.ReplyMessageCorrelatorBuilder;31import com.consol.citrus.message.correlation.ReplyMessageCorrelatorBuilderImpl;32import com.consol.citrus.message.cor

Full Screen

Full Screen

getCorrelationManager

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import org.springframework.context.support.ClassPathXmlApplicationContext;3import com.consol.citrus.message.Message;4import com.consol.citrus.samples.channelsyncconsumer.ChannelSyncConsumer;5public class ChannelSyncConsumerTest {6 public static void main(String[] args) {7 ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:channelsyncconsumer/spring-context.xml");8 ChannelSyncConsumer channelSyncConsumer = ctx.getBean("channelSyncConsumer", ChannelSyncConsumer.class);9 Message message = channelSyncConsumer.getMessage();10 System.out.println("Message received: " + message.getPayload());11 ctx.close();12 }13}14package com.consol.citrus.samples.channelsyncconsumer;15import org.springframework.beans.factory.annotation.Autowired;16import org.springframework.integration.annotation.ServiceActivator;17import org.springframework.integration.channel.QueueChannel;18import org.springframework.messaging.Message;19import org.springframework.messaging.MessageHandler;20import org.springframework.messaging.MessagingException;21import org.springframework.stereotype.Component;22import com.consol.citrus.message.CitrusMessageHeaders;23import com.consol.citrus.message.MessageCorrelator;24import com.consol.citrus.message.MessageCorrelatorRegistry;25import com.consol.citrus.message.MessageHeaderType;26import com.consol.citrus.message.MessageHeaders;27import com.consol.citrus.message.MessageType;28public class ChannelSyncConsumer {29 private QueueChannel channel;30 private MessageCorrelatorRegistry correlatorRegistry;31 public Message getMessage() {32 return channel.receive();33 }34 public Message getMessage(String correlationKey) {35 return channel.receive(10000L, correlationKey);36 }37 public Message getMessage(MessageCorrelator correlator) {38 return channel.receive(10000L, correlator);39 }40 @ServiceActivator(inputChannel = "channel")41 public void handle(Message<?> message) throws Exception {42 System.out.println("Message received: " + message.getPayload());43 if (message.getHeaders().containsKey(CitrusMessageHeaders.CORRELATION_KEY)) {44 String correlationKey = message.getHeaders().get(CitrusMessageHeaders.CORRELATION_KEY, String.class);45 MessageCorrelator correlator = correlatorRegistry.getCorrelator(correlationKey);

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.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful