Forum Discussion

Dchen's avatar
Dchen
Occasional Contributor
6 years ago

How to manipulate Values in combination with "get data" or "Message Content Assertion"

Hi,

 

I am using a stored procedure to get results and compare them to the API.

 

So example SQL stored procedure results:

Id, Type, Date

1, Address, 2018-08-18 00:00:00.000

2, Port, 2018-02-20 10:02:00.000

 

Response from the API:

"id" : "1",

"locationType" : "address",
"date" : "2018-08-18T00:00:00"

 

and

 

"id" : "2",

"locationType" : "port",
"date" : "2018-02-20T10:02:00"

 

 

So when i do a "Message Content Assertion", it will fail on the lowercase location type and it will fail on the date format.

 

Does anybody have an idea what the best way is to solve this?

 

Lets assume that i need to use the stored procedure, because of valid reasons.

See attachments of my real test case.

 

 

Regards,

Donny

 

6 Replies

  • richie's avatar
    richie
    Community Hero
    hi,

    are you aware of the UPPER and LOWER function in ANSI SQL? you said you need to use your sp, but can you change it slightly to force the returned locationtype to lower case.

    in regards to the insertion of the T char to indicate UCT or not....could you use a wildcard on your message content assertion? you could wildcard the position between the date and the time time. or instead of message content assertion perhaps you could use a regex assertion instead? although this may be a little less rigorous assertion than you actually need.

    this is reminding me of something i did before......i'm sure i had the same timezone indicator problem. i will look through my work tosee if i sorted it out.

    cheers

    richie
    • Dchen's avatar
      Dchen
      Occasional Contributor

      Hi Richie,

       

      I am aware of the UPPER and LOWER functions in SQL, but due to reasons i cannot do that here. (long boring story).

       

      I like your sugestion to use a wildcard with message assertion. I will try that out :)

       

      And so far i have been looking into groovy script: 

       

      Date:

      def requestedArrivalDate = context.expand( '${LDS SP TimeLine#requestedArrivalDate}.substring(0,19)' )
      Date date = Date.parse("yyyy-MM-dd HH:mm:ss",requestedArrivalDate)
      testRunner.testCase.setPropertyValue(requestedArrivalDate, date.format("yyyy-MM-dd'T'HH:mm:ss"))

       

      LowerCase:

      def locationDescription = context.expand( '${LDS SP TimeLine#locationDescription}' )
      testRunner.testCase.setPropertyValue("Location", locationDescription.toString().toLowerCase())

       

      But i was hoping for an far easier solution.

       

      For example that we can do "get data"

      and as a result do something like:

      '${LDS SP TimeLine#locationDescription}'.toString.toLower

       

       

      • richie's avatar
        richie
        Community Hero

        Hi,

         

        My groovy is rubbish - I can read what you've done - and I can do bits and bobs - but thats only due to the grace of other people's help on this forum.

         

        So - I can't comment on your code or improve it per se - but some of the other lads on the forum should be able to help.

         

        Is the upper case 'T' the only problem with your datetime?

         

         

        In one of my projects I have an event handler to remove the CDATA tag handler from my response 

         

        I use the RequestFilter.afterRequest event type with the following code

         

        def content = context.httpResponse.responseContent
        log.info( content )
        content = content.replaceAll( "<!\\[CDATA\\[", "" )
        content = content.replaceAll( "]]>", "" )
        
        log.info( content )
        
        context.httpResponse.responseContent = content
        log.info(context.httpResponse.responseContent)

        Now - this won't work for your situation because the 'T' is not unique in your response - HOWEVER - if you can determine a substring function this would be able to remove the 'T' from the datetime in your response.

         

        Unsure whether this approach will work because I asked this very question a couple of weeks ago on the forum and I didn't get an answer - but if there's bound to be a groovy or Java substring function you can use - I just don't know enough to check the java api to work out how to use it on my own.

         

        If you do manage to use a substring function - I would be very grateful if you could share it!

         

        sorry I can't be of more help!

         

        richie

  • Dchen's avatar
    Dchen
    Occasional Contributor

    Ok, enough time has been spent on this topic.

     

    I have solved it with Groovy using Substring and lowerCase functions.

     

    This was not my prefered solution, but it works.

     

    richie : if you need help with Groovy and Substring,

    you can have a look at this website: http://grails.asia/groovy-substring

     

    Or show me an example with the issue and the desired result.

    I might be able to help you.

     

    Donny

     

    • richie's avatar
      richie
      Community Hero

      Dchen

       

      thats real kind of you fella - thanks - I'll take a look!

       

      richie