How to use resolveDestination method of com.consol.citrus.jms.endpoint.JmsSyncProducer class

Best Citrus code snippet using com.consol.citrus.jms.endpoint.JmsSyncProducer.resolveDestination

Source:JmsSyncProducer.java Github

copy

Full Screen

...76 }77 destination = endpointConfiguration.getDestination();78 } else if (StringUtils.hasText(endpointConfiguration.getDestinationName())) {79 if (endpointConfiguration.getDestinationNameResolver() != null) {80 destination = resolveDestination(context.replaceDynamicContentInString(endpointConfiguration.getDestinationNameResolver().resolveEndpointUri(message, endpointConfiguration.getDestinationName())));81 } else {82 destination = resolveDestination(context.replaceDynamicContentInString(endpointConfiguration.getDestinationName()));83 }84 } else if (endpointConfiguration.getJmsTemplate().getDefaultDestination() != null) {85 if (log.isDebugEnabled()) {86 log.debug("Sending JMS message to destination: '" + endpointConfiguration.getDestinationName(endpointConfiguration.getJmsTemplate().getDefaultDestination()) + "'");87 }88 destination = endpointConfiguration.getJmsTemplate().getDefaultDestination();89 } else if (StringUtils.hasText(endpointConfiguration.getJmsTemplate().getDefaultDestinationName())) {90 destination = resolveDestination(context.replaceDynamicContentInString(endpointConfiguration.getJmsTemplate().getDefaultDestinationName()));91 } else {92 throw new CitrusRuntimeException("Unable to send message - JMS destination not set");93 }94 messageProducer = session.createProducer(destination);95 replyToDestination = getReplyDestination(session, message);96 if (replyToDestination instanceof TemporaryQueue || replyToDestination instanceof TemporaryTopic) {97 messageConsumer = session.createConsumer(replyToDestination);98 }99 jmsRequest.setJMSReplyTo(replyToDestination);100 messageProducer.send(jmsRequest);101 if (messageConsumer == null) {102 messageConsumer = createMessageConsumer(replyToDestination, jmsRequest.getJMSMessageID());103 }104 log.info("Message was sent to JMS destination: '{}'", endpointConfiguration.getDestinationName(destination));105 log.debug("Receiving reply message on destination: '{}'", replyToDestination);106 javax.jms.Message jmsReplyMessage = (endpointConfiguration.getTimeout() >= 0) ? messageConsumer.receive(endpointConfiguration.getTimeout()) : messageConsumer.receive();107 if (jmsReplyMessage == null) {108 throw new ActionTimeoutException("Reply timed out after " +109 endpointConfiguration.getTimeout() + "ms. Did not receive reply message on reply destination");110 }111 Message responseMessage = endpointConfiguration.getMessageConverter().convertInbound(jmsReplyMessage, endpointConfiguration, context);112 log.info("Received reply message on JMS destination: '{}'", replyToDestination);113 context.onInboundMessage(responseMessage);114 correlationManager.store(correlationKey, responseMessage);115 } catch (JMSException e) {116 throw new CitrusRuntimeException(e);117 } finally {118 JmsUtils.closeMessageProducer(messageProducer);119 JmsUtils.closeMessageConsumer(messageConsumer);120 deleteTemporaryDestination(replyToDestination);121 }122 }123 @Override124 public Message receive(TestContext context) {125 return receive(correlationManager.getCorrelationKey(126 endpointConfiguration.getCorrelator().getCorrelationKeyName(getName()), context), context);127 }128 @Override129 public Message receive(String selector, TestContext context) {130 return receive(selector, context, endpointConfiguration.getTimeout());131 }132 @Override133 public Message receive(TestContext context, long timeout) {134 return receive(correlationManager.getCorrelationKey(135 endpointConfiguration.getCorrelator().getCorrelationKeyName(getName()), context), context, timeout);136 }137 @Override138 public Message receive(String selector, TestContext context, long timeout) {139 Message message = correlationManager.find(selector, timeout);140 if (message == null) {141 throw new ActionTimeoutException("Action timeout while receiving synchronous reply message on jms destination");142 }143 return message;144 }145 /**146 * Create new JMS connection.147 * @return connection148 * @throws JMSException149 */150 protected void createConnection() throws JMSException {151 if (connection == null) {152 if (!endpointConfiguration.isPubSubDomain() && endpointConfiguration.getConnectionFactory() instanceof QueueConnectionFactory) {153 connection = ((QueueConnectionFactory) endpointConfiguration.getConnectionFactory()).createQueueConnection();154 } else if (endpointConfiguration.isPubSubDomain() && endpointConfiguration.getConnectionFactory() instanceof TopicConnectionFactory) {155 connection = ((TopicConnectionFactory) endpointConfiguration.getConnectionFactory()).createTopicConnection();156 connection.setClientID(getName());157 } else {158 log.warn("Not able to create a connection with connection factory '" + endpointConfiguration.getConnectionFactory() + "'" +159 " when using setting 'publish-subscribe-domain' (=" + endpointConfiguration.isPubSubDomain() + ")");160 connection = endpointConfiguration.getConnectionFactory().createConnection();161 }162 connection.start();163 }164 }165 /**166 * Create new JMS session.167 * @param connection to use for session creation.168 * @return session.169 * @throws JMSException170 */171 protected void createSession(Connection connection) throws JMSException {172 if (session == null) {173 if (!endpointConfiguration.isPubSubDomain() && connection instanceof QueueConnection) {174 session = ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);175 } else if (endpointConfiguration.isPubSubDomain() && endpointConfiguration.getConnectionFactory() instanceof TopicConnectionFactory) {176 session = ((TopicConnection) connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE);177 } else {178 log.warn("Not able to create a session with connection factory '" + endpointConfiguration.getConnectionFactory() + "'" +179 " when using setting 'publish-subscribe-domain' (=" + endpointConfiguration.isPubSubDomain() + ")");180 session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);181 }182 }183 }184 /**185 * Creates a message consumer on temporary/durable queue or topic. Durable queue/topic destinations186 * require a message selector to be set.187 *188 * @param replyToDestination the reply destination.189 * @param messageId the messageId used for optional message selector.190 * @return191 * @throws JMSException192 */193 private MessageConsumer createMessageConsumer(Destination replyToDestination, String messageId) throws JMSException {194 MessageConsumer messageConsumer;195 if (replyToDestination instanceof Queue) {196 messageConsumer = session.createConsumer(replyToDestination,197 "JMSCorrelationID = '" + messageId.replaceAll("'", "''") + "'");198 } else {199 messageConsumer = session.createDurableSubscriber((Topic)replyToDestination, getName(),200 "JMSCorrelationID = '" + messageId.replaceAll("'", "''") + "'", false);201 }202 return messageConsumer;203 }204 /**205 * Delete temporary destinations.206 * @param destination207 */208 private void deleteTemporaryDestination(Destination destination) {209 log.debug("Delete temporary destination: '{}'", destination);210 try {211 if (destination instanceof TemporaryQueue) {212 ((TemporaryQueue) destination).delete();213 } else if (destination instanceof TemporaryTopic) {214 ((TemporaryTopic) destination).delete();215 }216 } catch (JMSException e) {217 log.error("Error while deleting temporary destination '" + destination + "'", e);218 }219 }220 /**221 * Retrieve the reply destination either by injected instance, destination name or222 * by creating a new temporary destination.223 *224 * @param session current JMS session225 * @param message holding possible reply destination in header.226 * @return the reply destination.227 * @throws JMSException228 */229 private Destination getReplyDestination(Session session, Message message) throws JMSException {230 if (message.getHeader(org.springframework.messaging.MessageHeaders.REPLY_CHANNEL) != null) {231 if (message.getHeader(org.springframework.messaging.MessageHeaders.REPLY_CHANNEL) instanceof Destination) {232 return (Destination) message.getHeader(org.springframework.messaging.MessageHeaders.REPLY_CHANNEL);233 } else {234 return resolveDestinationName(message.getHeader(org.springframework.messaging.MessageHeaders.REPLY_CHANNEL).toString(), session);235 }236 } else if (endpointConfiguration.getReplyDestination() != null) {237 return endpointConfiguration.getReplyDestination();238 } else if (StringUtils.hasText(endpointConfiguration.getReplyDestinationName())) {239 return resolveDestinationName(endpointConfiguration.getReplyDestinationName(), session);240 }241 if (endpointConfiguration.isPubSubDomain() && session instanceof TopicSession) {242 return session.createTemporaryTopic();243 } else {244 return session.createTemporaryQueue();245 }246 }247 /**248 * Resolve destination from given name.249 * @param destinationName250 * @return251 * @throws JMSException252 */253 private Destination resolveDestination(String destinationName) throws JMSException {254 if (log.isDebugEnabled()) {255 log.debug("Sending JMS message to destination: '" + destinationName + "'");256 }257 return resolveDestinationName(destinationName, session);258 }259 /**260 * Resolves the destination name from Jms session.261 * @param name262 * @param session263 * @return264 */265 private Destination resolveDestinationName(String name, Session session) throws JMSException {266 if (endpointConfiguration.getDestinationResolver() != null) {267 return endpointConfiguration.getDestinationResolver().resolveDestinationName(session, name, endpointConfiguration.isPubSubDomain());268 }269 return new DynamicDestinationResolver().resolveDestinationName(session, name, endpointConfiguration.isPubSubDomain());270 }271 /**272 * Destroy method closing JMS session and connection273 */274 public void destroy() {275 JmsUtils.closeSession(session);276 if (connection != null) {277 ConnectionFactoryUtils.releaseConnection(connection, endpointConfiguration.getConnectionFactory(), true);278 }279 }280 /**281 * Gets the correlation manager.282 * @return283 */...

Full Screen

Full Screen

resolveDestination

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.runner.TestRunner2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner3import com.consol.citrus.jms.endpoint.JmsSyncProducer4import com.consol.citrus.message.MessageType5import org.springframework.beans.factory.annotation.Autowired6import org.springframework.jms.core.JmsTemplate7import org.springframework.jms.support.destination.DestinationResolver8class JmsSyncProducerTest extends TestNGCitrusTestDesigner {9 void testJmsSyncProducer() {10 def jmsSyncProducer = new JmsSyncProducer()11 jmsSyncProducer.setJmsTemplate(jmsTemplate)12 jmsSyncProducer.setDestinationResolver(destinationResolver)13 jmsSyncProducer.send("testMessage", "testQueue")14 receive("testQueue")15 .messageType(MessageType.PLAINTEXT)16 .payload("testMessage")17 }18}19 at com.consol.citrus.jms.endpoint.JmsSyncProducer.resolveDestination(JmsSyncProducer.java:100)20 at com.consol.citrus.jms.endpoint.JmsSyncProducer.send(JmsSyncProducer.java:76)21 at com.consol.citrus.jms.endpoint.JmsSyncProducerTest.testJmsSyncProducer(JmsSyncProducerTest.groovy:27)22 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)23 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)24 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)25 at java.lang.reflect.Method.invoke(Method.java:498)26 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)27 at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)28 at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)29 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)30 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)31 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)

Full Screen

Full Screen

resolveDestination

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.annotations.CitrusResource;2import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;3import com.consol.citrus.dsl.builder.SendMessageBuilder;4import com.consol.citrus.dsl.runner.TestRunner;5import com.consol.citrus.exceptions.CitrusRuntimeException;6import com.consol.citrus.jms.endpoint.JmsSyncProducer;7import com.consol.citrus.message.Message;8import com.consol.citrus.message.MessageType;9import com.consol.citrus.testng.CitrusParameters;10import org.springframework.beans.factory.annotation.Autowired;11import org.springframework.jms.core.JmsTemplate;12import org.springframework.jms.core.MessageCreator;13import org.springframework.jms.support.converter.MessageConverter;14import org.springframework.jms.support.destination.DestinationResolver;15import org.testng.annotations.Test;16import javax.jms.*;17import java.util.Collections;18import java.util.Map;19public class JmsSyncProducerTest extends AbstractJmsEndpointTest {20 private JmsTemplate jmsTemplate;21 private DestinationResolver destinationResolver;22 private MessageConverter messageConverter;23 @CitrusParameters({"messageId", "messagePayload"})24 public void testJmsSyncProducer(@CitrusResource TestRunner runner,25 String messagePayload) {26 runner.given(SendMessageBuilder.class)27 .endpoint(jmsSyncProducer)28 .message(message)29 .header("destination", "dynamicQueues/TEST.QUEUE")30 .header("replyTo", "dynamicQueues/TEST.QUEUE.REPLY")31 .header("JMSXGroupID", "TEST-GROUP")32 .header("JMSXGroupSeq", "1")33 .header("JMSXUserID", "citrus:randomNumber(4)")34 .header("citrus_jms_messageId", "citrus:randomNumber(4)")35 .header("citrus_jms_correlationId", "citrus:randomNumber(4)")36 .header("citrus_jms_deliveryMode", "PERSISTENT")37 .header("citrus_jms_priority", "5")38 .header("citrus_jms_timeToLive", "10000")39 .header("citrus_jms_type", "citrus:randomNumber(4)")40 .header("citrus_j

Full Screen

Full Screen

resolveDestination

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.design.TestDesigner2import com.consol.citrus.dsl.design.TestDesigner3import com.consol.citrus.dsl.runner.TestRunner4import com.consol.citrus.dsl.runner.TestRunner5import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner6import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner7import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner8import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner9import com.consol.citrus.message.MessageType10import com.consol.citrus.testng.CitrusParameters11import com.consol.citrus.testng.CitrusParameters12import org.testng.annotations.Test13import org.testng.annotations.Test14class JmsSyncProducerResolveDestinationTest extends TestNGCitrusTestRunner {15 @CitrusParameters("message")16 void testSend(String message) {17 description("JMS Sync Producer test using resolveDestination method of JmsSyncProducer class")18 echo("## Sending message to ${destination} ...")19 send("jmsSyncProducer")20 .payload(message)21 .header("destination", "${destination}")22 }23}24class JmsSyncProducerResolveDestinationTest extends TestNGCitrusTestRunner {25 @CitrusParameters("message")26 void testSend(String message) {27 description("JMS Sync Producer test using resolveDestination method of JmsSyncProducer class")28 echo("## Sending message to ${destination} ...")29 send("jmsSyncProducer")30 .payload(message)31 .header("destination", "${destination}")32 }33}34class JmsSyncProducerResolveDestinationTest extends TestNGCitrusTestRunner {35 @CitrusParameters("message")

Full Screen

Full Screen

resolveDestination

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.annotations.CitrusTest2import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner3import com.consol.citrus.jms.endpoint.JmsSyncProducer4import com.consol.citrus.message.MessageType5import org.springframework.beans.factory.annotation.Autowired6import org.springframework.beans.factory.annotation.Qualifier7import org.springframework.jms.core.JmsTemplate8import org.springframework.jms.support.destination.DestinationResolver9class JmsDynamicDestinationTest extends JUnit4CitrusTestDesigner {10 @Qualifier('jmsTemplate')11 @Qualifier('destinationResolver')12 void testJmsDynamicDestination() {13 variable('destinationName', 'dynamicDestination')14 send {15 endpoint(jmsSyncProducer())16 payload('Hello Citrus!')17 header('destinationName', '${destinationName}')18 }19 receive {20 endpoint(jmsSyncProducer())21 payload('Hello Citrus!')22 messageType(MessageType.TEXT)23 }24 variable('destinationName', 'dynamicDestination2')25 send {26 endpoint(jmsSyncProducer())27 payload('Hello Citrus!')28 header('destinationName', '${destinationName}')29 }30 receive {31 endpoint(jmsSyncProducer())32 payload('Hello Citrus!')33 messageType(MessageType.TEXT)34 }35 }36 private JmsSyncProducer jmsSyncProducer() {37 return new JmsSyncProducer() {38 protected String resolveDestinationName() {39 return testContext.getVariable('destinationName')40 }41 protected JmsTemplate getJmsTemplate() {42 }43 protected DestinationResolver getDestinationResolver() {44 }45 }46 }47}48The JmsSyncProducer class is a very simple class that extends the JmsProducer class and overrides the resolveDestinationName() method. The resolveDestinationName() method is called in the send() method of the JmsProducer class. The send() method is called by

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful