1

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?

hc_dev
  • 8,389
  • 1
  • 26
  • 38

2 Answers2

1

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.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • I understand and do test the actual SOAP services. Its just that the wsdl itself is used by clients either in build or runtime to generate/configure the stub code and wanted to ensure the file itself is complete (like external xsd imports are accessible from classpath/jars, etc...). Was looking at the bytes or xmlstring type conversions to match but still having challenges is there a current example for doing the file or even chksum of expected to actual? – Mark Diskin Jul 01 '22 at 12:17
  • @MarkDiskin I don't understand what you plan to do with the wsdl. maybe java interop is what you are looking for or you can even call an executable via the command line. I have no other suggestions – Peter Thomas Jul 01 '22 at 14:24
  • No worries; I have a solution (below) that allows me to do a match on the expected wsdl to the one the endpoint currently is presenting. The option for you would be match support on the xmlstrings to remove whitespaces or like below more of a hash match – Mark Diskin Jul 01 '22 at 15:28
  • @MarkDiskin karate has support for XML comparisons that are proper data-value based, ignoring white-space. so I'm still confused. anyway, whatever works. follow this process if you would like to provide an example of what is missing in karate that can be possibly improved: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Jul 02 '22 at 03:52
1

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