Reputation: 21
I'd like to ensure my WSDL contract is unchanged but matching on its response to a file
Scenario: Get demo.wsdl
Given path '/demo'
And param wsdl = 'demoLookup.wsdl'
When method get
Then status 200
# note how we focus only on the relevant part of the payload and read expected XML from a file
# And print 'response: ', response
* def expected = read('expected-demo.wsdl')
And match response contains expected
I get
match failed: CONTAINS
/ | data types don't match (XML:LIST)
[60,119,115,100,108,58,100,101,10....
I'm assuming this is not a supported feature, is there any workarounds like matching on a raw file?
Upvotes: 1
Views: 273
Reputation: 21
In case someone else is attempting a similar need.
ChkSum.java
import org.springframework.util.StringUtils;
import java.util.zip.CRC32;
public class ChkSum {
public static long generate(byte[] content){
CRC32 crc32 = new CRC32();
crc32.update(content, 0, content.length);
return crc32.getValue();
}
public static int match(String expected, String actual){
long exp_hash = generate(StringUtils.trimAllWhitespace(expected).getBytes());
long act_hash = generate(StringUtils.trimAllWhitespace(actual).getBytes());
return Long.compare(exp_hash,act_hash);
}
}
Feature
Scenario: Get demo.wsdl
* def chksum = Java.type('ChkSum')
Given path '/demo'
And param wsdl = 'demoLookup.wsdl'
When method get
Then status 200
# note how we focus only on the relevant part of the payload and read expected XML from a file
#And print 'response: ', response
* xmlstring exp = read('expected-demo.wsdl')
* xmlstring act = response
* def result = chksum.match(exp, act)
# And match exp == act
And match result == 0
Upvotes: 1
Reputation: 58058
Karate has no direct support for WSDL files. My personal opinion is that for the purposes of API end-to-end testing, you don't need it. Just get a sample XML payload and do a comparison. This is what most teams do.
I'll also add that in my experience teams look for short-cuts, like expecting a WSDL or some kind of "schema" to do all the hard work of testing for them. This always ends badly. You need to test for things like database state, business logic and so on. Just my 2 c.
Upvotes: 1