package org.dependencytrack.model;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class VulnerabilityAliasTest {

    @Test
    void testCopyFieldsFrom() {
        var alias = new VulnerabilityAlias();
        alias.setCveId("someCveId");
        alias.setSonatypeId("someSonatypeId");
        alias.setGhsaId("someGhsaId");
        alias.setOsvId("someOsvId");
        alias.setSnykId("someSnykId");
        alias.setGsdId("someGsdId");
        alias.setVulnDbId("someVulnDbId");
        alias.setInternalId("someInternalId");

        var other = new VulnerabilityAlias();
        other.setCveId("anotherCveId");
        other.setSonatypeId("anotherSonatypeId");
        other.setGhsaId("anotherGhsaId");
        other.setOsvId("anotherOsvId");
        other.setSnykId("anotherSnykId");
        other.setGsdId("anotherGsdId");
        other.setInternalId("anotherInternalId");
        other.setVulnDbId(null);

        alias.copyFieldsFrom(other);

        Assertions.assertEquals(other.getCveId(), alias.getCveId());
        Assertions.assertEquals(other.getSonatypeId(), alias.getSonatypeId());
        Assertions.assertEquals(other.getGhsaId(), alias.getGhsaId());
        Assertions.assertEquals(other.getOsvId(), alias.getOsvId());
        Assertions.assertEquals(other.getSnykId(), alias.getSnykId());
        Assertions.assertEquals(other.getGsdId(), alias.getGsdId());
        Assertions.assertEquals(other.getInternalId(), alias.getInternalId());

        // null does not overwrite existing value
        Assertions.assertEquals(alias.getVulnDbId(), alias.getVulnDbId());
    }
}
