I want to write JMeter requests in Java. I found some examples by googling but I am not understanding how to assert the response i.e. the way we use Response Assertion to check whether the page was loaded successfully or not. Please share step-by-step process for JMeter with java coding.
You can take a look at 5 Ways To Launch a JMeter Test without Using the JMeter GUI guide to learn how to run existing JMeter test scenario from Java code and how to create a JMeter test purely in Java.
Also refer jmeter-from-code snippet for working example.
In regards to implementing assertions, you can create a simple test plan i.e. having one request and one assertion, load it via SaveService.loadTree() method and inspect resulting HashTree to see how does it look under the hood.
Please refer the below link. Thought this might work. https://javaworks.wordpress.com/2013/06/28/beanshell-assertion-in-jmeter/