8

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

4

4 回答 4

23

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

于 2010-01-09T22:37:11.330 回答
1

使用脚本断言:

def project = messageExchange.modelItem.testStep.testCase.testSuite.project

def wsdlcontext = project.getInterfaceAt(0).getDefinitionContext()

def 验证器 = 新 com.eviware.soapui.impl.wsdl.support.wsdl.WsdlValidator(wsdlcontext);

def 错误 = validator.assertRequest(messageExchange, false)

断言errors.length < 1

于 2013-10-15T17:30:55.867 回答
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;
}

我希望这能帮到您 :-)

于 2015-05-01T05:36:15.307 回答
-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;
}
于 2020-11-09T15:24:58.960 回答