Forum Discussion

TheEnd's avatar
TheEnd
Occasional Contributor
5 years ago

Groovy script assertion to compare XML data

Thanks Rich,

@avidCoder@nmrao

Is it possible that one of you could help me with my issue? I'll post again:

NOTE: a Test step before this Test step(which I explain below) sets the polling interval (in this example to 10 sec).

1. Using an HTTP GET request call on a URL

2. The URL’s response is a list of events (<Event>) that have time stamps (<EventTime>)

3. These events, Event X, Event Y etc., are no more than polling events. So, if I send a polling interval for Event X to poll every 10 sec, then I want to verify that Event X is polling every 10 sec. Event Y could be polling at a different interval, no problem. I need to verify if I set the polling interval for Event X to be 10 sec, then when I send a GET on the URL, in the response I should see the time stamps for Event X to be 10 sec apart.

4. So, my Assertion should compare Event X with time stamp X and the next time that Event X polls the time stamp should be 10 sec from the previous Event X time stamp. Verifying polling interval was set correctly.

5. Example below shows there is a 10 sec diff between the Event X at 19:35:37.189 time and the same Event X at 19:35:47.24

<Response>

<e>
<Tplus>8201.19</Tplus>
<SinceLast>8.29</SinceLast>
<EventTime>2019-12-16T19:35:37.189</EventTime>
<Event>trapPATS-NE-MIB: patsConfigFileDownloadCompleteTrap"/test_lru_manifest.xml"XX.XX.XX.162</Event>
</e>
<e>
<Tplus>8211.24</Tplus>
<SinceLast>10.05</SinceLast>
<EventTime>2019-12-16T19:35:47.24</EventTime>
<Event>trapPATS-NE-MIB:patsConfigFileDownloadCompleteTrap"/test_lru_manifest.xml"XX.XX.XX.162</Event>
</e>

<Response>

6. Trying to verify the polling request was set correctly. If there is a better way than a groovyscript, please point me into that direction. But if the groovyscript is the way please provide code on how to do this and an explanation into what the code is doing, this way I can learn, until I can get more experience with groovy.

7. To start with, not sure if I should go to the end of the response file or parse through the entire response file?

Thanks, again, all help is greatly appreciated!

  • Hi TheEnd,  please provide the details richie needs and the Community will see how to help you solve this! 

     

    Also, a lot of users are using the XPath Match assertion for XML validation, could this be something you are looking for?  

     

    And, there’s a code sample in our documentation for comparing XML’s. Maybe, you could try creating your own code based on that.  

  • richie's avatar
    richie
    Community Hero
    Hey TheEnd,

    Just asking a couple of queries that may help in your config/setup and may help other lads understand if/when they look at this.

    Q1. The GET API youre hitting which retrieves the eventtype data. Currently what would be the content of response? What i mean is, does the response contain every event polling instance since the beginning of time or does it just list all polling events since the process was restarted? Reason i ask is that for an event that polls every 10 seconds would have 8640 records in your response....and thats for a single event. If the polling interval is less say 3 seconds, youd have 28800 records in your response in 1 day

    Q2. Your requirements for testing the interval.....is the requirement that the interval is configurable or is it that Event x has an interval of y seconds? Reason i ask is that if it's just the polling interval is configurable then you can simplify your testing somewhat.

    Q3. Where is the response actually sourced from? Is it sourcing database records or is it sourcing from a flat file? If its a flat file when is a new file created....is it when the underlying process is restarted, or perhaps is it just a certain file size? What i'm thinking about here is to minimise the number of records (as well as different event types) in your response so handling the response is easier...especially if you can have thousands of records in your response.
    If the data is sourced from a database, would you be able to truncate the tables (via either an HTTP delete method if your endpoint includes a delete API, OR more likely via a JDBC SQL step).? If the data is sourced via a DB, if you truncate the source tables immediately before the process starts, this means you'd only have a small number of records (perhaps only a single event type to deal with) to have to parse and validate.

    Q4. The GET API. Is it just a select * query or can you add a query filter to your GET clause (perhaps a uri/query or even header parameters) that allows you to restrict the type and number of records in your resultset? I know my queries keep circling this point, but it's gonna be hard work to validate a response with thousands of records in it..

    Ok...i'll stay out of this now,

    Nice one,

    Rich
    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      Hi TheEnd,  please provide the details richie needs and the Community will see how to help you solve this! 

       

      Also, a lot of users are using the XPath Match assertion for XML validation, could this be something you are looking for?  

       

      And, there’s a code sample in our documentation for comparing XML’s. Maybe, you could try creating your own code based on that.