0
votes

I need to test the performance of a web service method using Jmeter in Java, i found that Jmeter API provide StandardJMeterEngine class to run test method by Jmeter, and using parameter of type "String":

public class JMeterTestFromCode {
    public static void main(String[] args) {
        // Engine
        StandardJMeterEngine jm = new StandardJMeterEngine();
        // jmeter.properties
        JMeterUtils.loadJMeterProperties("c:/tmp/jmeter.properties");
        HashTree hashTree = new HashTree();
        // HTTP Sampler
        HTTPSampler httpSampler = new HTTPSampler();
        httpSampler.setDomain("www.google.com");
        httpSampler.setPort(80);
        httpSampler.setPath("/");
        httpSampler.setMethod("GET");
        // Loop Controller
        TestElement loopCtrl = new LoopController();
        ((LoopController) loopCtrl).setLoops(1);
        ((LoopController) loopCtrl).addTestElement(httpSampler);
        ((LoopController) loopCtrl).setFirst(true);
        // Thread Group
        SetupThreadGroup threadGroup = new SetupThreadGroup();
        threadGroup.setNumThreads(1);
        threadGroup.setRampUp(1);
        threadGroup.setSamplerController((LoopController) loopCtrl);
        // Test plan
        TestPlan testPlan = new TestPlan("MY TEST PLAN");
        hashTree.add("testPlan", testPlan);
        hashTree.add("loopCtrl", loopCtrl);
        hashTree.add("threadGroup", threadGroup);
        hashTree.add("httpSampler", httpSampler);
        jm.configure(hashTree);
        jm.run();
    }
}

my problem is that i'm using a web service of an EJB, this web service uses custom parameters (bean objects), here after how i run it by Soap :

String ENDPOINT_ADDRESS = "http://server:8080/server-ejb/MyServiceClass?wsdl";
QName SERVICE_DATA_FINDER = new QName(
    "http://test.service.com/", "MyServiceClass");
javax.xml.ws.Service service;

    service = javax.xml.ws.Service.create(
            new URL(ENDPOINT_ADDRESS), SERVICE_DATA_FINDER);
    IMyServiceClass finder = service.getPort(IMyServiceClass.class);
    MyBean bean = new MyBean();
    // bean.set...
    // bean.set...
    finder.myMethod("foo", bean);

The goal is to create a Maven project that provide an automated performance test for the Web-Service + retrieving test result (that's why i need to implement WS test in Jmeter using Java)

How can i test my web service using StandardJMeterEngine or other API ?

Thanks in advance !

1
Did you checkout the user manual?Keerthivasan
Which manual user ? do you mean JMeterEngine implementation ?Shessuky

1 Answers

0
votes

Is there any specific reason for testing your service from Java code? JMeter provides SOAP/XML-RPC Request Sampler for XML-based web services testing which is more real-life use case.

See Testing SOAP/REST Web Services Using JMeter guide for more details.

However, if testing a web service from Java code is a must, you can just add jar, containing IMyServiceClass and dependencies to JMeter's CLASSPATH.