0
votes

I want use improved version of: How can i use jar file into loop counter - Jmeter

//jar data

public class PabBDetailsIncluded {

public static String ARGENTINA(String sourceAccount)
    {
        String a = 
                "{"
                + "\"money\": {"
                + "\"amount\": 10,"
                + "\"currency\": \"EUR\""
                + "},"

                + "\"description\": \"Payment\","
                + "\"sourceAccount\": " + sourceAccount + ","



                + "}"
                + "}";

        return a;
        }

1) with above data i want to 'feed' Jmeter call

just instead of all values to be static from the jar file, i want to pass 'sourceAccount' during the execution, rather then being hard-coded into the jar file.

2) i tell loop counter to count with: ${__groovy(com.example.TestData.getDeclaredMethods().size(),)}

3) into JSR223 PreProcessor "Script" area is like:

    import com.example.PabBDetailsIncluded;

def sourceAccount = vars.get("accountNumberLogger");


def testData = new com.example.PabBDetailsIncluded()
def methods = testData.class.getDeclaredMethods(sourceAccount)
def payload = org.apache.commons.lang.reflect.MethodUtils.invokeExactMethod(testData, methods[vars.get('__jm__Loop Controller__idx') as int].getName())
sampler.addNonEncodedArgument('',payload,'')
sampler.setPostBodyRaw(true)

The error i got is:

2019-11-13 09:55:00,099 ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223 script, JSR223 PreProcessor1 javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: static com.example.PabBDetailsIncluded.getDeclaredMethods() is applicable for argument types: (java.lang.String) values: [5001000001573300] at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) ~[groovy-all-2.4.13.jar:2.4.13] at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72) ~[groovy-all-2.4.13.jar:2.4.13] at javax.script.CompiledScript.eval(Unknown Source) ~[?:1.8.0_231] at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:221) ~[ApacheJMeter_core.jar:4.0 r1823414] at org.apache.jmeter.modifiers.JSR223PreProcessor.process(JSR223PreProcessor.java:44) [ApacheJMeter_components.jar:4.0 r1823414] at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:849) [ApacheJMeter_core.jar:4.0 r1823414] at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:467) [ApacheJMeter_core.jar:4.0 r1823414] at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:416) [ApacheJMeter_core.jar:4.0 r1823414] at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:250) [ApacheJMeter_core.jar:4.0 r1823414] at java.lang.Thread.run(Unknown Source) [?:1.8.0_231] Caused by: groovy.lang.MissingMethodException: No signature of method: static com.example.PabBDetailsIncluded.getDeclaredMethods() is applicable for argument types: (java.lang.String) values: [5001000001573300] at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1501) ~[groovy-all-2.4.13.jar:2.4.13] at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1487) ~[groovy-all-2.4.13.jar:2.4.13] at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:53) ~[groovy-all-2.4.13.jar:2.4.13] at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) ~[groovy-all-2.4.13.jar:2.4.13] at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) ~[groovy-all-2.4.13.jar:2.4.13] at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) ~[groovy-all-2.4.13.jar:2.4.13] at Script26.run(Script26.groovy:13) ~[?:?] at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317) ~[groovy-all-2.4.13.jar:2.4.13] ... 9 more

If i use the data from jar file without dynamic values, everything is ok.

Any help would be appreciated.

1

1 Answers

1
votes

This is not the same as for some reason you're using static function which needs to be called a little bit differently.

Moreover now you need to pass the parameter to the function and I fail to see where you're passing this parameter.

Your code needs to be amended to look like:

def sourceAccount = vars.get("accountNumberLogger")
def testData = new com.example.PabBDetailsIncluded()
def methods = testData.class.getMethods()
def payload = methods[vars.get('__jm__Loop Controller__idx') as int].invoke(testData, sourceAccount)

Demo:

enter image description here

References: