package com.easyagents.federation.sql.source;

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

/**
 * KnownJdbcDriver 公共元数据契约测试。
 */
public class KnownJdbcDriverTest {

    /**
     * 验证计划内常见数据库使用标准驱动类名和 URL 前缀。
     */
    @Test
    public void shouldExposeMainstreamDriverMetadata() {
        assertDriver(KnownJdbcDriver.MYSQL, "com.mysql.cj.jdbc.Driver", "jdbc:mysql:");
        assertDriver(KnownJdbcDriver.POSTGRESQL, "org.postgresql.Driver", "jdbc:postgresql:");
        assertDriver(KnownJdbcDriver.ORACLE, "oracle.jdbc.OracleDriver", "jdbc:oracle:thin:");
        assertDriver(
            KnownJdbcDriver.SQL_SERVER,
            "com.microsoft.sqlserver.jdbc.SQLServerDriver",
            "jdbc:sqlserver:"
        );
    }

    /**
     * 验证计划内信创数据库使用已确认的厂商驱动类名和 URL 前缀。
     */
    @Test
    public void shouldExposePlannedDomesticDriverMetadata() {
        assertDriver(
            KnownJdbcDriver.GAUSSDB,
            "com.huawei.gaussdb.jdbc.Driver",
            "jdbc:gaussdb:"
        );
        assertDriver(KnownJdbcDriver.DM8, "dm.jdbc.driver.DmDriver", "jdbc:dm:");
        assertDriver(KnownJdbcDriver.GBASE_8A, "com.gbase.jdbc.Driver", "jdbc:gbase:");
        assertDriver(
            KnownJdbcDriver.GBASE_8S,
            "com.gbasedbt.jdbc.Driver",
            "jdbc:gbasedbt-sqli:"
        );
        assertDriver(
            KnownJdbcDriver.OCEANBASE,
            "com.oceanbase.jdbc.Driver",
            "jdbc:oceanbase:"
        );
    }

    /**
     * 验证公开 Maven 坐标与厂商包获取方式能够明确区分。
     */
    @Test
    public void shouldExposeOnlyKnownPublicMavenCoordinates() {
        Assert.assertEquals(
            "com.dameng:DmJdbcDriver8",
            KnownJdbcDriver.DM8.mavenCoordinate().orElseThrow()
        );
        Assert.assertEquals(
            "com.oceanbase:oceanbase-client",
            KnownJdbcDriver.OCEANBASE.mavenCoordinate().orElseThrow()
        );
        Assert.assertTrue(KnownJdbcDriver.GAUSSDB.mavenCoordinate().isEmpty());
        Assert.assertTrue(KnownJdbcDriver.GBASE_8A.mavenCoordinate().isEmpty());
        Assert.assertTrue(KnownJdbcDriver.GBASE_8S.mavenCoordinate().isEmpty());
    }

    /**
     * 断言驱动类名和 JDBC URL 前缀。
     *
     * @param driver 待验证驱动元数据
     * @param expectedClassName 预期驱动类名
     * @param expectedUrlPrefix 预期 JDBC URL 前缀
     */
    private static void assertDriver(
        KnownJdbcDriver driver,
        String expectedClassName,
        String expectedUrlPrefix
    ) {
        Assert.assertEquals(expectedClassName, driver.driverClassName());
        Assert.assertEquals(expectedUrlPrefix, driver.jdbcUrlPrefix());
    }
}
