Best Citrus code snippet using com.consol.citrus.ws.actions.AssertSoapFaultTest.testAssertSoapFault
Source:AssertSoapFaultTest.java
...42 @Autowired43 private SoapFaultValidator soapFaultValidator;44 45 @Test46 public void testAssertSoapFault() throws Exception {47 AssertSoapFault assertAction = new AssertSoapFault();48 assertAction.setValidator(soapFaultValidator);49 assertAction.setAction(new AbstractTestAction() {50 @Override51 public void doExecute(TestContext context) {52 SoapMessage faultMessage;53 54 faultMessage = messageFactory.createWebServiceMessage();55 56 Soap11Fault fault = ((Soap11Body)faultMessage.getSoapBody()).addFault(QNameUtils.parseQNameString("{http://citrusframework.org}ws:TEC-1001"), 57 "Internal server error", 58 Locale.GERMANY);59 60 fault.setFaultActorOrRole("SERVER");61 62 throw new SoapFaultClientException(faultMessage);63 }64 });65 66 assertAction.setFaultString("Internal server error");67 assertAction.setFaultCode("{http://citrusframework.org}ws:TEC-1001");68 assertAction.setFaultActor("SERVER");69 70 assertAction.execute(context);71 }72 73 @Test74 public void testAssertSoapFaultWithValidationMatchers() throws Exception {75 AssertSoapFault assertAction = new AssertSoapFault();76 assertAction.setValidator(soapFaultValidator);77 assertAction.setAction(new AbstractTestAction() {78 @Override79 public void doExecute(TestContext context) {80 SoapMessage faultMessage;81 82 faultMessage = messageFactory.createWebServiceMessage();83 84 Soap11Fault fault = ((Soap11Body)faultMessage.getSoapBody()).addFault(QNameUtils.parseQNameString("{http://citrusframework.org}ws:TEC-1001"), 85 "Internal server error", 86 Locale.GERMANY);87 88 fault.setFaultActorOrRole("SERVER");89 90 throw new SoapFaultClientException(faultMessage);91 }92 });93 94 assertAction.setFaultString("@equalsIgnoreCase('internal server error')@");95 assertAction.setFaultCode("{http://citrusframework.org}ws:TEC-1001");96 assertAction.setFaultActor("@equalsIgnoreCase('server')@");97 98 assertAction.execute(context);99 }100 101 @Test102 public void testNoPrefix() throws Exception {103 AssertSoapFault assertAction = new AssertSoapFault();104 assertAction.setValidator(soapFaultValidator);105 assertAction.setAction(new AbstractTestAction() {106 @Override107 public void doExecute(TestContext context) {108 SoapMessage faultMessage;109 110 faultMessage = messageFactory.createWebServiceMessage();111 112 ((Soap11Body)faultMessage.getSoapBody()).addFault(QNameUtils.parseQNameString("{http://citrusframework.org}TEC-1001"), 113 "Internal server error", 114 Locale.GERMANY);115 116 throw new SoapFaultClientException(faultMessage);117 }118 });119 120 assertAction.setFaultString("Internal server error");121 assertAction.setFaultCode("{http://citrusframework.org}TEC-1001");122 123 assertAction.execute(context);124 }125 126 @Test127 public void testWrongFaultCode() throws Exception {128 AssertSoapFault assertAction = new AssertSoapFault();129 assertAction.setValidator(soapFaultValidator);130 assertAction.setAction(new AbstractTestAction() {131 @Override132 public void doExecute(TestContext context) {133 SoapMessage faultMessage;134 135 faultMessage = messageFactory.createWebServiceMessage();136 137 ((Soap11Body)faultMessage.getSoapBody()).addFault(QNameUtils.parseQNameString("{http://citrusframework.org}ws:TEC-2002"), 138 "Internal server error", 139 Locale.GERMANY);140 141 throw new SoapFaultClientException(faultMessage);142 }143 });144 145 assertAction.setFaultString("Internal server error");146 assertAction.setFaultCode("{http://citrusframework.org}ws:TEC-1001");147 148 try {149 assertAction.execute(context);150 } catch(IllegalArgumentException e) {151 Assert.assertEquals(e.getMessage(), "SOAP fault validation failed! Fault code does not match - expected: '{http://citrusframework.org}TEC-1001' but was: '{http://citrusframework.org}TEC-2002'");152 return;153 }154 155 Assert.fail("Missing validation exception");156 }157 158 @Test159 public void testWrongFaultActor() throws Exception {160 AssertSoapFault assertAction = new AssertSoapFault();161 assertAction.setValidator(soapFaultValidator);162 assertAction.setAction(new AbstractTestAction() {163 @Override164 public void doExecute(TestContext context) {165 SoapMessage faultMessage;166 faultMessage = messageFactory.createWebServiceMessage();167 168 Soap11Fault fault = ((Soap11Body)faultMessage.getSoapBody()).addFault(QNameUtils.parseQNameString("{http://citrusframework.org}ws:TEC-1001"), 169 "Internal server error", 170 Locale.GERMANY);171 172 fault.setFaultActorOrRole("CLIENT");173 174 throw new SoapFaultClientException(faultMessage);175 }176 });177 178 assertAction.setFaultString("Internal server error");179 assertAction.setFaultCode("{http://citrusframework.org}ws:TEC-1001");180 assertAction.setFaultActor("SERVER");181 182 try {183 assertAction.execute(context);184 } catch(IllegalArgumentException e) {185 Assert.assertEquals(e.getMessage(), "SOAP fault validation failed! Fault actor does not match - expected: 'SERVER' but was: 'CLIENT'");186 return;187 }188 189 Assert.fail("Missing validation exception");190 }191 192 @Test193 public void testWrongFaultString() throws Exception {194 AssertSoapFault assertAction = new AssertSoapFault();195 assertAction.setValidator(soapFaultValidator);196 assertAction.setAction(new AbstractTestAction() {197 @Override198 public void doExecute(TestContext context) {199 SoapMessage faultMessage;200 201 faultMessage = messageFactory.createWebServiceMessage();202 203 ((Soap11Body)faultMessage.getSoapBody()).addFault(QNameUtils.parseQNameString("{http://citrusframework.org}ws:TEC-1001"), 204 "Internal server error", 205 Locale.GERMANY);206 207 throw new SoapFaultClientException(faultMessage);208 }209 });210 211 assertAction.setFaultString("Invalid request");212 assertAction.setFaultCode("{http://citrusframework.org}ws:TEC-1001");213 214 try {215 assertAction.execute(context);216 } catch(ValidationException e) {217 Assert.assertEquals(e.getMessage(), "SOAP fault validation failed! Fault string does not match - expected: 'Invalid request' but was: 'Internal server error'");218 return;219 }220 221 Assert.fail("Missing validation exception");222 }223 224 @Test225 public void testAssertSoapFaultDetail() throws Exception {226 AssertSoapFault assertAction = new AssertSoapFault();227 assertAction.setValidator(soapFaultValidator);228 assertAction.setAction(new AbstractTestAction() {229 @Override230 public void doExecute(TestContext context) {231 SoapMessage faultMessage;232 233 faultMessage = messageFactory.createWebServiceMessage();234 235 SoapFault fault =((Soap11Body)faultMessage.getSoapBody()).addFault(QNameUtils.parseQNameString("{http://citrusframework.org}ws:TEC-1001"), 236 "Internal server error", 237 Locale.GERMANY);238 239 try {240 TransformerFactory transformerFactory = TransformerFactory.newInstance();241 Transformer transformer = transformerFactory.newTransformer();242 transformer.transform(new StringSource("<FaultDetail><Reason>Invalid request</Reason></FaultDetail>"), fault.addFaultDetail().getResult());243 } catch (TransformerException e) {244 throw new CitrusRuntimeException(e);245 }246 247 throw new SoapFaultClientException(faultMessage);248 }249 });250 251 assertAction.setFaultString("Internal server error");252 assertAction.setFaultCode("{http://citrusframework.org}ws:TEC-1001");253 assertAction.getFaultDetails().add("<FaultDetail><Reason>Invalid request</Reason></FaultDetail>");254 255 assertAction.execute(context);256 }257 258 @Test259 public void testAssertSoapFaultDetailVariableSupport() throws Exception {260 AssertSoapFault assertAction = new AssertSoapFault();261 assertAction.setValidator(soapFaultValidator);262 assertAction.setAction(new AbstractTestAction() {263 @Override264 public void doExecute(TestContext context) {265 SoapMessage faultMessage;266 267 faultMessage = messageFactory.createWebServiceMessage();268 269 SoapFault fault =((Soap11Body)faultMessage.getSoapBody()).addFault(QNameUtils.parseQNameString("{http://citrusframework.org}ws:TEC-1001"), 270 "Internal server error", 271 Locale.GERMANY);272 273 try {274 TransformerFactory transformerFactory = TransformerFactory.newInstance();275 Transformer transformer = transformerFactory.newTransformer();276 transformer.transform(new StringSource("<FaultDetail><Reason>Invalid request</Reason></FaultDetail>"), fault.addFaultDetail().getResult());277 } catch (TransformerException e) {278 throw new CitrusRuntimeException(e);279 }280 281 throw new SoapFaultClientException(faultMessage);282 }283 });284 285 context.setVariable("faultReason", "Invalid request");286 287 assertAction.setFaultString("Internal server error");288 assertAction.setFaultCode("{http://citrusframework.org}ws:TEC-1001");289 assertAction.getFaultDetails().add("<FaultDetail><Reason>${faultReason}</Reason></FaultDetail>");290 291 assertAction.execute(context);292 }293 294 @Test295 public void testAssertSoapFaultDetailResource() throws Exception {296 AssertSoapFault assertAction = new AssertSoapFault();297 assertAction.setValidator(soapFaultValidator);298 assertAction.setAction(new AbstractTestAction() {299 @Override300 public void doExecute(TestContext context) {301 SoapMessage faultMessage;302 303 faultMessage = messageFactory.createWebServiceMessage();304 305 SoapFault fault =((Soap11Body)faultMessage.getSoapBody()).addFault(QNameUtils.parseQNameString("{http://citrusframework.org}ws:TEC-1001"), 306 "Internal server error", 307 Locale.GERMANY);308 309 try {310 TransformerFactory transformerFactory = TransformerFactory.newInstance();311 Transformer transformer = transformerFactory.newTransformer();312 transformer.transform(new StringSource("<FaultDetail><Reason>Invalid request</Reason></FaultDetail>"), fault.addFaultDetail().getResult());313 } catch (TransformerException e) {314 throw new CitrusRuntimeException(e);315 }316 317 throw new SoapFaultClientException(faultMessage);318 }319 });320 321 assertAction.setFaultString("Internal server error");322 assertAction.setFaultCode("{http://citrusframework.org}ws:TEC-1001");323 assertAction.getFaultDetailResourcePaths().add("classpath:com/consol/citrus/ws/actions/test-fault-detail.xml");324 325 assertAction.execute(context);326 }327 328 @Test329 public void testAssertSoapFaultDetailResourceVariableSupport() throws Exception {330 AssertSoapFault assertAction = new AssertSoapFault();331 assertAction.setValidator(soapFaultValidator);332 assertAction.setAction(new AbstractTestAction() {333 @Override334 public void doExecute(TestContext context) {335 SoapMessage faultMessage;336 337 faultMessage = messageFactory.createWebServiceMessage();338 339 SoapFault fault =((Soap11Body)faultMessage.getSoapBody()).addFault(QNameUtils.parseQNameString("{http://citrusframework.org}ws:TEC-1001"), 340 "Internal server error", 341 Locale.GERMANY);342 343 try {...
testAssertSoapFault
Using AI Code Generation
1package com.consol.citrus.ws.actions;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import com.consol.citrus.ws.client.WebServiceClient;5import com.consol.citrus.ws.message.SoapFault;6import org.springframework.beans.factory.annotation.Autowired;7import org.springframework.core.io.ClassPathResource;8import org.testng.annotations.Test;9public class AssertSoapFaultTestIT extends TestNGCitrusTestRunner {10 private WebServiceClient webServiceClient;11 public void testAssertSoapFault() {12 variable("faultString", "SOAP Fault: Server was unable to process request. ---> java.lang.RuntimeException: Error in business logic");13 variable("faultCode", "soap:Server");14 send(webServiceClient)15 .soap()16 .header("operation", "GetWeather")17 .header("Content-Type", "text/xml")18 .header("Accept-Encoding", "gzip,deflate")19 receive(webServiceClient)20 .soap()21 .header("operation", "GetWeather")22 .header("Content-Type", "text/xml")23 .header("Accept-Encoding", "gzip,deflate")
testAssertSoapFault
Using AI Code Generation
1public void testAssertSoapFault() {2 run(new TestActionBuilder() {3 public void doExecute(TestRunner runner) {4 runner.soap().assertSoapFault(new AssertSoapFault.Builder()5 .faultString("Fault string")6 .faultActor("Fault actor")7 .build());8 }9 });10}
testAssertSoapFault
Using AI Code Generation
1public void testAssertSoapFault() {2 MockWebServiceServer mockServer = MockWebServiceServer.createServer(applicationContext, "soapFaultClient");3 run(new TestRunner(getClass().getResource("testAssertSoapFault.xml")));4 mockServer.verify();5}6public function testAssertSoapFault() {7 var mockServer = MockWebServiceServer.createServer(applicationContext, "soapFaultClient");8 run(new TestRunner(getClass().getResource("testAssertSoapFault.xml")));9 mockServer.verify();10}11public void testAssertSoapFault() {12 MockWebServiceServer mockServer = MockWebServiceServer.createServer(applicationContext, "soapFaultClient");
testAssertSoapFault
Using AI Code Generation
1SoapFaultAction soapFaultAction = new SoapFaultAction();2soapFaultAction.setFaultString("Stockquote service not available");3soapFaultAction.setFaultDetail("<detail><message>Stockquote service not available</message></detail>");4soapFaultAction.setFaultDetailResource(new ClassPathResource("com/consol/citrus/ws/soap-fault-detail.xml"));5soapFaultAction.setFaultDetailResourcePath("classpath:com/consol/citrus/ws/soap-fault-detail.xml");6soapFaultAction.setFaultDetailFactory(new DefaultSoapFaultDetailFactory());7soapFaultAction.setFaultDetailFactoryName("faultDetailFactory");8soapFaultAction.setFaultDetailData("<detail><message>Stockquote service not available</message></detail>");9soapFaultAction.setFaultDetailDataResource(new ClassPathResource("com/consol/citrus/ws/soap-fault-detail.xml"));10soapFaultAction.setFaultDetailDataResourcePath("classpath:com/consol/citrus/ws/soap-fault-detail.xml"));11soapFaultAction.setFaultDetailDataFactory(new DefaultSoapFaultDetailDataFactory());12soapFaultAction.setFaultDetailDataFactoryName("faultDetailDataFactory");
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!!