https://bz.apache.org/bugzilla/show_bug.cgi?id=58316

Vincent <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

--- Comment #1 from Vincent <[email protected]> ---
1. I have a Junit test which sends web request and get the response
2. I have another java project in which, I call Jmeter run method, to run this
Junit test.
I'm getting the error java.lang.ExceptionInInitializerError. Here is the stack
trace. Anu help is much appreciated. Thanks in advance:

Code used:-


package Tests;

import static org.junit.Assert.*;

import org.apache.jmeter.control.LoopController;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
import org.apache.jmeter.protocol.java.sampler.JUnitSampler;
import org.apache.jmeter.reporters.ResultCollector;
import org.apache.jmeter.reporters.Summariser;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.threads.SetupThreadGroup;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.collections.HashTree;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class RatTest {

    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
    }

    @AfterClass
    public static void tearDownAfterClass() throws Exception {
    }

    @Test
    public void test() {
         StandardJMeterEngine jm = new StandardJMeterEngine();
            // jmeter.properties
           
JMeterUtils.loadJMeterProperties("c:/Tools/apache-jmeter-2.13/bin/jmeter.properties");
            JMeterUtils.setJMeterHome("c:/Tools/apache-jmeter-2.13");

            System.out.println("Jmeter Home : "+JMeterUtils.getJMeterHome());
            System.out.println("Jmeter Bin : "+JMeterUtils.getJMeterBinDir());
            String[] s= JMeterUtils.getSearchPaths();
            for(String s1 : JMeterUtils.getSearchPaths())
            {
            System.out.println("Search Path = "+s1);
            }

            HashTree hashTree = new HashTree();     

            // HTTP Sampler
         /*   HTTPSampler httpSampler = new HTTPSampler();
            httpSampler.setDomain("www.google.com");
            httpSampler.setPort(80);
            httpSampler.setPath("/");
            httpSampler.setMethod("GET");  */      

            JUnitSampler junitSampler = new JUnitSampler();
            junitSampler.setClassname("Ratable.Service.RestAssuredTests");
            junitSampler.setMethod("testFindUsingGroovyClosure");


            // Loop Controller
            TestElement loopCtrl = new LoopController();
            ((LoopController)loopCtrl).setLoops(1);
            ((LoopController)loopCtrl).addTestElement(junitSampler);
            ((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("junitSampler", junitSampler);       

            jm.configure(hashTree);

            //log results

            Summariser summer = null;
            String summariserName =
JMeterUtils.getPropDefault("summariser.name", "summary");//$NON-NLS-1$
            if (summariserName.length() > 0) {
                summer = new Summariser(summariserName);
            }

            String logFile = "c:/outfile.jtl";
            ResultCollector logger = new ResultCollector(summer);
            logger.setFilename(logFile);
            hashTree.add(hashTree.getArray()[0], logger);

            jm.run();
            jm.exit();

    }

}

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to