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

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;

/**
 * YQSB-UT-014、015
 */
@DisplayName("BizEpidemicReportMapper.xml")
class BizEpidemicReportMapperXmlTest
{

    @Test
    @DisplayName("YQSB-UT-014 列表筛选")
    void ut014_listFilter() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("transmission_route = #{transmissionRoute}"));
        assertTrue(xml.contains("risk_level = #{riskLevel}"));
        assertTrue(xml.contains("release_date is null"));
        assertTrue(xml.contains("release_date is not null"));
    }

    @Test
    @DisplayName("YQSB-UT-015 列表排序")
    void ut015_orderBy() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("order by report_date desc, create_time desc, id desc"));
    }

    private static String readMapperXml()
    {
        try (InputStream in = BizEpidemicReportMapperXmlTest.class.getClassLoader()
                .getResourceAsStream("mapper/epidemic/BizEpidemicReportMapper.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);
        }
    }
}
