How to create a Maven java project in IntelliJ IDEA

IntelliJ IDEA: is a Java integrated development environment (IDE) for developing computer software. It is developed by JetBrains (formerly known as IntelliJ), and is available as an Apache 2 Licensed community edition and in a proprietary commercial edition. Both can be used for commercial development. 
Prerequisite Software:
1. Jdk download and install

2. IntelliJ IDEA download and install
3. Gradle distribution download and extract desired location
Create a Maven Java project in IntelliJ IDEA:

1.  File --> New --> Project
       a. Select 'Maven' from left sidebar, Set jdk path and Click 'Next' button

       b. Enter GroupId and ArtifactId, then Click 'Next' button

      c. Type Project name and set desired Project location which want to save project, finally Click 'Finish' button
   d. Choose an option to open project
e. Maven project created and download necessary things
3. Add gradle dependencies
     a.  Click View --> Tools Windows --> Maven
     b. Click on 'pom.xml' file from left sidebar (1) 
     c. Add desired dependency under <dependencies> </dependencies>  (2)
   <dependencies>  
     <dependency>  
       <groupId>io.rest-assured</groupId>  
       <artifactId>rest-assured</artifactId>  
       <version>3.0.1</version>  
       <scope>test</scope>  
     </dependency>  
   </dependencies>  

        added upper dependencies for REST Assured
Note: Two https://mvnrepository.com/ and http://search.maven.org/ site where you will desired maven dependency    
         d. Click refresh button (3)  to import jar files and Synchronizing Changes in Maven Project


4. Add java package or class 
   a. add main project code : src --> main --> java
  b. add code testing main project : src --> test --> java



How to create a Gradle java project in IntelliJ IDEA

IntelliJ IDEA: is a Java integrated development environment (IDE) for developing computer software. It is developed by JetBrains (formerly known as IntelliJ), and is available as an Apache 2 Licensed community edition and in a proprietary commercial edition. Both can be used for commercial development. 
Prerequisite Software:
1. Jdk download and install

2. IntelliJ IDEA download and install
3. Gradle distribution download and extract desired location
Create a Gradle Java project in IntelliJ IDEA:
1. Open IntelliJ IDEA, install or enable Gradle Plugins from here File --> Settings --> Plugins  and restart

2.  File --> New --> Project
       a. Select 'Gradle' from left sidebar, Set jdk path, Select Java and Click 'Next' button

          b. Enter GroupId and ArtifactId, then Click 'Next' button

             c. Select 'Create directories for empty content roots automatically', 'Create separate module per source set' and 'Use local gradle distribution' then set gradle distribution path as 'gradle home' input and Click 'Next' button

           d. Type Project name and set desired Project location which want to save project, finally Click 'Finish' button
         e. Gradle project created
3. Add gradle dependencies
     a.  Click View --> Tools WIndows --> Gradle
     b. Click on 'build.gradle' file from left sidebar (1) 
     c. Add desired dependency under (2)

  dependencies {  
    testCompile group: 'junit', name: 'junit', version: '4.12'  
   // https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java  
   compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.0.1'  
 // https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver  
   compile group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: '3.0.1'  
   // https://mvnrepository.com/artifact/info.cukes/cucumber-junit  
   compile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.5'  
   // https://mvnrepository.com/artifact/info.cukes/cucumber-java  
   compile group: 'info.cukes', name: 'cucumber-java', version: '1.2.5'  
 // https://mvnrepository.com/artifact/info.cukes/cucumber-core  
   compile group: 'info.cukes', name: 'cucumber-core', version: '1.2.5'  
 )  
        added upper dependencies for Cucumber and Selenium Webdriver 
Note:
Two https://mvnrepository.com/ and http://search.maven.org/ site where you will desired dependency 
     d. Click refresh button (3)  to import jar files and Synchronizing Changes in Gradle Project

4. Add java package or class 
   a. add main project code : src --> main --> java
  b. add code testing main project : src --> test --> java

How to write a completed Jmeter Test Plan for load testing using Jmeter API in Java

 Jmeter is excellent tool used to do load testing on the application. Jmeter has graphical(GUI) and Non graphical(Non GUI) options. Non graphical option use Jmeter API to write a complete test plan for loading testing in java.
Pre-prerequisites:
1. JMeter install somewhere.
2. Add JMeter jars from /lib and especially /lib/ext folders in your project or module class path.

Load the jmeter properties:
 //Set jmeter home for the jmeter utils to load  
 String jmeterHomelocation = "F:\\apache-jmeter-2.13\\";  
 String jmeterPropertieslocation = jmeterHomelocation + "bin\\jmeter.properties";  
   
 //JMeter Engine  
 StandardJMeterEngine jmeter = new StandardJMeterEngine();  
   
 //JMeter initialization (properties, log levels, locale, etc)  
 JMeterUtils.setJMeterHome(new File(jmeterHomelocation).getPath());  
 JMeterUtils.loadJMeterProperties(new File(jmeterPropertieslocation).getPath());  
 // see extra log messages of i.e. DEBUG level  
 JMeterUtils.initLogging();  
 JMeterUtils.initLocale();  

Create "Test Plan" Object and JOrphan HashTree:
 // JMeter Test Plan, basically JOrphan HashTree  
 HashTree testPlanTree = new HashTree();  
             
 // Test Plan  
 TestPlan testPlan = new TestPlan("Java code Test Plan");  
 testPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName());  
 testPlan.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());  
 testPlan.setUserDefinedVariables((Arguments) new ArgumentsPanel().createTestElement());  

Graphical: Thread Group
Right-click on the Test Plan > Add > Threads (Users) > Thread Group
Type below values in corresponding field
Number of Threads (users)   : 1
Ramp-Up Period (in seconds) : 1
Loop Count  : 1
Non Graphical: Thread Group
 // Thread Group  
 ThreadGroup threadGroup = new ThreadGroup();  
 threadGroup.setName("Test Thread Group");  
 threadGroup.setNumThreads(1);  
 threadGroup.setRampUp(1);  
 threadGroup.setSamplerController(loopCtrl);  
 threadGroup.setProperty(TestElement.TEST_CLASS, ThreadGroup.class.getName());  
 threadGroup.setProperty(TestElement.GUI_CLASS, ThreadGroupGui.class.getName());  

Graphical: Sampler
Right-click on the Thread Group > Add > Sampler > HTTP request
Write below values in corresponding field
Server Name or IP : hiromia.blogspot.com
Port NUmber       : 80
Path              : /

Non Graphical: Sampler
 HTTPSampler examplecomSampler = new HTTPSampler();  
 examplecomSampler.setDomain("www.google.com");  
 examplecomSampler.setPort(80);  
 examplecomSampler.setPath("/");  
 examplecomSampler.setMethod("GET");  
 examplecomSampler.setName("google");  
 examplecomSampler.setProperty(TestElement.TEST_CLASS, HTTPSampler.class.getName());  
 examplecomSampler.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());  
Loop Controller:
 // Loop Controller  
  LoopController loopCtrl = new LoopController();  
  loopCtrl.setLoops(10);  
  loopCtrl.setFirst(true);  
  loopCtrl.setProperty(TestElement.TEST_CLASS, LoopController.class.getName());  
  loopCtrl.setProperty(TestElement.GUI_CLASS, LoopControlPanel.class.getName());  
  loopCtrl.initialize();  

Graphical: Summary Report
Right-click on the Thread Group > Add > Listener > Summary Report

Non Graphical: Summary Report
 Summariser summer = null;  
  String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");  
  if (summariserName.length() > 0) {  
    summer = new Summariser(summariserName);  
  }  
   
 // Store execution results into a .jtl file, we can save file as csv also  
  String reportFile = "report\\report.jtl";  
  String csvFile = "report\\report.csv";  
  ResultCollector logger = new ResultCollector(summer);  
  logger.setFilename(reportFile);  
  ResultCollector csvlogger = new ResultCollector(summer);  
  csvlogger.setFilename(csvFile);  
  testPlanTree.add(testPlanTree.getArray()[0], logger);  
  testPlanTree.add(testPlanTree.getArray()[0], csvlogger);  
   

Run Test Plan:
 // Run Test Plan  
 jmeter.configure(testPlanTree);  
 jmeter.run()  

Completed Jmeter Test Plan java source code:
 import java.io.File;  
 import java.io.FileOutputStream;  
 import org.apache.jmeter.config.Arguments;  
 import org.apache.jmeter.config.gui.ArgumentsPanel;  
 import org.apache.jmeter.control.LoopController;  
 import org.apache.jmeter.control.gui.LoopControlPanel;  
 import org.apache.jmeter.control.gui.TestPlanGui;  
 import org.apache.jmeter.engine.StandardJMeterEngine;  
 import org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui;  
 import org.apache.jmeter.protocol.http.sampler.HTTPSampler;  
 import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;  
 import org.apache.jmeter.reporters.ResultCollector;  
 import org.apache.jmeter.reporters.Summariser;  
 import org.apache.jmeter.save.SaveService;  
 import org.apache.jmeter.testelement.TestElement;  
 import org.apache.jmeter.testelement.TestPlan;  
 import org.apache.jmeter.threads.ThreadGroup;  
 import org.apache.jmeter.threads.gui.ThreadGroupGui;  
 import org.apache.jmeter.util.JMeterUtils;  
 import org.apache.jorphan.collections.HashTree;  
   
   
 public class CompleteNongraphicaljplan {  
   public static void main(String[] argv) throws Exception {  
   
     //Set jmeter home for the jmeter utils to load  
     String jmeterHomelocation = "F:\\apache-jmeter-2.13\\";  
     String jmeterPropertieslocation = jmeterHomelocation + "bin\\jmeter.properties";  
   
   
     //JMeter Engine  
     StandardJMeterEngine jmeter = new StandardJMeterEngine();  
   
     //JMeter initialization (properties, log levels, locale, etc)  
     JMeterUtils.setJMeterHome(new File(jmeterHomelocation).getPath());  
     JMeterUtils.loadJMeterProperties(new File(jmeterPropertieslocation).getPath());  
     // see extra log messages of i.e. DEBUG level  
     JMeterUtils.initLogging();  
     JMeterUtils.initLocale();  
   
     // JMeter Test Plan, basically JOrphan HashTree  
     HashTree testPlanTree = new HashTree();  
   
     // First HTTP Sampler - open google.com  
     HTTPSampler examplecomSampler = new HTTPSampler();  
     examplecomSampler.setDomain("www.google.com");  
     examplecomSampler.setPort(80);  
     examplecomSampler.setPath("/");  
     examplecomSampler.setMethod("GET");  
     examplecomSampler.setName("google");  
     examplecomSampler.setProperty(TestElement.TEST_CLASS, HTTPSampler.class.getName());  
     examplecomSampler.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());  
   
   
     // Loop Controller  
     LoopController loopCtrl = new LoopController();  
     loopCtrl.setLoops(10);  
     loopCtrl.setFirst(true);  
     loopCtrl.setProperty(TestElement.TEST_CLASS, LoopController.class.getName());  
     loopCtrl.setProperty(TestElement.GUI_CLASS, LoopControlPanel.class.getName());  
     loopCtrl.initialize();  
   
     // Thread Group  
     ThreadGroup threadGroup = new ThreadGroup();  
     threadGroup.setName("Test Thread Group");  
     threadGroup.setNumThreads(1);  
     threadGroup.setRampUp(1);  
     threadGroup.setSamplerController(loopCtrl);  
     threadGroup.setProperty(TestElement.TEST_CLASS, ThreadGroup.class.getName());  
     threadGroup.setProperty(TestElement.GUI_CLASS, ThreadGroupGui.class.getName());  
   
     // Test Plan  
     TestPlan testPlan = new TestPlan("Java code Test Plan");  
     testPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName());  
     testPlan.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());  
     testPlan.setUserDefinedVariables((Arguments) new ArgumentsPanel().createTestElement());  
   
     // Construct Test Plan from previously initialized elements  
     testPlanTree.add(testPlan);  
     HashTree threadGroupHashTree = testPlanTree.add(testPlan, threadGroup);  
     threadGroupHashTree.add(examplecomSampler);  
       
   
     // save generated test plan to JMeter's .jmx file format  
     SaveService.saveTree(testPlanTree, new FileOutputStream("report\\jmeter_api_sample.jmx"));  
   
     //add Summarizer output to get test progress in stdout like:  
     // summary =   2 in  1.3s =  1.5/s Avg:  631 Min:  290 Max:  973 Err:   0 (0.00%)  
     Summariser summer = null;  
     String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");  
     if (summariserName.length() > 0) {  
       summer = new Summariser(summariserName);  
     }  
   
   
     // Store execution results into a .jtl file, we can save file as csv also  
     String reportFile = "summaryreport.jtl";  
     String csvFile = "summaryreport.csv";  
     ResultCollector logger = new ResultCollector(summer);  
     logger.setFilename(reportFile);  
     ResultCollector csvlogger = new ResultCollector(summer);  
     csvlogger.setFilename(csvFile);  
     testPlanTree.add(testPlanTree.getArray()[0], logger);  
     testPlanTree.add(testPlanTree.getArray()[0], csvlogger);  
       
           // Run Test Plan  
     jmeter.configure(testPlanTree);  
     jmeter.run();  
   
   
     System.exit(0);  
   
   
   }  
 }  
   

Output: