Re: problem with json path extractor
Thank you Roberto. It's very encouraging to have such kind words from happy users :-) Such feedback is unfortunately not frequent enough. And thanks for your contribution and your time. Regards On Fri, Oct 21, 2016 at 10:00 PM, Roberto Bragawrote: > thank you all for the wonderfull jemeter and the prompt support > > > > Il 21/10/2016 21:09, Felix Schumacher ha scritto: > >> Am 21.10.2016 um 11:54 schrieb Roberto Braga: >> >>> I have attached a patch and two test cases, that show the behaviour for Regex and (modified) JSON Extractor. >>> >>> Is this patch already in the nightly build? >>> >>> >>> I committed the patch. It should be in the next available nightly. >> >> Thanks for your investigations in this bug. >> >> Felix >> >> >> - >> To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org >> For additional commands, e-mail: user-h...@jmeter.apache.org >> >> > > -- > "Ai sensi e per gli effetti della legge sulla tutela dei dati personali > (D.lgs 196/2003), > le informazioni contenute nella presente @mail sono di natura riservata e > destinate > ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso > personale; come tali, > pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E' > proibito leggere, > copiare, usare o diffondere il contenuto della presente @mail senza > autorizzazione. > Se avete ricevuto questa @mail per errore, siete pregati di rispedire la > stessa al mittente. > Grazie" > > - > To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org > For additional commands, e-mail: user-h...@jmeter.apache.org > > -- Cordialement. Philippe Mouawad.
Re: problem with json path extractor
thank you all for the wonderfull jemeter and the prompt support Il 21/10/2016 21:09, Felix Schumacher ha scritto: Am 21.10.2016 um 11:54 schrieb Roberto Braga: I have attached a patch and two test cases, that show the behaviour for Regex and (modified) JSON Extractor. Is this patch already in the nightly build? I committed the patch. It should be in the next available nightly. Thanks for your investigations in this bug. Felix - To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org For additional commands, e-mail: user-h...@jmeter.apache.org -- "Ai sensi e per gli effetti della legge sulla tutela dei dati personali (D.lgs 196/2003), le informazioni contenute nella presente @mail sono di natura riservata e destinate ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso personale; come tali, pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E' proibito leggere, copiare, usare o diffondere il contenuto della presente @mail senza autorizzazione. Se avete ricevuto questa @mail per errore, siete pregati di rispedire la stessa al mittente. Grazie" - To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org For additional commands, e-mail: user-h...@jmeter.apache.org
Re: problem with json path extractor
Am 21.10.2016 um 11:54 schrieb Roberto Braga: I have attached a patch and two test cases, that show the behaviour for Regex and (modified) JSON Extractor. Is this patch already in the nightly build? I committed the patch. It should be in the next available nightly. Thanks for your investigations in this bug. Felix - To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org For additional commands, e-mail: user-h...@jmeter.apache.org
Re: problem with json path extractor
I have attached a patch and two test cases, that show the behaviour for Regex and (modified) JSON Extractor. Is this patch already in the nightly build? -- "Ai sensi e per gli effetti della legge sulla tutela dei dati personali (D.lgs 196/2003), le informazioni contenute nella presente @mail sono di natura riservata e destinate ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso personale; come tali, pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E' proibito leggere, copiare, usare o diffondere il contenuto della presente @mail senza autorizzazione. Se avete ricevuto questa @mail per errore, siete pregati di rispedire la stessa al mittente. Grazie" - To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org For additional commands, e-mail: user-h...@jmeter.apache.org
Re: problem with json path extractor
+1 On Thu, Oct 20, 2016 at 9:43 PM, Felix Schumacher < felix.schumac...@internetallee.de> wrote: > Am 20.10.2016 um 16:31 schrieb Felix Schumacher: > >> Am 20.10.2016 16:01, schrieb Roberto Braga: >> >>> I think there is a bug in the file >>> >>> apache-jmeter-3.0-src/src/components/org/apache/jmeter/extra >>> ctor/json/jsonpath/JSONPostProcessor.java >>> >>> >>> at line 163, there is the else where i goes if only one match >>> >> >> The below src code is not in sync with the current code. >> >> But I think the important step for you is to place an additional var with >> 'name_1' into vars in the case, when only one element is found and -1 is >> used to indicate, that all elements are wanted. >> If you want to update your patch you could have a look at the current >> trunk and use the function stringify(Object). >> > After comparing the current behaviour of JSON Extractor with that of the > Regex Extractor, I think we should extract to _1 only, when > matchNumber is -1 and only one element could be matched. > > I have attached a patch and two test cases, that show the behaviour for > Regex and (modified) JSON Extractor. > > Regards, > Felix > > >> Regards, >> Felix >> >> >>> } else { >>> >>> // else just one value extracted >>> >>> Object obj = extractedValues.get(0); >>> >>> String objAsString = >>> >>> obj != null ? obj.toString() : ""; //$NON-NLS-1$ >>> >>> * vars.put(currentRefName, * >>> >>> * objAsString); * >>> >>> * if (matchNumber < 0 && getComputeConcatenation()) {* >>> >>> * vars.put(currentRefName + ALL_SUFFIX, objAsString);* >>> >>> * }* >>> >>> } >>> >>> >>> The part which set the vars is worng it should be like the following: >>> >>> } else { >>> >>> // else just one value extracted >>> >>> Object obj = extractedValues.get(0); >>> >>> String objAsString = >>> >>> obj != null ? obj.toString() : ""; //$NON-NLS-1$ >>> >>> * if (matchNumber < 0 && getComputeConcatenation()) {* >>> >>> * vars.put(currentRefName + "_1", * >>> >>> * objAsString);* >>> >>> * vars.put(currentRefName + ALL_SUFFIX, objAsString);* >>> >>> * } else {* >>> >>> * vars.put(currentRefName, * >>> >>> * objAsString);* >>> >>> * }* >>> >>> } >>> >>> >>> In this way it respect the matchNumber docs specification even if only >>> one value is extracted. >>> >> >> - >> To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org >> For additional commands, e-mail: user-h...@jmeter.apache.org >> >> > > > - > To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org > For additional commands, e-mail: user-h...@jmeter.apache.org > -- Cordialement. Philippe Mouawad.
Re: problem with json path extractor
Am 20.10.2016 um 16:31 schrieb Felix Schumacher: Am 20.10.2016 16:01, schrieb Roberto Braga: I think there is a bug in the file apache-jmeter-3.0-src/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java at line 163, there is the else where i goes if only one match The below src code is not in sync with the current code. But I think the important step for you is to place an additional var with 'name_1' into vars in the case, when only one element is found and -1 is used to indicate, that all elements are wanted. If you want to update your patch you could have a look at the current trunk and use the function stringify(Object). After comparing the current behaviour of JSON Extractor with that of the Regex Extractor, I think we should extract to _1 only, when matchNumber is -1 and only one element could be matched. I have attached a patch and two test cases, that show the behaviour for Regex and (modified) JSON Extractor. Regards, Felix Regards, Felix } else { // else just one value extracted Object obj = extractedValues.get(0); String objAsString = obj != null ? obj.toString() : ""; //$NON-NLS-1$ * vars.put(currentRefName, * * objAsString); * * if (matchNumber < 0 && getComputeConcatenation()) {* * vars.put(currentRefName + ALL_SUFFIX, objAsString);* * }* } The part which set the vars is worng it should be like the following: } else { // else just one value extracted Object obj = extractedValues.get(0); String objAsString = obj != null ? obj.toString() : ""; //$NON-NLS-1$ * if (matchNumber < 0 && getComputeConcatenation()) {* * vars.put(currentRefName + "_1", * * objAsString);* * vars.put(currentRefName + ALL_SUFFIX, objAsString);* * } else {* * vars.put(currentRefName, * * objAsString);* * }* } In this way it respect the matchNumber docs specification even if only one value is extracted. - To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org For additional commands, e-mail: user-h...@jmeter.apache.org >From 006fab5d6a622bc3e54a196aa00428e412d99a84 Mon Sep 17 00:00:00 2001 From: Felix SchumacherDate: Thu, 20 Oct 2016 21:38:46 +0200 Subject: [PATCH] Extract json elements into varname_1 when matchnumber is -1 and only one element is found. --- .../extractor/json/jsonpath/JSONPostProcessor.java | 2 +- .../jmeter/extractor/RegexExtractorTest.java | 51 ++ .../json/jsonpath/JSONPostProcessorTest.java | 50 + 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 test/src/org/apache/jmeter/extractor/RegexExtractorTest.java create mode 100644 test/src/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessorTest.java diff --git a/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java b/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java index d8c1856..f9ab1f5 100644 --- a/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java +++ b/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java @@ -161,7 +161,7 @@ public class JSONPostProcessor extends AbstractScopedTestElement implements Seri } } else { // else just one value extracted -placeObjectIntoVars(vars, currentRefName, extractedValues, 0); +placeObjectIntoVars(vars, currentRefName + "_1", extractedValues, 0); if (matchNumber < 0 && getComputeConcatenation()) { vars.put(currentRefName + ALL_SUFFIX, vars.get(currentRefName)); } diff --git a/test/src/org/apache/jmeter/extractor/RegexExtractorTest.java b/test/src/org/apache/jmeter/extractor/RegexExtractorTest.java new file mode 100644 index 000..7503fd7 --- /dev/null +++ b/test/src/org/apache/jmeter/extractor/RegexExtractorTest.java @@ -0,0 +1,51 @@ +package org.apache.jmeter.extractor; + +import static org.junit.Assert.*; + +import org.apache.jmeter.samplers.SampleResult; +import org.apache.jmeter.threads.JMeterContext; +import org.apache.jmeter.threads.JMeterContextService; +import org.apache.jmeter.threads.JMeterVariables; +import org.hamcrest.CoreMatchers; +import org.junit.Before; +import org.junit.Test; + +public class RegexExtractorTest { + +JMeterVariables vars; +JMeterContext context; +RegexExtractor extractor; + +@Before +public void setUp() { +vars = new JMeterVariables(); +context = JMeterContextService.getContext(); +context.setVariables(vars); +extractor = new RegexExtractor(); +
Re: problem with json path extractor
Am 20.10.2016 16:01, schrieb Roberto Braga: I think there is a bug in the file apache-jmeter-3.0-src/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java at line 163, there is the else where i goes if only one match The below src code is not in sync with the current code. But I think the important step for you is to place an additional var with 'name_1' into vars in the case, when only one element is found and -1 is used to indicate, that all elements are wanted. If you want to update your patch you could have a look at the current trunk and use the function stringify(Object). Regards, Felix } else { // else just one value extracted Object obj = extractedValues.get(0); String objAsString = obj != null ? obj.toString() : ""; //$NON-NLS-1$ * vars.put(currentRefName, * * objAsString); * * if (matchNumber < 0 && getComputeConcatenation()) {* * vars.put(currentRefName + ALL_SUFFIX, objAsString);* * }* } The part which set the vars is worng it should be like the following: } else { // else just one value extracted Object obj = extractedValues.get(0); String objAsString = obj != null ? obj.toString() : ""; //$NON-NLS-1$ * if (matchNumber < 0 && getComputeConcatenation()) {* * vars.put(currentRefName + "_1", * * objAsString);* * vars.put(currentRefName + ALL_SUFFIX, objAsString);* * } else {* * vars.put(currentRefName, * * objAsString);* * }* } In this way it respect the matchNumber docs specification even if only one value is extracted. - To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org For additional commands, e-mail: user-h...@jmeter.apache.org
Re: problem with json path extractor
I think there is a bug in the file apache-jmeter-3.0-src/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java at line 163, there is the else where i goes if only one match } else { // else just one value extracted Object obj = extractedValues.get(0); String objAsString = obj != null ? obj.toString() : ""; //$NON-NLS-1$ * vars.put(currentRefName, * * objAsString); * * if (matchNumber < 0 && getComputeConcatenation()) {* * vars.put(currentRefName + ALL_SUFFIX, objAsString);* * }* } The part which set the vars is worng it should be like the following: } else { // else just one value extracted Object obj = extractedValues.get(0); String objAsString = obj != null ? obj.toString() : ""; //$NON-NLS-1$ * if (matchNumber < 0 && getComputeConcatenation()) {* * vars.put(currentRefName + "_1", * * objAsString);* * vars.put(currentRefName + ALL_SUFFIX, objAsString);* * } else {* * vars.put(currentRefName, * * objAsString);* * }* } In this way it respect the matchNumber docs specification even if only one value is extracted. -- "Ai sensi e per gli effetti della legge sulla tutela dei dati personali (D.lgs 196/2003), le informazioni contenute nella presente @mail sono di natura riservata e destinate ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso personale; come tali, pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E' proibito leggere, copiare, usare o diffondere il contenuto della presente @mail senza autorizzazione. Se avete ricevuto questa @mail per errore, siete pregati di rispedire la stessa al mittente. Grazie"
Re: problem with json path extractor
The problem persist, but I found out why. I attach a testing sample to explain it. At first I have to admit that I had a some misunderstanding * JSON extractor gives multiples vars as result, not an array * the foreach loop (it loop trough varname_1..N and not on array) I was misguided by imprecise and poor article on rest api testing, I should have read carefully the docs first. Anyway there is still a problem. I think that the json component ignore the Match Numbers = -1 when it match only one From the docs: Match Numbers If the JSON Path query leads to many results, you can choose which one(s) to extract as Variables: 0 : means random (Default Value) -1 means extract all results, they will be named as variable name_N (where N goes from 1 to Number of results X : means extract the Xth result. If this Xth is greater than number of matches, then nothing is returned. Default value will be used When JSON extractor match only one result it return the var name without the counter number even if Match Numbers = -1 In the example I attached the problem is evident. Il 17/10/2016 22:47, Philippe Mouawad ha scritto: Hello, There are some fixes in nightly build. Could you try it ? http://jmeter.apache.org/nightly.html If issue persists, can you create a demo Test plan using Java Request where you put the JSON in ResponseData and the JSON-PATH POST PROCESSOR that you use. Thank you On Mon, Oct 17, 2016 at 4:17 PM, Roberto Bragawrote: I'm having a problem not sure if it is a bug or not. Making the long story short. I use jmeter 3.0 and bundled json path extractor with some rest api to make subsequent calls with foreach. Lets say we have this scenario country api -> region api ->city api->shop list Get the country list and extract the array of country id and pass it to a foreach get regions list for each country, another call to region api and exctract the cities from the result Generally everithing works, I get an array and the foreach works as expected. But there are situation where I get only one result, because for instance there is only one region in the country. In this case json path extractor do not give an array but a simple string var. This cause the following foreach to not get executed. I'm not sure if this is the normal behaviour but this completely broke my script. Another strange thinks is that I used the debug sampler to monitor the script and the array never appear there but it exist since the foreach get executed, the var appear only when is a string. Here is a debug example: idCountryList_1=37 idCountryList_2=38 idCountryList_ALL=37,38 idCountryList_matchNr=2 idR=8 idRegioneList_1=8 idRegioneList_2=12 idRegioneList_3=3 idRegioneList_ALL=8,12,3 idRegioneList_matchNr=3 idCityList=37006 idCityList_ALL=37006 idCityList_matchNr=1 for idCountryList I expect to see as first line something like idCountryList = [37, 38] While idCityList appear because is not an array since the json contain just one result. In this real example after extracting the city list I have another api call that do not get executed because idCityList is not an array so the foreach get jumped. I hope I've been clear. Thank for any support Roberto -- "Ai sensi e per gli effetti della legge sulla tutela dei dati personali (D.lgs 196/2003), le informazioni contenute nella presente @mail sono di natura riservata e destinate ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso personale; come tali, pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E' proibito leggere, copiare, usare o diffondere il contenuto della presente @mail senza autorizzazione. Se avete ricevuto questa @mail per errore, siete pregati di rispedire la stessa al mittente. Grazie" - To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org For additional commands, e-mail: user-h...@jmeter.apache.org -- "Ai sensi e per gli effetti della legge sulla tutela dei dati personali (D.lgs 196/2003), le informazioni contenute nella presente @mail sono di natura riservata e destinate ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso personale; come tali, pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E' proibito leggere, copiare, usare o diffondere il contenuto della presente @mail senza autorizzazione. Se avete ricevuto questa @mail per errore, siete pregati di rispedire la stessa al mittente. Grazie" false false false saveConfig true true true true true true true true true false true true false false false true false
Re: problem with json path extractor
Hello, There are some fixes in nightly build. Could you try it ? http://jmeter.apache.org/nightly.html If issue persists, can you create a demo Test plan using Java Request where you put the JSON in ResponseData and the JSON-PATH POST PROCESSOR that you use. Thank you On Mon, Oct 17, 2016 at 4:17 PM, Roberto Bragawrote: > I'm having a problem not sure if it is a bug or not. > Making the long story short. > I use jmeter 3.0 and bundled json path extractor with some rest api to > make subsequent calls with foreach. > > Lets say we have this scenario > country api -> region api ->city api->shop list > Get the country list and extract the array of country id and pass it to a > foreach get regions list for each country, another call to region api and > exctract the cities from the result > > Generally everithing works, I get an array and the foreach works as > expected. > But there are situation where I get only one result, because for instance > there is only one region in the country. > In this case json path extractor do not give an array but a simple string > var. This cause the following foreach to not get executed. > I'm not sure if this is the normal behaviour but this completely broke my > script. > Another strange thinks is that I used the debug sampler to monitor the > script and the array never appear there but it exist since the foreach get > executed, the var appear only when is a string. > > Here is a debug example: > > idCountryList_1=37 > idCountryList_2=38 > idCountryList_ALL=37,38 > idCountryList_matchNr=2 > idR=8 > idRegioneList_1=8 > idRegioneList_2=12 > idRegioneList_3=3 > idRegioneList_ALL=8,12,3 > idRegioneList_matchNr=3 > idCityList=37006 > idCityList_ALL=37006 > idCityList_matchNr=1 > > > for idCountryList I expect to see as first line something like > idCountryList = [37, 38] > While idCityList appear because is not an array since the json contain > just one result. > In this real example after extracting the city list I have another api > call that do not get executed because idCityList is not an array so the > foreach get jumped. > I hope I've been clear. > Thank for any support > Roberto > > > > > > -- > "Ai sensi e per gli effetti della legge sulla tutela dei dati personali > (D.lgs 196/2003), > le informazioni contenute nella presente @mail sono di natura riservata e > destinate > ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso > personale; come tali, > pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E' > proibito leggere, > copiare, usare o diffondere il contenuto della presente @mail senza > autorizzazione. > Se avete ricevuto questa @mail per errore, siete pregati di rispedire la > stessa al mittente. > Grazie" > > - > To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org > For additional commands, e-mail: user-h...@jmeter.apache.org > > -- Cordialement. Philippe Mouawad.
problem with json path extractor
I'm having a problem not sure if it is a bug or not. Making the long story short. I use jmeter 3.0 and bundled json path extractor with some rest api to make subsequent calls with foreach. Lets say we have this scenario country api -> region api ->city api->shop list Get the country list and extract the array of country id and pass it to a foreach get regions list for each country, another call to region api and exctract the cities from the result Generally everithing works, I get an array and the foreach works as expected. But there are situation where I get only one result, because for instance there is only one region in the country. In this case json path extractor do not give an array but a simple string var. This cause the following foreach to not get executed. I'm not sure if this is the normal behaviour but this completely broke my script. Another strange thinks is that I used the debug sampler to monitor the script and the array never appear there but it exist since the foreach get executed, the var appear only when is a string. Here is a debug example: idCountryList_1=37 idCountryList_2=38 idCountryList_ALL=37,38 idCountryList_matchNr=2 idR=8 idRegioneList_1=8 idRegioneList_2=12 idRegioneList_3=3 idRegioneList_ALL=8,12,3 idRegioneList_matchNr=3 idCityList=37006 idCityList_ALL=37006 idCityList_matchNr=1 for idCountryList I expect to see as first line something like idCountryList = [37, 38] While idCityList appear because is not an array since the json contain just one result. In this real example after extracting the city list I have another api call that do not get executed because idCityList is not an array so the foreach get jumped. I hope I've been clear. Thank for any support Roberto -- "Ai sensi e per gli effetti della legge sulla tutela dei dati personali (D.lgs 196/2003), le informazioni contenute nella presente @mail sono di natura riservata e destinate ad un uso aziendale-lavorativo con esclusione di utilizzi ad uso personale; come tali, pertanto, sono riservate esclusivamente ai destinatari sopra indicati. E' proibito leggere, copiare, usare o diffondere il contenuto della presente @mail senza autorizzazione. Se avete ricevuto questa @mail per errore, siete pregati di rispedire la stessa al mittente. Grazie" - To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org For additional commands, e-mail: user-h...@jmeter.apache.org