Can JMeter mock HTTP request
Solution 1:
The easiest option would be going for i.e. WireMock which is extremely powerful and flexible.
You can integrate it with JMeter by adding WireMock jar (along with dependencies) to JMeter Classpath and running the WireMockServer from the JSR223 Test Elements using Groovy language.
If you're not too comfortable with Groovy you can run WireMock as a standalone Java application using OS Process Sampler
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
public class WireMockTest {
public static void main(String[] args) {
WireMockServer wireMockServer = new WireMockServer();
configureFor("0.0.0.0", 8080);
wireMockServer.start();
StubMapping foo = stubFor(get(urlEqualTo("/wiretest"))
.willReturn(aResponse()
.withStatus(200)
.withBody("Hello World")));
wireMockServer.addStubMapping(foo);
}
}