Forum Discussion

amelaao's avatar
amelaao
New Contributor
6 years ago
Solved

JSONPath Existence Match always returns true

Hello,

I am using  JSONPath Existence Match Assertion on an array and I noticed that it always evaluates to true.

This is my expression and no matter which custom property I use inside the condition, the result always evaluates to true.

 

$.ApplicationResult.HotelList[?(@.HotelId==${#TestSuite#hotelIId})]

 

I'm using SOAPUI 5.4.0.

 

Thanks!

 

  • It looks like a bug. I also tested this on the PRO version and it is not reproducible there. 

     

    You could also use a JSONPath RegEx Match Configuration. The JSONPath Expression can stay the same. You will only have to add a regular expression like:

     

    \[.+\]

     

    Then you can set the expected results to 'true'.

     

     

    You will notice then that if the id doesn't exist the assertion will fail.

     

    Cheers!

4 Replies

  • Lucian's avatar
    Lucian
    Community Hero

    Hi,

     

    Can you post a sample response so we can better see what happens?

     

  • amelaao's avatar
    amelaao
    New Contributor
    {
        "Result": {
            "ResultCode": "SUCCESS"
        },
        "ApplicationResult": {
            "HotelList": [{
                "HotelId": "67194",
                "HotelName": "Jemi1 Hotel VA",
                "HotelCode": "Jemi1 HOTEL",
                "CRO": {
                    "Id": "17687",
                    "ChainId": "17686",
                    "Name": "JJT CRO"
                },
                "Location": {
                    "Address": {
                        "AddressLine": "123 Campus circle",
                        "City": "Los Angeles",
                        "StateProvCode": "CA",
                        "StateProv": "California",
                        "CountryCode": "US",
                        "CountryName": "United States",
                        "Latitude": 34.05223,
                        "Longitude": -118.24368
                    },
                    "ContactNumberList": [{
                        "Number": "3104676226"
                    }],
                    "TimeZone": "-0600",
                    "Airport": {
                        "Name": "Dallas Area"
                    },
                    "TimeZoneOffset": "-6"
                },
                "ActiveStartDate": "16-May-16",
                "ActiveEndDate": "N/A",
                "Terminated": "false",
                "Suspended": "false",
                "AvailStatus": "Available",
                "WeatherCityId": "5368361",
                "Brand": {
                    "Id": "8000554",
                    "Name": "JEM Brand2",
                    "Default": true,
                    "Code": "JEM Brand2"
                },
                "Brands": [{
                    "Id": "8000553",
                    "Name": "JEM Brand1",
                    "Default": false,
                    "Code": "JEM Brand1"
                }, {
                    "Id": "8000554",
                    "Name": "JEM Brand2",
                    "Default": true,
                    "Code": "JEM Brand2"
                }]
            }, {
                "HotelId": "50916",
                "HotelName": "Chris K ARI Test Hotel - AutoClerK",
                "HotelCode": "CJKHOTEL05",
                "CRO": {
                    "Id": "17687",
                    "ChainId": "17686",
                    "Name": "JJT CRO"
                },
                "Location": {
                    "Address": {
                        "AddressLine": "111 Main st",
                        "City": "Newton",
                        "StateProvCode": "MA",
                        "StateProv": "Massachusetts",
                        "PostalCode": "02458",
                        "CountryCode": "US",
                        "CountryName": "United States",
                        "Latitude": 0,
                        "Longitude": 0
                    },
                    "ContactNumberList": [{
                        "Number": "617 454 6989"
                    }],
                    "TimeZone": "-0500",
                    "Airport": {},
                    "TimeZoneOffset": "-5",
                    "DISTANCE": 4886.105
                },
                "ActiveStartDate": "30-Mar-11",
                "ActiveEndDate": "N/A",
                "Terminated": "false",
                "Suspended": "false",
                "AvailStatus": "Available",
                "WeatherCityId": "5101848"
            }, {
                "HotelId": "67204",
                "HotelName": "Jemi6 Hotel",
                "HotelCode": "Jemi6 Hotel",
                "CRO": {
                    "Id": "17687",
                    "ChainId": "17686",
                    "Name": "JJT CRO"
                },
                "Location": {
                    "Address": {
                        "AddressLine": "116 Walter Blvd",
                        "City": "Los Angeles",
                        "StateProvCode": "ESX",
                        "StateProv": "East Sussex",
                        "CountryCode": "GB",
                        "CountryName": "United Kingdom",
                        "Latitude": 39.668903,
                        "Longitude": -74.22333
                    },
                    "ContactNumberList": [{
                        "Number": "31000000"
                    }],
                    "TimeZone": "-0600",
                    "Airport": {},
                    "TimeZoneOffset": "-6",
                    "DISTANCE": 7795.3257
                },
                "ActiveStartDate": "18-May-16",
                "ActiveEndDate": "N/A",
                "Terminated": "false",
                "Suspended": "false",
                "AvailStatus": "Available",
                "Brand": {
                    "Id": "8000553",
                    "Name": "JEM Brand1",
                    "Default": true,
                    "Code": "JEM Brand1"
                },
                "Brands": [{
                    "Id": "8000553",
                    "Name": "JEM Brand1",
                    "Default": true,
                    "Code": "JEM Brand1"
                }, {
                    "Id": "8000554",
                    "Name": "JEM Brand2",
                    "Default": false,
                    "Code": "JEM Brand2"
                }, {
                    "Id": "8000575",
                    "Name": "JEM Brand4",
                    "Default": false,
                    "Code": "JEM Brand4"
                }]
            }],
            "Paging": {
                "Start": 1,
                "Size": 3,
                "Total": 7
            }
        }
    }
    • Lucian's avatar
      Lucian
      Community Hero

      It looks like a bug. I also tested this on the PRO version and it is not reproducible there. 

       

      You could also use a JSONPath RegEx Match Configuration. The JSONPath Expression can stay the same. You will only have to add a regular expression like:

       

      \[.+\]

       

      Then you can set the expected results to 'true'.

       

       

      You will notice then that if the id doesn't exist the assertion will fail.

       

      Cheers!

    • amelaao's avatar
      amelaao
      New Contributor

      Just to add a clarification:

       

      Even If I change the expression in assertion from

       

      $.ApplicationResult.HotelList[?(@.HotelId==${#TestSuite#hotelId})]

       

      $.ApplicationResult.HotelList[?(@.HotelId==${#TestSuite#xyz})] it still evaluates to true, although there is even no TestSuite variable "xyz".