All Downloads are FREE. Search and download functionalities are using the official Maven repository.

us.abstracta.jmeter.javadsl.codegeneration.params.EnumParam Maven / Gradle / Ivy

Go to download

Simple API to run JMeter performance tests in an VCS and programmers friendly way.

There is a newer version: 028
Show newest version
package us.abstracta.jmeter.javadsl.codegeneration.params;

import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import us.abstracta.jmeter.javadsl.codegeneration.params.EnumParam.EnumPropertyValue;

/**
 * Is a parameter with an enum value.
 *
 * @param  is the type of the enum value.
 * @since 0.62
 */
public class EnumParam & EnumPropertyValue> extends FixedParam {

  public EnumParam(Class paramType, String expression, T defaultValue) {
    super(paramType, expression, e -> parse(paramType, e), defaultValue);
  }

  private static  & EnumPropertyValue> T parse(Class enumType,
      String propertyValue) {
    if (propertyValue.isEmpty()) {
      return null;
    }
    Optional ret = Arrays.stream(enumType.getEnumConstants())
        .filter(v -> v.propertyValue().equals(propertyValue))
        .findAny();
    return ret.orElseThrow(() -> new IllegalArgumentException(
        "Unknown " + enumType.getSimpleName() + " property value: " + propertyValue));
  }

  @Override
  public Set getImports() {
    return Collections.singleton(paramType.getName());
  }

  @Override
  public String buildCode(String indent) {
    return paramType.getSimpleName() + "." + value.name();
  }

  public interface EnumPropertyValue {

    String propertyValue();

  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy