Best Citrus code snippet using com.consol.citrus.jms.endpoint.TextMessageImpl.acknowledge
Source:JmsEndpointSyncConsumerTest.java
1/*2 * Copyright 2006-2010 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus.jms.endpoint;17import com.consol.citrus.exceptions.CitrusRuntimeException;18import com.consol.citrus.jms.message.JmsMessage;19import com.consol.citrus.message.*;20import com.consol.citrus.message.Message;21import com.consol.citrus.testng.AbstractTestNGUnitTest;22import org.mockito.Mockito;23import org.springframework.jms.core.JmsTemplate;24import org.springframework.jms.core.MessageCreator;25import org.testng.Assert;26import org.testng.annotations.Test;27import javax.jms.*;28import java.util.HashMap;29import java.util.Map;30import static org.mockito.Mockito.*;31/**32 * @author Christoph Deppisch33 */34public class JmsEndpointSyncConsumerTest extends AbstractTestNGUnitTest {35 private ConnectionFactory connectionFactory = Mockito.mock(ConnectionFactory.class);36 private Connection connection = Mockito.mock(Connection.class);37 private Session session = Mockito.mock(Session.class);38 private Destination destination = Mockito.mock(Destination.class);39 private Destination replyDestination = Mockito.mock(Destination.class);40 private MessageConsumer messageConsumer = Mockito.mock(MessageConsumer.class);41 private MessageProducer messageProducer = Mockito.mock(MessageProducer.class);42 private JmsTemplate jmsTemplate = Mockito.mock(JmsTemplate.class);43 @Test44 public void testWithReplyDestination() throws JMSException {45 JmsSyncEndpoint endpoint = new JmsSyncEndpoint();46 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);47 endpoint.getEndpointConfiguration().setDestination(destination);48 49 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");50 Map<String, Object> headers = new HashMap<String, Object>();51 52 reset(connectionFactory, destination, connection, session, messageConsumer);53 when(connectionFactory.createConnection()).thenReturn(connection);54 when(connection.createSession(anyBoolean(), anyInt())).thenReturn(session);55 when(session.getTransacted()).thenReturn(false);56 when(session.getAcknowledgeMode()).thenReturn(Session.AUTO_ACKNOWLEDGE);57 58 when(session.createConsumer(destination, null)).thenReturn(messageConsumer);59 TextMessageImpl jmsTestMessage = new TextMessageImpl(60 "<TestRequest><Message>Hello World!</Message></TestRequest>", headers);61 jmsTestMessage.setJMSReplyTo(replyDestination);62 when(messageConsumer.receive(5000L)).thenReturn(jmsTestMessage);63 JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer) endpoint.createConsumer();64 Message receivedMessage = jmsSyncConsumer.receive(context);65 Assert.assertEquals(receivedMessage.getPayload(), controlMessage.getPayload());66 Assert.assertEquals(jmsSyncConsumer.getCorrelationManager().find(endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKey(receivedMessage),67 endpoint.getEndpointConfiguration().getTimeout()), replyDestination);68 verify(connection).start();69 }70 @Test71 public void testWithMessageCorrelator() throws JMSException {72 JmsSyncEndpoint endpoint = new JmsSyncEndpoint();73 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);74 endpoint.getEndpointConfiguration().setDestination(destination);75 76 MessageCorrelator correlator = new DefaultMessageCorrelator();77 endpoint.getEndpointConfiguration().setCorrelator(correlator);78 79 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");80 Map<String, Object> headers = new HashMap<String, Object>();81 82 reset(connectionFactory, destination, connection, session, messageConsumer);83 when(connectionFactory.createConnection()).thenReturn(connection);84 when(connection.createSession(anyBoolean(), anyInt())).thenReturn(session);85 when(session.getTransacted()).thenReturn(false);86 when(session.getAcknowledgeMode()).thenReturn(Session.AUTO_ACKNOWLEDGE);87 88 when(session.createConsumer(destination, null)).thenReturn(messageConsumer);89 TextMessageImpl jmsTestMessage = new TextMessageImpl(90 "<TestRequest><Message>Hello World!</Message></TestRequest>", headers);91 jmsTestMessage.setJMSReplyTo(replyDestination);92 when(messageConsumer.receive(5000L)).thenReturn(jmsTestMessage);93 JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer) endpoint.createConsumer();94 Message receivedMessage = jmsSyncConsumer.receive(context);95 Assert.assertEquals(receivedMessage.getPayload(), controlMessage.getPayload());96 Assert.assertNull(jmsSyncConsumer.getCorrelationManager().find(97 correlator.getCorrelationKey("wrongIdKey"), endpoint.getEndpointConfiguration().getTimeout()));98 Assert.assertEquals(jmsSyncConsumer.getCorrelationManager().find(99 correlator.getCorrelationKey(receivedMessage), endpoint.getEndpointConfiguration().getTimeout()), replyDestination);100 verify(connection).start();101 }102 @Test103 public void testSendMessageWithJmsTemplate() {104 JmsSyncEndpoint endpoint = new JmsSyncEndpoint();105 endpoint.getEndpointConfiguration().setJmsTemplate(jmsTemplate);106 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");107 reset(jmsTemplate, connectionFactory, messageProducer);108 JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer)endpoint.createConsumer();109 jmsSyncConsumer.saveReplyDestination(new JmsMessage().replyTo(replyDestination), context);110 jmsSyncConsumer.send(message, context);111 verify(jmsTemplate).send(eq(replyDestination), any(MessageCreator.class));112 }113 @Test114 public void testSendMessageWithConnectionFactory() throws JMSException {115 JmsSyncEndpoint endpoint = new JmsSyncEndpoint();116 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);117 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");118 reset(jmsTemplate, connectionFactory, messageProducer, connection, session);119 when(connectionFactory.createConnection()).thenReturn(connection);120 when(connection.createSession(anyBoolean(), anyInt())).thenReturn(session);121 when(session.createProducer(replyDestination)).thenReturn(messageProducer);122 when(session.createTextMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")).thenReturn(123 new TextMessageImpl("<TestRequest><Message>Hello World!</Message></TestRequest>", new HashMap<String, Object>()));124 when(session.getTransacted()).thenReturn(false);125 JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer)endpoint.createConsumer();126 jmsSyncConsumer.saveReplyDestination(new JmsMessage().replyTo(replyDestination), context);127 jmsSyncConsumer.send(message, context);128 verify(messageProducer).send((TextMessage)any());129 }130 @Test131 public void testSendMessageWithReplyMessageCorrelator() throws JMSException {132 JmsSyncEndpoint endpoint = new JmsSyncEndpoint();133 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);134 MessageCorrelator correlator = new DefaultMessageCorrelator();135 endpoint.getEndpointConfiguration().setCorrelator(correlator);136 JmsMessage requestMessage = new JmsMessage()137 .replyTo(replyDestination);138 ((JmsSyncConsumer)endpoint.createConsumer()).getCorrelationManager().saveCorrelationKey(139 endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKeyName(endpoint.createConsumer().getName()),140 requestMessage.getId(), context);141 Map<String, Object> headers = new HashMap<String, Object>();142 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", headers);143 reset(jmsTemplate, connectionFactory, messageProducer, connection, session);144 when(connectionFactory.createConnection()).thenReturn(connection);145 when(connection.createSession(anyBoolean(), anyInt())).thenReturn(session);146 when(session.createProducer(replyDestination)).thenReturn(messageProducer);147 when(session.createTextMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")).thenReturn(148 new TextMessageImpl("<TestRequest><Message>Hello World!</Message></TestRequest>", new HashMap<String, Object>()));149 when(session.getTransacted()).thenReturn(false);150 JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer)endpoint.createConsumer();151 jmsSyncConsumer.saveReplyDestination(requestMessage, context);152 jmsSyncConsumer.send(message, context);153 verify(messageProducer).send((TextMessage)any());154 }155 @Test156 public void testNoCorrelationKeyFound() {157 JmsSyncEndpoint endpoint = new JmsSyncEndpoint();158 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);159 JmsMessage requestMessage = new JmsMessage();160 MessageCorrelator correlator = new DefaultMessageCorrelator();161 endpoint.getEndpointConfiguration().setCorrelator(correlator);162 JmsSyncEndpoint dummyEndpoint = new JmsSyncEndpoint();163 dummyEndpoint.setName("dummyEndpoint");164 ((JmsSyncConsumer)dummyEndpoint.createConsumer()).getCorrelationManager().saveCorrelationKey(165 dummyEndpoint.getEndpointConfiguration().getCorrelator().getCorrelationKeyName(dummyEndpoint.createConsumer().getName()),166 "123456789", context);167 Map<String, Object> headers = new HashMap<String, Object>();168 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", headers);169 try {170 JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer) endpoint.createConsumer();171 jmsSyncConsumer.saveReplyDestination(requestMessage, context);172 jmsSyncConsumer.send(message, context);173 } catch(CitrusRuntimeException e) {174 Assert.assertTrue(e.getMessage().startsWith("Failed to get correlation key"));175 return;176 }177 Assert.fail("Missing " + IllegalArgumentException.class + " because no reply destination found");178 }179 @Test180 public void testSendMessageWithMissingReplyTo() throws JMSException {181 JmsSyncEndpoint endpoint = new JmsSyncEndpoint();182 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);183 JmsMessage requestMessage = new JmsMessage();184 MessageCorrelator correlator = new DefaultMessageCorrelator();185 endpoint.getEndpointConfiguration().setCorrelator(correlator);186 ((JmsSyncConsumer)endpoint.createConsumer()).getCorrelationManager().saveCorrelationKey(187 endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKeyName(endpoint.createConsumer().getName()),188 "123456789", context);189 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");190 try {191 JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer)endpoint.createConsumer();192 jmsSyncConsumer.saveReplyDestination(requestMessage, context);193 jmsSyncConsumer.send(message, context);194 } catch(IllegalArgumentException e) {195 Assert.assertTrue(e.getMessage().startsWith("Failed to find JMS reply destination"), e.getMessage());196 return;197 }198 Assert.fail("Missing " + IllegalArgumentException.class + " because of missing correlation key");199 }200 @Test201 public void testNoReplyDestinationFound() throws JMSException {202 JmsSyncEndpoint endpoint = new JmsSyncEndpoint();203 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);204 MessageCorrelator correlator = new DefaultMessageCorrelator();205 endpoint.getEndpointConfiguration().setCorrelator(correlator);206 ((JmsSyncConsumer)endpoint.createConsumer()).getCorrelationManager().saveCorrelationKey(207 endpoint.getEndpointConfiguration().getCorrelator().getCorrelationKeyName(endpoint.createConsumer().getName()),208 "123456789", context);209 Map<String, Object> headers = new HashMap<String, Object>();210 final Message message = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", headers);211 try {212 JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer)endpoint.createConsumer();213 jmsSyncConsumer.send(message, context);214 } catch(IllegalArgumentException e) {215 Assert.assertTrue(e.getMessage().startsWith("Failed to find JMS reply destination for message correlation key"));216 return;217 }218 Assert.fail("Missing " + IllegalArgumentException.class + " because no reply destination found");219 }220 @Test221 public void testSendEmptyMessage() throws JMSException {222 JmsSyncEndpoint endpoint = new JmsSyncEndpoint();223 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);224 try {225 JmsSyncConsumer jmsSyncConsumer = (JmsSyncConsumer)endpoint.createConsumer();226 jmsSyncConsumer.send(null, context);227 } catch(IllegalArgumentException e) {228 Assert.assertEquals(e.getMessage(), "Message is empty - unable to send empty message");229 return;230 }231 Assert.fail("Missing " + IllegalArgumentException.class + " because of sending empty message");232 }233}...
Source:JmsEndpointConsumerTest.java
1/*2 * Copyright 2006-2010 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus.jms.endpoint;17import com.consol.citrus.exceptions.ActionTimeoutException;18import com.consol.citrus.exceptions.CitrusRuntimeException;19import com.consol.citrus.message.DefaultMessage;20import com.consol.citrus.message.Message;21import com.consol.citrus.testng.AbstractTestNGUnitTest;22import org.mockito.Mockito;23import org.springframework.jms.core.JmsTemplate;24import org.testng.Assert;25import org.testng.annotations.Test;26import javax.jms.*;27import java.util.HashMap;28import java.util.Map;29import static org.mockito.Mockito.*;30/**31 * @author Christoph Deppisch32 */33public class JmsEndpointConsumerTest extends AbstractTestNGUnitTest {34 private ConnectionFactory connectionFactory = Mockito.mock(ConnectionFactory.class);35 private Connection connection = Mockito.mock(Connection.class);36 private Session session = Mockito.mock(Session.class);37 private Destination destination = Mockito.mock(Destination.class);38 private Queue destinationQueue = Mockito.mock(Queue.class);39 private MessageConsumer messageConsumer = Mockito.mock(MessageConsumer.class);40 41 private JmsTemplate jmsTemplate = Mockito.mock(JmsTemplate.class);42 @Test43 public void testReceiveMessageWithJmsTemplate() {44 JmsEndpoint endpoint = new JmsEndpoint();45 endpoint.getEndpointConfiguration().setJmsTemplate(jmsTemplate);46 47 Map<String, Object> controlHeaders = new HashMap<String, Object>();48 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");49 reset(jmsTemplate, connectionFactory, destination);50 when(jmsTemplate.getDefaultDestination()).thenReturn(destination);51 when(jmsTemplate.receive(destination)).thenReturn(new TextMessageImpl(controlMessage.getPayload(String.class), controlHeaders));52 Message receivedMessage = endpoint.createConsumer().receive(context);53 Assert.assertEquals(receivedMessage.getPayload(), controlMessage.getPayload());54 verify(jmsTemplate).setReceiveTimeout(5000L);55 }56 57 @Test58 public void testWithDestination() throws JMSException {59 JmsEndpoint endpoint = new JmsEndpoint();60 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);61 endpoint.getEndpointConfiguration().setDestination(destination);62 63 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");64 Map<String, Object> headers = new HashMap<String, Object>();65 66 reset(jmsTemplate, connectionFactory, destination, connection, session, messageConsumer);67 when(connectionFactory.createConnection()).thenReturn(connection);68 when(connection.createSession(anyBoolean(), anyInt())).thenReturn(session);69 when(session.getTransacted()).thenReturn(false);70 when(session.getAcknowledgeMode()).thenReturn(Session.AUTO_ACKNOWLEDGE);71 72 when(session.createConsumer(destination, null)).thenReturn(messageConsumer);73 when(messageConsumer.receive(5000L)).thenReturn(new TextMessageImpl("<TestRequest><Message>Hello World!</Message></TestRequest>", headers));74 Message receivedMessage = endpoint.createConsumer().receive(context);75 Assert.assertEquals(receivedMessage.getPayload(), controlMessage.getPayload());76 verify(connection).start();77 }78 79 @Test80 public void testReceiveMessageWithDestinationName() throws JMSException {81 JmsEndpoint endpoint = new JmsEndpoint();82 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);83 endpoint.getEndpointConfiguration().setDestinationName("myDestination");84 85 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");86 Map<String, Object> headers = new HashMap<String, Object>();87 88 reset(jmsTemplate, connectionFactory, destination, connection, session, messageConsumer);89 when(connectionFactory.createConnection()).thenReturn(connection);90 when(connection.createSession(anyBoolean(), anyInt())).thenReturn(session);91 when(session.getTransacted()).thenReturn(false);92 when(session.getAcknowledgeMode()).thenReturn(Session.AUTO_ACKNOWLEDGE);93 94 when(session.createQueue("myDestination")).thenReturn(destinationQueue);95 when(session.createConsumer(destinationQueue, null)).thenReturn(messageConsumer);96 when(messageConsumer.receive(5000L)).thenReturn(new TextMessageImpl("<TestRequest><Message>Hello World!</Message></TestRequest>", headers));97 Message receivedMessage = endpoint.createConsumer().receive(context);98 Assert.assertEquals(receivedMessage.getPayload(), controlMessage.getPayload());99 verify(connection).start();100 }101 102 @Test103 public void testReceiveMessageTimeout() throws JMSException {104 JmsEndpoint endpoint = new JmsEndpoint();105 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);106 endpoint.getEndpointConfiguration().setDestination(destination);107 108 reset(jmsTemplate, connectionFactory, destination, connection, session, messageConsumer);109 when(connectionFactory.createConnection()).thenReturn(connection);110 when(connection.createSession(anyBoolean(), anyInt())).thenReturn(session);111 when(session.getTransacted()).thenReturn(false);112 when(session.getAcknowledgeMode()).thenReturn(Session.AUTO_ACKNOWLEDGE);113 114 when(session.createConsumer(destination, null)).thenReturn(messageConsumer);115 116 when(messageConsumer.receive(5000L)).thenReturn(null);117 try {118 endpoint.createConsumer().receive(context);119 } catch(ActionTimeoutException e) {120 Assert.assertTrue(e.getMessage().startsWith("Action timed out while receiving JMS message on"));121 verify(connection).start();122 return;123 }124 125 Assert.fail("Missing " + CitrusRuntimeException.class + " because of receiveing message timeout");126 }127 128 @Test129 public void testWithCustomTimeout() throws JMSException {130 JmsEndpoint endpoint = new JmsEndpoint();131 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);132 endpoint.getEndpointConfiguration().setDestination(destination);133 endpoint.getEndpointConfiguration().setTimeout(10000L);134 135 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");136 Map<String, Object> headers = new HashMap<String, Object>();137 138 reset(jmsTemplate, connectionFactory, destination, connection, session, messageConsumer);139 when(connectionFactory.createConnection()).thenReturn(connection);140 when(connection.createSession(anyBoolean(), anyInt())).thenReturn(session);141 when(session.getTransacted()).thenReturn(false);142 when(session.getAcknowledgeMode()).thenReturn(Session.AUTO_ACKNOWLEDGE);143 144 when(session.createConsumer(destination, null)).thenReturn(messageConsumer);145 when(messageConsumer.receive(10000L)).thenReturn(new TextMessageImpl("<TestRequest><Message>Hello World!</Message></TestRequest>", headers));146 Message receivedMessage = endpoint.createConsumer().receive(context);147 Assert.assertEquals(receivedMessage.getPayload(), controlMessage.getPayload());148 verify(connection).start();149 }150 @Test151 public void testWithMessageHeaders() throws JMSException {152 JmsEndpoint endpoint = new JmsEndpoint();153 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);154 endpoint.getEndpointConfiguration().setDestination(destination);155 156 Map<String, Object> controlHeaders = new HashMap<String, Object>();157 controlHeaders.put("Operation", "sayHello");158 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>", controlHeaders);159 Map<String, Object> headers = new HashMap<String, Object>();160 headers.put("Operation", "sayHello");161 162 reset(jmsTemplate, connectionFactory, destination, connection, session, messageConsumer);163 when(connectionFactory.createConnection()).thenReturn(connection);164 when(connection.createSession(anyBoolean(), anyInt())).thenReturn(session);165 when(session.getTransacted()).thenReturn(false);166 when(session.getAcknowledgeMode()).thenReturn(Session.AUTO_ACKNOWLEDGE);167 168 when(session.createConsumer(destination, null)).thenReturn(messageConsumer);169 when(messageConsumer.receive(5000L)).thenReturn(new TextMessageImpl("<TestRequest><Message>Hello World!</Message></TestRequest>", headers));170 Message receivedMessage = endpoint.createConsumer().receive(context);171 Assert.assertEquals(receivedMessage.getPayload(), controlMessage.getPayload());172 Assert.assertNotNull(receivedMessage.getHeader("Operation"));173 Assert.assertTrue(receivedMessage.getHeader("Operation").equals("sayHello"));174 verify(connection).start();175 }176 177 @Test178 public void testWithMessageSelector() throws JMSException {179 JmsEndpoint endpoint = new JmsEndpoint();180 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);181 endpoint.getEndpointConfiguration().setDestination(destination);182 183 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");184 Map<String, Object> headers = new HashMap<String, Object>();185 186 reset(jmsTemplate, connectionFactory, destination, connection, session, messageConsumer);187 when(connectionFactory.createConnection()).thenReturn(connection);188 when(connection.createSession(anyBoolean(), anyInt())).thenReturn(session);189 when(session.getTransacted()).thenReturn(false);190 when(session.getAcknowledgeMode()).thenReturn(Session.AUTO_ACKNOWLEDGE);191 192 when(session.createConsumer(destination, "Operation = 'sayHello'")).thenReturn(messageConsumer);193 when(messageConsumer.receive(5000L)).thenReturn(new TextMessageImpl("<TestRequest><Message>Hello World!</Message></TestRequest>", headers));194 Message receivedMessage = endpoint.createConsumer().receive("Operation = 'sayHello'", context);195 Assert.assertEquals(receivedMessage.getPayload(), controlMessage.getPayload());196 verify(connection).start();197 }198 199 @Test200 public void testWithMessageSelectorAndCustomTimeout() throws JMSException {201 JmsEndpoint endpoint = new JmsEndpoint();202 endpoint.getEndpointConfiguration().setConnectionFactory(connectionFactory);203 endpoint.getEndpointConfiguration().setDestination(destination);204 endpoint.getEndpointConfiguration().setTimeout(10000L);205 206 final Message controlMessage = new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");207 Map<String, Object> headers = new HashMap<String, Object>();208 209 reset(jmsTemplate, connectionFactory, destination, connection, session, messageConsumer);210 when(connectionFactory.createConnection()).thenReturn(connection);211 when(connection.createSession(anyBoolean(), anyInt())).thenReturn(session);212 when(session.getTransacted()).thenReturn(false);213 when(session.getAcknowledgeMode()).thenReturn(Session.AUTO_ACKNOWLEDGE);214 215 when(session.createConsumer(destination, "Operation = 'sayHello'")).thenReturn(messageConsumer);216 when(messageConsumer.receive(10000L)).thenReturn(new TextMessageImpl("<TestRequest><Message>Hello World!</Message></TestRequest>", headers));217 Message receivedMessage = endpoint.createConsumer().receive("Operation = 'sayHello'", context);218 Assert.assertEquals(receivedMessage.getPayload(), controlMessage.getPayload());219 verify(connection).start();220 }221}...
acknowledge
Using AI Code Generation
1import com.consol.citrus.Citrus;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.annotations.CitrusXmlTest;4import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;5import com.consol.citrus.dsl.runner.TestRunner;6import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;7import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;8import com.consol.citrus.message.MessageType;9import com.consol.citrus.testng.CitrusParameters;10import com.consol.citrus.ws.client.WebServiceClient;11import com.consol.citrus.ws.message.SoapAttachment;12import com.consol.citrus.ws.message.SoapMessage;13import com.consol.citrus.ws.server.WebServiceServer;14import com.consol.citrus.ws.validation.SoapAttachmentValidationContext;15import com.consol.citrus.ws.validation.SoapMessageValidationContext;16import org.springframework.beans.factory.annotation.Autowired;17import org.springframework.beans.factory.annotation.Qualifier;18import org.springframework.core.io.ClassPathResource;19import org.springframework.http.HttpStatus;20import org.springframework.http.MediaType;21import org.springframework.util.StringUtils;22import org.testng.annotations.Test;23import org.testng.annotations.Test;24import org.testng.annotations.Test;
acknowledge
Using AI Code Generation
1package com.consol.citrus;2import java.util.ArrayList;3import java.util.List;4import org.springframework.context.annotation.Bean;5import org.springframework.context.annotation.Configuration;6import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;7import com.consol.citrus.dsl.builder.SendMessageBuilder;8import com.consol.citrus.dsl.runner.TestRunner;9import com.consol.citrus.jms.endpoint.JmsEndpoint;10import com.consol.citrus.message.MessageType;11import com.consol.citrus.testng.AbstractTestNGCitrusTest;12import com.consol.citrus.ws.client.WebServiceClient;13import com.consol.citrus.ws.server.WebServiceServer;14import com.consol.citrus.ws.validation.SoapAttachmentValidator;15import com.consol.citrus.ws.validation.SoapFaultDetailValidator;16import com.consol.citrus.ws.validation.SoapFaultValidator;17import com.consol.citrus.ws.validation.SoapHeaderValidator;18import com.consol.citrus.ws.validation.SoapMessageValidator;19import com.consol.citrus.ws.validation.SoapPayloadElementValidator;20import com.consol.citrus.ws.validation.SoapPayloadXpathValidator;21import com.consol.citrus.ws.validation.SoapSchemaValidator;22import com.consol.citrus.ws.validation.SoapSecurityValidator;23import com.consol.citrus.ws.validation.SoapValidator;24import com.consol.citrus.ws.validation.SoapXmlValidator;25import com.consol.citrus.ws.validation.WsdlXsdSchemaRepository;26import com.consol.citrus.ws.validation.WsdlXsdSchemaValidator;27import com.consol.citrus.ws.validation.matcher.SoapAttachmentValidationMatcher;28import com.consol.citrus.ws.validation.matcher.SoapElementValidationMatcher;29import com.consol.citrus.ws.validation.matcher.SoapHeaderValidationMatcher;30import com.consol.citrus.ws.validation.matcher.SoapPayloadElementValidationMatcher;31import com.consol.citrus.ws.validation.matcher.SoapPayloadValidationMatcher;32import com.consol.citrus.ws.validation.matcher.SoapSecurityValidationMatcher;33import com.consol.citrus.ws.validation.matcher.SoapValidationMatcher;34import com.consol.citrus.ws.validation.matcher.SoapXmlValidationMatcher;35import com.consol.citrus.ws.validation.matcher.ValidationMatcherUtils;36import com.consol.citrus.ws.validation.script.GroovyXmlMessageValidationContext;37import com.consol.citrus.ws.validation.script.ScriptMessageValidation
acknowledge
Using AI Code Generation
1import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;2import com.consol.citrus.dsl.builder.SendMessageBuilder;3import com.consol.citrus.dsl.runner.TestRunner;4import com.consol.citrus.dsl.runner.TestRunnerSupport;5import com.consol.citrus.jms.endpoint.JmsEndpoint;6import com.consol.citrus.jms.endpoint.JmsSyncEndpointConfiguration;7import com.consol.citrus.message.MessageType;8import org.apache.activemq.ActiveMQConnectionFactory;9import org.apache.activemq.command.ActiveMQQueue;10import org.testng.annotations.Test;11import javax.jms.ConnectionFactory;12import javax.jms.Destination;13public class JmsAcknowledgementTest {14 public void testJmsAcknowledgement() {15 TestRunner runner = new TestRunnerSupport();16 Destination destination = new ActiveMQQueue("test.queue");17 JmsEndpoint jmsEndpoint = new JmsEndpoint(new JmsSyncEndpointConfiguration());18 jmsEndpoint.setConnectionFactory(connectionFactory);19 jmsEndpoint.setDestination(destination);20 jmsEndpoint.setMessageType(MessageType.TEXT);21 runner.receive(jmsEndpoint)22 .messageType(MessageType.TEXT)23 .payload("Hello Citrus!")24 .extractFromHeader("JMSCorrelationID", "correlationId");25 runner.send(jmsEndpoint)26 .messageType(MessageType.TEXT)27 .payload("Hello Citrus!")28 .header("JMSCorrelationID", "${correlationId}");29 runner.receive(jmsEndpoint)30 .messageType(MessageType.TEXT)31 .payload("Hello Citrus!")32 .extractFromHeader("JMSCorrelationID", "correlationId");33 runner.send(jmsEndpoint)34 .messageType(MessageType.TEXT)35 .payload("Hello Citrus!")36 .header("JMSCorrelationID", "${correlationId}");37 runner.run();38 }39}40import com.consol.citrus.dsl.builder.ReceiveMessageBuilder;41import com.consol.citrus.dsl.builder.SendMessageBuilder;42import com.consol.citrus.dsl.runner.TestRunner;43import com.consol.citrus.dsl.runner.TestRunnerSupport;44import com.consol.citrus.jms.endpoint
acknowledge
Using AI Code Generation
1package com.consol.citrus;2import org.testng.annotations.Test;3import com.consol.citrus.annotations.CitrusTest;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5import com.consol.citrus.message.MessageType;6public class JmsMessageIdTest extends TestNGCitrusTestDesigner {7 public void jmsMessageIdTest() {8 variable("messageId", "12345");9 variable("message", "Hello Citrus");10 send("jms:queue:inbound.queue")11 .messageType(MessageType.PLAINTEXT)12 .message()13 .body("${message}")14 .header("JMSCorrelationID", "${messageId}");15 receive("jms:queue:outbound.queue")16 .messageType(MessageType.PLAINTEXT)17 .message()18 .body("${message}")19 .header("JMSCorrelationID", "${messageId}")20 .extractFromHeader("JMSMessageID", "messageId");21 echo("Message Id is: ${messageId}");22 }23}24package com.consol.citrus;25import org.testng.annotations.Test;26import com.consol.citrus.annotations.CitrusTest;27import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;28import com.consol.citrus.message.MessageType;29public class JmsMessageIdTest extends TestNGCitrusTestDesigner {30 public void jmsMessageIdTest() {31 variable("messageId", "12345");32 variable("message", "Hello Citrus");33 send("jms:queue:inbound.queue")34 .messageType(MessageType.PLAINTEXT)35 .message()36 .body("${message}")37 .header("JMSCorrelationID", "${messageId}");38 receive("jms:queue:outbound.queue")39 .messageType(MessageType.PLAINTEXT)40 .message()41 .body("${message}")42 .header("JMSCorrelationID", "${messageId}")
acknowledge
Using AI Code Generation
1package com.consol.citrus.samples;2import com.consol.citrus.dsl.endpoint.CitrusEndpoints;3import com.consol.citrus.dsl.junit.JUnit4CitrusTestDesigner;4import com.consol.citrus.jms.endpoint.JmsEndpoint;5import com.consol.citrus.jms.endpoint.JmsSyncEndpointConfiguration;6import com.consol.citrus.message.JmsMessageHeaders;7import org.apache.activemq.command.ActiveMQQueue;8import org.apache.activemq.command.ActiveMQTextMessage;9import org.junit.Test;10import org.springframework.beans.factory.annotation.Autowired;11import org.springframework.beans.factory.annotation.Qualifier;12import org.springframework.context.annotation.Bean;13import org.springframework.context.annotation.Configuration;14import org.springframework.context.annotation.Import;15import org.springframework.jms.core.JmsTemplate;16import javax.jms.Destination;17public class JmsSampleIT extends JUnit4CitrusTestDesigner {18 @Qualifier("jmsEndpoint")19 private JmsEndpoint jmsEndpoint;20 @Qualifier("jmsSyncEndpoint")21 private JmsSyncEndpointConfiguration jmsSyncEndpoint;22 private JmsTemplate jmsTemplate;23 public void testJms() {24 send(jmsEndpoint)25 .payload("Hello Citrus!");26 receive(jmsEndpoint)27 .payload("Hello Citrus!");28 }29 public void testJmsSync() {30 send(jmsSyncEndpoint)31 .payload("Hello Citrus!");32 receive(jmsSyncEndpoint)33 .payload("Hello Citrus!");34 }35 public void testJmsSyncWithReplyTo() {36 send(jmsSyncEndpoint)37 .payload("Hello Citrus!")38 .header(JmsMessageHeaders.JMS_REPLY_TO, "jmsReplyQueue");39 receive(jmsSyncEndpoint)40 .payload("Hello Citrus!");41 send(jmsSyncEndpoint)42 .payload("Hello Citrus!")43 .header(JmsMessageHeaders.JMS_REPLY_TO, "jmsReplyQueue");44 receive(jmsSyncEndpoint)45 .payload("Hello Citrus!");46 }47 public void testJmsSyncWithReplyToMessage() {48 send(jmsSyncEndpoint)49 .payload("Hello Citrus!");50 receive(jmsSyncEndpoint)
acknowledge
Using AI Code Generation
1package com.consol.citrus.jms.endpoint;2import org.testng.annotations.Test;3import javax.jms.JMSException;4import static org.testng.Assert.assertEquals;5import static org.testng.Assert.assertTrue;6public class TextMessageImplTest {7 public void testAcknowledge() throws JMSException {8 TextMessageImpl textMessage = new TextMessageImpl("Hello");9 textMessage.acknowledge();10 assertTrue(textMessage.isAcknowledged());11 }12}13package com.consol.citrus.jms.endpoint;14import org.testng.annotations.Test;15import javax.jms.JMSException;16import static org.testng.Assert.assertEquals;17import static org.testng.Assert.assertTrue;18public class TextMessageImplTest {19 public void testAcknowledge() throws JMSException {20 TextMessageImpl textMessage = new TextMessageImpl("Hello");21 textMessage.acknowledge();22 assertTrue(textMessage.isAcknowledged());23 }24}25package com.consol.citrus.jms.endpoint;26import org.testng.annotations.Test;27import javax.jms.JMSException;28import static org.testng.Assert.assertEquals;29import static org.testng.Assert.assertTrue;30public class TextMessageImplTest {31 public void testAcknowledge() throws JMSException {32 TextMessageImpl textMessage = new TextMessageImpl("Hello");33 textMessage.acknowledge();34 assertTrue(textMessage.isAcknowledged());35 }36}
acknowledge
Using AI Code Generation
1import com.consol.citrus.jms.endpoint.TextMessageImpl;2import javax.jms.*;3import javax.naming.*;4import java.util.*;5public class 3{6 public static void main(String[] args) throws Exception{7 Properties props = new Properties();8 props.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.activemq.jndi.ActiveMQInitialContextFactory");9 InitialContext ctx = new InitialContext(props);10 ConnectionFactory cf = (ConnectionFactory)ctx.lookup("ConnectionFactory");11 Connection connection = cf.createConnection();12 connection.start();13 Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);14 Destination dest = (Destination)ctx.lookup("queue1");15 MessageProducer producer = session.createProducer(dest);16 TextMessage message = session.createTextMessage("Hello World!");17 producer.send(message);18 Destination dest1 = (Destination)ctx.lookup("queue2");19 MessageConsumer consumer = session.createConsumer(dest1);20 TextMessageImpl message1 = (TextMessageImpl)consumer.receive();21 String cid = message1.acknowledge();22 System.out.println(cid);23 }24}
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!!