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

com.github.ddemin.envrouter.base.TestEntityWrapper Maven / Gradle / Ivy

Go to download

This library helps to route yours parallel tests to different environments and allows to use personal environment settings for each parallel test (java thread)

The newest version!
package com.github.ddemin.envrouter.base;

import static java.lang.String.format;

import com.github.ddemin.envrouter.RouterConfig;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import lombok.Getter;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;

/**
 * Created by Dmitrii Demin on 30.11.2017.
 */
@Getter
@Slf4j(topic = "wrapper")
public class TestEntityWrapper {

  public static final String ANY_ENV = "any";

  private T entity;
  private String requiredEnvironmentName;
  private int priority;
  // TODO Unit-test
  private boolean requiresHardLock;

  public String getName() {
    return "";
  }

  public String getPath() {
    return "";
  }

  /**
   * Creates wrapper for test entity.
   *
   * @param entity entity
   * @param requiredEnvironmentName name of environment that required for this entity
   * @param priority entity's priority. Lower - more chances to be tested first
   */
  @SuppressFBWarnings
  public TestEntityWrapper(
      @NonNull T entity,
      String requiredEnvironmentName,
      int priority
  ) {
    this(entity, requiredEnvironmentName, priority, false);
  }

  /**
   * Creates wrapper for test entity.
   *
   * @param entity entity
   * @param requiredEnvironmentName name of environment that required for this entity
   * @param priority entity's priority. Lower - more chances to be tested first
   * @param requiresHardLock entity requires hard-lock of target environment
   */
  @SuppressFBWarnings
  public TestEntityWrapper(
      @NonNull T entity,
      String requiredEnvironmentName,
      int priority,
      boolean requiresHardLock
  ) {
    this.entity = entity;

    if (RouterConfig.ENV_FORCED != null) {
      this.requiredEnvironmentName = RouterConfig.ENV_FORCED.toLowerCase();
    } else {
      this.requiredEnvironmentName = requiredEnvironmentName == null
          ? chooseAnyOrDefaultEnv().toLowerCase()
          : requiredEnvironmentName.toLowerCase();
    }
    this.priority = priority;
    this.requiresHardLock = requiresHardLock;
  }

  @Override
  public String toString() {
    return format(
        "%s (Env: %s, Priority: %d)",
        getEntity(),
        getRequiredEnvironmentName(),
        getPriority()
    );
  }

  private String chooseAnyOrDefaultEnv() {
    return RouterConfig.ENV_DEFAULT == null ? ANY_ENV : RouterConfig.ENV_DEFAULT;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy