package com.emoon.tongue.config;

import lombok.extern.slf4j.Slf4j;
import org.testng.annotations.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

/**
 * 舌象图片检查规则配置测试类
 * 验证配置是否正确加载和解析
 *
 * @author emoon
 * @date 2024-12-15
 */
@Slf4j
@SpringBootTest
class TongueImageCheckPropertiesTest {

    @Autowired
    private TongueImageCheckProperties tongueImageCheckProperties;

    @Test
    void testConfigurationLoaded() {
        log.info("测试舌象图片检查规则配置加载...");

        // 验证配置不为空
        org.junit.jupiter.api.Assertions.assertNotNull(tongueImageCheckProperties);
        org.junit.jupiter.api.Assertions.assertNotNull(tongueImageCheckProperties.getRules());

        List<TongueImageCheckProperties.CheckRule> rules = tongueImageCheckProperties.getRules();
        log.info("成功加载{}条检查规则", rules.size());

        // 验证规则数量
        org.junit.jupiter.api.Assertions.assertTrue(rules.size() > 0);

        // 打印前3条规则信息
        for (int i = 0; i < Math.min(3, rules.size()); i++) {
            TongueImageCheckProperties.CheckRule rule = rules.get(i);
            log.info("规则{}: 错误码={}, 错误类型={}",
                    i + 1, rule.getErrorCode(), rule.getErrorType());
        }

        // 验证具体字段不为空
        TongueImageCheckProperties.CheckRule firstRule = rules.get(0);
        org.junit.jupiter.api.Assertions.assertNotNull(firstRule.getErrorCode());
        org.junit.jupiter.api.Assertions.assertNotNull(firstRule.getErrorType());
        org.junit.jupiter.api.Assertions.assertNotNull(firstRule.getJudgeStandard());
        org.junit.jupiter.api.Assertions.assertNotNull(firstRule.getOptimizeSuggestion());

        log.info("配置测试通过！");
    }
}
