Skip to main content

Template

Template are the best way to create node in three node, template implement interface org.anasoid.jmc.core.wrapper.template.JmcTemplate and teh quick way is the extends org.anasoid.jmc.core.wrapper.template.AbstractJmcTemplate.

All node in JMC can add children as wrapper or as template, template can construct complex content.

AbstractJmcTemplate has 3 methods to override:

  1. abstract JmcWrapperBuilder<?> init() : Create the builder.

  2. void prepareBuilder(T builder) {} : prepare builder adding children node, attribute ....

  3. void prepareWrapper(W wrapper) {}: Alter wrapper after been generated by the builder.

Example#

Home Page is a simple template, we can use it whn needed with calling constructor (new HomePageTemplate())

public class HomePageTemplate
extends AbstractJmcTemplate<
HTTPSamplerProxyWrapper, HTTPSamplerProxyWrapper.HTTPSamplerProxyWrapperBuilder> {
@Override
protected JmcWrapperBuilder<?> init() {
return HTTPSamplerProxyWrapper.builder().withPath("/");
}
}

Contact us is Http Sampler with email as input.

public class ContactUsPageTemplate
extends AbstractJmcTemplate<
HTTPSamplerProxyWrapper, HTTPSamplerProxyWrapper.HTTPSamplerProxyWrapperBuilder> {
private String email;
public ContactUsPageTemplate(String email) {
this.email = email;
}
@Override
protected void prepareBuilder(HTTPSamplerProxyWrapperBuilder builder) {
super.prepareBuilder(builder);
builder
.withMethod(HttpMethod.POST)
.addArgument("email", email)
.addArgument(
"content",
"lorem ipsum dolor sit amet consectetur adipiscing elit '..");
}
@Override
protected JmcWrapperBuilder<?> init() {
return HTTPSamplerProxyWrapper.builder().withPath("/contactus");
}
}

In this test we add sampler home as contactus with variable 'email'.

TestPlanWrapper testPlanWrapper =
TestPlanWrapper.builder()
.addThread(
ThreadGroupWrapper.builder()
.addSampler(new HomePageTemplate())
.addSampler(new ContactUsPageTemplate("${email}"))
.build())
.build();

SimplePageTemplate#

org.anasoid.jmc.core.wrapper.template.samplers.http.SimplePageTemplate is helper to construct template with the following attribute name,domain,path, method

Extend Wrapper

It's recommended to extend from SimplePageTemplate and use constructor without argument.

SimplePageControllerTemplate#

org.anasoid.jmc.core.wrapper.template.samplers.http.controller.SimplePageControllerTemplate is a helper that can include HttpSampler in a Controller, the controller is of type RecordingControllerWrapper.

The name of controller will be "{samplername} CTRL"

SimplePageControllerTemplate has 3 methods to override:

  1. void prepareSamplerBuilder(HTTPSamplerProxyWrapperBuilder builder) : prepare main sampler, builder is available and can alter sampler.
  2. void beforeMainSampler(RecordingControllerWrapperBuilder controller) : called before add man sampler to controller, we Alter controller at this level.
  3. void afterMainSampler(RecordingControllerWrapperBuilder controller) : called after add man sampler to controller, we Alter controller at this level.