SOAPUI:根据 xsd 架构文件验证响应

发布于 2024-07-09 13:06:39 字数 94 浏览 7 评论 0原文

如何根据定义响应架构的 XSD 文件验证 SOAP 响应。 我调用的 Web 服务有一个 XMLDocument 作为输入和输出,因此无法使用 WSDL 进行响应架构验证。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

柠檬色的秋千 2024-07-16 13:06:40

使用脚本断言:

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 (wsdl上下文);

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

断言错误.length < 1

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

与之呼应 2024-07-16 13:06:40

您可以使用 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;
}

希望对您有所帮助:-)

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 :-)

多情癖 2024-07-16 13:06:40

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

In case you still need this (valid for SOAP UI version 2.5.1):
File, Preferences, Editor Setting, Validate Response.

旧伤还要旧人安 2024-07-16 13:06:40

这对我不起作用,因为尝试不起作用

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

This not worked me caused try not working

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文