public class MethodCallContext extends Object
MethodCallBuilder instances to create
MethodCalls for a given JMeter test plan subtree.
One MethodCallContext is created for each JMeter test element in a test plan tree, and they are
linked in tree structure (through getParent() method to provide entire structure to
MethodCallBuilder instances when building a MethodCall
| Modifier and Type | Class and Description |
|---|---|
static interface |
MethodCallContext.MethodCallContextEndListener |
| Constructor and Description |
|---|
MethodCallContext(org.apache.jmeter.testelement.TestElement testElement,
org.apache.jorphan.collections.HashTree childrenTree,
MethodCallContext parent,
MethodCallBuilderRegistry builderRegistry) |
| Modifier and Type | Method and Description |
|---|---|
void |
addEndListener(MethodCallContext.MethodCallContextEndListener listener)
Allows registering logic that needs to be executed at the end of MethodCall build for this
context.
|
MethodCall |
buildMethodCall()
Builds a MethodCall for the current context.
|
MethodCallContext |
child(org.apache.jmeter.testelement.TestElement element,
org.apache.jorphan.collections.HashTree childrenTree)
Allows creating a child context for the given test element and tree.
|
<V> V |
computeEntryIfAbsent(Object key,
Supplier<V> computation)
Gets existing entry or creates a new one using provided computation function.
|
<T extends MethodCallBuilder> |
findBuilder(Class<T> builderClass)
Finds the builder associated to the given JMeter test element class.
|
Object |
getBuilderOption(String optionName) |
org.apache.jorphan.collections.HashTree |
getChildrenTree()
Gets the JMeter test plan subtree of children elements of current context test element.
|
Object |
getEntry(Object key)
Gets a value associated to a given key in the context.
|
MethodCall |
getMethodCall()
The method call created for this context.
|
MethodCallContext |
getParent()
Gets the parent context.
|
MethodCallContext |
getRoot()
Gets the root context associated to the test plan.
|
org.apache.jmeter.testelement.TestElement |
getTestElement()
Gets the JMeter test element associated to this context.
|
MethodCallContext |
prependChild(org.apache.jmeter.testelement.TestElement testElement,
org.apache.jorphan.collections.HashTree childrenTree)
Adds a child method call context, as first child call, built using provided test element and
tree.
|
MethodCallContext |
removeChild(Predicate<org.apache.jmeter.testelement.TestElement> filter)
Allows removing an instance of the given test element class from the children tree.
|
void |
replaceMethodCall(org.apache.jmeter.testelement.TestElement element,
UnaryOperator<MethodCall> operator)
Allows replacing or transforming the method call associated to a given test element.
|
void |
setEntry(Object key,
Object value)
Allows to store a value associated to a given key in the context.
|
public MethodCallContext(org.apache.jmeter.testelement.TestElement testElement,
org.apache.jorphan.collections.HashTree childrenTree,
MethodCallContext parent,
MethodCallBuilderRegistry builderRegistry)
public org.apache.jmeter.testelement.TestElement getTestElement()
public MethodCallContext getParent()
This is useful in some scenarios to register end listeners on parent node, or access root
context for globally shared entries (check setEntry(Object, Object)).
public MethodCallContext getRoot()
This is useful when some data has to only be processed once and at root of the test plan build context.
public org.apache.jorphan.collections.HashTree getChildrenTree()
This is useful when some alteration or inspection is required in the tree before other builder methods try to convert contained test elements.
Eg: DslHttpSampler.CodeBuilder uses this method to
remove children HTTP Headers which are directly included as chained methods of httpSampler
method invocation.
public Object getEntry(Object key)
The context allows you to store (through setEntry(Object, Object)) any sort of
information on it that may be required later on be used by the builder in some other test
element context (for example: check if a test element already was processed by this builder).
key - is an object identifying an entry in the context. A simple way of sharing info for a
MethodCallBuilder is just use the MethodCallBuilder class as key, storing some
custom class instance with structured context info for the particular
MethodCallBuilder.public void setEntry(Object key, Object value)
key - identifies the entry in context to later on be able to retrieve it.value - the value to store in the context, associated to the given key.for more detailspublic <V> V computeEntryIfAbsent(Object key, Supplier<V> computation)
key - identifies the entry in context to later on be able to retrieve it.computation - function used to build the new entry for the given key, if none exists.for more detailspublic void addEndListener(MethodCallContext.MethodCallContextEndListener listener)
This allows to do some advance stuff, like registering some action/logic to be executed on a parent context after processing current context and only under some specific condition (eg: when no other sibling test element is included in parent context).
listener - specifies the listener containing the logic to be executed at the end of
MethodCall build.public MethodCall buildMethodCall()
This might be useful in some MethodCallBuilders to trigger a build of children context (after removal for example).
MethodCall instance.public MethodCallContext child(org.apache.jmeter.testelement.TestElement element, org.apache.jorphan.collections.HashTree childrenTree)
element - the test element associated to the child context.childrenTree - the test element subtree.public MethodCallContext prependChild(org.apache.jmeter.testelement.TestElement testElement, org.apache.jorphan.collections.HashTree childrenTree)
This is useful when it is needed to modify existing test plan, for example, to optimize it and use default config elements that avoid code duplication in children elements.
testElement - specifies the test element from which to create the new method call.childrenTree - specifies children elements of the test element, which are also going to be
built and attached as children method calls of the method call created for
the test element.public MethodCallContext removeChild(Predicate<org.apache.jmeter.testelement.TestElement> filter)
If multiple instances exists, then only the first one is removed.
filter - specifies condition to be matched by test element to be removed.public <T extends MethodCallBuilder> T findBuilder(Class<T> builderClass)
T - is the type of the builder to find. This provides proper type safety when
using the method.builderClass - is the class of the builder to find.public MethodCall getMethodCall()
This is useful mainly when method calls need to be modified after their creation, for example
in an end listener (addEndListener(MethodCallContextEndListener)).
public void replaceMethodCall(org.apache.jmeter.testelement.TestElement element,
UnaryOperator<MethodCall> operator)
This is particularly helpful in scenarios like module controller, where basic conversion of a controller has to be replaced by a call to a test fragment containing the target controller pointed by the module controller
element - is the test element associated to the method call to be replaced/transformed.operator - provides the logic to be applied to create a new method call from the original
test element method call.Copyright © 2023. All rights reserved.