I have a Java test project that I would like to import in my JMeter test so that I can call the existing methods in the test project. I did some research, and came to know that I can create a jar of my Java project, copy the jar into the JMETER_HOME/lib/ext folder, and then use the BeanShell Processor to call the external methods.
I am trying to use the existing test project, and call its methods to generate a JSON payload. I added a BeanShell PreProcessor, and did something like:
import com.qa.base.services.user.User;
User user = User.generateSimpleUser();
user.setField("username", "testUsername");
user.setField("password", "testPassword");
vars.put("requestJsonPayload", user.toString());
This does not seem to work, and I get an ERROR:
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import com.qa.base.services.user.User'' : Typed variable declaration : Method Invocation User.generateSimpleUser()
Anybody know how I can achieve what I am trying to do? Any suggestions, comments, links to tutorials, examples would be helpful. Thanks in advance!
More Info:
I am also using a BeanShell PostProcessor that gets the response payload of one of my requests, removes some fields in the payload, and constructs a new payload which I can send as a request payload for another request. The BeanShell PostProcessor works without any issues. I used JSONObject for this, and my code looks like:
import org.json.JSONObject;
String jsonString = prev.getResponseDataAsString();
print(jsonString);
JSONObject responseJSON = new JSONObject(jsonString);
responseJSON.remove("createTime");
responseJSON.remove("id");
vars.put("updatedJsonPayload",responseJSON.toString());
Put the jar that contains "com.qa.base.services.user.User" and all its dependencies in jmeter/lib folder and it should work.