How to use AssertSoapFault method of com.consol.citrus.ws.actions.AssertSoapFault class

Best Citrus code snippet using com.consol.citrus.ws.actions.AssertSoapFault.AssertSoapFault

Source:AssertSoapFault.java Github

copy

Full Screen

...39 * 40 * @author Christoph Deppisch 41 * @since 200942 */43public class AssertSoapFault extends AbstractActionContainer {44 /** TestAction to be executed */45 private TestAction action;46 /** Localized fault string */47 private String faultString = null;48 49 /** OName representing fault code */50 private String faultCode = null;51 52 /** Fault actor */53 private String faultActor = null;54 55 /** List of fault details, either inline data or file resource path */56 private List<String> faultDetails = new ArrayList<String>();57 /** List of fault detail resource paths */58 private List<String> faultDetailResourcePaths = new ArrayList<String>();59 60 /** Soap fault validator implementation */61 private SoapFaultValidator validator = new SimpleSoapFaultValidator();62 63 /** Validation context */64 private ValidationContext validationContext;65 66 /** Logger */67 private static Logger log = LoggerFactory.getLogger(AssertSoapFault.class);68 /**69 * Default constructor.70 */71 public AssertSoapFault() {72 setName("soap-fault");73 }74 @Override75 public void doExecute(TestContext context) {76 log.debug("Asserting SOAP fault ...");77 try {78 action.execute(context);79 } catch (SoapFaultClientException soapFaultException) {80 log.debug("Validating SOAP fault ...");81 82 SoapFault controlFault = constructControlFault(context);83 84 validator.validateSoapFault(SoapFault.from(soapFaultException.getSoapFault()), controlFault, context, validationContext);85 86 log.debug("Asserted SOAP fault as expected: " + soapFaultException.getFaultCode() + ": " + soapFaultException.getFaultStringOrReason());87 log.info("Assert SOAP fault validation successful");88 89 return;90 } catch (RuntimeException e) {91 throw new ValidationException("SOAP fault validation failed for asserted exception type - expected: '" + 92 SoapFaultClientException.class + "' but was: '" + e.getClass().getName() + "'", e);93 } catch (Exception e) {94 throw new ValidationException("SOAP fault validation failed for asserted exception type - expected: '" + 95 SoapFaultClientException.class + "' but was: '" + e.getClass().getName() + "'", e);96 }97 98 throw new ValidationException("SOAP fault validation failed! Missing asserted SOAP fault exception");99 }100 /**101 * Constructs the control soap fault holding all expected fault information102 * like faultCode, faultString and faultDetail.103 * 104 * @return the constructed SoapFault instance.105 */106 private SoapFault constructControlFault(TestContext context) {107 SoapFault controlFault= new SoapFault();108 if (StringUtils.hasText(faultActor)) {109 controlFault.faultActor(context.replaceDynamicContentInString(faultActor));110 }111 controlFault.faultCode(context.replaceDynamicContentInString(faultCode));112 controlFault.faultString(context.replaceDynamicContentInString(faultString));113 for (String faultDetail : faultDetails) {114 controlFault.addFaultDetail(context.replaceDynamicContentInString(faultDetail));115 }116 try {117 for (String faultDetailPath : faultDetailResourcePaths) {118 String resourcePath = context.replaceDynamicContentInString(faultDetailPath);119 controlFault.addFaultDetail(context.replaceDynamicContentInString(FileUtils.readToString(FileUtils.getFileResource(resourcePath, context), FileUtils.getCharset(resourcePath))));120 }121 } catch (IOException e) {122 throw new CitrusRuntimeException("Failed to create SOAP fault detail from file resource", e);123 }124 return controlFault;125 }126 /**127 * Set the nested test action.128 * @param action the action to set129 */130 public AssertSoapFault setAction(TestAction action) {131 addTestAction(action);132 return this;133 }134 /**135 * Set the fault code.136 * @param faultCode the faultCode to set137 */138 public AssertSoapFault setFaultCode(String faultCode) {139 this.faultCode = faultCode;140 return this;141 }142 /**143 * Set the fault string.144 * @param faultString the faultString to set145 */146 public AssertSoapFault setFaultString(String faultString) {147 this.faultString = faultString;148 return this;149 }150 /**151 * @param validator the validator to set152 */153 public AssertSoapFault setValidator(SoapFaultValidator validator) {154 this.validator = validator;155 return this;156 }157 @Override158 public AssertSoapFault addTestAction(TestAction action) {159 this.action = action;160 super.addTestAction(action);161 return this;162 }163 @Override164 public TestAction getTestAction(int index) {165 if (index == 0) {166 return action;167 } else {168 throw new IndexOutOfBoundsException("Illegal index in action list:" + index);169 }170 }171 @Override172 public AssertSoapFault setActions(List<TestAction> actions) {173 if (actions.size() > 1) {174 throw new CitrusRuntimeException("Invalid number of nested test actions - only one single nested action is allowed");175 }176 action = actions.get(0);177 super.setActions(actions);178 return this;179 }180 /**181 * Gets the action.182 * @return the action183 */184 public TestAction getAction() {185 return action;186 }187 /**188 * Gets the faultString.189 * @return the faultString190 */191 public String getFaultString() {192 return faultString;193 }194 /**195 * Gets the faultCode.196 * @return the faultCode197 */198 public String getFaultCode() {199 return faultCode;200 }201 /**202 * Gets the list of fault details.203 * @return the faultDetails204 */205 public List<String> getFaultDetails() {206 return faultDetails;207 }208 209 /**210 * Sets the faultDetails.211 * @param faultDetails the faultDetails to set212 */213 public AssertSoapFault setFaultDetails(List<String> faultDetails) {214 this.faultDetails = faultDetails;215 return this;216 }217 /**218 * Gets the fault detail resource paths.219 * @return220 */221 public List<String> getFaultDetailResourcePaths() {222 return faultDetailResourcePaths;223 }224 /**225 * Sets the fault detail resource paths.226 * @param faultDetailResourcePaths227 */228 public AssertSoapFault setFaultDetailResourcePaths(List<String> faultDetailResourcePaths) {229 this.faultDetailResourcePaths = faultDetailResourcePaths;230 return this;231 }232 /**233 * Gets the validator.234 * @return the validator235 */236 public SoapFaultValidator getValidator() {237 return validator;238 }239 /**240 * Gets the faultActor.241 * @return the faultActor the faultActor to get.242 */243 public String getFaultActor() {244 return faultActor;245 }246 /**247 * Sets the faultActor.248 * @param faultActor the faultActor to set249 */250 public AssertSoapFault setFaultActor(String faultActor) {251 this.faultActor = faultActor;252 return this;253 }254 /**255 * Gets the validationContext.256 * @return the validationContext the validationContext to get.257 */258 public ValidationContext getValidationContext() {259 return validationContext;260 }261 /**262 * Sets the validationContext.263 * @param validationContext the validationContext to set264 */265 public AssertSoapFault setValidationContext(ValidationContext validationContext) {266 this.validationContext = validationContext;267 return this;268 }269 270}...

Full Screen

Full Screen

Source:SchemaValidation_Error_1_IT.java Github

copy

Full Screen

...18import com.consol.citrus.testng.spring.TestNGCitrusSpringSupport;19import com.consol.citrus.ws.client.WebServiceClient;20import org.springframework.beans.factory.annotation.Autowired;21import org.testng.annotations.Test;22import static com.consol.citrus.ws.actions.AssertSoapFault.Builder.assertSoapFault;23import static com.consol.citrus.ws.actions.SoapActionBuilder.soap;24/**25 * @author Christoph Deppisch26 */27public class SchemaValidation_Error_1_IT extends TestNGCitrusSpringSupport {28 @Autowired29 private WebServiceClient bookStoreClient;30 @Test31 @CitrusTest(name = "SchemaValidation_Error_1_IT")32 public void schemaValidation_Error_1_IT() {33 description("This test gets schema validation errors in SOAP fault response from server as the request is not " +34 "valid ('year'=>'03.Okt.2008' not a valid number).");35 variable("isbn", "978-0596517335");36 variable("faultCode", "{http://www.consol.com/citrus/samples/errorcodes}CITRUS:999");...

Full Screen

Full Screen

Source:GetBookDetails_Error_1_IT.java Github

copy

Full Screen

...18import com.consol.citrus.testng.spring.TestNGCitrusSpringSupport;19import com.consol.citrus.ws.client.WebServiceClient;20import org.springframework.beans.factory.annotation.Autowired;21import org.testng.annotations.Test;22import static com.consol.citrus.ws.actions.AssertSoapFault.Builder.assertSoapFault;23import static com.consol.citrus.ws.actions.SoapActionBuilder.soap;24/**25 * @author Christoph Deppisch26 */27public class GetBookDetails_Error_1_IT extends TestNGCitrusSpringSupport {28 @Autowired29 private WebServiceClient bookStoreClient;30 @Test31 @CitrusTest(name = "GetBookDetails_Error_1_IT")32 public void getBookDetails_Error_1_IT() {33 description("This test forces a SOAP fault in WebService response. Citrus asks for book details regarding a non-existent book." +34 "SOAP WebService server creates a SOAP fault that is validated in Citrus.");35 variable("isbn", "000-0000000000");36 variable("faultCode", "{http://www.consol.com/citrus/samples/errorcodes}CITRUS:1002");...

Full Screen

Full Screen

AssertSoapFault

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.actions;2import com.consol.citrus.context.TestContext;3import com.consol.citrus.testng.AbstractTestNGUnitTest;4import com.consol.citrus.ws.message.SoapFault;5import com.consol.citrus.ws.validation.SoapFaultValidator;6import org.mockito.Mockito;7import org.springframework.ws.soap.SoapFaultDetail;8import org.springframework.ws.soap.SoapFaultDetailElement;9import org.springframework.ws.soap.SoapFaultDetailElementName;10import org.springframework.ws.soap.SoapFaultDetailException;11import org.springframework.ws.soap.SoapFaultDetailSource;12import org.springframework.ws.soap.SoapFaultDetailText;13import org.springframework.ws.soap.SoapFaultElement;14import org.springframework.ws.soap.SoapFaultElementName;15import org.springframework.ws.soap.SoapFaultException;16import org.springframework.ws.soap.SoapFaultReason;17import org.springframework.ws.soap.SoapFaultSource;18import org.springframework.ws.soap.SoapMessage;19import org.springframework.ws.soap.SoapMessageFactory;20import org.springframework.ws.soap.SoapMessageHeader;21import org.springframework.ws.soap.SoapVersion;22import org.springframework.ws.soap.client.SoapFaultClientException;23import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;24import org.testng.Assert;25import org.testng.annotations.BeforeClass;26import org.testng.annotations.Test;27import javax.xml.namespace.QName;28import javax.xml.soap.MessageFactory;29import javax.xml.soap.SOAPException;30import javax.xml.soap.SOAPFactory;31import javax.xml.soap.SOAPFault;32import java.util.Locale;33import static org.mockito.Mockito.*;34public class AssertSoapFaultTest extends AbstractTestNGUnitTest {35 private SoapFaultValidator soapFaultValidator = Mockito.mock(SoapFaultValidator.class);36 private SoapFault soapFault = Mockito.mock(SoapFault.class);37 private SoapFault soapFault1 = Mockito.mock(SoapFault.class);38 private SoapFault soapFault2 = Mockito.mock(SoapFault.class);39 private SoapFault soapFault3 = Mockito.mock(SoapFault.class);40 private SoapFault soapFault4 = Mockito.mock(SoapFault.class);41 private SoapFault soapFault5 = Mockito.mock(SoapFault.class);42 private SoapFault soapFault6 = Mockito.mock(SoapFault.class);43 private SoapFault soapFault7 = Mockito.mock(SoapFault.class);

Full Screen

Full Screen

AssertSoapFault

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.actions;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import org.springframework.core.io.ClassPathResource;4import org.testng.annotations.Test;5public class AssertSoapFaultJavaIT extends TestNGCitrusTestDesigner {6 public void configure() {7 soap().client(soapClient)8 .send()9 .payload(new ClassPathResource("templates/soap-fault-request-payload.xml"));10 soap().client(soapClient)11 .receive()12 .payload(new ClassPathResource("templates/soap-fault-response-payload.xml"));13 soap().client(soapClient)14 .send()15 .payload(new ClassPathResource("templates/soap-fault-request-payload.xml"));16 soap().client(soapClient)17 .receive()18 .payload(new ClassPathResource("templates/soap-fault-response-payload.xml"));19 soap().client(soapClient)20 .send()21 .payload(new ClassPathResource("templates/soap-fault-request-payload.xml"));22 soap().client(soapClient)23 .receive()24 .payload(new ClassPathResource("templates/soap-fault-response-payload.xml"));25 soap().client(soapClient)26 .send()27 .payload(new ClassPathResource("templates/soap-fault-request-payload.xml"));28 soap().client(soapClient)29 .receive()30 .payload(new ClassPathResource("templates/soap-fault-response-payload.xml"));31 soap().client(soapClient)32 .send()33 .payload(new ClassPathResource("templates/soap-fault-request-payload.xml"));34 soap().client(soapClient)35 .receive()36 .payload(new ClassPathResource("templates/soap-fault-response-payload.xml"));37 soap().client(soapClient)38 .send()39 .payload(new ClassPathResource("templates/soap-fault-request-payload.xml"));40 soap().client(soapClient)41 .receive()42 .payload(new ClassPathResource("templates/soap-fault-response-payload.xml"));43 soap().client(soapClient)44 .send()45 .payload(new ClassPathResource("templates/soap-fault-request-payload.xml"));46 soap().client(soapClient)47 .receive()48 .payload(new ClassPathResource("templates/soap-fault-response-payload.xml"));49 soap().client(soapClient)

Full Screen

Full Screen

AssertSoapFault

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.actions;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import org.springframework.http.HttpStatus;4import org.testng.annotations.Test;5public class AssertSoapFaultJavaIT extends TestNGCitrusTestDesigner {6 public void assertSoapFaultJavaIT() {7 variable("faultCode", "soap:Server");8 variable("faultString", "Internal Server Error");9 variable("faultDetail", "<faultDetail>Internal Server Error</faultDetail>");10 http().client("httpClient")11 .send()12 .post("/services/someService");13 http().client("httpClient")14 .receive()15 .response(HttpStatus.INTERNAL_SERVER_ERROR);16 assertSoapFault()17 .faultCode("${faultCode}")18 .faultString("${faultString}")19 .faultActor("${faultActor}")20 .faultDetail("${faultDetail}");21 }22}23package com.consol.citrus.ws.actions;24import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;25import org.springframework.http.HttpStatus;26import org.testng.annotations.Test;27public class AssertSoapFaultJavaIT extends TestNGCitrusTestDesigner {28 public void assertSoapFaultJavaIT() {29 variable("faultCode", "soap:Server");30 variable("faultString", "Internal Server Error");31 variable("faultDetail", "<faultDetail>Internal Server Error</faultDetail>");32 http().client("httpClient")33 .send()34 .post("/services/someService");35 http().client("httpClient")36 .receive()37 .response(HttpStatus.INTERNAL_SERVER_ERROR);38 assertSoapFault()39 .faultCode("${faultCode}")40 .faultString("${faultString}")41 .faultActor("${faultActor}")42 .faultDetail("${faultDetail}")43 .messageName("faultMessage");44 }45}46package com.consol.citrus.ws.actions;47import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;48import org.springframework.http.HttpStatus;49import org

Full Screen

Full Screen

AssertSoapFault

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.actions;2import com.consol.citrus.ws.message.SoapFault;3import com.consol.citrus.ws.validation.SoapFaultValidator;4import org.springframework.ws.soap.SoapFaultDetail;5import org.springframework.ws.soap.SoapFaultDetailElement;6import javax.xml.namespace.QName;7import java.util.ArrayList;8import java.util.Collections;9import java.util.List;10public class AssertSoapFault extends AbstractSoapFaultAction<AssertSoapFault> {11 private SoapFaultValidator faultValidator = new SoapFaultValidator();12 private String faultCode;13 private String faultString;14 private String faultDetail;15 private List<SoapFaultDetailElement> faultDetailElements = new ArrayList<SoapFaultDetailElement>();16 private List<SoapFaultDetailElement> faultDetailElementsToIgnore = new ArrayList<SoapFaultDetailElement>();17 private List<QName> faultDetailElementQNames = new ArrayList<QName>();18 private List<QName> faultDetailElementQNamesToIgnore = new ArrayList<QName>();19 private List<String> faultDetailElementNamespaces = new ArrayList<String>();20 private List<String> faultDetailElementNamespacesToIgnore = new ArrayList<String>();21 private List<String> faultDetailElementLocalNames = new ArrayList<String>();22 private List<String> faultDetailElementLocalNamesToIgnore = new ArrayList<String>();23 private List<String> faultDetailElementValues = new ArrayList<String>();24 private List<String> faultDetailElementValuesToIgnore = new ArrayList<String>();25 public void doExecute() {26 SoapFault soapFault = getFault();27 if (soapFault == null) {28 throw new AssertionError("No SOAP fault in received message!");29 }30 if (fault

Full Screen

Full Screen

AssertSoapFault

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ws.samples;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import org.springframework.http.HttpStatus;4import org.springframework.http.MediaType;5import org.springframework.web.bind.annotation.RequestMethod;6import org.testng.annotations.Test;7public class AssertSoapFaultIT extends TestNGCitrusTestDesigner {8 public void assertSoapFaultTest() {9 variable("name", "citrus:concat('Hello ', citrus:randomString(8))");10 http(builder -> builder.client("httpClient")11 .send()12 .post()13 "<ns0:Message>${name}</ns0:Message>" +14 .contentType(MediaType.APPLICATION_XML_VALUE));15 http(builder -> builder.client("httpClient")16 .receive()17 .response(HttpStatus.BAD_REQUEST)18 .contentType(MediaType.APPLICATION_XML_VALUE)19 "</soapenv:Envelope>"));20 assertSoapFault(builder -> builder.faultCode("soapenv:Client")21 .faultString("Invalid request")22 "<ns0:Message>${name}</ns0:Message>" +23 "</ns0:SayHello>"));24 http(builder -> builder.client("httpClient")25 .send()26 .post()27 "<ns0:Message>${name}</ns0:Message>" +28 .contentType(MediaType.APPLICATION_XML_VALUE));29 http(builder -> builder.client

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