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

com.katalon.testops.JunitUploader Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package com.katalon.testops;

import com.katalon.testops.helper.ExceptionHelper;
import com.katalon.testops.helper.LogHelper;
import com.katalon.testops.helper.ParameterHelper;
import com.katalon.testops.testops.TestOpsService;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.File;

@Mojo( name = "junit-uploader", defaultPhase = LifecyclePhase.TEST)
public class JunitUploader extends AbstractMojo {

  private final Log log = getLog();

  @Parameter(property = "serverUrl", defaultValue = "https://analytics.katalon.com")
  private String serverUrl;

  @Parameter(property = "apiKey", required = true)
  private String apiKey;

  @Parameter(property = "projectId", required = true)
  private long projectId;

  @Parameter(property = "reportPath" , defaultValue = "${project.build.directory}/surefire-reports")
  private String reportPath;

  @Parameter(property = "isSilent" , defaultValue = "false")
  private boolean isSilent;

  @Parameter(property = "proxyOption", required = true, defaultValue = "NO_PROXY")
  private String proxyOption;

  @Parameter(property = "proxyServerType")
  private String proxyServerType;

  @Parameter(property = "proxyServerAddress")
  private String proxyServerAddress;

  @Parameter(property = "proxyServerPort")
  private String proxyServerPort;

  @Parameter(property = "proxyUsername")
  private String proxyUsername;

  @Parameter(property = "proxyPassword")
  private String proxyPassword;

  @Parameter(property = "proxyExceptionList")
  private String proxyExceptionList;

  public void execute() throws MojoExecutionException {
    try {
      serverUrl = StringUtils.removeEnd(serverUrl, "/");

      log.info("--------------INFO----------------");
      log.info("Server URL: " + serverUrl);
      log.info("Project IDL: " + projectId);
      log.info("Report Path: " + reportPath);
      log.info("--------------INFO----------------");

      File reportDir = new File(reportPath);
      if (!reportDir.exists() || !reportDir.isDirectory()) {
        throw new IllegalStateException("Report directory is not exist: " + reportPath);
      }

      ParameterHelper.set("proxy.option", proxyOption);
      ParameterHelper.set("proxy.serverType", proxyServerType);
      ParameterHelper.set("proxy.serverAddress", proxyServerAddress);
      ParameterHelper.set("proxy.serverPort", proxyServerPort);
      ParameterHelper.set("proxy.username", proxyUsername);
      ParameterHelper.set("proxy.password", proxyPassword);
      ParameterHelper.set("proxy.exceptionList", proxyExceptionList);

      LogHelper.setLogSupplier(this::getLog);
      TestOpsService service = new TestOpsService(serverUrl, apiKey);
      service.uploadJunitReport(projectId, reportPath);
    } catch (Exception e) {
      if (isSilent) {
        log.error(e.getMessage(), e);
      } else {
        ExceptionHelper.wrap(e);
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy