Advertisement
Guest User

Untitled

a guest
Dec 5th, 2014
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. package com.emerge.nongui.test.LoadTestingNonGUI;
  2.  
  3. import org.apache.jmeter.config.Argument;
  4. import org.apache.jmeter.control.LoopController;
  5. import org.apache.jmeter.engine.StandardJMeterEngine;
  6. import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
  7. import org.apache.jmeter.protocol.http.util.HTTPArgument;
  8. import org.apache.jmeter.testelement.TestPlan;
  9. import org.apache.jmeter.threads.ThreadGroup;
  10. import org.apache.jmeter.util.JMeterUtils;
  11. import org.apache.jorphan.collections.HashTree;
  12. import org.junit.Test;
  13.  
  14. public class JmeterNonGuiTest {
  15. @Test
  16. public void test()
  17. {
  18. StandardJMeterEngine jmeter = new StandardJMeterEngine();
  19. HashTree testPlanTree = new HashTree();
  20. HTTPSampler httpSampler = new HTTPSampler();
  21. httpSampler.setProtocol("http");
  22. httpSampler.setDomain("hostname");
  23. httpSampler.setPort(8080);
  24. httpSampler.setPath("pathname");
  25. httpSampler.setMethod("POST");
  26. HTTPArgument httpArgument = new HTTPArgument();
  27. httpArgument.setValue("[{ \"firstname\": \"venkatachalam\", \"name\": \"Venkata\"}]");
  28. // Loop Controller
  29. LoopController loopController = new LoopController();
  30. loopController.setLoops(1);
  31. loopController.addTestElement(httpSampler);
  32. loopController.setFirst(true);
  33. loopController.initialize();
  34. // Test Plan
  35. TestPlan testPlan = new TestPlan("Create JMeter Script From Java Code");
  36. // Thread Group
  37. ThreadGroup threadGroup = new ThreadGroup();
  38. threadGroup.setNumThreads(1);
  39. threadGroup.setRampUp(1);
  40. threadGroup.setSamplerController(loopController);
  41. // Construct Test Plan from previously initialized elements
  42. testPlanTree.add("testPlan", testPlan);
  43. testPlanTree.add("loopController", loopController);
  44. testPlanTree.add("threadGroup", threadGroup);
  45. testPlanTree.add("httpSampler", httpSampler);
  46. // Run Test Plan
  47. jmeter.configure(testPlanTree);
  48. jmeter.run();
  49.  
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement