JMeter Custom Plugin Variable Substitution - jmeter

Context
I am developing a custom JMeter plugin which generates test data dynamically from a tree like structure.
The editor for the tree generates GUI input fields as needed, and therefore I have no set of defined configuration properties which are set in the respective TestElement. Instead, I serialize the tree as a whole in the GUI class, set the result as one property and deserialize it in the config element where it is processed further during test execution.
Problem
This works just fine, except that JMeter variable/function expressions like ${foo} or ${_bar(..)} in the dynamic input fields are not evaluated. As far as I understand the JMeter source code, the evaluation is triggered somehow if the respective property setters in org.apache.jmeter.testelement.TestElement are used which is not possible for my plugin.
Unfortunately, I was not able to find a proper implementation which can be used in my config element to evaluate such expressions explicitly after deserialization.
Question
I need a pointer to JMeter source code or documentation for evaluating variable/function expressions explicitly.

After I manages to setup the JMeter-Project properly in my IDE, I found org.apache.jmeter.engine.util.CompoundVariable which can be used like this:
CompoundVariable compoundVariable = new CompoundVariable();
compoundVariable.setParameters("${foo}");
// returns the value of the expression in the current context
compoundVariable.execute();

Related

Get parameter contexts from Nifi custom processor

I need to create a Nifi (v1.17.0) custom processor with a property having several possible values. These values are generated during the execution of the previous processors in the flow.
The flow is as follows:
Processor A : Generate a yaml file.
Processor B : (the one I've been trying to create) Get the values in the yaml file generated previously and use them to populate a property in order to let the user select the one he needs. The process will then be adapted depending on the value selected.
I've found a solution based on the property method identifiesControllerService(DistributedMapCacheClient.class). It offers the possibility to have a property based on a dropdown menu with several possible choice (use a controller service or parameter contexts).
My idea is to use a parameter contexts available for the processor. So I would like to add the values I need in a Parameter context. This has to be done in the Processor A (which is also a custom processor) in order to use them in the property in the Processor B.
But I didn't find any way to add a parameter in the Parameter context programmaticaly in the onTrigger method of the Processor A. How can I add this parameter?

Can not get number of xml nodes from document using spring integration

I am attempting to get the count of the //Root/Record elements using spring integrations int-xml:xpath-header-enricher. It comes back zero regardless of the document passed in.
You have to configure your XPath expression like this:
<int-xml:xpath-expression id="countExpression" expression="count(//ns:Ephemeris/ns:Record)"
ns-prefix="ns"
ns-uri="http://www.sandia.gov/pgmm/Ephemeris"/>
And have it as a reference from the <int-xml:header> instead.
The problem is that your root element in the XML comes with the xmlns="http://www.sandia.gov/pgmm/Ephemeris", so, there is no other way unless we honor namespaces in your source XML. For this purpose we introduce artificial prefix, even if your source XML does have then. We need that in XPath to properly distinguish elements based on some namespace.
I think default DocumentBuilderFactory just doesn't honor namespaces making your possible XPath expressions much horrible when it comes to several namespaces support.

Nifi: Reading external properties in custom Processor

I have updated the variable registry to point to a custom properties file and i am able to read those in my processors using expression language with out any issues.
How ever i want to read them in my Custom Processor's (extending the AbstractProcessor) onTrigger()
I tried flowFile.getAttributes() and context.getAllProperties() and it is not getting picked up.
Appreciate any inputs.
Thanks
To clarify, you want to reference the value of these externally-defined variables inside the application logic of your CustomProcessor#onTrigger() method?
You can:
Load the variable definitions by querying NiFiProperties#getVariableRegistryProperties() or NiFiProperties#getVariableRegistryPropertiesPaths. Once you have a reference to the variable definitions, you can parse and use them as you wish.
You can reference them via the flowfile attributes or processor properties if those attributes or properties support Expression Language and it is appropriately scoped. The PropertyDescriptor will list expressionLanguageSupported() and return an ExpressionLanguageScope, which is an enum consisting of NONE, VARIABLE_REGISTRY, and FLOWFILE_ATTRIBUTES (which also includes the VR).
I don't understand the scenario where you want your code to load custom variables that aren't controllable by the flow administrator, which would be populated via processor properties or flowfile attributes. If you really feel you need to access custom variables that aren't available via the context or flowfile, you can use Option 1 above, but you could also theoretically store those variables in environment variables, System properties, etc.

What is the best way to pass variables among tests from data entry till validation?

I have some test cases for a web application in Robot Framework. In some cases I define a unit and then validate this action by checking database and GUI. The variables which I use in define, should be available in validation in order to check details; keep in mind they are randomly generated in the test case. I have three approaches in mind to pass variables from define to validation:
Make variables global and use their global names further; it makes the scenarios ambiguous since the reader can't detect where did this variable come from without checking inner steps.
Pass variables to both define and validation keywords; scenarios look weird when vast number of parameters are required.
Save variables in a dictionary and pass it to both define and validation keywords.
Which one is the best? Are there any other ways to do the process? Are there any other pros and cons which I've forgotten?
3rd option is better to storing variables in dictionary.
There is similar way out also
Consider following is keyword
My Keyword
[Argument] #{data}
// get respective values from keys and use further for validation
${value1}= Get Template Value From List ${Key1} #{data}
${value2}= Get Template Value From List ${Key2} #{data}
Call above keyword as follows
*** Test Cases ***
Test data
My Keyword
... key1=value1
... key2=value2
So above code will increase readability as you know what kind of data your test case is using
As you are passing data at your test case level, you don't need to go anywhere else to find data.
I finally use a combination of #2 & #3. I used #3 in the top level of test cases and #2 for some inner keywords which don't need all the data and a subclass of that is sufficient for them.

How to set dynamic input dependency on gradle task

I'm working on a Gradle plugin that has a task that generates compilable Java source code. It takes as input for the code generator a "static" directory (property value) which should contain files in a special language (using a specific extent). In addition, if a particular configuration property is set to true, it will also search for files with the same extent in the entire classpath (or better, in a specific configuration).
I want to make sure that the task runs if any of its input dependencies are new.
It's easy enough to add #InputDirectory to the property definition for the "static" location, but I'm unsure how to handle the "dynamic" input dependency.
I have a property that defines the name of the configuration that would be used to search for additional files with that extent. We'll call that "searchConfiguration". This property is optional. If it's not set, it will use "compile". I also have the property that specifies whether we will search for additional files in the first place. We'll call that "inspectDependencies".
I think I could write a #Input-annotated method that returns essentially the "configurations.searchConfiguration.files" list. We'll call that "getDependencies". I think that is the basic idea. However, I don't understand what to do about "inspectDependencies". I could easily make "getDependencies" return an empty list if "inspectDependencies" is false, but is that truly the correct thing to do? It seems likely that if someone changed "inspectDependencies" from "true" to "false" after a build, the next build should run the task again.
Well, this is tentative, but I asked about this on the Gradle Forum and Mark Viera convinced me that it really should be this simple, although it requires #InputFiles instead of #Input. My particular method looks like this:
#InputFiles
def getOptionalYangClasspath() {
return inspectDependencies ? project.configurations[yangFilesConfiguration] : Collections.emptyList()
}

Resources