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

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

Source:ReceiveSoapMessageTestRunnerTest.java Github

copy

Full Screen

...30import com.consol.citrus.validation.context.HeaderValidationContext;31import com.consol.citrus.validation.json.JsonMessageValidationContext;32import com.consol.citrus.validation.xml.XmlMessageValidationContext;33import com.consol.citrus.ws.actions.ReceiveSoapMessageAction;34import com.consol.citrus.ws.message.SoapAttachment;35import com.consol.citrus.ws.message.SoapMessage;36import com.consol.citrus.ws.server.WebServiceServer;37import org.mockito.Mockito;38import org.springframework.context.ApplicationContext;39import org.springframework.core.io.Resource;40import org.testng.Assert;41import org.testng.annotations.BeforeClass;42import org.testng.annotations.Test;43import java.io.ByteArrayInputStream;44import java.io.IOException;45import java.util.HashMap;46import static org.mockito.Mockito.*;47/**48 * @author Christoph Deppisch49 */50public class ReceiveSoapMessageTestRunnerTest extends AbstractTestNGUnitTest {51 52 private Consumer messageConsumer = Mockito.mock(Consumer.class);53 private EndpointConfiguration configuration = Mockito.mock(EndpointConfiguration.class);54 private WebServiceServer server = Mockito.mock(WebServiceServer.class);55 private ApplicationContext applicationContextMock = Mockito.mock(ApplicationContext.class);56 private Resource resource = Mockito.mock(Resource.class);57 58 private SoapAttachment testAttachment = new SoapAttachment();59 60 /**61 * Setup test attachment.62 */63 @BeforeClass64 public void setup() {65 testAttachment.setContentId("attachment01");66 testAttachment.setContent("This is an attachment");67 testAttachment.setContentType("text/plain");68 testAttachment.setCharsetName("UTF-8");69 }70 @Test71 public void testWebServiceServerReceive() {72 reset(server, messageConsumer, configuration);73 when(server.createConsumer()).thenReturn(messageConsumer);74 when(server.getEndpointConfiguration()).thenReturn(configuration);75 when(configuration.getTimeout()).thenReturn(100L);76 when(server.getActor()).thenReturn(null);77 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new SoapMessage("Foo")78 .setHeader("operation","foo")79 .addAttachment(testAttachment));80 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {81 @Override82 public void execute() {83 soap(action -> action.server(server)84 .receive()85 .messageType(MessageType.PLAINTEXT)86 .message(new DefaultMessage("Foo").setHeader("operation", "foo"))87 .attachment(testAttachment));88 }89 };90 TestCase test = builder.getTestCase();91 Assert.assertEquals(test.getActionCount(), 1);92 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);93 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveSoapMessageAction.class);94 ReceiveSoapMessageAction action = ((ReceiveSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());95 Assert.assertEquals(action.getName(), "receive");96 Assert.assertEquals(action.getMessageType(), MessageType.PLAINTEXT.name());97 Assert.assertEquals(action.getEndpoint(), server);98 Assert.assertEquals(action.getValidationContexts().size(), 3);99 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);100 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);101 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);102 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);103 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "Foo");104 Assert.assertNotNull(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getHeader("operation"));105 Assert.assertEquals(action.getAttachments().size(), 1L);106 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());107 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent());108 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());109 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());110 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());111 }112 @Test113 public void testSoapAttachment() {114 reset(server, messageConsumer, configuration);115 when(server.createConsumer()).thenReturn(messageConsumer);116 when(server.getEndpointConfiguration()).thenReturn(configuration);117 when(configuration.getTimeout()).thenReturn(100L);118 when(server.getActor()).thenReturn(null);119 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")120 .setHeader("operation","foo")121 .addAttachment(testAttachment));122 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {123 @Override124 public void execute() {125 soap(action -> action.server(server)126 .receive()127 .message(new DefaultMessage("<TestRequest><Message>Hello World!</Message></TestRequest>").setHeader("operation", "foo"))128 .attachment(testAttachment));129 }130 };131 TestCase test = builder.getTestCase();132 Assert.assertEquals(test.getActionCount(), 1);133 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);134 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveSoapMessageAction.class);135 ReceiveSoapMessageAction action = ((ReceiveSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());136 Assert.assertEquals(action.getName(), "receive");137 138 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());139 Assert.assertEquals(action.getEndpoint(), server);140 Assert.assertEquals(action.getValidationContexts().size(), 3);141 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);142 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);143 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);144 145 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);146 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");147 Assert.assertNotNull(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getHeader("operation"));148 Assert.assertEquals(action.getAttachments().size(), 1L);149 Assert.assertNull(action.getAttachments().get(0).getContentResourcePath());150 Assert.assertEquals(action.getAttachments().get(0).getContent(), testAttachment.getContent());151 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());152 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());153 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());154 }155 @Test156 public void testSoapAttachmentData() {157 reset(server, messageConsumer, configuration);158 when(server.createConsumer()).thenReturn(messageConsumer);159 when(server.getEndpointConfiguration()).thenReturn(configuration);160 when(configuration.getTimeout()).thenReturn(100L);161 when(server.getActor()).thenReturn(null);162 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")163 .setHeader("operation","foo")164 .addAttachment(testAttachment));165 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {166 @Override167 public void execute() {168 soap(action -> action.server(server)169 .receive()170 .payload("<TestRequest><Message>Hello World!</Message></TestRequest>")171 .attachment(testAttachment.getContentId(), testAttachment.getContentType(), testAttachment.getContent()));172 }173 };174 TestCase test = builder.getTestCase();175 Assert.assertEquals(test.getActionCount(), 1);176 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);177 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveSoapMessageAction.class);178 ReceiveSoapMessageAction action = ((ReceiveSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());179 Assert.assertEquals(action.getName(), "receive");180 181 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());182 Assert.assertEquals(action.getEndpoint(), server);183 Assert.assertEquals(action.getValidationContexts().size(), 3);184 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);185 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);186 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);187 188 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);189 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");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 @Test198 public void testSoapAttachmentResource() throws IOException {199 final Resource attachmentResource = Mockito.mock(Resource.class);200 reset(server, messageConsumer, configuration, resource, attachmentResource);201 when(server.createConsumer()).thenReturn(messageConsumer);202 when(server.getEndpointConfiguration()).thenReturn(configuration);203 when(configuration.getTimeout()).thenReturn(100L);204 when(server.getActor()).thenReturn(null);205 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")206 .setHeader("operation","foo")207 .addAttachment(testAttachment));208 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream("<TestRequest><Message>Hello World!</Message></TestRequest>".getBytes()));209 when(attachmentResource.getInputStream()).thenReturn(new ByteArrayInputStream("This is an attachment".getBytes()));210 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {211 @Override212 public void execute() {213 soap(action -> action.server(server)214 .receive()215 .payload(resource)216 .attachment(testAttachment.getContentId(), testAttachment.getContentType(), attachmentResource));217 }218 };219 TestCase test = builder.getTestCase();220 Assert.assertEquals(test.getActionCount(), 1);221 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);222 Assert.assertEquals(((DelegatingTestAction)test.getActions().get(0)).getDelegate().getClass(), ReceiveSoapMessageAction.class);223 ReceiveSoapMessageAction action = ((ReceiveSoapMessageAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate());224 Assert.assertEquals(action.getName(), "receive");225 226 Assert.assertEquals(action.getMessageType(), MessageType.XML.name());227 Assert.assertEquals(action.getEndpoint(), server);228 Assert.assertEquals(action.getValidationContexts().size(), 3);229 Assert.assertEquals(action.getValidationContexts().get(0).getClass(), HeaderValidationContext.class);230 Assert.assertEquals(action.getValidationContexts().get(1).getClass(), XmlMessageValidationContext.class);231 Assert.assertEquals(action.getValidationContexts().get(2).getClass(), JsonMessageValidationContext.class);232 233 Assert.assertTrue(action.getMessageBuilder() instanceof StaticMessageContentBuilder);234 Assert.assertEquals(((StaticMessageContentBuilder)action.getMessageBuilder()).getMessage().getPayload(), "<TestRequest><Message>Hello World!</Message></TestRequest>");235 236 Assert.assertEquals(action.getAttachments().get(0).getContent(), "This is an attachment");237 Assert.assertEquals(action.getAttachments().get(0).getContentId(), testAttachment.getContentId());238 Assert.assertEquals(action.getAttachments().get(0).getContentType(), testAttachment.getContentType());239 Assert.assertEquals(action.getAttachments().get(0).getCharsetName(), testAttachment.getCharsetName());240 }241 @Test242 public void testMultipleSoapAttachmentData() {243 final SoapAttachment attachment1 = new SoapAttachment();244 attachment1.setContentId("attachment01");245 attachment1.setContent("This is an attachment");246 attachment1.setContentType("text/plain");247 attachment1.setCharsetName("UTF-8");248 final SoapAttachment attachment2 = new SoapAttachment();249 attachment2.setContentId("attachment02");250 attachment2.setContent("This is an attachment");251 attachment2.setContentType("text/plain");252 attachment2.setCharsetName("UTF-8");253 reset(server, messageConsumer, configuration);254 when(server.createConsumer()).thenReturn(messageConsumer);255 when(server.getEndpointConfiguration()).thenReturn(configuration);256 when(configuration.getTimeout()).thenReturn(100L);257 when(server.getActor()).thenReturn(null);258 when(messageConsumer.receive(any(TestContext.class), anyLong())).thenReturn(new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>")259 .setHeader("operation","foo")260 .addAttachment(attachment1)261 .addAttachment(attachment2));262 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {...

Full Screen

Full Screen

SoapAttachment

Using AI Code Generation

copy

Full Screen

1 public void testSoapAttachment() {2 run(new ReceiveSoapMessageTestRunner() {3 public void configure() {4 soap()5 .client(soapClient)6 .send()7 "</ns0:RequestMessage>"));8 soap()9 .server(soapServer)10 .receive()11 .attachment("citrus:file:src/test/resources/soap/attachment.txt", "text/plain");12 }13 });14 }15 public void testSoapAttachment() {16 run(new ReceiveSoapMessageTestRunner() {17 public void configure() {18 soap()19 .client(soapClient)20 .send()21 "</ns0:RequestMessage>"));22 soap()23 .server(soapServer)24 .receive()25 .attachment(new SoapAttachmentBuilder()26 .content("citrus:file:src/test/resources/soap/attachment.txt")27 .contentType("

Full Screen

Full Screen

SoapAttachment

Using AI Code Generation

copy

Full Screen

1receive()2 .soap()3 .attachment()4 .name("attachment")5 .content("Hello Citrus!")6 .contentType("text/plain");7receive()8 .soap()9 .attachment()10 .name("attachment")11 .content("Hello Citrus!")12 .contentType("text/plain");13receive()14 .soap()15 .attachment()16 .name("attachment")17 .attachment(new StringAttachment("Hello Citrus!", "text/plain"));18receive()19 .soap()20 .attachment()21 .name("attachment")22 .attachment(new StringAttachment("Hello Citrus!", "text/plain"));23receive()24 .soap()25 .attachment()26 .name("attachment")27 .attachment(new StringAttachment("Hello Citrus!", "text/plain"));28receive()29 .soap()30 .attachment()31 .name("attachment")32 .attachment(new StringAttachment("Hello Citrus!", "text/plain"));33receive()34 .soap()35 .attachment()36 .name("attachment")37 .attachment(new StringAttachment("Hello Citrus!", "text

Full Screen

Full Screen

SoapAttachment

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.runner;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner;4import com.consol.citrus.message.MessageType;5import org.junit.Test;6public class SOAPAttachmentTest extends JUnit4CitrusTestRunner {7 public void SOAPAttachmentTest() {8 variable("attachmentContent", "Hello Citrus!");9 variable("attachmentType", "text/plain");10 variable("attachmentName", "test.txt");11 variable("attachmentId", "cid:1234567890");12 soap()13 .client("soapClient")14 .send()15 .soapAction("testAction")16 .payload("<TestRequestMessage>" +17 .attachment()18 .content("${attachmentContent}")19 .contentType("${attachmentType}")20 .contentId("${attachmentId}")21 .name("${attachmentName}")22 .build();23 soap()24 .server("soapServer")25 .receive()26 .payload("<TestRequestMessage>" +27 .attachment()28 .content("${attachmentContent}")29 .contentType("${attachmentType}")30 .contentId("${attachmentId}")31 .name("${attachmentName}")32 .build();33 }34}35The soapAction() method of the com.consol.citrus.dsl.builder.SendSoapMessageBuilder class sets the SOAP action of

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