Class MethodCall

    • Method Detail

      • forStaticMethod

        public static MethodCall forStaticMethod​(Class<?> methodClass,
                                                 String methodName,
                                                 MethodParam... params)
        Generates a new instance for a static method within a given class that is applicable to a given set of parameters.

        This is usually used to get clas factory methods calls. Eg: Duration.ofSeconds.

        Parameters:
        methodClass - the class that contains the static method.
        methodName - the name of the method to search for in the given class.
        params - the parameters used to search the method in the given class and to associate to the method call.
        Returns:
        the newly created instance
      • buildUnsupported

        public static MethodCall buildUnsupported()
        Allows to build a special method call used when some conversion is not supported.
        Returns:
        the special method call to include as child of other method calls.
      • setCommented

        public void setCommented​(boolean commented)
        Marks or un-marks this method call as to be commented out.

        This is mainly used when you want to provide users with an easy way to enable an existing part of a test plan that is currently not enabled or used.

        Parameters:
        commented - specifies to comment or uncomment this method call.
        Since:
        1.3
      • isCommented

        public boolean isCommented()
        Allows to check if this method call is marked to be commented out.
        Returns:
        true if the method call is marked to be commented out, false otherwise.
        Since:
        1.3
      • headingComment

        public void headingComment​(String comment)
        Allow to add a heading comment to the method call.

        This is helpful to add some note or comment on created element. Mainly comments that require users attention, like reviewing and/or changing a particular part of test plan.

        Parameters:
        comment - specifies the comment to add before the method call.
        Since:
        1.8
      • emptyCall

        public static MethodCall emptyCall()
        Generates a method call that should be ignored (no code should be generated).

        This is helpful when some MethodCallBuilder supports a given test element conversion, but no associated generated DSL code should be included.

        Returns:
        the empty method call.
      • getReturnType

        public Class<?> getReturnType()
      • child

        public MethodCall child​(MethodCall child)
        Allows adding a child call to this call.

        This method should only be used in seldom scenarios where you need to manually add children calls. In most of the cases this is not necessary, since DSL framework automatically takes care of JMeter children conversion.

        If the call defines a ChildrenParam parameter, then children are just added as parameters of the call. Otherwise, a children method will be looked into the class retunrned by this method, and if there is, then chained into this call and used to register provided child element.

        Warning: You should only use this method after applying any required chaining.

        Parameters:
        child - specifies the method call to be added as child call of this call.
        Returns:
        the current call instance for further configuration.
      • replaceChild

        public void replaceChild​(MethodCall original,
                                 MethodCall replacement)
        Allows replacing a child method call with another.

        This is useful when some element has to alter an already built method call, for example when replacing module controllers by test fragment method calls.

        Parameters:
        original - the method call to be replaced.
        replacement - the method call to be used instead of the original one.
        Since:
        1.3
      • prependChild

        public void prependChild​(MethodCall child)
        Allows adding a child method at the beginning of children methods.

        This is mainly useful when in need to add configuration elements, that are usually added at the beginning of children calls.

        Parameters:
        child - the child method to add at the beginning of children methods.
        Since:
        1.8
      • chain

        public MethodCall chain​(String methodName,
                                MethodParam... params)
        Allows chaining a method call to this call.

        This method is useful when adding property configuration methods (like DslTestPlan.sequentialThreadGroups()) or other chained methods that further configure the element (like DslHttpSampler.post(String, ContentType).

        This method abstracts some common logic regarding chaining. For example: if chained method only contains a parameter and its value is the default one, then method is not chained, since it is not necessary. It also takes care of handling boolean parameters which chained method may or may not include a boolean parameter.

        Parameters:
        methodName - is the name of the method contained in the returned instance of this method call, which has to be chained to this method call.
        params - is the list of parameters used to find the method and associated to the chained method call. Take into consideration that the exact same number and type of parameters must be specified for the method to be found, otherwise an exception will be generated.
        Returns:
        this call instance for further chaining or addition of children elements.
        Throws:
        UnsupportedOperationException - when no method with given names and/or parameters can be found to be chained in current method call.
      • chain

        public MethodCall chain​(MethodCall methodCall)
        Allows to chain a method call in current method call.

        This method is handy when you want to chain a method that actually currently is not available. Mainly as a marker of a feature that could be implemented in the future but still isn't (like authentication methods still not implemented).

        In general cases chain(String, MethodParam...) should be used instead.

        Parameters:
        methodCall - specifies the method call to chain
        Returns:
        current method call for further usage.
        Since:
        1.5
      • chainComment

        public MethodCall chainComment​(String comment)
        Allows to add a comment as part of the chain of commands.

        This is useful to add notes to drive user attention to some particular chained method. For example, when parameters passed to a chained method need to be reviewed or changed.

        Parameters:
        comment - the comment to chain.
        Returns:
        the method call for further usage.
        Since:
        1.5
      • reChain

        public void reChain​(MethodCall other)
        Allows extracting from a given call the list of chained method calls and re assign them to this call.

        This is usually helpful when you provide in a DSL element alias methods for children elements. Eg: DslBaseHttpSampler.header(String, String).

        Parameters:
        other - is the call to extract the chained methods from.
      • unchain

        public void unchain​(String methodName)
        Allows to remove an existing chained method call.

        This is useful when you need to alter an already created method call, for example, when optimizing a conversion and removing settings that are already covered by some other configuration element (eg: httpDefaults).

        Parameters:
        methodName - specifies the name of the chained method to be removed. If there are multiple methods chained with same name, then all of them will be removed.
        Since:
        1.8
      • chainSize

        public int chainSize()
        Allows to check the number of method calls chained into current method call.

        This is useful to check, for example, if a particular test element has any non default settings.

        Returns:
        the number chained method calls.
        Since:
        1.8
      • buildCode

        public String buildCode()
        Generates the code for this method call and all associated parameters, children elements and chained methods.
        Returns:
        the generated code.
      • buildAssignmentCode

        public String buildAssignmentCode​(String indent)
      • buildParamsCode

        protected String buildParamsCode​(String indent)