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;

/**
 * SS-BZ-UT-008～012
 */
@DisplayName("设备实施作业标准校验 EquipmentWorkStandardValidation")
class EquipmentWorkStandardValidationTest
{

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

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

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

    @Test
    @DisplayName("正文附件校验：非法路径")
    void validateContent_badPath()
    {
        assertThrows(ServiceException.class,
                () -> EquipmentWorkStandardValidation.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);
    }
}
