Jmeter sampler does not see resources file

Viewed 1276

I am creating custom sampler for JMeter. I am able to import my jar into library, the sampler is visible within the GUI, but the fields are not displayed properly.

Project structure

Here is my code.

Custom.java

public class Custom extends AbstractSampler implements TestBean {

  private String email = "";

  public Custom() {
    super();
  }

  public SampleResult sample(Entry entry) {
    SampleResult res = new SampleResult();
    res.setSampleLabel(getName());
    res.setResponseData(("Hello " + getEmail()).getBytes());
    res.setSuccessful(Boolean.TRUE);
    return res;
  }

  public void setEmail(String email){ this.email = email; }
  public String getEmail(){ return email; }
}

CustomBeanInfo.java

public class CustomBeanInfo extends BeanInfoSupport {

  protected CustomBeanInfo() {
    super(Custom.class);

    createPropertyGroup("contact", new String[]{
      "email"
    });

    PropertyDescriptor p = property("email");
    p.setValue(NOT_UNDEFINED, Boolean.TRUE);
    p.setValue(DEFAULT, "asd");
  }
}

CustomResources.properties

displayName=Custom Sampler
email.displayName=Email Address
email.shortDescription=User Email Address
contact.displayName=Contact

And this is how it looks in JMeter GUI. My guess is that the properties file is not correctly attached to sampler or the constructor is not executed.

JMeter Gui

EDIT 1: Added pom.xml file content

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.apache.jmeter</groupId>
  <artifactId>custom-sampler</artifactId>
  <version>0.2.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.apache.jmeter</groupId>
      <artifactId>ApacheJMeter_core</artifactId>
      <version>2.10</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
  </build>
</project>

EDIT 2: When using sampler (adding it to thread group) following error appears in log

2016/03/25 09:28:23 WARN  - jmeter.testbeans.gui.GenericTestBeanCustomizer: org.apache.jmeter.protocol.java.sampler.Custom#email(java.lang.String) does not appear to have been configured 
3 Answers

I had same issue. I solve putting *Resource.properties in same package of BeanInfo.java

IE:

src
|-main
  |-java
    |-org.apache.jmeter.custom
      |-Custom.java
      |-CustomBeanInfo.java
      |-CustomResource.properties

Make this test: Open your jar with winrar (or other tools) and move properties file

NB: When you build project, resources won't put in java packages, for example in maven you have to specify which file keep in package

Related