Best Citrus code snippet using com.consol.citrus.dsl.runner.SendSoapFaultTestRunnerTest.execute
Source:SendSoapFaultTestRunnerTest.java
...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 @Override264 public void execute() {265 soap(builder -> builder.server(soapServer)266 .sendFault()267 .faultCode(FAULT_CODE)268 .faultDetail("DETAIL1")269 .faultDetail("DETAIL2")270 .faultString(FAULT_STRING));271 }272 };273 TestCase test = builder.getTestCase();274 Assert.assertEquals(test.getActionCount(), 1);275 Assert.assertEquals(test.getActions().get(0).getClass(), DelegatingTestAction.class);276 SendSoapFaultAction action = (SendSoapFaultAction)((DelegatingTestAction)test.getActions().get(0)).getDelegate();277 Assert.assertEquals(action.getName(), "send");278 Assert.assertEquals(action.getEndpoint(), soapServer);...
execute
Using AI Code Generation
1package com.consol.citrus.dsl.runner;2import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;3import com.consol.citrus.exceptions.CitrusRuntimeException;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.testng.CitrusParameters;6import com.consol.citrus.validation.xml.XmlMessageValidationContext;7import com.consol.citrus.ws.message.SoapFault;8import org.testng.Assert;9import org.testng.annotations.Test;10import java.util.Collections;11import static com.consol.citrus.actions.EchoAction.Builder.echo;12import static com.consol.citrus.actions.FailAction.Builder.fail;13import static com.consol.citrus.actions.SendMessageAction.Builder.withSoapFault;14import static com.consol.citrus.actions.SleepAction.Builder.sleep;15import static com.consol.citrus.actions.StopTimeAction.Builder.stopTime;16import static com.consol.citrus.actions.TraceVariablesAction.Builder.traceVariables;17import static com.consol.citrus.actions.TraceVariablesAction.Builder.traceVariablesAction;18import static com.consol.citrus.actions.ValidateSoapFault.Builder.validateSoapFault;19import static com.consol.citrus.actions.WaitAction.Builder.waitFor;20public class SendSoapFaultTestRunnerTest extends TestNGCitrusTestRunner {21 @CitrusParameters({ "faultCode", "faultString", "faultActor", "faultDetail", "faultDetailResourcePath" })22 public void testSendSoapFault(String faultCode, String faultString, String faultActor, String faultDetail, String faultDetailResourcePath) {23 description("This is a SOAP fault test");24 variable("faultCode", faultCode);25 variable("faultString", faultString);26 variable("faultActor", faultActor);27 variable("faultDetail", faultDetail);28 variable("faultDetailResourcePath", faultDetailResourcePath);29 sendSoapFault()30 .soapFault(SoapFault.serverOrReceiverFault()31 .faultCode("${faultCode}")32 .faultString("${faultString}")33 .faultActor("${faultActor}")34 .faultDetail("${faultDetail}")35 .faultDetailResourcePath("${faultDetailResourcePath}"))36 .messageType(MessageType.XML)37 .header("operation", "fooOperation")38 .header("foo:operation", "fooOperation")39 .header("foo:operation", "
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!