I am learning how to use ReadyAPI and trying to validate a response's XML content against a Schema file. My code is pretty simple, but I am receiving "Could not find named-arg compatible constructor". I have confirmed the existence of the schema file. And that there is an appropriate response in XML format. I have peppered the code with logs but still don't have any idea where to focus.
import javax.xml.XMLConstants
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.SchemaFactory
import com.eviware.soapui.support.XmlHolder
// retrieve schema file
def xsdSchema = "/schema/v2_0/qm.xsd"
log.info xsdSchema.toString()
// get the XML Response
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def response = groovyUtils.getXmlHolder( 'Get Test Case Result#ResponseAsXML' )
log.info response
// create validation objects
def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
def schema = factory.newSchema(new StreamSource(xsdSchema))
def validator = schema.newValidator()
log.info factory.toString()
log.info schema.toString()
log.info validator.toString()
// Validate the response against the schema
assert validator.validate(new StreamSource(new StringReader(response))) == null // This is line 28
The output of my logs are as follows:
Wed Jan 25 13:15:43 EST 2023: INFO: /schema/v2_0/qm.xsd
Wed Jan 25 13:15:43 EST 2023: INFO: com.eviware.soapui.support.XmlHolder@79c0a307
Wed Jan 25 13:15:44 EST 2023: INFO: org.apache.xerces.jaxp.validation.XMLSchemaFactory@a4effe4
Wed Jan 25 13:15:44 EST 2023: INFO: org.apache.xerces.jaxp.validation.XMLSchema@1a8a805d
Wed Jan 25 13:15:44 EST 2023: INFO: org.apache.xerces.jaxp.validation.ValidatorImpl@201dce24
Full Error message:
groovy.lang.GroovyRuntimeException: Could not find named-arg compatible constructor. Expecting one of:
java.io.StringReader(com.eviware.soapui.support.XmlHolder)
java.io.StringReader()
error at line: 28