SOAPUI:验证对xsd模式文件的响应

时间:2008-11-25 11:11:54

标签: xsd wsdl soapui

如何针对定义响应模式的XSD文件验证SOAP响应。我正在调用的Web服务有一个XMLDocument作为输入和输出,因此不能使用WSDL进行响应模式验证。

4 个答案:

答案 0 :(得分:21)

我仍然需要这个(对于SOAP UI版本2.5.1有效): 文件,首选项,编辑器设置,验证响应。

答案 1 :(得分:1)

使用脚本断言:

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)

断言errors.length< 1

答案 2 :(得分:0)

您可以使用groovy脚本验证对xsd文件的响应。 以下是验证的方法

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;
}

我希望这会对你有所帮助: - )

答案 3 :(得分:-1)

这对我不起作用,导致尝试不起作用

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.
// trim - XSD SCHEME no spaces
def xsdscheme = context.expand('${Properties-XSD_Scheme_Black_and_White#XSDSchemeWhite}')
def xsdscheme2 = xsdscheme.replace(' ', '')
xsdscheme2 = xsdscheme2.replaceAll("[\n\r]", "");
log.info "RES2 TRIMED " + xsdscheme2
def xsdContent = xsdscheme2;

//Take the response into another variable that you have to validate.

Res = context.expand('${#TestCase#WhiteListDecoded}');
def Res2 = Res.replace(' ', '')
Res2 = Res2.replaceAll("[\n\r]", "");
log.info "RES2 TRIMED " + Res2
def actualXMLResponse = Res2

//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;
}