Using JMeter, how to compare table data with JSON data?











up vote
0
down vote

favorite












I've got a task to compare all data fetched from postgreSQL table and all data located on a website that uses REST API (HTTP request with JSON data) in order to see which is missing.



I fetch data from postgreSQL using JDBC request (SELECT * FROM exampleTable), data is in standard SQL table format.



And I get REST API data using HTTP request sampler, data is in JSON format:



{"records":[{"id":"rec6iT8M0YFZc9kxf","fields":{"Birthday":"2010-09-01","Gender":"Female","Currently In Pasture":["rec7hRbjrgTaKWdCs"],"Breed":"Jersey","Weight":1800,"Name":"Jerri","Attachments":[{"id":"attbz","url":"https://IaGSYtK8SlS.jpg","filename":"Jersey_cow.jpg","size":1555316,"type":"image/jpeg","thumbnails":{"small":{"url":"https://_Jersey_cow.jpg","width":27,"height":36},"large":{"url":"https://dl/S4tl79.jpg","width":256,"height":341}}}]}



etc etc



both requests should have the same format of data (same "columns" for comparison > name, gender, breed, weight, etc)



I've tried using JSON Extractor post processor element to get individual variables from HTTP response and compare them to individual variables from JDBC request using the Response Assertion element but with no luck



I either get this error: Assertion failure message: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.String (probably cause I am using the whole SQL data set instead of data from individual columns)



or something like:
Assertion failure message: Test failed: text expected to match /${gender}/



I dont know how to successfully assign variables to data from SQL table and JSON response and then matching those variable values (seeing which entries are absent from what REST API fetches)



is there any easy way to do this using jmeter GUI and not having to rely on beanshell/groovy or any other kind of scripting (so just by using the elements available in jmeter) ?



thank you!










share|improve this question


























    up vote
    0
    down vote

    favorite












    I've got a task to compare all data fetched from postgreSQL table and all data located on a website that uses REST API (HTTP request with JSON data) in order to see which is missing.



    I fetch data from postgreSQL using JDBC request (SELECT * FROM exampleTable), data is in standard SQL table format.



    And I get REST API data using HTTP request sampler, data is in JSON format:



    {"records":[{"id":"rec6iT8M0YFZc9kxf","fields":{"Birthday":"2010-09-01","Gender":"Female","Currently In Pasture":["rec7hRbjrgTaKWdCs"],"Breed":"Jersey","Weight":1800,"Name":"Jerri","Attachments":[{"id":"attbz","url":"https://IaGSYtK8SlS.jpg","filename":"Jersey_cow.jpg","size":1555316,"type":"image/jpeg","thumbnails":{"small":{"url":"https://_Jersey_cow.jpg","width":27,"height":36},"large":{"url":"https://dl/S4tl79.jpg","width":256,"height":341}}}]}



    etc etc



    both requests should have the same format of data (same "columns" for comparison > name, gender, breed, weight, etc)



    I've tried using JSON Extractor post processor element to get individual variables from HTTP response and compare them to individual variables from JDBC request using the Response Assertion element but with no luck



    I either get this error: Assertion failure message: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.String (probably cause I am using the whole SQL data set instead of data from individual columns)



    or something like:
    Assertion failure message: Test failed: text expected to match /${gender}/



    I dont know how to successfully assign variables to data from SQL table and JSON response and then matching those variable values (seeing which entries are absent from what REST API fetches)



    is there any easy way to do this using jmeter GUI and not having to rely on beanshell/groovy or any other kind of scripting (so just by using the elements available in jmeter) ?



    thank you!










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I've got a task to compare all data fetched from postgreSQL table and all data located on a website that uses REST API (HTTP request with JSON data) in order to see which is missing.



      I fetch data from postgreSQL using JDBC request (SELECT * FROM exampleTable), data is in standard SQL table format.



      And I get REST API data using HTTP request sampler, data is in JSON format:



      {"records":[{"id":"rec6iT8M0YFZc9kxf","fields":{"Birthday":"2010-09-01","Gender":"Female","Currently In Pasture":["rec7hRbjrgTaKWdCs"],"Breed":"Jersey","Weight":1800,"Name":"Jerri","Attachments":[{"id":"attbz","url":"https://IaGSYtK8SlS.jpg","filename":"Jersey_cow.jpg","size":1555316,"type":"image/jpeg","thumbnails":{"small":{"url":"https://_Jersey_cow.jpg","width":27,"height":36},"large":{"url":"https://dl/S4tl79.jpg","width":256,"height":341}}}]}



      etc etc



      both requests should have the same format of data (same "columns" for comparison > name, gender, breed, weight, etc)



      I've tried using JSON Extractor post processor element to get individual variables from HTTP response and compare them to individual variables from JDBC request using the Response Assertion element but with no luck



      I either get this error: Assertion failure message: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.String (probably cause I am using the whole SQL data set instead of data from individual columns)



      or something like:
      Assertion failure message: Test failed: text expected to match /${gender}/



      I dont know how to successfully assign variables to data from SQL table and JSON response and then matching those variable values (seeing which entries are absent from what REST API fetches)



      is there any easy way to do this using jmeter GUI and not having to rely on beanshell/groovy or any other kind of scripting (so just by using the elements available in jmeter) ?



      thank you!










      share|improve this question













      I've got a task to compare all data fetched from postgreSQL table and all data located on a website that uses REST API (HTTP request with JSON data) in order to see which is missing.



      I fetch data from postgreSQL using JDBC request (SELECT * FROM exampleTable), data is in standard SQL table format.



      And I get REST API data using HTTP request sampler, data is in JSON format:



      {"records":[{"id":"rec6iT8M0YFZc9kxf","fields":{"Birthday":"2010-09-01","Gender":"Female","Currently In Pasture":["rec7hRbjrgTaKWdCs"],"Breed":"Jersey","Weight":1800,"Name":"Jerri","Attachments":[{"id":"attbz","url":"https://IaGSYtK8SlS.jpg","filename":"Jersey_cow.jpg","size":1555316,"type":"image/jpeg","thumbnails":{"small":{"url":"https://_Jersey_cow.jpg","width":27,"height":36},"large":{"url":"https://dl/S4tl79.jpg","width":256,"height":341}}}]}



      etc etc



      both requests should have the same format of data (same "columns" for comparison > name, gender, breed, weight, etc)



      I've tried using JSON Extractor post processor element to get individual variables from HTTP response and compare them to individual variables from JDBC request using the Response Assertion element but with no luck



      I either get this error: Assertion failure message: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.String (probably cause I am using the whole SQL data set instead of data from individual columns)



      or something like:
      Assertion failure message: Test failed: text expected to match /${gender}/



      I dont know how to successfully assign variables to data from SQL table and JSON response and then matching those variable values (seeing which entries are absent from what REST API fetches)



      is there any easy way to do this using jmeter GUI and not having to rely on beanshell/groovy or any other kind of scripting (so just by using the elements available in jmeter) ?



      thank you!







      postgresql rest jmeter compare assertion






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      user1866757

      142




      142
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Not knowing your database structure it is quite tricky to come up with exact solution, however you can convert JDBC Request output into a JSON using JSR223 PostProcessor



          Example:





          • Given the following JDBC Request sampler configuration:



            enter image description here




          • Which produces the following output:



            enter image description here




          • I can convert it into JSON using the following Groovy code:



            def result = vars.getObject('result')
            def json = new groovy.json.JsonBuilder(result).toPrettyString()
            log.info(json)


            enter image description here



            as you can see it contains column names along with the values, you should be able to use it for assertions.




          More information: Debugging JDBC Sampler Results in JMeter






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372351%2fusing-jmeter-how-to-compare-table-data-with-json-data%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Not knowing your database structure it is quite tricky to come up with exact solution, however you can convert JDBC Request output into a JSON using JSR223 PostProcessor



            Example:





            • Given the following JDBC Request sampler configuration:



              enter image description here




            • Which produces the following output:



              enter image description here




            • I can convert it into JSON using the following Groovy code:



              def result = vars.getObject('result')
              def json = new groovy.json.JsonBuilder(result).toPrettyString()
              log.info(json)


              enter image description here



              as you can see it contains column names along with the values, you should be able to use it for assertions.




            More information: Debugging JDBC Sampler Results in JMeter






            share|improve this answer

























              up vote
              0
              down vote













              Not knowing your database structure it is quite tricky to come up with exact solution, however you can convert JDBC Request output into a JSON using JSR223 PostProcessor



              Example:





              • Given the following JDBC Request sampler configuration:



                enter image description here




              • Which produces the following output:



                enter image description here




              • I can convert it into JSON using the following Groovy code:



                def result = vars.getObject('result')
                def json = new groovy.json.JsonBuilder(result).toPrettyString()
                log.info(json)


                enter image description here



                as you can see it contains column names along with the values, you should be able to use it for assertions.




              More information: Debugging JDBC Sampler Results in JMeter






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Not knowing your database structure it is quite tricky to come up with exact solution, however you can convert JDBC Request output into a JSON using JSR223 PostProcessor



                Example:





                • Given the following JDBC Request sampler configuration:



                  enter image description here




                • Which produces the following output:



                  enter image description here




                • I can convert it into JSON using the following Groovy code:



                  def result = vars.getObject('result')
                  def json = new groovy.json.JsonBuilder(result).toPrettyString()
                  log.info(json)


                  enter image description here



                  as you can see it contains column names along with the values, you should be able to use it for assertions.




                More information: Debugging JDBC Sampler Results in JMeter






                share|improve this answer












                Not knowing your database structure it is quite tricky to come up with exact solution, however you can convert JDBC Request output into a JSON using JSR223 PostProcessor



                Example:





                • Given the following JDBC Request sampler configuration:



                  enter image description here




                • Which produces the following output:



                  enter image description here




                • I can convert it into JSON using the following Groovy code:



                  def result = vars.getObject('result')
                  def json = new groovy.json.JsonBuilder(result).toPrettyString()
                  log.info(json)


                  enter image description here



                  as you can see it contains column names along with the values, you should be able to use it for assertions.




                More information: Debugging JDBC Sampler Results in JMeter







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered yesterday









                Dmitri T

                66.3k33256




                66.3k33256






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372351%2fusing-jmeter-how-to-compare-table-data-with-json-data%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    'app-layout' is not a known element: how to share Component with different Modules

                    android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                    WPF add header to Image with URL pettitions [duplicate]