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("BizMarketStallMapper.xml")
class BizMarketStallMapperXmlTest
{

    @Test
    @DisplayName("栏位编号模糊筛选与排序")
    void fuzzyStallCode() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("stall_code like concat('%', #{stallCode}, '%')"));
        assertTrue(xml.contains("order by stall_code asc, id asc"));
        assertTrue(xml.contains("del_flag = '0'"));
    }

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