package org.dependencytrack.model;

import org.junit.Assert;
import org.junit.Test;

public class VulnerabilityAliasTest {

    @Test
    public 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);

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

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