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;

/**
 * SYJC-UT-013、014
 */
@DisplayName("BizLabDetectionMapper.xml")
class BizLabDetectionMapperXmlTest
{

    @Test
    @DisplayName("SYJC-UT-013 列表样本来源筛选")
    void ut013_listFilter() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("d.sample_source = #{sampleSource}"));
    }

    @Test
    @DisplayName("SYJC-UT-014 列表排序")
    void ut014_orderBy() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("order by d.test_date desc, d.create_time desc, d.id desc"));
    }

    @Test
    @DisplayName("列表检疫点精确筛选")
    void listQuarantineStationFilter() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("quarantine_station_id = #{quarantineStationId}"));
        assertTrue(xml.contains("biz_quarantine_station"));
    }

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