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

@DisplayName("BizDataSendRecordMapper.xml")
class BizDataSendRecordMapperXmlTest
{

    @Test
    @DisplayName("筛选与排序 SQL")
    void listSql()
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("del_flag = '0'"));
        assertTrue(xml.contains("date(send_time)"));
        assertTrue(xml.contains("lower(receiver_name) = lower(#{receiverName})"));
        assertTrue(xml.contains("order by send_time desc, id desc"));
    }

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