vlsi commented on issue #5946:
URL: https://github.com/apache/jmeter/issues/5946#issuecomment-1567341770

   I've some progress in https://github.com/apache/jmeter/pull/5944.
   
   Sample usage in Kotlin.
   
   Note: BeanShellSampler has methods like `setScript(String)`, however, it 
sets plain Java field instead of passing the value to `setProperty(...)`.
   `props[{ script }] =...` sets a corresponding JMeter property.
   
   ```kotlin
   val sampler = BeanShellSampler().apply {
       name = "BeanShell Sampler"
       props[{ script }] = 
"""ResponseMessage="COUNTER=${"$"}{__counter(FALSE)}""""
       props[{ filename }] = ""
       props[{ parameters }] = ""
       TestElementPropertyTransformer.USE_FUNCTIONS.visit(this)
       isRunningVersion = true
   }
   ```
   
   The same in Java:
   
   ```java
   BeanShellSampler sampler = new BeanShellSampler();
   sampler.setName("BeanShell Sampler");
   sampler.getProps().set(BeanShellSamplerClass::getScript, 
"ResponseMessage=\"COUNTER=${__counter(FALSE)}\"");
   sampler.getProps().set(BeanShellSamplerClass::getFilename, "");
   sampler.getProps().set(BeanShellSamplerClass::getParameters, "");
   TestElementPropertyTransformer.USE_FUNCTIONS.visit(sampler);
   sampler.setRunningVersion(true);
   ```
   
   In the ideal case, `BeanShellSampler` should expose the proper getters and 
setters on its own (e.g. `setScript(...)` that would propagate to 
`JMeterProperty`), however, having a common low-level API would be great.
   
   It would be nice to deprecate older "getPropertyAs(String, ..)` as they are 
unsafe form the `default value` point of view.
   In other words, if a property has a default value, then `getPropertyAs...` 
should return that default value instead of returning something else.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@jmeter.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to