如何使用 SOAP UI 测试响应内容类型 [英] How to test the response content-type using SOAP UI
问题描述
我是这个 SOAP UI 的新手.我需要测试响应正文是否为空.
你能告诉我怎么解决吗.
我的想法是使用断言脚本检查响应的 content-length
,但它不适用于 equals()
.
contains()
正在工作,但 不是 equals
:
//有效:assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders["Content-Length"]).contains("0")//不工作:assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders["C ontent-Length"]).equals("0")//不工作:assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders["C ontent-Length"]) == 0
请帮我解决问题.
在您的代码中:
//有效:assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders[Content-Length"]).contains(0")//不工作:assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders[C ontent-Length"]).equals(0")//不工作:assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders[C ontent-Length"]) == 0
表达式 messageExchange.responseHeaders["Content-Length"]
返回一个 StringList
[参见此处的文档],这是一个ArrayList
它的内容类似于几个 Strings
,例如 ("abc"
, "def"
, "ghi"
).
包含(0")
:
这样,当您调用 list.contains("abc")
时,您是在询问 "abc"
是否是列表的元素之一.您的 Content-Length
标头可能是一个包含一个元素的列表,例如 ("0"
).这就是 list.contains("0")
返回 true
的原因,因为 String
"0"
是列表中的元素之一.
等于(0")
:
因此,当您调用:list.equals(something)
时,如果作为参数传递的 something
是一个,它只会返回 true
String
的列表也是如此."0"
不是 String
的列表,它只是一个.
== 0
:
同样,当你调用 list == 0
时,你是在测试 list
是否是整数 0
,而不是.>
messageExchange.responseHeaders["Content-Length"] == 0
不应该工作,因为.messageExchange.responseHeaders["Content-Length"]
返回一个 List
的 String
s,即 >不同于整数0
.
messageExchange.getResponse().getContentLength() == 0
有效,因为 messageExchange.getResponse().getContentLength()
返回 Content-Length
code> 标头作为 long
整数值.
messageExchange.getResponse().getContentLength()
与获取列表的第一个值并转换为 long
相同.看看这是如何工作的:Long.valueOf(messageExchange.responseHeaders["Content-Length"].get(0)) == 0
.
I am new to this SOAP UI . I got a requirement to test if the response body is not empty .
Can you please tell me how to solve.
My idea was to check the content-length
of the response using assertion script but it is not working for equals()
.
contains()
is working but not equals
:
// works:
assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders["Content-Length"]).contains("0")
// not working:
assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders["Content-Length"]).equals("0")
// not working:
assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders["Content-Length"]) == 0
Please help me to solve the issue.
In your code:
// works:
assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders["Content-Length"]).contains("0")
// not working:
assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders["Content-Length"]).equals("0")
// not working:
assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders["Content-Length"]) == 0
The expression messageExchange.responseHeaders["Content-Length"]
returns a StringList
[see doc here], which is a ArrayList<String>
.
It's content would be something like several Strings
, like ("abc"
, "def"
, "ghi"
).
contains("0")
:
This way, when you call list.contains("abc")
, you are asking if the "abc"
is one of the elements of the list. Your Content-Length
header is probably a list with one element, like ("0"
). That's why list.contains("0")
returns true
, because the String
"0"
is one of the elements on the list.
equals("0")
:
So, when you call: list.equals(something)
, it will only return true
if the something
passed as parameter is a list of String
s as well. "0"
is not a list of String
s, it is just one.
== 0
:
Same way, when you call list == 0
you are testing if list
is the integer 0
, which is not.
messageExchange.responseHeaders["Content-Length"] == 0
should not work because. messageExchange.responseHeaders["Content-Length"]
returns a List
of String
s, that is different than the integer number 0
.
messageExchange.getResponse().getContentLength() == 0
works because messageExchange.getResponse().getContentLength()
returns the Content-Length
header as a long
integer value.
messageExchange.getResponse().getContentLength()
is the same as getting the first value of the list and converting to long
. Look how this will work: Long.valueOf(messageExchange.responseHeaders["Content-Length"].get(0)) == 0
.
这篇关于如何使用 SOAP UI 测试响应内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!