package com.ruoyi.web.modules.video.mapper;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@DisplayName("BizLivestockMonitorMapper.xml")
class BizLivestockMonitorMapperXmlTest
{

    @Test
    @DisplayName("列表与详情 SQL 含监控字段、含逻辑删除")
    void listAndDetailSql()
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("selectListVo"));
        assertTrue(xml.contains("selectVo"));
        assertFalse(xml.contains("ip_address"));
        assertTrue(xml.contains("monitor_id"));
        assertTrue(xml.contains("video_source"));
        assertTrue(xml.contains("del_flag = '2'"));
        assertTrue(xml.contains("logicDeleteBizLivestockMonitorByIds"));
        assertTrue(xml.contains("updateBizLivestockMonitorFromSync"));
        assertFalse(xml.contains("video_url"));
    }

    private static String readMapperXml()
    {
        try (InputStream in = BizLivestockMonitorMapperXmlTest.class.getClassLoader()
                .getResourceAsStream("mapper/video/BizLivestockMonitorMapper.xml"))
        {
            if (in == null)
            {
                throw new IllegalStateException("mapper xml not found");
            }
            return IOUtils.toString(in, StandardCharsets.UTF_8);
        }
        catch (Exception ex)
        {
            throw new RuntimeException(ex);
        }
    }
}
