How to use testSendSoapFault method of com.consol.citrus.dsl.runner.SendSoapFaultTestRunnerTest class

Best Citrus code snippet using com.consol.citrus.dsl.runner.SendSoapFaultTestRunnerTest.testSendSoapFault

Source:SendSoapFaultTestRunnerTest.java Github

copy

Full Screen

...52 private Producer messageProducer = Mockito.mock(Producer.class);53 private ApplicationContext applicationContextMock = Mockito.mock(ApplicationContext.class);54 private Resource resource = Mockito.mock(Resource.class);55 @Test56 public void testSendSoapFault() {57 reset(soapServer, messageProducer);58 when(soapServer.createProducer()).thenReturn(messageProducer);59 when(soapServer.getActor()).thenReturn(null);60 doAnswer(invocation -> {61 SoapFault message = (SoapFault) invocation.getArguments()[0];62 Assert.assertEquals(message.getFaultActor(), "faultActor");63 Assert.assertEquals(message.getFaultCode(), FAULT_CODE);64 Assert.assertEquals(message.getFaultString(), FAULT_STRING);65 return null;66 }).when(messageProducer).send(any(Message.class), any(TestContext.class));67 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {68 @Override69 public void execute() {70 soap(builder -> builder.server(soapServer)71 .sendFault()72 .faultActor("faultActor")73 .faultCode(FAULT_CODE)74 .faultString(FAULT_STRING));75 }76 };77 TestCase test = builder.getTestCase();78 Assert.assertEquals(test.getActionCount(), 1);79 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);80 SendSoapFaultAction action = (SendSoapFaultAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate();81 Assert.assertEquals(action.getName(), "send");82 Assert.assertEquals(action.getEndpoint(), soapServer);83 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);84 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();85 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "");86 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);87 Assert.assertEquals(action.getFaultActor(), "faultActor");88 Assert.assertEquals(action.getFaultCode(), FAULT_CODE);89 Assert.assertEquals(action.getFaultString(), FAULT_STRING);90 }91 @Test92 public void testSendSoapFaultByEndpointName() {93 TestContext context = applicationContext.getBean(TestContext.class);94 context.setApplicationContext(applicationContextMock);95 reset(applicationContextMock, soapServer, messageProducer);96 when(soapServer.createProducer()).thenReturn(messageProducer);97 when(soapServer.getActor()).thenReturn(null);98 doAnswer(invocation -> {99 SoapFault message = (SoapFault) invocation.getArguments()[0];100 Assert.assertEquals(message.getFaultCode(), FAULT_CODE);101 Assert.assertEquals(message.getFaultString(), FAULT_STRING);102 return null;103 }).when(messageProducer).send(any(Message.class), any(TestContext.class));104 when(applicationContextMock.getBean(TestContext.class)).thenReturn(context);105 when(applicationContextMock.getBean("soapServer", Endpoint.class)).thenReturn(soapServer);106 when(applicationContextMock.getBean(TestActionListeners.class)).thenReturn(new TestActionListeners());107 when(applicationContextMock.getBeansOfType(SequenceBeforeTest.class)).thenReturn(new HashMap<String, SequenceBeforeTest>());108 when(applicationContextMock.getBeansOfType(SequenceAfterTest.class)).thenReturn(new HashMap<String, SequenceAfterTest>());109 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContextMock, context) {110 @Override111 public void execute() {112 soap(builder -> builder.server("soapServer")113 .sendFault()114 .faultCode(FAULT_CODE)115 .faultString(FAULT_STRING));116 }117 };118 TestCase test = builder.getTestCase();119 Assert.assertEquals(test.getActionCount(), 1);120 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);121 SendSoapFaultAction action = (SendSoapFaultAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate();122 Assert.assertEquals(action.getName(), "send");123 Assert.assertEquals(action.getEndpoint(), soapServer);124 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);125 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();126 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "");127 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);128 Assert.assertNull(action.getFaultActor());129 Assert.assertEquals(action.getFaultCode(), FAULT_CODE);130 Assert.assertEquals(action.getFaultString(), FAULT_STRING);131 }132 @Test133 public void testSendSoapFaultWithDetailResource() throws IOException {134 reset(resource, soapServer, messageProducer);135 when(soapServer.createProducer()).thenReturn(messageProducer);136 when(soapServer.getActor()).thenReturn(null);137 doAnswer(invocation -> {138 SoapFault message = (SoapFault) invocation.getArguments()[0];139 Assert.assertEquals(message.getFaultCode(), FAULT_CODE);140 Assert.assertEquals(message.getFaultString(), FAULT_STRING);141 Assert.assertEquals(message.getFaultDetails().size(), 1L);142 Assert.assertEquals(message.getFaultDetails().get(0), ERROR_DETAIL);143 return null;144 }).when(messageProducer).send(any(Message.class), any(TestContext.class));145 when(resource.getInputStream()).thenReturn(new ByteArrayInputStream(ERROR_DETAIL.getBytes()));146 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {147 @Override148 public void execute() {149 soap(builder -> builder.server(soapServer)150 .sendFault()151 .faultCode(FAULT_CODE)152 .faultDetailResource(resource)153 .faultString(FAULT_STRING));154 }155 };156 TestCase test = builder.getTestCase();157 Assert.assertEquals(test.getActionCount(), 1);158 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);159 SendSoapFaultAction action = (SendSoapFaultAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate();160 Assert.assertEquals(action.getName(), "send");161 Assert.assertEquals(action.getEndpoint(), soapServer);162 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);163 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();164 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "");165 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);166 Assert.assertEquals(action.getFaultDetails().size(), 1L);167 Assert.assertEquals(action.getFaultDetails().get(0), ERROR_DETAIL);168 Assert.assertEquals(action.getFaultCode(), FAULT_CODE);169 Assert.assertEquals(action.getFaultString(), FAULT_STRING);170 }171 @Test172 public void testSendSoapFaultWithDetail() {173 reset(soapServer, messageProducer);174 when(soapServer.createProducer()).thenReturn(messageProducer);175 when(soapServer.getActor()).thenReturn(null);176 doAnswer(invocation -> {177 SoapFault message = (SoapFault) invocation.getArguments()[0];178 Assert.assertEquals(message.getFaultCode(), FAULT_CODE);179 Assert.assertEquals(message.getFaultString(), FAULT_STRING);180 Assert.assertEquals(message.getFaultDetails().size(), 1L);181 Assert.assertEquals(message.getFaultDetails().get(0), "DETAIL");182 return null;183 }).when(messageProducer).send(any(Message.class), any(TestContext.class));184 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {185 @Override186 public void execute() {187 soap(builder -> builder.server(soapServer)188 .sendFault()189 .faultCode(FAULT_CODE)190 .faultDetail("DETAIL")191 .faultString(FAULT_STRING));192 }193 };194 TestCase test = builder.getTestCase();195 Assert.assertEquals(test.getActionCount(), 1);196 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);197 SendSoapFaultAction action = (SendSoapFaultAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate();198 Assert.assertEquals(action.getName(), "send");199 Assert.assertEquals(action.getEndpoint(), soapServer);200 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);201 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();202 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "");203 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);204 Assert.assertEquals(action.getFaultDetails().size(), 1L);205 Assert.assertEquals(action.getFaultDetails().get(0), "DETAIL");206 Assert.assertEquals(action.getFaultCode(), FAULT_CODE);207 Assert.assertEquals(action.getFaultString(), FAULT_STRING);208 }209 @Test210 public void testSendSoapFaultWithDetailResourcePath() {211 reset(soapServer, messageProducer);212 when(soapServer.createProducer()).thenReturn(messageProducer);213 when(soapServer.getActor()).thenReturn(null);214 doAnswer(invocation -> {215 SoapFault message = (SoapFault) invocation.getArguments()[0];216 Assert.assertEquals(message.getFaultCode(), FAULT_CODE);217 Assert.assertEquals(message.getFaultString(), FAULT_STRING);218 Assert.assertEquals(message.getFaultDetails().size(), 1L);219 Assert.assertEquals(message.getFaultDetails().get(0), ERROR_DETAIL);220 return null;221 }).when(messageProducer).send(any(Message.class), any(TestContext.class));222 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {223 @Override224 public void execute() {225 soap(builder -> builder.server(soapServer)226 .sendFault()227 .faultCode(FAULT_CODE)228 .faultDetailResource("classpath:com/consol/citrus/dsl/runner/soap-fault-detail.xml")229 .faultString(FAULT_STRING));230 }231 };232 TestCase test = builder.getTestCase();233 Assert.assertEquals(test.getActionCount(), 1);234 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);235 SendSoapFaultAction action = (SendSoapFaultAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate();236 Assert.assertEquals(action.getName(), "send");237 Assert.assertEquals(action.getEndpoint(), soapServer);238 Assert.assertEquals(action.getMessageBuilder().getClass(), StaticMessageContentBuilder.class);239 StaticMessageContentBuilder messageBuilder = (StaticMessageContentBuilder) action.getMessageBuilder();240 Assert.assertEquals(messageBuilder.getMessage().getPayload(), "");241 Assert.assertEquals(messageBuilder.getMessageHeaders().size(), 0L);242 Assert.assertEquals(action.getFaultDetails().size(), 0L);243 Assert.assertEquals(action.getFaultDetailResourcePaths().size(), 1L);244 Assert.assertEquals(action.getFaultDetailResourcePaths().get(0), "classpath:com/consol/citrus/dsl/runner/soap-fault-detail.xml");245 Assert.assertEquals(action.getFaultCode(), FAULT_CODE);246 Assert.assertEquals(action.getFaultString(), FAULT_STRING);247 }248 @Test249 public void testSendSoapFaultWithMultipleDetail() {250 reset(soapServer, messageProducer);251 when(soapServer.createProducer()).thenReturn(messageProducer);252 when(soapServer.getActor()).thenReturn(null);253 doAnswer(invocation -> {254 SoapFault message = (SoapFault) invocation.getArguments()[0];255 Assert.assertEquals(message.getFaultCode(), FAULT_CODE);256 Assert.assertEquals(message.getFaultString(), FAULT_STRING);257 Assert.assertEquals(message.getFaultDetails().size(), 2L);258 Assert.assertEquals(message.getFaultDetails().get(0), "DETAIL1");259 Assert.assertEquals(message.getFaultDetails().get(1), "DETAIL2");260 return null;261 }).when(messageProducer).send(any(Message.class), any(TestContext.class));262 MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {263 @Override...

Full Screen

Full Screen

testSendSoapFault

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.dsl.runner;2import com.consol.citrus.dsl.runner.core.TestRunner;3import com.consol.citrus.dsl.runner.core.TestRunnerCore;4import com.consol.citrus.exceptions.CitrusRuntimeException;5import com.consol.citrus.message.MessageType;6import com.consol.citrus.testng.AbstractTestNGUnitTest;7import com.consol.citrus.validation.builder.DefaultMessageBuilder;8import com.consol.citrus.validation.xml.XmlMessageValidationContext;9import com.consol.citrus.ws.actions.SoapFaultAction;10import org.mockito.Mockito;11import org.springframework.core.io.ClassPathResource;12import org.springframework.core.io.Resource;13import org.springframework.ws.soap.SoapFault;14import org.springframework.ws.soap.SoapFaultDetail;15import org.springframework.ws.soap.SoapFaultDetailElement;16import org.springframework.ws.soap.SoapFaultDetailElementName;17import org.springframework.ws.soap.SoapFaultReason;18import org.springframework.ws.soap.SoapFaultReasonText;19import org.springframework.ws.soap.SoapVersion;20import org.springframework.ws.soap.client.SoapFaultClientException;21import org.testng.Assert;22import org.testng.annotations.Test;23import javax.xml.namespace.QName;24import java.util.ArrayList;25import java.util.List;26import static org.mockito.Mockito.*;27public class SendSoapFaultTestRunnerTest extends AbstractTestNGUnitTest {28 private SoapFaultClientException soapFaultClientException;29 public void testSendSoapFault() {30 reset(applicationContext);31 SoapFaultAction soapFaultAction = Mockito.spy(new SoapFaultAction());32 soapFaultAction.setApplicationContext(applicationContext);33 SoapVersion soapVersion = mock(SoapVersion.class);34 SoapFaultDetailElementName soapFaultDetailElementName = mock(SoapFaultDetailElementName.class);35 when(soapFaultDetailElementName.getText()).thenReturn("detail");36 SoapFaultDetailElement soapFaultDetailElement = mock(SoapFaultDetailElement.class);37 when(soapFaultDetailElement.getName()).thenReturn(soapFaultDetailElementName);38 SoapFaultDetail soapFaultDetail = mock(SoapFaultDetail.class);39 when(soapFaultDetail.getDetailEntries()).thenReturn(new SoapFaultDetail

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