Service Virtualization

 View Only
  • 1.  How to validate multiple XML transformation/mapping?

    Posted Mar 11, 2017 09:34 AM

    I've to validate the mapping for the XMLs transformed at multiple points. Currently, I'm filtering all the XML values and putting assertion one by one.


    For example :

    <intialTag>dataRemainsSame</intialTag>  --->  <finalTag>dataRemainsSame</finalTag>

    So I filter the value of intialTag and finalTag, put an assertion {intialTag == finalTag} and everything works fine.


    However, this becomes a very painful and tedious task since the generated XML has more than 70 fields each. So, is there a better way in which this particular case can be handled? 


    Is it possible that we define the mapping in excel and DevTest reads it; and checks if everything is mapped correctly.


    Secondly, how to handle cases when some of the optional fields (as defined in the XSD :: minOccurs=0) are not coming in the input XML (it becomes null to null map as the assertions are still defined in the test step)?



    Also, filtering the value from XML is easy but I believe it will come handy if we have something that extracts the data from all the fields in the XML and store it in respective properties (with same name as in DOM with some prefix or suffix)

  • 2.  Re: How to validate multiple XML transformation/mapping?

    Posted Mar 13, 2017 09:53 AM

    For question 1, have you tried the Graphical XML Side-By-Side Comparison Assertion?  

    This assertion might help you compare an expected XML to the XML response.  You could read the expected XML from a dataset, and store this value in a property to handle the situation where your XML is changing as a result of a loop.  Rather than loading the XML from a file, use the {{ }} property notation for your expected value.  Use the Settings Tab to define configurations according to your requirements. 


    For XML validation against WSDL, you might see if the Ensure XML Validation Assertion will work.


    For XSD validation, a scripted approach may or may not help you.  Not sure if the following would solve your issue or not.

    NOTE:  Non-verified/untested sample code:

    import javax.xml.transform.Source;


    import javax.xml.validation.Schema;

    import javax.xml.validation.SchemaFactory;

    import javax.xml.validation.Validator;


    // set these values accordingly

    // XMLShema is a variable that holds the text of the XSD file

    // XMLData is a variable that holds the text of the XML document to validate


    try {

        SchemaFactory factory = SchemaFactory.newInstance( "" );

        Schema schema = factory.newSchema( new StreamSource( new StringReaderXMLSchema ) ) );

        Validator validator = schema.newValidator();

        Source source = new StreamSource( new StringReaderXMLData ) );

        validator.validate( source );"schema check successful");


        catch ( SAXParseException ex ) {

           // TO DO: Trap Logic


  • 3.  Re: How to validate multiple XML transformation/mapping?

    Posted Mar 13, 2017 04:56 PM

    Hey Joel, Thanks for your reply!


    I believe it's a good suggestion, only if I know the expected XML beforehand but in this scenario there are a lot many variation coming into the input XML only. This makes it again a tedious task, maybe increase the amount of work here


    Any comments on this - Is it possible that we define the mapping in excel and DevTest reads it; and checks if everything is mapped correctly?


    I can validate the XSD directly with Ensure XML Validation Assertion only, so the scripted approach will not be needed. Thanks for the effort though.


    Let me elaborate my question a bit more - In the XSD many fields are set as optional fields that means if they don't come in the actual XML it'll still pass the XSD validation. However, I'm filtering all the possible values from the XML. Now, when one or more of the optional fields doesn't come in the XML it automatically assigns a null value to the corresponding property and since it is a one to one map the same happens with the response XML. 


    Now two problems arise here: One, When it assigns it a null value it doesn't clarify whether it was an empty tag or the tag was missing from the XML. Second, derivatively it becomes a null to null map!


    Hope it clarifies the confusion!

  • 4.  Re: How to validate multiple XML transformation/mapping?
    Best Answer

    Posted Mar 14, 2017 08:11 AM

    My apologies, I was headed down the thought that your Test Case knows the expected response for a given input request. So, a dataset having two columns would provide:

    a) the input request that generates a given response

    b) the expected response for the input request

    Then, when your steps execute, you compare the expected response to the actual.  


    I am not aware of any DevTest feature that can compare an unknown input to an unknown output and resolve the differences.  I believe you will need to develop custom logic capable of iterating both DOMs in order to implement the comparisons and allow the exclusions to handle the nuances of your requirement.