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

io.github.ericdriggs.reportcard.model.TestCaseFaultModel Maven / Gradle / Ivy

There is a newer version: 0.1.19
Show newest version
package io.github.ericdriggs.reportcard.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.github.ericdriggs.reportcard.util.truncate.TruncateUtils;
import lombok.Data;
import lombok.experimental.SuperBuilder;

import java.util.ArrayList;
import java.util.List;

@Data
@SuperBuilder(toBuilder = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class TestCaseFaultModel extends io.github.ericdriggs.reportcard.dto.TestCaseFault {

    public TestCaseFaultModel() {
    }

    private FaultContext faultContext;

    @JsonProperty("faultContext")
    public FaultContext getFaultContext() {
        if (faultContext == null && getFaultContextFk() != null) {
            setFaultContextFk(getFaultContextFk());
        }
        return faultContext;
    }

    public TestCaseFaultModel setFaultContextFk(Byte faultContextFk) {
        this.faultContext = FaultContext.fromFaultContextId(faultContextFk);
        this.faultContextFk = faultContextFk;
        return this;
    }

    public TestCaseFaultModel withTruncateErrorMessages() {
        return this.toBuilder()
                .message(truncateString(message))
                .value(truncateString(value))
                .build();
    }

    public static List withTruncatedErrorMessages(List fs) {
        if (fs == null || fs.isEmpty()) {
            return fs;
        }
        List faults = new ArrayList<>();
        for (TestCaseFaultModel f : fs) {
            faults.add(f.withTruncateErrorMessages());
        }
        return faults;
    }


    static String truncateString(String str) {
        return TruncateUtils.truncateString(str, truncateLength);
    }

    private final static int truncateLength = 512;


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy