Class MethodCallContext
- java.lang.Object
-
- us.abstracta.jmeter.javadsl.codegeneration.MethodCallContext
-
public class MethodCallContext extends Object
Contains information and logic needed byMethodCallBuilderinstances 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 toMethodCallBuilderinstances when building a MethodCall- Since:
- 0.45
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMethodCallContext.MethodCallContextEndListener
-
Constructor Summary
Constructors Constructor Description MethodCallContext(org.apache.jmeter.testelement.TestElement testElement, org.apache.jorphan.collections.HashTree childrenTree, MethodCallContext parent, MethodCallBuilderRegistry builderRegistry)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEndListener(MethodCallContext.MethodCallContextEndListener listener)Allows registering logic that needs to be executed at the end of MethodCall build for this context.MethodCallbuildMethodCall()Builds a MethodCall for the current context.MethodCallContextchild(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> VcomputeEntryIfAbsent(Object key, Supplier<V> computation)Gets existing entry or creates a new one using provided computation function.<T extends MethodCallBuilder>
TfindBuilder(Class<T> builderClass)Finds the builder associated to the given JMeter test element class.ObjectgetBuilderOption(String optionName)org.apache.jorphan.collections.HashTreegetChildrenTree()Gets the JMeter test plan subtree of children elements of current context test element.ObjectgetEntry(Object key)Gets a value associated to a given key in the context.MethodCallgetMethodCall()The method call created for this context.MethodCallContextgetParent()Gets the parent context.MethodCallContextgetRoot()Gets the root context associated to the test plan.org.apache.jmeter.testelement.TestElementgetTestElement()Gets the JMeter test element associated to this context.MethodCallContextprependChild(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.MethodCallContextremoveChild(Predicate<org.apache.jmeter.testelement.TestElement> filter)Allows removing an instance of the given test element class from the children tree.voidreplaceMethodCall(org.apache.jmeter.testelement.TestElement element, UnaryOperator<MethodCall> operator)Allows replacing or transforming the method call associated to a given test element.voidsetEntry(Object key, Object value)Allows to store a value associated to a given key in the context.
-
-
-
Constructor Detail
-
MethodCallContext
public MethodCallContext(org.apache.jmeter.testelement.TestElement testElement, org.apache.jorphan.collections.HashTree childrenTree, MethodCallContext parent, MethodCallBuilderRegistry builderRegistry)
-
-
Method Detail
-
getTestElement
public org.apache.jmeter.testelement.TestElement getTestElement()
Gets the JMeter test element associated to this context.- Returns:
- the test element.
-
getParent
public MethodCallContext getParent()
Gets the parent context.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)).- Returns:
- the parent context. Null is returned if the current context is the root context.
-
getRoot
public MethodCallContext getRoot()
Gets the root context associated to the test plan.This is useful when some data has to only be processed once and at root of the test plan build context.
- Returns:
- the parent context. Null is returned if the current context is the root context.
-
getChildrenTree
public org.apache.jorphan.collections.HashTree getChildrenTree()
Gets the JMeter test plan subtree of children elements of current context test element.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.CodeBuilderuses this method to remove children HTTP Headers which are directly included as chained methods of httpSampler method invocation.- Returns:
- the JMeter test plan children subtree.
-
getEntry
public Object getEntry(Object key)
Gets a value associated to a given key in the context.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).- Parameters:
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.- Returns:
- the value associated to the key. Null is returned if no entry is associated to the key.
-
setEntry
public void setEntry(Object key, Object value)
Allows to store a value associated to a given key in the context.- Parameters:
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.- See Also:
for more details
-
computeEntryIfAbsent
public <V> V computeEntryIfAbsent(Object key, Supplier<V> computation)
Gets existing entry or creates a new one using provided computation function.- Parameters:
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.- Since:
- 1.3
- See Also:
for more details
-
addEndListener
public void addEndListener(MethodCallContext.MethodCallContextEndListener listener)
Allows registering logic that needs to be executed at the end of MethodCall build for this context.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).
- Parameters:
listener- specifies the listener containing the logic to be executed at the end of MethodCall build.
-
buildMethodCall
public MethodCall buildMethodCall()
Builds a MethodCall for the current context.This might be useful in some MethodCallBuilders to trigger a build of children context (after removal for example).
- Returns:
- the
MethodCallinstance.
-
child
public 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.- Parameters:
element- the test element associated to the child context.childrenTree- the test element subtree.- Returns:
- the created child method context.
- Since:
- 1.3
-
prependChild
public 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.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.
- Parameters:
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.- Returns:
- the created child method call context.
- Since:
- 1.8
-
removeChild
public MethodCallContext removeChild(Predicate<org.apache.jmeter.testelement.TestElement> filter)
Allows removing an instance of the given test element class from the children tree.If multiple instances exists, then only the first one is removed.
- Parameters:
filter- specifies condition to be matched by test element to be removed.- Returns:
- the context associated to the removed test element, or null if no test element is found.
-
findBuilder
public <T extends MethodCallBuilder> T findBuilder(Class<T> builderClass)
Finds the builder associated to the given JMeter test element class.- Type Parameters:
T- is the type of the builder to find. This provides proper type safety when using the method.- Parameters:
builderClass- is the class of the builder to find.- Returns:
- the builder associated to the given JMeter test element class, or null if none is found.
-
getMethodCall
public MethodCall getMethodCall()
The method call created for this context.This is useful mainly when method calls need to be modified after their creation, for example in an end listener (
addEndListener(MethodCallContextEndListener)).- Returns:
- the created method call, if it has been already created, null otherwise.
- Since:
- 1.8
-
replaceMethodCall
public void replaceMethodCall(org.apache.jmeter.testelement.TestElement element, UnaryOperator<MethodCall> operator)Allows replacing or transforming the method call associated to a given test element.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
- Parameters:
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.- Since:
- 1.3
-
-