How to dynamically pass JSON values in jmeter http request body

∥☆過路亽.° 提交于 2021-02-02 09:57:25

问题


I have 10 http requests, where I pass the JSON value of parameter "lang" in body data as "java", "java1","java2", "java3", "java4" then again "java", "java1", "java2", "java3" ,"java4" for every requedst from 1-10.

first 5 requests contain the correct code and the remaining 5 requests contain the incorrect code.

Also, in the last 5 requests I need to pass a custom code i.e. the value of the code is :

"import java.io.BufferedReader;\r\nimport java.io.InputStreamReader;\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\nimport java.util.stream.Collectors;\r\n\r\nclass Main\r\n{\r\n    public static void main (String[] args) throws java.lang.Exception\r\n    {\r\n\r\n        \/\/use the following code to fetch input from console\r\n        BufferedReader inp = new BufferedReader (new InputStreamReader(System.in));\r\n        String[] arrInput1 = inp.readLine().split(\" \"); \/\/ enter first input and split to array\r\n        String[] arrInput2 = inp.readLine().split(\" \"); \/\/ enter second input and split to array\r\n\r\n        List<Integer> numList1 = new ArrayList<>(); \r\n        List<Integer> numList2 = new ArrayList<>();\r\n      \r\n      \r\n\t\t\/\/ put inputs in a List<Integer>\r\n        for(int i = 0; i < 11; i++){\r\n            numList1.add(Integer.parseInt(arrInput1[i])); \r\n            numList2.add(Integer.parseInt(arrInput2[i])); \r\n        }\r\n\r\n\r\n        \/\/ Check if the inputs are permutation\r\n        if(isPermutable(numList1, numList2))\r\n            System.out.println(\"YES\");\r\n        else\r\n            System.out.println(\"NO\");\r\n\r\n    }\r\n  \r\n  \r\n    \/\/ Check whether two inputs are a permutation\r\n    public static boolean isPermutable(List<Integer> numList1, List<Integer> numList2){\r\n        boolean isPermutable = true;\r\n        numList1 = numList1.stream().sorted().collect(Collectors.toList());\r\n        numList2 = numList2.stream().sorted().collect(Collectors.toList());\r\n        if(numList1.size() != numList2.size()){\r\n            isPermutable = false;\r\n        }else{\r\n            for(int i = 0; i < numList1.size(); --i){\r\n                if(!numList1.get(i).equals(numList2.get(i))){\r\n                    isPermutable =  false;\r\n                }\r\n            }\r\n        }\r\n        return isPermutable;\r\n    }\r\n}\r\n"

Here is how it should run:

In the 1st iteration (or say loop), Submission Request "6" having "java" as lang code should have the custom code and the remaining requests should have the normal value of code

In the 2nd iteration,Submission Request "7" having "java1" as lang code should have custom code and the remaining requests should have the normal value of code

In the 3rd iteration, Submission Request "8" having "java2" as lang code should have custom code and the remaining requests should have the normal value of code

In the 4th iteration, Submission Request "9" having "java3" as lang code should have custom code and the remaining requests should have the normal value of code

In the 5th iteration, Submission Request "10" having "java4" as lang code should have custom code and the remaining requests should have the normal value of code

Also the normal value of the code is:

import java.io.BufferedReader;\r\nimport java.io.InputStreamReader;\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\nimport java.util.stream.Collectors;\r\n\r\nclass Main\r\n{\r\n    public static void main (String[] args) throws java.lang.Exception\r\n    {\r\n\r\n        \/\/use the following code to fetch input from console\r\n        BufferedReader inp = new BufferedReader (new InputStreamReader(System.in));\r\n        String[] arrInput1 = inp.readLine().split(\" \"); \/\/ enter first input and split to array\r\n        String[] arrInput2 = inp.readLine().split(\" \"); \/\/ enter second input and split to array\r\n\r\n        List<Integer> numList1 = new ArrayList<>(); \r\n        List<Integer> numList2 = new ArrayList<>();\r\n      \r\n      \r\n\t\t\/\/ put inputs in a List<Integer>kerfnaek\r\n        for(int i = 0; i < 11; i++){\r\n            numList1.add(Integer.parseInt(arrInput1[i])); \r\n            numList2.add(Integer.parseInt(arrInput2[i])); \r\n        }\r\n\r\n\r\n        \/\/ Check if the inputs are permutation\r\n        if(isPermutable(numList1, numList2))\r\n            System.out.println(\"YES\");\r\n        else\r\n            System.out.println(\"NO\");\r\n\r\n    }\r\n  \r\n  \r\n    \/\/ Check whether two inputs are a permutation\r\n    public static boolean isPermutable(List<Integer> numList1, List<Integer> numList2){\r\n        boolean isPermutable = truejshfrew\r\n        numList1 = numList1.stream().sorted().collect(Collectors.toList());\r\n        numList2 = numList2.stream().sorted().collect(Collectors.toList());\r\n        if(numList1.size() != numList2.size()){\r\n            isPermutable = false;\r\n        }else{\r\n            for(int i = 0; i < numList1.size(); i++){\r\n                if(!numList1.get(i).equals(numList2.get(i))){\r\n                    isPermutable =  false;\r\n                }\r\n            }\r\n        }\r\n        return isPermutable;\r\n    }\r\n}\r\n

Kindly guide me with detailed steps. Thank you in advance!

来源:https://stackoverflow.com/questions/63053225/how-to-dynamically-pass-json-values-in-jmeter-http-request-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!