package com.ruoyi.web.modules.innovation.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;

/**
 * KJXM-UT-016
 */
@DisplayName("BizTechProjectGuideMapper.xml")
class BizTechProjectGuideMapperXmlTest
{

    @Test
    @DisplayName("KJXM-UT-016 列表筛选与排序")
    void ut016_listFilterAndOrder() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("project_name like concat('%', #{projectName}, '%')"));
        assertTrue(xml.contains("project_type = #{projectType}"));
        assertTrue(xml.contains("publish_status = #{publishStatus}"));
        assertTrue(xml.contains("publish_time desc, create_time desc, id desc"));
    }

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