Setting variables from Mule 4 Script (Groovy) - groovy

Previously in Mule 3.x.x, we would be able to set variables from within a groovy script using. message.setInvocationProperty("name", "value").
I cannot seem find a way to do this anymore. I am aware that the mule message structure has changed, but is there a way for one to set variables/attributes from a Mule 4 script similar to the way we could in Mule 3?
Thanks in advance.

No, in Mule 4 you cannot modify vars directly.
You can set the return value of the script to go directly to a variable though using the target attribute, with it's value being the name of the variable:
<scripting:execute engine="groovy" target="myVar">
Probably best as well - to keep the script decoupled from mule specifics.

Related

In JMeter 5.3, variables do not work in functions [duplicate]

This question already has an answer here:
JMeter - submit JMeter function inside a script (JSR223 element)
(1 answer)
Closed 1 year ago.
I use groovy to write a script. In the screenshot, No. 1 works, No. 2 doesn't work, No. 3 works. It's normal to print No. 1 separately. No. 2 and No. 3 are written in a custom function. The parameter passed in by No. 2 is still ${re} instead of value
Don't inline JMeter Functions or Variables into Groovy scripts, your "No 1" and "No 3" work because they're GStrings and your "No 2" conflicts with JMeter Functions and/or Variables syntax.
So I would recommend moving your function into "Parameters" tab like:
Also according to JSR223 Sampler documentation:
Or Use Script Text and check Cache compiled script if available property.
When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.
So if your ${secretKey} variable changes from iteration to iteration only first value will be used and this may ruin your test so you might want to change it to vars.get('secretKey') expression
Also be aware that according to 9 Easy Solutions for a JMeter Load Test “Out of Memory” Failure article you should always be using the latest version of JMeter so consider upgrading to JMeter 5.4.1 (or whatever is the latest stable version available at JMeter Downloads page) on next available opportunity.

Store custom Groovy function in JMeter UI

Been struggling with this a lot lately: How do I store a custom Groovy script with imports etc in the JMeter UI so I can reuse it later?
I don't want to alter JMeter startup property files in any way
I want to be able to call this Groovy 20+ times within the JMX with different parameters
From the JMeter doc:
Once the script is working properly, it can be stored as a variable on
the Test Plan. The script variable can then be used to create the
function call.
The groovy (compatible with Beanshell) is 62 lines and includes imports of custom JAR files. If I could store this as a var callable with __groovy(param) that would be great, I don't see how to do that from the docs. Setting up 20 JSR223s is incredibly clunky but I am coming up with workarounds if there is no JMeter way to do this.
References:
https://jmeter.apache.org/usermanual/best-practices.html#developing_scripts
Depending on what you're trying to achieve:
There is a possibility to specify a path to the file with your code in any of JSR223 Test Elements so you won't have to copy and paste it multiple times into "Script" area so in case of changes you will need to amend it in one place only:
There is groovy.utilities property where you can specify the path to your .groovy file containing the logic callable from the __groovy() function, it defaults to bin/utility.groovy
You can compile your code to .jar file and store it under JMeter Classpath, this way you will be able to call your functions from any place. See How to Reuse Your JMeter Code with JAR Files and Save Time article for example implementation/usage details

Jenkins Extended Choice Parameter Plugin Groovy Script

So in the website for the plugin, the change-log for Version 0.61 (Mar 30, 2016) mentions that they have exposed Jenkins and project bindings for use in a groovy script. I'm currently trying to set a parameter (multi select) and i want it to have different options based on the value of another parameter which is set before this one in the Jenkins job. However i'm not able to get the value of that other parameter in the script.
My problem is very similar to the one explained here
I've tried using ${param}, $(param), $param, bindings.variables.get('param') in the script, and none of it works
I've also tried to set that parameter in the Variable bindings section of the script but still no success.
Any ideas about the correct way to obtain the value?
I set the variable binding as param on the other field that you want to dynamically populate and used param (please note that i didnt use $ ${} or binding.get etc). It worked for me.
As a side note, Will active choice reactive parameter work in your case?

Can we merge JAVA_OPTS variables through recipe in chef?

I have installed Java through some cookbook and have set some default variables, now I want to add some more variables (Application specific) through my cookbook. How can I do that through Recipes in Chef. I tried to pass some variables in setenv.sh but it is overriding the default values instead I want to merge the variables and override existing variable values.
My code in setenv.sh:
export JAVA_OPTS="$JAVA_OPTS -Xmx2048m"
where $JAVA_OPTS - default variables
First way to do it would be to update the attribute defining the bases values in your application cookbook, as the attributes are read before the recipes are evaluated your file would end up with the correct values.
You're not saying with which cookbook you're using so I'll base the example on the tomcat cookbook
This cookbook define an attribute default['tomcat']['java_options'] = '-Xmx128M -Djava.awt.headless=true'
The easiest way it to complement this by using something like
default['tomcat']['java_options'] = "#{default['tomcat']['java_options']} -Xmx2048m"
The obvious problem is that you end up with 2 -Xmx values, usually the JVM will take the latest but it become hard to find what options is at which value when there's a lot of overwriting.
Second option is to take advantage of jvmargs cookbook wich gives helpers functions to deine the java options and use in your setenv.sh template at end.

Can I use Groovy scripts in SoapUI to enable/disable assertions?

I'm using SoapUI Pro and a DataSource/DataSink loop to test a web service.
To make life more fun, I need to pull from four distinct source files, all of which will cause different expected results.
I'd really like to do this in a single test loop, because having scripts with multiple loops tends to crash SoapUI more often than not, but the sticking point is assertions.
How can I enable or disable assertions in a Groovy script in SoapUI? GetData doesn't give me anything to hook onto, and a documentation dive did not reveal the proper syntax. I'd assume something like testCase.assertion, but there's no such property as "assertion" on testCase.
Alternately, can I use a Groovy script to change the assertion's content? In other words, if I want phrase X with file 1, phrase Y with file 2, I'm just as happy using the same assertion, so long as I can change the content it's trying to match.
You could use your Groovy script to set some kind of property testCase.setPropertyValue('expected', 'value'), based on which file you are reading. You could then use property expansion ${testCase#expected#} in the assertion content.

Resources