package com.ruoyi.web.modules.architecture.support;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

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

import com.ruoyi.common.exception.ServiceException;

/**
 * WF-BZ-UT-008～012：参数与附件路径校验
 */
@DisplayName("饲喂标准校验 FeedingStandardValidation")
class FeedingStandardValidationTest
{

    @Test
    @DisplayName("WF-BZ-UT-008 标准名称长度 1～20")
    void ut008_standardName()
    {
        assertThrows(ServiceException.class, () -> FeedingStandardValidation.validateStandardName(null));
        assertThrows(ServiceException.class, () -> FeedingStandardValidation.validateStandardName(""));
        assertDoesNotThrow(() -> FeedingStandardValidation.validateStandardName("甲"));
        assertDoesNotThrow(() -> FeedingStandardValidation.validateStandardName("12"));
        assertDoesNotThrow(() -> FeedingStandardValidation.validateStandardName(repeat('a', 20)));
        assertThrows(ServiceException.class, () -> FeedingStandardValidation.validateStandardName(repeat('a', 21)));
    }

    @Test
    @DisplayName("WF-BZ-UT-009 简介 ≤50")
    void ut009_introduction()
    {
        assertDoesNotThrow(() -> FeedingStandardValidation.validateIntroduction(null));
        assertDoesNotThrow(() -> FeedingStandardValidation.validateIntroduction(repeat('b', 50)));
        assertThrows(ServiceException.class, () -> FeedingStandardValidation.validateIntroduction(repeat('b', 51)));
    }

    @Test
    @DisplayName("WF-BZ-UT-010 标准类型编码非空")
    void ut010_standardType()
    {
        assertThrows(ServiceException.class, () -> FeedingStandardValidation.validateStandardType(null));
        assertThrows(ServiceException.class, () -> FeedingStandardValidation.validateStandardType(""));
        assertDoesNotThrow(() -> FeedingStandardValidation.validateStandardType("001005"));
    }

    @Test
    @DisplayName("正文附件校验：非法路径")
    void validateContent_badPath()
    {
        assertThrows(ServiceException.class,
                () -> FeedingStandardValidation.validateContentAttachment("a.pdf", "/wrong/a.pdf"));
    }

    private static String repeat(char c, int n)
    {
        char[] a = new char[n];
        java.util.Arrays.fill(a, c);
        return new String(a);
    }
}
