Bug 61760 - Add "__isPropDefined" and "__isVarDefined" functions to know if property or variable exist
Summary: Add "__isPropDefined" and "__isVarDefined" functions to know if property or v...
Status: RESOLVED FIXED
Alias: None
Product: JMeter
Classification: Unclassified
Component: Main (show other bugs)
Version: 3.3
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-14 18:32 UTC by Philippe Mouawad
Modified: 2017-11-19 11:05 UTC (History)
2 users (show)



Attachments
Add patch with 2 functions, tests and xdocs (14.36 KB, patch)
2017-11-19 07:01 UTC, orimarko
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Mouawad 2017-11-14 18:32:15 UTC
This functions checks if variable isVarDefined

- __isVarDefined(varName)

It would return true or false
Comment 1 orimarko 2017-11-15 09:34:52 UTC
what about property? should we have another parameter to allow checking is property defined?
Comment 2 Philippe Mouawad 2017-11-15 18:11:18 UTC
(In reply to orimarko from comment #1)
> what about property? should we have another parameter to allow checking is
> property defined?

Don't know if it's really useful , in this case functions should be named:

__isSet(boolean isVar, String varOrProp)

isVar : true or false


Thoughts ?
Comment 3 Graham Russell 2017-11-15 18:38:41 UTC
I think that in general having flags to change function behaviour can be confusing, if they are boolean, what do they mean (when reading the code) and if they are strings or something, how do we find out what we should use?

I presume most of the time you don't care if it's a var or property?

I think that simply, __isDefined(varOrPropName) is best, unless more complex knowledge is required.

If vars and props can have the same name and you care about only the one being defined, how about:
__isVarDefined(name)
__isPropDefined(name)

or if they cannot have the same name, maybe:
__isDefined(varOrPropName) - true or false if var or prop is defined
and
__isVar(name) and __isProp(name) if you then care about the difference once you've done but this wouldn't work very well if both are defined and you are trying to find out which is defined, but that doesn't seem to be the use case here anyway.
Comment 4 Philippe Mouawad 2017-11-15 20:03:54 UTC
(In reply to Graham Russell from comment #3)
> I think that in general having flags to change function behaviour can be
> confusing, if they are boolean, what do they mean (when reading the code)
> and if they are strings or something, how do we find out what we should use?
> 

Function Helper Dialog can describe this.
We could use a mode instead of boolean.

> I presume most of the time you don't care if it's a var or property?

Not sure. User may have named by error a property and a variable the same.

> 
> I think that simply, __isDefined(varOrPropName) is best, unless more complex
> knowledge is required.
> 
> If vars and props can have the same name and you care about only the one
> being defined, how about:
> __isVarDefined(name)
> __isPropDefined(name)

Yes, my idea was just to avoid having too many functions.
> 
> or if they cannot have the same name, maybe:
> __isDefined(varOrPropName) - true or false if var or prop is defined
> and

This name is already taken by jmeter-plugins functions.

> __isVar(name) and __isProp(name) if you then care about the difference once
> you've done but this wouldn't work very well if both are defined and you are
> trying to find out which is defined, but that doesn't seem to be the use
> case here anyway.

But intuitively, I would say that this function tells me if name is a property or a variable, not if it's defined.

So I would end up to the following:

- Option 1 : isVarDefined / isPropDefined
- Option 2 : isSet(MODE, name), where mode is Property, Variable


Except for the additional function I feel Option 1 is better
Comment 5 orimarko 2017-11-16 13:40:22 UTC
I accept your suggestion and think isPropDefined is a good addition,
I wanted to point out that __V function code will
be almost equal to isVarDefined except return true/false instead of the value.

Can __V function be added is defined 2nd parameter, and if it's true return true/false instead of the value (default false as now)?
Comment 6 Philippe Mouawad 2017-11-16 18:46:32 UTC
(In reply to orimarko from comment #5)
> I accept your suggestion and think isPropDefined is a good addition,
> I wanted to point out that __V function code will
> be almost equal to isVarDefined except return true/false instead of the
> value.
> 
> Can __V function be added is defined 2nd parameter, and if it's true return
> true/false instead of the value (default false as now)?

I prefer a more meaningful name in fact. So let's go for a new function.
Comment 7 orimarko 2017-11-19 07:01:30 UTC
Created attachment 35537 [details]
Add patch with 2 functions, tests and xdocs
Comment 8 Philippe Mouawad 2017-11-19 11:05:17 UTC
Author: pmouawad
Date: Sun Nov 19 11:04:53 2017
New Revision: 1815725

URL: http://svn.apache.org/viewvc?rev=1815725&view=rev
Log:
Bug 61760 - Add "__isPropDefined" and "__isVarDefined" functions to know if property or variable exist
Contributed by Orimarko
Bugzilla Id: 61760

Added:
    jmeter/trunk/src/functions/org/apache/jmeter/functions/IsPropDefined.java   (with props)
    jmeter/trunk/src/functions/org/apache/jmeter/functions/IsVarDefined.java   (with props)
    jmeter/trunk/test/src/org/apache/jmeter/functions/TestIsPropDefined.java   (with props)
    jmeter/trunk/test/src/org/apache/jmeter/functions/TestIsVarDefined.java   (with props)
Modified:
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/functions.xml