SOAPUI: Validate response against xsd schema file
Question
How can I validate a SOAP response against an XSD file that defines the response schema. the web service I'm calling has an XMLDocument as input and output, so can't use WSDL for response schema validation.
Solution
I case you still need this (valid for SOAP UI version 2.5.1): File, Preferences, Editor Setting, Validate Response.
OTHER TIPS
Use script assertion:
def project = messageExchange.modelItem.testStep.testCase.testSuite.project
def wsdlcontext = project.getInterfaceAt(0).getDefinitionContext()
def validator = new com.eviware.soapui.impl.wsdl.support.wsdl.WsdlValidator(wsdlcontext);
def errors = validator.assertRequest(messageExchange, false)
assert errors.length < 1
You can use the groovy script for validation the response against the xsd file. Here is the way to validate
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.SchemaFactory;
import javax.xml.XMLConstants;
//Read your xsd file and get the conten into a variable like below.
def xsdContent = "Some Schema Standard";
//Take the response into another variable that you have to validate.
def actualXMLResponse = "Actual XML Response ";
//create a SchemaFactory object
def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
//Create a given schema object with help of factory
def schema = factory.newSchema(new StreamSource(new StringReader(xsdContent ));
//Create a validator
def validator = schema.newValidator();
//now validate the actual response against the given schema
try {
validator.validate(new StreamSource(new StringReader(actualXMLResponse )));
} catch(Exception e) {
log.info (e);
assert false;
}
I hope this will help you :-)