How to use SoapAttachment method of com.consol.citrus.dsl.design.SendSoapMessageTestDesignerTest class

Best Citrus code snippet using com.consol.citrus.dsl.design.SendSoapMessageTestDesignerTest.SoapAttachment

Source:SendSoapMessageTestDesignerTest.java Github

copy

Full Screen

...24import com.consol.citrus.testng.AbstractTestNGUnitTest;25import com.consol.citrus.validation.builder.StaticMessageContentBuilder;26import com.consol.citrus.ws.actions.SendSoapMessageAction;27import com.consol.citrus.ws.client.WebServiceClient;28import com.consol.citrus.ws.message.SoapAttachment;29import com.consol.citrus.ws.message.SoapMessageHeaders;30import org.mockito.Mockito;31import org.springframework.context.ApplicationContext;32import org.springframework.core.io.Resource;33import org.testng.Assert;34import org.testng.annotations.BeforeClass;35import org.testng.annotations.Test;36import java.io.ByteArrayInputStream;37import java.io.IOException;38import java.util.HashMap;39import static org.mockito.Mockito.reset;40import static org.mockito.Mockito.when;41/**42 * @author Christoph Deppisch43 */44public class SendSoapMessageTestDesignerTest extends AbstractTestNGUnitTest {45 46 private WebServiceClient soapClient = Mockito.mock(WebServiceClient.class);47 private ApplicationContext applicationContextMock = Mockito.mock(ApplicationContext.class);48 private Resource resource = Mockito.mock(Resource.class);49 50 private SoapAttachment testAttachment = new SoapAttachment();51 52 /**53 * Setup test attachment.54 */55 @BeforeClass56 public void setup() {57 testAttachment.setContentId("attachment01");58 testAttachment.setContent("This is an attachment");59 testAttachment.setContentType("text/plain");60 testAttachment.setCharsetName("UTF-8");61 }62 @Test63 public void testFork() {64 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {65 @Override66 public void configure() {67 send(soapClient)68 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))69 .header("additional", "additionalValue");70 71 send(soapClient)72 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))73 .fork(true);74 }75 };76 builder.configure();77 TestCase test = builder.getTestCase();78 Assert.assertEquals(test.getActionCount(), 2);79 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);80 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendMessageAction.class);81 Assert.assertEquals(test.getActions().get(1).getClass(), DelegatingTestAction.class);82 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(1)).getDelegate().getClass(), SendMessageAction.class);83 84 SendMessageAction action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();85 Assert.assertEquals(action.getName(), "send");86 87 Assert.assertEquals(action.getEndpoint(), soapClient);88 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);89 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();90 Assert.assertEquals(messageBuilder.getMessage().getPayload(String.class), "Foo");91 Assert.assertEquals(messageBuilder.getMessage().getHeader("operation"), "foo");92 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 1L);93 Assert.assertEquals(messageBuilder.getMessageHeaders().get("additional"), "additionalValue");94 Assert.assertFalse(action.isForkMode());95 96 action = (SendMessageAction) ((DelegatingTestAction)test.getActions().get(1)).getDelegate();97 Assert.assertEquals(action.getName(), "send");98 99 Assert.assertEquals(action.getEndpoint(), soapClient);100 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);101 102 Assert.assertTrue(action.isForkMode());103 }104 @Test105 public void testSoapAction() {106 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {107 @Override108 public void configure() {109 soap().client(soapClient)110 .send()111 .soapAction("TestService/sayHello")112 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>");113 }114 };115 builder.configure();116 TestCase test = builder.getTestCase();117 Assert.assertEquals(test.getActionCount(), 1);118 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);119 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendSoapMessageAction.class);120 SendSoapMessageAction action = (SendSoapMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();121 Assert.assertEquals(action.getName(), "send");122 Assert.assertEquals(action.getEndpoint(), soapClient);123 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);124 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();125 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");126 Assert.assertEquals(messageBuilder.getMessage().getHeaders().size(), 3L);127 Assert.assertEquals(messageBuilder.getMessage().getHeaders().get(SoapMessageHeaders.SOAP_ACTION), "TestService/sayHello");128 }129 @Test130 public void testSoapAttachment() {131 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {132 @Override133 public void configure() {134 soap().client(soapClient)135 .send()136 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")137 .attachment(testAttachment);138 }139 };140 builder.configure();141 TestCase test = builder.getTestCase();142 Assert.assertEquals(test.getActionCount(), 1);143 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);144 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendSoapMessageAction.class);145 146 SendSoapMessageAction action = (SendSoapMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();147 Assert.assertEquals(action.getName(), "send");148 149 Assert.assertEquals(action.getEndpoint(), soapClient);150 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);151 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();152 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");153 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);154 Assert.assertEquals(action.getAttachments().size(), 1L);155 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());156 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent());157 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());158 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());159 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());160 }161 162 @Test163 public void testMtomSoapAttachment() {164 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {165 @Override166 public void configure() {167 soap().client(soapClient)168 .send()169 .mtomEnabled(true)170 .payload("<TestRequest><data>cid:attachment01</data></TestRequest>")171 .attachment(testAttachment);172 }173 };174 builder.configure();175 TestCase test = builder.getTestCase();176 Assert.assertEquals(test.getActionCount(), 1);177 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);178 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendSoapMessageAction.class);179 180 SendSoapMessageAction action = (SendSoapMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();181 Assert.assertEquals(action.getName(), "send");182 183 Assert.assertEquals(action.getEndpoint(), soapClient);184 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);185 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();186 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "<TestRequest><data>cid:attachment01</data></TestRequest>");187 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);188 Assert.assertTrue(action.getMtomEnabled());189 190 Assert.assertEquals(action.getAttachments().size(), 1L);191 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());192 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent());193 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());194 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());195 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());196 } 197 198 @Test199 public void testSoapAttachmentData() {200 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {201 @Override202 public void configure() {203 soap().client(soapClient)204 .send()205 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")206 .attachment(testAttachment.getContentId(), testAttachment.getContentType(), testAttachment.getContent());207 }208 };209 builder.configure();210 TestCase test = builder.getTestCase();211 Assert.assertEquals(test.getActionCount(), 1);212 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);213 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendSoapMessageAction.class);214 215 SendSoapMessageAction action = (SendSoapMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();216 Assert.assertEquals(action.getName(), "send");217 218 Assert.assertEquals(action.getEndpoint(), soapClient);219 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);220 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();221 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");222 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);223 Assert.assertEquals(action.getAttachments().size(), 1L);224 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());225 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent());226 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());227 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());228 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());229 }230 @Test231 public void testMultipleSoapAttachmentData() {232 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {233 @Override234 public void configure() {235 soap().client(soapClient)236 .send()237 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")238 .attachment(testAttachment.getContentId() + 1, testAttachment.getContentType(), testAttachment.getContent() + 1)239 .attachment(testAttachment.getContentId() + 2, testAttachment.getContentType(), testAttachment.getContent() + 2);240 }241 };242 builder.configure();243 TestCase test = builder.getTestCase();244 Assert.assertEquals(test.getActionCount(), 1);245 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);246 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), SendSoapMessageAction.class);247 SendSoapMessageAction action = (SendSoapMessageAction) ((DelegatingTestAction)test.getActions().get(0)).getDelegate();248 Assert.assertEquals(action.getName(), "send");249 Assert.assertEquals(action.getEndpoint(), soapClient);250 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);251 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();252 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");253 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);254 Assert.assertEquals(action.getAttachments().size(), 2L);255 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());256 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent() + 1);257 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId() + 1);258 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());259 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());260 Assert.assertNull(action.getAttachments().get(1).getContentResourcePath());261 Assert.assertEquals(action.getAttachments().get(1).getContent(), testAttachment.getContent() + 2);262 Assert.assertEquals(action.getAttachments().get(1).getContentId(), testAttachment.getContentId() + 2);263 Assert.assertEquals(action.getAttachments().get(1).getContentType(), testAttachment.getContentType());264 Assert.assertEquals(action.getAttachments().get(1).getCharsetName(), testAttachment.getCharsetName());265 }266 267 @Test268 public void testSoapAttachmentResource() throws IOException {269 MockTestDesigner builder = new MockTestDesigner(applicationContext, context) {270 @Override271 public void configure() {272 soap().client(soapClient)273 .send()274 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")275 .attachment(testAttachment.getContentId(), testAttachment.getContentType(), resource);276 }277 };278 279 reset(resource);280 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("someAttachmentData".getBytes()));281 builder.configure();282 TestCase test = builder.getTestCase();...

Full Screen

Full Screen

SoapAttachment

Using AI Code Generation

copy

Full Screen

1File file = new File("C:\\Users\\user\\Desktop\\test.txt");2file.createNewFile();3FileWriter fw = new FileWriter(file.getAbsoluteFile());4BufferedWriter bw = new BufferedWriter(fw);5bw.write("Hello");6bw.close();7java.io.FileNotFoundException: C:\Users\user\Desktop\test.txt (The system cannot find the path specified)8File file = new File("C:\\Users\\user\\Desktop\\test.txt");9file.createNewFile();10FileWriter fw = new FileWriter(file.getAbsoluteFile());11BufferedWriter bw = new BufferedWriter(fw);12bw.write("Hello");13bw.close();14java.io.FileNotFoundException: C:\Users\user\Desktop\test.txt (The system cannot find the path specified)15File file = new File("C:\\Users\\user\\Desktop\\test.txt

Full Screen

Full Screen

SoapAttachment

Using AI Code Generation

copy

Full Screen

1public void testSendSoapMessageWithAttachment() {2 MockWebServiceServer mockServer = MockWebServiceServer.createServer(applicationContext, "soapAttachmentTestClient");3 .andExpect(attachment("citrus:resource:classpath:com/consol/citrus/ws/soap-attachment.txt"))4 "<Message>Hello Citrus!</Message></ns0:SayHelloResponse>"));5 run(sendSoapMessage()6 .endpoint(soapAttachmentTestClient)7 .soap()8 .attachment("citrus:resource:classpath:com/consol/citrus/ws/soap-attachment.txt"));9}10public void testSendSoapMessageWithAttachmentFromFile() {11 MockWebServiceServer mockServer = MockWebServiceServer.createServer(applicationContext, "soapAttachmentTestClient");12 .andExpect(attachment("citrus:resource:file:src/test/resources/soap-attachment.txt"))13 "<Message>Hello Citrus!</Message></ns0:SayHelloResponse>"));14 run(sendSoapMessage

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