How to use SoapAttachment method of com.consol.citrus.dsl.runner.SendSoapMessageTestRunnerTest class

Best Citrus code snippet using com.consol.citrus.dsl.runner.SendSoapMessageTestRunnerTest.SoapAttachment

Source:SendSoapMessageTestRunnerTest.java Github

copy

Full Screen

...49 private Producer messageProducer = Mockito.mock(Producer.class);50 private ApplicationContext applicationContextMock = Mockito.mock(ApplicationContext.class);51 private Resource resource = Mockito.mock(Resource.class);52 53 private SoapAttachment testAttachment = new SoapAttachment();54 55 /**56 * Setup test attachment.57 */58 @BeforeClass59 public void setup() {60 testAttachment.setContentId("attachment01");61 testAttachment.setContent("This is an attachment");62 testAttachment.setContentType("text/plain");63 testAttachment.setCharsetName("UTF-8");64 }65 @Test66 public void testFork() {67 reset(soapClient, messageProducer);68 when(soapClient.createProducer()).thenReturn(messageProducer);69 when(soapClient.getActor()).thenReturn(null);70 doAnswer(invocation -> {71 Message message = (Message) invocation.getArguments()[0];72 Assert.assertEquals(message.getPayload(String.class), "Foo");73 return null;74 }).when(messageProducer).send(any(Message.class), any(TestContext.class));75 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {76 @Override77 public void execute() {78 soap(builder -> builder.client(soapClient)79 .send()80 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))81 .header("additional", "additionalValue"));82 83 soap(builder -> builder.client(soapClient)84 .send()85 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))86 .fork(true));87 }88 };89 TestCase test = builder.getTestCase();90 Assert.assertEquals(test.getActionCount(), 2);91 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendSoapMessageAction.class);92 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), SendSoapMessageAction.class);93 94 SendSoapMessageAction action = ((SendSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());95 Assert.assertEquals(action.getName(), "send");96 97 Assert.assertEquals(action.getEndpoint(), soapClient);98 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);99 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();100 Assert.assertEquals(messageBuilder.getMessage().getPayload(String.class), "Foo");101 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");102 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 1L);103 Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "additionalValue");104 Assert.assertFalse(action.isForkMode());105 106 action = ((SendSoapMessageAction)((DelegatingTestAction)test.getActions().get(1)).getDelegate());107 Assert.assertEquals(action.getName(), "send");108 109 Assert.assertEquals(action.getEndpoint(), soapClient);110 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);111 112 Assert.assertTrue(action.isForkMode());113 }114 @Test115 public void testSoapAction() {116 reset(soapClient, messageProducer);117 when(soapClient.createProducer()).thenReturn(messageProducer);118 when(soapClient.getActor()).thenReturn(null);119 doAnswer(invocation -> {120 SoapMessage message = (SoapMessage) invocation.getArguments()[0];121 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");122 Assert.assertEquals(message.getSoapAction(), "TestService/sayHello");123 return null;124 }).when(messageProducer).send(any(Message.class), any(TestContext.class));125 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {126 @Override127 public void execute() {128 soap(builder -> builder.client(soapClient)129 .send()130 .soapAction("TestService/sayHello")131 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>"));132 }133 };134 TestCase test = builder.getTestCase();135 Assert.assertEquals(test.getActionCount(), 1);136 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendSoapMessageAction.class);137 SendSoapMessageAction action = ((SendSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());138 Assert.assertEquals(action.getName(), "send");139 Assert.assertEquals(action.getEndpoint(), soapClient);140 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);141 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();142 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");143 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), 3L);144 Assert.assertEquals(messageBuilder.getMessage().getHeaders().get(SoapMessageHeaders.SOAP_ACTION), "TestService/sayHello");145 }146 @Test147 public void testSoapAttachment() {148 reset(soapClient, messageProducer);149 when(soapClient.createProducer()).thenReturn(messageProducer);150 when(soapClient.getActor()).thenReturn(null);151 doAnswer(invocation -> {152 SoapMessage message = (SoapMessage) invocation.getArguments()[0];153 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");154 Assert.assertEquals(message.getAttachments().size(), 1L);155 Assert.assertEquals(message.getAttachments().get(0).getContent(), testAttachment.getContent());156 return null;157 }).when(messageProducer).send(any(Message.class), any(TestContext.class));158 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {159 @Override160 public void execute() {161 soap(builder -> builder.client(soapClient)162 .send()163 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")164 .attachment(testAttachment));165 }166 };167 TestCase test = builder.getTestCase();168 Assert.assertEquals(test.getActionCount(), 1);169 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendSoapMessageAction.class);170 171 SendSoapMessageAction action = ((SendSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());172 Assert.assertEquals(action.getName(), "send");173 174 Assert.assertEquals(action.getEndpoint(), soapClient);175 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);176 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();177 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");178 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);179 Assert.assertEquals(action.getAttachments().size(), 1L);180 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());181 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent());182 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());183 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());184 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());185 }186 @Test187 public void testSoapAttachmentData() {188 reset(soapClient, messageProducer);189 when(soapClient.createProducer()).thenReturn(messageProducer);190 when(soapClient.getActor()).thenReturn(null);191 doAnswer(invocation -> {192 SoapMessage message = (SoapMessage) invocation.getArguments()[0];193 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");194 Assert.assertEquals(message.getAttachments().size(), 1L);195 Assert.assertEquals(message.getAttachments().get(0).getContent(), testAttachment.getContent());196 return null;197 }).when(messageProducer).send(any(Message.class), any(TestContext.class));198 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {199 @Override200 public void execute() {201 soap(builder -> builder.client(soapClient)202 .send()203 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")204 .attachment(testAttachment.getContentId(), testAttachment.getContentType(), testAttachment.getContent()));205 }206 };207 TestCase test = builder.getTestCase();208 Assert.assertEquals(test.getActionCount(), 1);209 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendSoapMessageAction.class);210 211 SendSoapMessageAction action = ((SendSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());212 Assert.assertEquals(action.getName(), "send");213 214 Assert.assertEquals(action.getEndpoint(), soapClient);215 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);216 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();217 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");218 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);219 Assert.assertEquals(action.getAttachments().size(), 1L);220 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());221 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent());222 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());223 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());224 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());225 }226 @Test227 public void testMtomSoapAttachmentData() {228 reset(soapClient, messageProducer);229 when(soapClient.createProducer()).thenReturn(messageProducer);230 when(soapClient.getActor()).thenReturn(null);231 doAnswer(invocation -> {232 SoapMessage message = (SoapMessage) invocation.getArguments()[0];233 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><data><xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" href=\"cid:attachment01\"/></data></TestRequest>");234 Assert.assertEquals(message.getAttachments().size(), 1L);235 Assert.assertEquals(message.getAttachments().get(0).getContent(), testAttachment.getContent());236 return null;237 }).when(messageProducer).send(any(Message.class), any(TestContext.class));238 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {239 @Override240 public void execute() {241 soap(builder -> builder.client(soapClient)242 .send()243 .mtomEnabled(true)244 .payload("<TestRequest><data>cid:attachment01</data></TestRequest>")245 .attachment(testAttachment.getContentId(), testAttachment.getContentType(), testAttachment.getContent()));246 }247 };248 TestCase test = builder.getTestCase();249 Assert.assertEquals(test.getActionCount(), 1);250 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendSoapMessageAction.class);251 SendSoapMessageAction action = ((SendSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());252 Assert.assertEquals(action.getName(), "send");253 Assert.assertEquals(action.getEndpoint(), soapClient);254 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);255 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();256 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "<TestRequest><data>cid:attachment01</data></TestRequest>");257 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);258 Assert.assertTrue(action.getMtomEnabled());259 Assert.assertEquals(action.getAttachments().size(), 1L);260 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());261 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent());262 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());263 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());264 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());265 }266 @Test267 public void testMultipleSoapAttachmentData() {268 reset(soapClient, messageProducer);269 when(soapClient.getActor()).thenReturn(null);270 doAnswer(invocation -> {271 SoapMessage message = (SoapMessage) invocation.getArguments()[0];272 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");273 Assert.assertEquals(message.getAttachments().size(), 2L);274 Assert.assertEquals(message.getAttachments().get(0).getContent(), testAttachment.getContent() + 1);275 Assert.assertEquals(message.getAttachments().get(1).getContent(), testAttachment.getContent() + 2);276 return null;277 }).when(messageProducer).send(any(Message.class), any(TestContext.class));278 when(soapClient.createProducer()).thenReturn(messageProducer);279 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {280 @Override281 public void execute() {282 soap(builder -> builder.client(soapClient)283 .send()284 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")285 .attachment(testAttachment.getContentId() + 1, testAttachment.getContentType(), testAttachment.getContent() + 1)286 .attachment(testAttachment.getContentId() + 2, testAttachment.getContentType(), testAttachment.getContent() + 2));287 }288 };289 TestCase test = builder.getTestCase();290 Assert.assertEquals(test.getActionCount(), 1);291 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendSoapMessageAction.class);292 SendSoapMessageAction action = ((SendSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());293 Assert.assertEquals(action.getName(), "send");294 Assert.assertEquals(action.getEndpoint(), soapClient);295 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);296 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();297 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");298 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);299 Assert.assertEquals(action.getAttachments().size(), 2L);300 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());301 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent() + 1);302 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId() + 1);303 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());304 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());305 Assert.assertNull(action.getAttachments().get(1).getContentResourcePath());306 Assert.assertEquals(action.getAttachments().get(1).getContent(), testAttachment.getContent() + 2);307 Assert.assertEquals(action.getAttachments().get(1).getContentId(), testAttachment.getContentId() + 2);308 Assert.assertEquals(action.getAttachments().get(1).getContentType(), testAttachment.getContentType());309 Assert.assertEquals(action.getAttachments().get(1).getCharsetName(), testAttachment.getCharsetName());310 }311 @Test312 public void testSoapAttachmentResource() throws IOException {313 reset(resource, soapClient, messageProducer);314 when(soapClient.createProducer()).thenReturn(messageProducer);315 when(soapClient.getActor()).thenReturn(null);316 doAnswer(invocation -> {317 SoapMessage message = (SoapMessage) invocation.getArguments()[0];318 Assert.assertEquals(message.getPayload(String.class), "<TestRequest><Message>Hello World!</Message></TestRequest>");319 Assert.assertEquals(message.getAttachments().size(), 1L);320 Assert.assertEquals(message.getAttachments().get(0).getContent(), "someAttachmentData");321 return null;322 }).when(messageProducer).send(any(Message.class), any(TestContext.class));323 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("someAttachmentData".getBytes()));324 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {325 @Override326 public void execute() {...

Full Screen

Full Screen

SoapAttachment

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.runner;2import com.consol.citrus.TestAction;3import com.consol.citrus.actions.EchoAction;4import com.consol.citrus.annotations.CitrusTest;5import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner;6import com.consol.citrus.message.MessageType;7import org.springframework.core.io.ClassPathResource;8import org.testng.annotations.Test;9public class SendSoapMessageTestRunnerTest extends JUnit4CitrusTestRunner {10 public void sendSoapMessage() {11 variable("operation", "addNumbers");12 send(soap()13 .payload(new ClassPathResource("templates/request.xml"))14 .header("operation", "${operation}")15 .attachment("file1", "text/plain", "attachment1")16 .attachment("file2", "text/plain", "attachment2"));17 send(soap()18 .payload(new ClassPathResource("templates/request.xml"))19 .header("operation", "${operation}")20 .attachment("file1", "text/plain", "attachment1")21 .attachment("file2", "text/plain", "attachment2")22 .attachment("file3", "text/plain", "attachment3"));23 send(soap()24 .payload(new ClassPathResource("templates/request.xml"))25 .header("operation", "${operation}")26 .attachment("file1", "text/plain", "attachment1")27 .attachment("file2", "text/plain", "attachment2")28 .attachment("file3", "text/plain", "attachment3")29 .attachment("file4", "text/plain", "attachment4"));30 send(soap()31 .payload(new ClassPathResource("templates/request.xml"))32 .header("operation", "${operation}")33 .attachment("file1", "text/plain", "attachment1")34 .attachment("file2", "text/plain", "attachment2")35 .attachment("file3", "text/plain", "attachment3")36 .attachment("file4", "text/plain", "attachment4")37 .attachment("file5", "text/plain", "attachment

Full Screen

Full Screen

SoapAttachment

Using AI Code Generation

copy

Full Screen

1 public void testSoapAttachment() {2 send(soap()3 .client(soapClient)4 .send()5 .soapAction("TestAction")6 .message()7 .body("<testMessage><text>Hello Citrus!</text></testMessage>")8 .attachment(attachmentDataBuilder -> attachmentDataBuilder9 .contentId("cid:123456789")10 .contentType("text/plain")11 .data("Hello Citrus!")));12 receive(soap()13 .server(soapServer)14 .receive()15 .message()16 .body("<testMessage><text>Hello Citrus!</text></testMessage>")17 .attachment(attachmentDataBuilder -> attachmentDataBuilder18 .contentId("cid:123456789")19 .contentType("text/plain")20 .data("Hello Citrus!")));21 }22}23Apache CXF – SOAP with Attachments API (SAAJ)24Apache CXF – SOAP with Attachments API (SAAJ) – Documentation25Apache CXF – SOAP with Attachments API (SAAJ) – User Guide26Apache CXF – SOAP with Attachments API (SAAJ) – Reference Guide27Apache CXF – SOAP with Attachments API (SAAJ) – Examples28Apache CXF – SOAP with Attachments API (SAAJ) – Maven Repository29Apache CXF – SOAP with Attachments API (SAAJ) – Downloads30Apache CXF – SOAP with Attachments API (SAAJ) – Issues31Apache CXF – SOAP with Attachments API (SAAJ) – Source Code32Apache CXF – SOAP with Attachments API (SAAJ) – Javadocs33Apache CXF – SOAP with Attachments API (SAAJ) – License34Apache CXF – SOAP with Attachments API (SAAJ) – Release Notes35Apache CXF – SOAP with Attachments API (SAAJ) – Change Log

Full Screen

Full Screen

SoapAttachment

Using AI Code Generation

copy

Full Screen

1send(soap()2 .client(soapClient)3 .message(soapMessage)4 .attachment(new SoapAttachment()5 .contentType("text/xml")6 .content("<test>Test</test>")7 .contentId("test")));

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