package com.ruoyi.web.modules.circulation.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;

/**
 * ZCZX-JYZGL-UT-012～014
 */
@DisplayName("BizQuarantineStationMapper.xml")
class BizQuarantineStationMapperXmlTest
{

    @Test
    @DisplayName("ZCZX-JYZGL-UT-012 名称模糊 SQL")
    void ut012_nameLike() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("station_name like concat('%', #{stationName}, '%')"));
    }

    @Test
    @DisplayName("ZCZX-JYZGL-UT-013 运营状态精确 SQL")
    void ut013_operateStatusExact() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("operate_status = #{operateStatus}"));
    }

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

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