Forum Discussion

testhrishi's avatar
testhrishi
Frequent Contributor
9 years ago

What is a better way to validate the response coming back from JDBC request?

What is the best way to validate the response coming back from JDBC request?

 

CONTAINS assertion may not validate the case where more than expected data comes back in response.

Contains will still hold true when it finds all the expected values in the response; however in my case if more data comes back thats a issue. Then I amy have to play combination of contains and not-contains.

Wonder if there is better way to assert the exact response message

 

Thanks!

14 Replies

  • You seem to try to do several things in one assertion.

    Here is how you can try and assert the response::

    • Use Message Content assertion to verify the contents of the response. With it you can configure what information you expect in specific response field.
    • Use Script assertion to verify response lenght. Depending on your response, there are multiple ways to do this. The simplest one is checking response lenght:
      assert messageExchange.response.contentLength < 500
      This is obviously very basic, a script should be custom for what you expect in your response. You can, for example, get a response as XML, count the number of specific nodes in it and fail the assertion if there are too many.
    • testhrishi's avatar
      testhrishi
      Frequent Contributor

      Thank you for the input, the < length may work to cover for more than expected scenario. But it may not cover the less than expected part, right. Also some of the fields coming back in the response are new every time, hence its gets tricky to assert on specific ones

      • IgorG's avatar
        IgorG
        Icon for Staff rankStaff

        You can use this code to check both minimum and maximum length:

         

        assert ((messageExchange.response.contentLength > 10) && (messageExchange.response.contentLength < 500))

        Of course, this will only work if short, normal and long messages are different enough.

         

  • Radford's avatar
    Radford
    Super Contributor

    Are you asserting the contains on the entire JDBC response or individual fields?

      • Radford's avatar
        Radford
        Super Contributor

        I've always run into issues when I used to attempt to match the entire response. Can you just assert the individual fields in the returned JDBC XML response?