On 20 December 2013 22:43, RL <[email protected]> wrote:
> I'm trying to test a JSON value that may be = null.
>
> jp@gc - JSON Path Assertion doesn't appear to return anything or define the
> variable if it encounters a null value, so I was trying to get it to work
> like this:
>
> - use jp@gc - JSON Path Extractor to try to extract the value to a variable.
> - use Beanshell Assertion to try to test to see if the variable exists or
> has a null value
> - If the variable does not exist, or exists and has a null value, I know
> that the JSON value was null.
>
> I haven't written any scripts with Jmeter before, so I may be doing
> something obviously wrong, but here is what I've tried:
>
> try {
>   String blobvalue = vars.get("myValue");

blobvalue is not used anwhere else; should be myValue

No need to declare variables.

>   log.info("myValue =" + myValue);
> }
> catch (e) {

Will not be thrown.

>   log.info( "caught exception: "+e );
>   string myValue = null;

"string" is not valid - and anyway should not (re)declare variables

> }
>
>
> if (myValue.length() > 0  && myValue != 0 ){

myValue can be null here, hence the NPE.

>  Failure = true;
>  FailureMessage = "myValue was " + myValue + ".";
> }
> else{
>   Failure = false;
> }
>
> For this test, a null value actually passes the test.
>
> The problem I'm running into is that the try/catch block doesn't work.
> Instead, I see the following message in the log:
>
> jmeter.assertions.BeanShellAssertion:
> org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval
> Sourced file: inline evaluation of: ``import
> org.apache.jmeter.util.JMeterUtils; try {   //myValue = JMeterUtils.get . .
> . '' : Attempt to resolve method: length() on undefined variable or class
> name: myValue
>
> Can anyone tell me what I'm doing wrong and/or how to get this test of a
> null JSON value to work?
>
> Thanks very much!

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to