package com.ruoyi.web.modules.trading.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("BizDistributorMapper.xml")
class BizDistributorMapperXmlTest
{

    @Test
    @DisplayName("编号名称模糊筛选")
    void fuzzyFilter() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("distributor_code like concat('%', #{distributorCode}, '%')"));
        assertTrue(xml.contains("distributor_name like concat('%', #{distributorName}, '%')"));
    }

    @Test
    @DisplayName("列表排序")
    void orderBy() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("order by distributor_code asc, id asc"));
    }

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