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("BizIsolationPenMapper.xml")
class BizIsolationPenMapperXmlTest
{

    @Test
    @DisplayName("圈位编号模糊筛选")
    void fuzzyPenCode() throws Exception
    {
        String xml = readPenMapperXml();
        assertTrue(xml.contains("pen_code like concat('%', #{penCode}, '%')"));
        assertTrue(xml.contains("order by pen_code asc, id asc"));
    }

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