package com.ruoyi.web.modules.technology.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("BizPracticalTrainingMapper.xml")
class BizPracticalTrainingMapperXmlTest
{

    @Test
    @DisplayName("主题精确筛选与排序")
    void listSql() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("training_topic = #{trainingTopic}"));
        assertTrue(xml.contains("date(training_time)"));
        assertTrue(xml.contains("order by training_time desc, id desc"));
        assertTrue(xml.contains("del_flag = '0'"));
    }

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