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

com.testdroid.api.model.APITestCaseRun Maven / Gradle / Ivy

There is a newer version: 3.34.0
Show newest version
package com.testdroid.api.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.testdroid.api.APIEntity;
import com.testdroid.api.APIList;
import com.testdroid.api.util.TimeConverter;
import org.apache.commons.lang3.StringUtils;

import jakarta.xml.bind.annotation.XmlType;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;

import static java.math.RoundingMode.HALF_UP;

/**
 * @author Slawomir Pawluk 
 */
public class APITestCaseRun extends APIEntity {

    public static final String DEFAULT_SUITE_NAME = "all";

    @XmlType(namespace = "APITestCaseRun")
    public enum Result {
        PASSED,
        FAILED,
        SKIPPED,
        NOT_AVAILABLE
    }

    private String className;

    private Date createTime;

    private double duration;

    private String errorMessage;

    private String methodName;

    private Result result = Result.PASSED;

    private String stacktrace;

    private APIList steps;

    private String suiteName = DEFAULT_SUITE_NAME;

    public APITestCaseRun() {
    }

    @SuppressWarnings("squid:S107")
    public APITestCaseRun(
            Long id, BigDecimal duration, Result result, String errorMessage, String stacktrace,
            LocalDateTime createTime, String className, String methodName, String suiteName) {
        super(id);
        this.duration = duration.doubleValue();
        this.result = result;
        this.errorMessage = errorMessage;
        this.stacktrace = stacktrace;
        this.createTime = TimeConverter.toDate(createTime);
        this.className = className;
        this.methodName = methodName;
        this.suiteName = suiteName;
    }

    public double getDuration() {
        return duration;
    }

    public void setDuration(double duration) {
        this.duration = duration;
    }

    public void setDuration(String durationString) {
        BigDecimal bigDecimal = BigDecimal.ZERO;
        if (StringUtils.isNotEmpty(durationString)) {
            try {
                bigDecimal = new BigDecimal(durationString.replace(",", "."));
            } catch (NumberFormatException ignored) {
                // ignored
            }
        }
        duration = bigDecimal.setScale(2, HALF_UP).doubleValue();
    }

    public Result getResult() {
        return result;
    }

    public void setResult(Result result) {
        this.result = result;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public String getStacktrace() {
        return stacktrace;
    }

    public void setStacktrace(String stacktrace) {
        this.stacktrace = stacktrace;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public APIList getSteps() {
        return steps;
    }

    public void setSteps(APIList steps) {
        this.steps = steps;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public String getSuiteName() {
        return suiteName;
    }

    public void setSuiteName(String suiteName) {
        this.suiteName = StringUtils.defaultIfEmpty(suiteName, DEFAULT_SUITE_NAME);
    }

    @Override
    @JsonIgnore
    protected  void clone(T from) {
        APITestCaseRun apiTestCaseRun = (APITestCaseRun) from;
        cloneBase(from);
        this.className = apiTestCaseRun.className;
        this.createTime = apiTestCaseRun.createTime;
        this.duration = apiTestCaseRun.duration;
        this.errorMessage = apiTestCaseRun.errorMessage;
        this.methodName = apiTestCaseRun.methodName;
        this.result = apiTestCaseRun.result;
        this.stacktrace = apiTestCaseRun.stacktrace;
        this.steps = apiTestCaseRun.steps;
        this.suiteName = apiTestCaseRun.suiteName;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy