How to use getContentId method of com.consol.citrus.ws.message.SoapAttachment class

Best Citrus code snippet using com.consol.citrus.ws.message.SoapAttachment.getContentId

Source:ReceiveSoapMessageActionTest.java Github

copy

Full Screen

...68 public Object answer(InvocationOnMock invocation) throws Throwable {69 Assert.assertEquals(((List<SoapAttachment>)invocation.getArguments()[1]).size(), 1L);70 SoapAttachment soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(0);71 Assert.assertEquals(soapAttachment.getContent(), "TestAttachment!");72 Assert.assertNull(soapAttachment.getContentId());73 Assert.assertEquals(soapAttachment.getContentType(), "text/plain");74 return null;75 }76 }).when(attachmentValidator).validateAttachment((SoapMessage)any(), any(List.class));77 when(endpoint.getActor()).thenReturn(null);78 79 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();80 validationContexts.add(validationContext);81 soapMessageAction.setValidationContexts(validationContexts);82 soapMessageAction.execute(context);83 }84 @Test85 public void testSoapMessageWithAttachmentDataTest() throws Exception {86 ReceiveSoapMessageAction soapMessageAction = new ReceiveSoapMessageAction();87 soapMessageAction.setEndpoint(endpoint);88 soapMessageAction.setAttachmentValidator(attachmentValidator);89 soapMessageAction.addValidator(new DomXmlMessageValidator());90 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();91 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();92 soapMessageAction.setMessageBuilder(controlMessageBuilder);93 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");94 SoapAttachment attachment = new SoapAttachment();95 attachment.setContentId("myAttachment");96 attachment.setContentType("text/xml");97 attachment.setContent("<TestAttachment><Message>Hello World!</Message></TestAttachment>");98 attachment.setCharsetName("UTF-16");99 soapMessageAction.setAttachments(Collections.singletonList(attachment));100 Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");101 reset(endpoint, consumer, endpointConfiguration, attachmentValidator);102 when(endpoint.createConsumer()).thenReturn(consumer);103 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);104 when(endpointConfiguration.getTimeout()).thenReturn(5000L);105 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);106 doAnswer(new Answer() {107 @Override108 public Object answer(InvocationOnMock invocation) throws Throwable {109 Assert.assertEquals(((List<SoapAttachment>)invocation.getArguments()[1]).size(), 1L);110 SoapAttachment soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(0);111 Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");112 Assert.assertEquals(soapAttachment.getContentId(), "myAttachment");113 Assert.assertEquals(soapAttachment.getContentType(), "text/xml");114 Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-16");115 return null;116 }117 }).when(attachmentValidator).validateAttachment((SoapMessage)any(), (List)any());118 when(endpoint.getActor()).thenReturn(null);119 120 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();121 validationContexts.add(validationContext);122 soapMessageAction.setValidationContexts(validationContexts);123 soapMessageAction.execute(context);124 }125 @Test126 public void testSoapMessageWithMultipleAttachmentDataTest() throws Exception {127 ReceiveSoapMessageAction soapMessageAction = new ReceiveSoapMessageAction();128 soapMessageAction.setEndpoint(endpoint);129 soapMessageAction.setAttachmentValidator(attachmentValidator);130 soapMessageAction.addValidator(new DomXmlMessageValidator());131 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();132 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();133 soapMessageAction.setMessageBuilder(controlMessageBuilder);134 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");135 List<SoapAttachment> attachments = new ArrayList<SoapAttachment>();136 SoapAttachment attachment = new SoapAttachment();137 attachment.setContentId("1stAttachment");138 attachment.setContentType("text/xml");139 attachment.setContent("<TestAttachment><Message>Hello World1!</Message></TestAttachment>");140 attachment.setCharsetName("UTF-8");141 attachments.add(attachment);142 SoapAttachment attachment2 = new SoapAttachment();143 attachment2.setContentId("2ndAttachment");144 attachment2.setContentType("text/xml");145 attachment2.setContent("<TestAttachment><Message>Hello World2!</Message></TestAttachment>");146 attachment2.setCharsetName("UTF-16");147 attachments.add(attachment2);148 soapMessageAction.setAttachments(attachments);149 Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");150 reset(endpoint, consumer, endpointConfiguration, attachmentValidator);151 when(endpoint.createConsumer()).thenReturn(consumer);152 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);153 when(endpointConfiguration.getTimeout()).thenReturn(5000L);154 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);155 doAnswer(new Answer() {156 @Override157 public Object answer(InvocationOnMock invocation) throws Throwable {158 Assert.assertEquals(((List<SoapAttachment>)invocation.getArguments()[1]).size(), 2L);159 SoapAttachment soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(0);160 Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World1!</Message></TestAttachment>");161 Assert.assertEquals(soapAttachment.getContentId(), "1stAttachment");162 Assert.assertEquals(soapAttachment.getContentType(), "text/xml");163 Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-8");164 soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(1);165 Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World2!</Message></TestAttachment>");166 Assert.assertEquals(soapAttachment.getContentId(), "2ndAttachment");167 Assert.assertEquals(soapAttachment.getContentType(), "text/xml");168 Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-16");169 return null;170 }171 }).when(attachmentValidator).validateAttachment((SoapMessage)any(), (List)any());172 when(endpoint.getActor()).thenReturn(null);173 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();174 validationContexts.add(validationContext);175 soapMessageAction.setValidationContexts(validationContexts);176 soapMessageAction.execute(context);177 }178 179 @Test180 public void testSoapMessageWithEmptyAttachmentContentTest() throws Exception {181 ReceiveSoapMessageAction soapMessageAction = new ReceiveSoapMessageAction();182 soapMessageAction.setEndpoint(endpoint);183 soapMessageAction.setAttachmentValidator(attachmentValidator);184 soapMessageAction.addValidator(new DomXmlMessageValidator());185 186 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();187 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();188 soapMessageAction.setMessageBuilder(controlMessageBuilder);189 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");190 SoapAttachment attachment = new SoapAttachment();191 attachment.setContentId("myAttachment");192 attachment.setContent("");193 soapMessageAction.setAttachments(Collections.singletonList(attachment));194 Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");195 reset(endpoint, consumer, endpointConfiguration, attachmentValidator);196 when(endpoint.createConsumer()).thenReturn(consumer);197 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);198 when(endpointConfiguration.getTimeout()).thenReturn(5000L);199 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);200 doAnswer(new Answer() {201 @Override202 public Object answer(InvocationOnMock invocation) throws Throwable {203 Assert.assertEquals(((List<SoapAttachment>)invocation.getArguments()[1]).size(), 1L);204 SoapAttachment soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(0);205 Assert.assertEquals(soapAttachment.getContent(), "");206 Assert.assertEquals(soapAttachment.getContentId(), "myAttachment");207 Assert.assertEquals(soapAttachment.getContentType(), "text/plain");208 Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-8");209 return null;210 }211 }).when(attachmentValidator).validateAttachment((SoapMessage)any(), (List) any());212 when(endpoint.getActor()).thenReturn(null);213 214 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();215 validationContexts.add(validationContext);216 soapMessageAction.setValidationContexts(validationContexts);217 soapMessageAction.execute(context);218 }219 220 @Test221 public void testSoapMessageWithNoAttachmentExpected() throws Exception {222 ReceiveSoapMessageAction soapMessageAction = new ReceiveSoapMessageAction();223 soapMessageAction.setEndpoint(endpoint);224 soapMessageAction.setAttachmentValidator(attachmentValidator);225 226 soapMessageAction.addValidator(new DomXmlMessageValidator());227 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();228 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();229 soapMessageAction.setMessageBuilder(controlMessageBuilder);230 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");231 232 Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");233 reset(endpoint, consumer, endpointConfiguration, attachmentValidator);234 when(endpoint.createConsumer()).thenReturn(consumer);235 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);236 when(endpointConfiguration.getTimeout()).thenReturn(5000L);237 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);238 when(endpoint.getActor()).thenReturn(null);239 240 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();241 validationContexts.add(validationContext);242 soapMessageAction.setValidationContexts(validationContexts);243 soapMessageAction.execute(context);244 }245 246 @Test247 public void testSoapMessageWithAttachmentResourceTest() throws Exception {248 ReceiveSoapMessageAction soapMessageAction = new ReceiveSoapMessageAction();249 soapMessageAction.setEndpoint(endpoint);250 soapMessageAction.setAttachmentValidator(attachmentValidator);251 soapMessageAction.addValidator(new DomXmlMessageValidator());252 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();253 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();254 soapMessageAction.setMessageBuilder(controlMessageBuilder);255 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");256 SoapAttachment attachment = new SoapAttachment();257 attachment.setContentId("myAttachment");258 attachment.setContentType("text/xml");259 attachment.setContentResourcePath("classpath:com/consol/citrus/ws/actions/test-attachment.xml");260 soapMessageAction.setAttachments(Collections.singletonList(attachment));261 Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");262 reset(endpoint, consumer, endpointConfiguration, attachmentValidator);263 when(endpoint.createConsumer()).thenReturn(consumer);264 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);265 when(endpointConfiguration.getTimeout()).thenReturn(5000L);266 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);267 doAnswer(new Answer() {268 @Override269 public Object answer(InvocationOnMock invocation) throws Throwable {270 Assert.assertEquals(((List<SoapAttachment>)invocation.getArguments()[1]).size(), 1L);271 SoapAttachment soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(0);272 Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");273 Assert.assertEquals(soapAttachment.getContentId(), "myAttachment");274 Assert.assertEquals(soapAttachment.getContentType(), "text/xml");275 Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-8");276 return null;277 }278 }).when(attachmentValidator).validateAttachment((SoapMessage)any(), (List) any());279 when(endpoint.getActor()).thenReturn(null);280 281 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();282 validationContexts.add(validationContext);283 soapMessageAction.setValidationContexts(validationContexts);284 soapMessageAction.execute(context);285 }286 287 @Test288 public void testSoapMessageWithAttachmentResourceVariablesSupportTest() throws Exception {289 ReceiveSoapMessageAction soapMessageAction = new ReceiveSoapMessageAction();290 soapMessageAction.setEndpoint(endpoint);291 soapMessageAction.setAttachmentValidator(attachmentValidator);292 soapMessageAction.addValidator(new DomXmlMessageValidator());293 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();294 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();295 soapMessageAction.setMessageBuilder(controlMessageBuilder);296 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");297 298 context.setVariable("myText", "Hello World!");299 SoapAttachment attachment = new SoapAttachment();300 attachment.setContentId("myAttachment");301 attachment.setContentType("text/xml");302 attachment.setContentResourcePath("classpath:com/consol/citrus/ws/actions/test-attachment-with-variables.xml");303 soapMessageAction.setAttachments(Collections.singletonList(attachment));304 Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");305 reset(endpoint, consumer, endpointConfiguration, attachmentValidator);306 when(endpoint.createConsumer()).thenReturn(consumer);307 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);308 when(endpointConfiguration.getTimeout()).thenReturn(5000L);309 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);310 doAnswer(new Answer() {311 @Override312 public Object answer(InvocationOnMock invocation) throws Throwable {313 Assert.assertEquals(((List<SoapAttachment>)invocation.getArguments()[1]).size(), 1L);314 SoapAttachment soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(0);315 Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");316 Assert.assertEquals(soapAttachment.getContentId(), "myAttachment");317 Assert.assertEquals(soapAttachment.getContentType(), "text/xml");318 Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-8");319 return null;320 }321 }).when(attachmentValidator).validateAttachment((SoapMessage)any(), (List) any());322 when(endpoint.getActor()).thenReturn(null);323 324 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();325 validationContexts.add(validationContext);326 soapMessageAction.setValidationContexts(validationContexts);327 soapMessageAction.execute(context);328 }329 330 @Test331 public void testSoapMessageWithAttachmentDataVariablesSupportTest() throws Exception {332 ReceiveSoapMessageAction soapMessageAction = new ReceiveSoapMessageAction();333 soapMessageAction.setEndpoint(endpoint);334 soapMessageAction.setAttachmentValidator(attachmentValidator);335 soapMessageAction.addValidator(new DomXmlMessageValidator());336 PayloadTemplateMessageBuilder controlMessageBuilder = new PayloadTemplateMessageBuilder();337 XmlMessageValidationContext validationContext = new XmlMessageValidationContext();338 soapMessageAction.setMessageBuilder(controlMessageBuilder);339 controlMessageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");340 341 context.setVariable("myText", "Hello World!");342 SoapAttachment attachment = new SoapAttachment();343 attachment.setContentId("myAttachment");344 attachment.setContentType("text/xml");345 attachment.setContent("<TestAttachment><Message>${myText}</Message></TestAttachment>");346 soapMessageAction.setAttachments(Collections.singletonList(attachment));347 Message controlMessage = new SoapMessage("<TestRequest><Message>Hello World!</Message></TestRequest>");348 reset(endpoint, consumer, endpointConfiguration, attachmentValidator);349 when(endpoint.createConsumer()).thenReturn(consumer);350 when(endpoint.getEndpointConfiguration()).thenReturn(endpointConfiguration);351 when(endpointConfiguration.getTimeout()).thenReturn(5000L);352 when(consumer.receive(any(TestContext.class), anyLong())).thenReturn(controlMessage);353 doAnswer(new Answer() {354 @Override355 public Object answer(InvocationOnMock invocation) throws Throwable {356 Assert.assertEquals(((List<SoapAttachment>)invocation.getArguments()[1]).size(), 1L);357 SoapAttachment soapAttachment = ((List<SoapAttachment>)invocation.getArguments()[1]).get(0);358 Assert.assertEquals(soapAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");359 Assert.assertEquals(soapAttachment.getContentId(), "myAttachment");360 Assert.assertEquals(soapAttachment.getContentType(), "text/xml");361 Assert.assertEquals(soapAttachment.getCharsetName(), "UTF-8");362 return null;363 }364 }).when(attachmentValidator).validateAttachment((SoapMessage)any(), (List) any());365 when(endpoint.getActor()).thenReturn(null);366 367 List<ValidationContext> validationContexts = new ArrayList<ValidationContext>();368 validationContexts.add(validationContext);369 soapMessageAction.setValidationContexts(validationContexts);370 soapMessageAction.execute(context);371 }372}...

Full Screen

Full Screen

Source:AbstractSoapAttachmentValidator.java Github

copy

Full Screen

...43 log.debug("Validating SOAP attachments ...");44 for (SoapAttachment controlAttachment : controlAttachments) {45 SoapAttachment attachment = findAttachment(soapMessage, controlAttachment);46 if (log.isDebugEnabled()) {47 log.debug("Found attachment with contentId '" + controlAttachment.getContentId() + "'");48 }49 validateAttachmentContentId(attachment, controlAttachment);50 validateAttachmentContentType(attachment, controlAttachment);51 validateAttachmentContent(attachment, controlAttachment);52 log.info("SOAP attachment validation successful: All values OK");53 }54 }55 /**56 * Finds attachment in list of soap attachments on incoming soap message. By default57 * uses content id of control attachment as search key. If no proper attachment with this content id58 * was found in soap message throws validation exception.59 *60 * @param soapMessage61 * @param controlAttachment62 * @return63 */64 protected SoapAttachment findAttachment(SoapMessage soapMessage, SoapAttachment controlAttachment) {65 List<SoapAttachment> attachments = soapMessage.getAttachments();66 Attachment matching = null;67 if (controlAttachment.getContentId() == null) {68 if (attachments.size() == 1) {69 matching = attachments.get(0);70 } else {71 throw new ValidationException("Found more than one SOAP attachment - need control attachment content id for validation!");72 }73 } else {74 // try to find attachment by its content id75 for (Attachment attachment : attachments) {76 if (controlAttachment.getContentId() != null &&77 controlAttachment.getContentId().equals(attachment.getContentId())) {78 matching = attachment;79 }80 }81 }82 if (matching != null) {83 return SoapAttachment.from(matching);84 } else {85 throw new ValidationException(String.format("Unable to find SOAP attachment with content id '%s'", controlAttachment.getContentId()));86 }87 }88 /**89 * Validating SOAP attachment content id.90 * @param receivedAttachment91 * @param controlAttachment92 */93 protected void validateAttachmentContentId(SoapAttachment receivedAttachment, SoapAttachment controlAttachment) {94 //in case contentId was not set in test case, skip validation 95 if (!StringUtils.hasText(controlAttachment.getContentId())) { return; }96 97 if (receivedAttachment.getContentId() != null) {98 Assert.isTrue(controlAttachment.getContentId() != null, 99 buildValidationErrorMessage("Values not equal for attachment contentId", 100 null, receivedAttachment.getContentId()));101 Assert.isTrue(receivedAttachment.getContentId().equals(controlAttachment.getContentId()),102 buildValidationErrorMessage("Values not equal for attachment contentId", 103 controlAttachment.getContentId(), receivedAttachment.getContentId()));104 } else {105 Assert.isTrue(controlAttachment.getContentId() == null || controlAttachment.getContentId().length() == 0, 106 buildValidationErrorMessage("Values not equal for attachment contentId", 107 controlAttachment.getContentId(), null));108 }109 110 if (log.isDebugEnabled()) {111 log.debug("Validating attachment contentId: " + receivedAttachment.getContentId() + 112 "='" + controlAttachment.getContentId() + "': OK.");113 }114 }115 116 /**117 * Validating SOAP attachment content type.118 * @param receivedAttachment119 * @param controlAttachment120 */121 protected void validateAttachmentContentType(SoapAttachment receivedAttachment, SoapAttachment controlAttachment) {122 //in case contentType was not set in test case, skip validation123 if (!StringUtils.hasText(controlAttachment.getContentType())) { return; }124 125 if (receivedAttachment.getContentType() != null) {126 Assert.isTrue(controlAttachment.getContentType() != null, ...

Full Screen

Full Screen

Source:SendSoapMessageAction.java Github

copy

Full Screen

...52 for (SoapAttachment attachment : attachments) {53 attachment.setTestContext(context);54 if (mtomEnabled) {55 String messagePayload = soapMessage.getPayload(String.class);56 String cid = CID_MARKER + attachment.getContentId();57 if (attachment.isMtomInline() && messagePayload.contains(cid)) {58 byte[] attachmentBinaryData = FileUtils.readToString(attachment.getInputStream(), Charset.forName(attachment.getCharsetName())).getBytes(Charset.forName(attachment.getCharsetName()));59 if (attachment.getEncodingType().equals(SoapAttachment.ENCODING_BASE64_BINARY)) {60 if (log.isDebugEnabled()) {61 log.debug("Adding inline base64Binary data for attachment: %s", cid);62 }63 messagePayload = messagePayload.replaceAll(cid, Base64.encodeBase64String(attachmentBinaryData));64 } else if (attachment.getEncodingType().equals(SoapAttachment.ENCODING_HEX_BINARY)) {65 if (log.isDebugEnabled()) {66 log.debug("Adding inline hexBinary data for attachment: %s", cid);67 }68 messagePayload = messagePayload.replaceAll(cid, Hex.encodeHexString(attachmentBinaryData).toUpperCase());69 } else {70 throw new CitrusRuntimeException(String.format("Unsupported encoding type '%s' for SOAP attachment: %s - choose one of %s or %s",71 attachment.getEncodingType(), cid, SoapAttachment.ENCODING_BASE64_BINARY, SoapAttachment.ENCODING_HEX_BINARY));72 }73 } else {74 messagePayload = messagePayload.replaceAll(cid, String.format("<xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" href=\"%s\"/>", CID_MARKER + URLEncoder.encode(attachment.getContentId(), "UTF-8")));75 soapMessage.addAttachment(attachment);76 }77 soapMessage.setPayload(messagePayload);78 } else {79 soapMessage.addAttachment(attachment);80 }81 }82 } catch (IOException e) {83 throw new CitrusRuntimeException(e);84 }85 return soapMessage;86 }87 /**88 * Gets the attachments....

Full Screen

Full Screen

getContentId

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import com.consol.citrus.ws.message.SoapAttachment;5import org.springframework.core.io.ClassPathResource;6import org.testng.annotations.Test;7public class 3 extends TestNGCitrusTestRunner {8 public void test() {9 send("webServiceClient")10 " <ws:contentId>citrus:randomUUID()</ws:contentId>\n" +11 " <ws:content>${file:src/test/resources/text.txt}</ws:content>\n" +12 .header("SOAPAction", "echoAttachment");13 receive("webServiceServer")14 " <ws:contentId>${soap:attachment:contentId}</ws:contentId>\n" +15 " <ws:contentType>${soap:attachment:contentType}</ws:contentType>\n" +16 " <ws:content>${soap:attachment:content}</ws:content>\n" +

Full Screen

Full Screen

getContentId

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.actions;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.exceptions.ValidationException;4import com.consol.citrus.testng.AbstractTestNGUnitTest;5import com.consol.citrus.validation.context.ValidationContext;6import com.consol.citrus.validation.matcher.ValidationMatcherUtils;7import com.consol.citrus.ws.message.SoapAttachment;8import org.mockito.Mockito;9import org.springframework.core.io.ClassPathResource;10import org.springframework.core.io.Resource;11import org.springframework.ws.WebServiceMessage;12import org.springframework.ws.soap.SoapMessage;13import org.springframework.ws.soap.SoapMessageFactory;14import org.testng.Assert;15import org.testng.annotations.Test;16import java.io.IOException;17import java.util.Collections;18import static org.mockito.Mockito.*;19public class ReceiveSoapAttachmentActionTest extends AbstractTestNGUnitTest {20 private SoapMessageFactory messageFactory = Mockito.mock(SoapMessageFactory.class);21 private WebServiceMessage webServiceMessage = Mockito.mock(WebServiceMessage.class);22 private SoapMessage soapMessage = Mockito.mock(SoapMessage.class);23 public void testReceiveSoapAttachmentActionBuilder() {24 reset(messageFactory, webServiceMessage, soapMessage);25 SoapAttachment attachment = new SoapAttachment("test", "text/plain", new ClassPathResource("test.txt", ReceiveSoapAttachmentAction.class));26 when(messageFactory.createWebServiceMessage()).thenReturn(webServiceMessage);27 when(webServiceMessage.getPayloadSource()).thenReturn(soapMessage);28 when(soapMessage.getAttachments()).thenReturn(Collections.singletonList(attachment));29 MockBuilder builder = new MockBuilder(applicationContext) {30 public void configure() {31 receive(soapAttachment("test").contentId("test"));32 }33 };34 builder.run();35 }36 public void testReceiveSoapAttachmentActionBuilderWithPayloadResource() {37 reset(messageFactory, webServiceMessage, soapMessage);38 SoapAttachment attachment = new SoapAttachment("test", "text/plain", new ClassPathResource("test.txt", ReceiveSoapAttachmentAction.class));39 when(messageFactory.createWebServiceMessage()).thenReturn(webServiceMessage);40 when(webServiceMessage.getPayloadSource()).thenReturn(soapMessage);41 when(soapMessage.getAttachments()).thenReturn(Collections.singletonList(attachment));42 MockBuilder builder = new MockBuilder(applicationContext) {43 public void configure() {44 receive(soapAttachment("test").payloadResource(new ClassPath

Full Screen

Full Screen

getContentId

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import com.consol.citrus.ws.message.SoapAttachment;4import org.springframework.core.io.ClassPathResource;5import org.testng.annotations.Test;6public class SoapAttachmentTest extends TestNGCitrusTestDesigner {7 public void soapAttachmentTest() {8 SoapAttachment soapAttachment = new SoapAttachment(new ClassPathResource("com/consol/citrus/ws/attachment.xml"));9 System.out.println(soapAttachment.getContentId());10 }11}12Your name to display (optional):13Your name to display (optional):14Your name to display (optional):

Full Screen

Full Screen

getContentId

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.message;2import org.springframework.core.io.ClassPathResource;3import org.springframework.ws.soap.SoapMessage;4import org.springframework.ws.soap.SoapMessageFactory;5import org.springframework.ws.soap.SoapVersion;6import org.springframework.ws.soap.axiom.AxiomSoapMessageFactory;7import org.springframework.ws.soap.axiom.AxiomSoapMessage;8import org.springframework.ws.soap.axiom.AxiomSoapMessageUtils;9import org.springframework.ws.soap.axiom.AxiomSoapBody;10import org.springframework.ws.soap.axiom.AxiomSoapHeader;11import org.springframework.ws.soap.axiom.AxiomSoapHeaderElement;12import org.springframework.ws.soap.axiom.AxiomSoapFault;13import org.springframework.ws.soap.axiom.AxiomSoapFaultDetail;14import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailElement;15import org.springframework.ws.soap.axiom.AxiomSoapFaultReason;16import org.springframework.ws.soap.axiom.AxiomSoapFaultText;17import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntry;18import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntryElement;19import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntryText;20import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntryElement;21import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntryElementText;22import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntryElementElement;23import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntryElementElementText;24import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntryElementElementElement;25import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntryElementElementElementText;26import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntryElementElementElementElement;27import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntryElementElementElementElementText;28import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntryElementElementElementElementElement;29import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntryElementElementElementElementElementText;30import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntryElementElementElementElementElementElement;31import org.springframework.ws.soap.axiom.AxiomSoapFaultDetailEntryElementElementElementElement

Full Screen

Full Screen

getContentId

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.message;2import org.springframework.util.Assert;3import org.springframework.util.StringUtils;4import org.springframework.ws.soap.SoapMessage;5import org.springframework.ws.soap.SoapMessageFactory;6import org.springframework.ws.soap.SoapVersion;7import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;8import org.springframework.ws.soap.saaj.SaajSoapMessageUtils;9import org.springframework.ws.soap.saaj.SaajSoapMessageUtils.SaajSoapMessage;10import org.springframework.ws.soap.saaj.SaajSoapMessageUtils.SaajSoapMessageFactory;11import org.springframework.ws.soap.saaj.SaajSoapMessageUtils.SaajSoapMessageFactoryImpl;12import org.springframework.ws.soap.saaj.SaajSoapMessageUtils.SaajSoapMessageImpl;13import javax.xml.soap.AttachmentPart;14import javax.xml.soap.MimeHeader;15import javax.xml.soap.SOAPException;16import javax.xml.soap.SOAPMessage;17import javax.xml.transform.Source;18import java.io.IOException;19import java.util.List;20public class SoapAttachment extends SoapMessageImpl {21 private AttachmentPart attachmentPart;22 public SoapAttachment(AttachmentPart attachmentPart) {23 this.attachmentPart = attachmentPart;24 }25 public String getContentId() {26 return attachmentPart.getContentId();27 }28 public String getContentType() {29 return attachmentPart.getContentType();30 }31 public String getHeader(String name) {32 return attachmentPart.getHeader(name);33 }34 public String[] getHeaderNames() {35 try {36 List<MimeHeader> mimeHeaders = attachmentPart.getMimeHeaders().getAllHeaders();37 String[] headerNames = new String[mimeHeaders.size()];38 for (int i = 0; i < mimeHeaders.size(); i++) {39 headerNames[i] = mimeHeaders.get(i).getName();40 }41 return headerNames;42 } catch (SOAPException e) {43 throw new CitrusRuntimeException("Failed to get mime headers", e);44 }45 }46 public Object getContent() {47 try {48 return attachmentPart.getContent();49 } catch (IOException e) {50 throw new CitrusRuntimeException("Failed to get attachment content", e);51 } catch (SOAPException e) {52 throw new CitrusRuntimeException("Failed to get attachment content", e);53 }54 }55 public Source getContentAsSource() {56 try {

Full Screen

Full Screen

getContentId

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws;2import org.testng.annotations.Test;3import com.consol.citrus.annotations.CitrusTest;4import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;5public class SOAPAttachmentTest extends TestNGCitrusTestDesigner {6 public void test() {7 send("client")8 + "</ns0:echoRequest>");9 receive("server")10 + "</ns0:echoResponse>");11 receive("client")12 + "</ns0:echoRequest>");13 send("server")14 + "</ns0:echoResponse>");15 receive("client")16 + "</ns0:echoRequest>");17 send("server")18 + "</ns0:echoResponse>");19 receive("client")20 + "</ns0:echoRequest>");21 send("server")

Full Screen

Full Screen

getContentId

Using AI Code Generation

copy

Full Screen

1public class 3 {2public static void main(String[] args) throws Exception {3SoapAttachment soapAttachment = new SoapAttachment();4soapAttachment.setContentId("contentId");5System.out.println(soapAttachment.getContentId());6}7}8public class 4 {9public static void main(String[] args) throws Exception {10SoapAttachment soapAttachment = new SoapAttachment();11soapAttachment.setContentType("contentType");12System.out.println(soapAttachment.getContentType());13}14}15public class 5 {16public static void main(String[] args) throws Exception {17SoapAttachment soapAttachment = new SoapAttachment();18soapAttachment.setHeaders("headers");19System.out.println(soapAttachment.getHeaders());20}21}22public class 6 {23public static void main(String[] args) throws Exception {24SoapAttachment soapAttachment = new SoapAttachment();25soapAttachment.setPayload("payload");26System.out.println(soapAttachment.getPayload());27}28}29public class 7 {30public static void main(String[] args) throws Exception {31SoapAttachment soapAttachment = new SoapAttachment();32soapAttachment.setCharset("charset");33System.out.println(soapAttachment.getCharset());34}35}36public class 8 {37public static void main(String[] args) throws Exception {38SoapAttachment soapAttachment = new SoapAttachment();39soapAttachment.setContentId("contentId");40System.out.println(soapAttachment.getContentId());41}42}43public class 9 {44public static void main(String[] args) throws Exception {45SoapAttachment soapAttachment = new SoapAttachment();46soapAttachment.setContentType("contentType");47System.out.println(soapAttachment.getContentType());48}49}

Full Screen

Full Screen

getContentId

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.message;2import org.springframework.util.Assert;3import org.springframework.util.StringUtils;4import org.springframework.ws.soap.SoapMessage;5import org.springframework.ws.soap.SoapMessageFactory;6import org.springframework.ws.soap.SoapVersion;7import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;8import org.springframework.ws.soap.saaj.SaajSoapMessageUtils;9import org.springframework.ws.soap.saaj.SaajSoapMessageUtils.SaajSoapMessage;10import org.springframework.ws.soap.saaj.SaajSoapMessageUtils.SaajSoapMessageFactory;11import org.springframework.ws.soap.saaj.SaajSoapMessageUtils.SaajSoapMessageFactoryImpl;12import org.springframework.ws.soap.saaj.SaajSoapMessageUtils.SaajSoapMessageImpl;13import javax.xml.soap.AttachmentPart;14import javax.xml.soap.MimeHeader;15import javax.xml.soap.SOAPException;16import javax.xml.soap.SOAPMessage;17import javax.xml.transform.Source;18import java.io.IOException;19import java.util.List;20public class SoapAttachment extends SoapMessageImpl {21 private AttachmentPart attachmentPart;22 public SoapAttachment(AttachmentPart attachmentPart) {23 this.attachmentPart = attachmentPart;24 }25 public String getContentId() {26 return attachmentPart.getContentId();27 }28 public String getContentType() {29 return attachmentPart.getContentType();30 }31 public String getHeader(String name) {32 return attachmentPart.getHeader(name);33 }34 public String[] getHeaderNames() {35 try {36 List<MimeHeader> mimeHeaders = attachmentPart.getMimeHeaders().getAllHeaders();37 String[] headerNames = new String[mimeHeaders.size()];38 for (int i = 0; i < mimeHeaders.size(); i++) {39 headerNames[i] = mimeHeaders.get(i).getName();40 }41 return headerNames;42 } catch (SOAPException e) {43 throw new CitrusRuntimeException("Failed to get mime headers", e);44 }45 }46 public Object getContent() {47 try {48 return attachmentPart.getContent();49 } catch (IOException e) {50 throw new CitrusRuntimeException("Failed to get attachment content", e);51 } catch (SOAPException e) {52 throw new CitrusRuntimeException("Failed to get attachment content", e);53 }54 }55 public Source getContentAsSource() {56 try {

Full Screen

Full Screen

getContentId

Using AI Code Generation

copy

Full Screen

1public class 3 {2public static void main(String[] args) throws Exception {3SoapAttachment soapAttachment = new SoapAttachment();4soapAttachment.setContentId("contentId");5System.out.println(soapAttachment.getContentId());6}7}8public class 4 {9public static void main(String[] args) throws Exception {10SoapAttachment soapAttachment = new SoapAttachment();11soapAttachment.setContentType("contentType");12System.out.println(soapAttachment.getContentType());13}14}15public class 5 {16public static void main(String[] args) throws Exception {17SoapAttachment soapAttachment = new SoapAttachment();18soapAttachment.setHeaders("headers");19System.out.println(soapAttachment.getHeaders());20}21}22public class 6 {23public static void main(String[] args) throws Exception {24SoapAttachment soapAttachment = new SoapAttachment();25soapAttachment.setPayload("payload");26System.out.println(soapAttachment.getPayload());27}28}29public class 7 {30public static void main(String[] args) throws Exception {31SoapAttachment soapAttachment = new SoapAttachment();32soapAttachment.setCharset("charset");33System.out.println(soapAttachment.getCharset());34}35}36public class 8 {37public static void main(String[] args) throws Exception {38SoapAttachment soapAttachment = new SoapAttachment();39soapAttachment.setContentId("contentId");40System.out.println(soapAttachment.getContentId());41}42}43public class 9 {44public static void main(String[] args) throws Exception {45SoapAttachment soapAttachment = new SoapAttachment();46soapAttachment.setContentType("contentType");47System.out.println(soapAttachment.getContentType());48}49}

Full Screen

Full Screen

getContentId

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.ws.message.SoapAttachment;2import org.springframework.core.io.ClassPathResource;3import org.springframework.core.io.Resource;4import org.springframework.ws.soap.SoapMessage;5import org.springframework.ws.soap.saaj.SaajSoapMessage;6import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;7import org.springframework.xml.transform.StringSource;8import javax.xml.transform.Source;9import java.io.IOException;10import java.util.Iterator;11import java.util.List;12public class 3 {13 public static void main(String[] args) throws IOException {14 SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();15 messageFactory.afterPropertiesSet();16 SoapMessage soapMessage = messageFactory.createWebServiceMessage();17 Resource resource = new ClassPathResource("soap-request.xml");18 Source source = new StringSource(resource.getFileContent());19 soapMessage.getPayloadResult().setResult(source);20 SaajSoapMessage saajSoapMessage = (SaajSoapMessage) soapMessage;21 List<SoapAttachment> attachments = saajSoapMessage.getAttachments();22 Iterator<SoapAttachment> iterator = attachments.iterator();23 while (iterator.hasNext()) {24 SoapAttachment soapAttachment = iterator.next();25 System.out.println(soapAttachment.getContentId());26 }27 }28}

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful