How to test the response content-type using SOAP UI

谁说我不能喝 提交于 2019-12-12 23:27:51

问题


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["C‌​ontent-Length"]).equals("0") 
// not working:
assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders["C‌​ontent-Length"]) == 0 

Please help me to solve the issue.


回答1:


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["C‌​ontent-Length"]).equals("0") 
// not working:
assert ((com.eviware.soapui.support.types.StringList)messageExchange.responseHeaders["C‌​ontent-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 Strings as well. "0" is not a list of Strings, 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 Strings, 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.



来源:https://stackoverflow.com/questions/16662959/how-to-test-the-response-content-type-using-soap-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!