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("BizMarketDailyQuoteMapper.xml")
class BizMarketDailyQuoteMapperXmlTest
{
    @Test
    @DisplayName("列表筛选与排序")
    void listSql() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("q.del_flag = '0'"));
        assertTrue(xml.contains("q.quote_date = #{quoteDate}"));
        assertTrue(xml.contains("q.quote_date &gt;= #{beginQuoteDate}"));
        assertTrue(xml.contains("q.trade_market_id = #{tradeMarketId}"));
        assertTrue(xml.contains("q.county_code = #{countyCode}"));
        assertTrue(xml.contains("order by q.quote_date desc, q.create_time desc, q.id desc"));
        assertTrue(xml.contains("countDuplicateDimension"));
        assertTrue(xml.contains("IFNULL(weight_grade, 0)"));
    }

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