package com.ruoyi.config;

import org.junit.jupiter.api.Test;
import org.springframework.boot.env.YamlPropertySourceLoader;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

class TongWebIntegrationConfigurationTest {

    @Test
    void shouldExposeTongWebLicenseResourceOnClasspath() {
        assertThat(getClass().getClassLoader().getResource("license.dat"))
            .as("TongWeb license 文件应随应用资源一起打包")
            .isNotNull();
    }

    @Test
    void shouldDeclareTongWebLicensePathInApplicationYaml() throws IOException {
        YamlPropertySourceLoader loader = new YamlPropertySourceLoader();
        List<PropertySource<?>> propertySources = loader.load("application", new ClassPathResource("application.yml"));

        Object propertyValue = propertySources.stream()
            .map(source -> source.getProperty("server.tongweb.license.path"))
            .filter(value -> value != null)
            .findFirst()
            .orElse(null);

        assertThat(propertyValue)
            .as("基础配置中应声明 TongWeb license 路径")
            .isEqualTo("classpath:license.dat");
    }
}
