package com.ruoyi.web.modules.farming.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("BizLivestockKnowledgeMapper.xml")
class BizLivestockKnowledgeMapperXmlTest
{

    @Test
    @DisplayName("列表筛选与排序")
    void listSql() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("del_flag = '0'"));
        assertTrue(xml.contains("knowledge_title like concat('%', #{keyword}, '%')"));
        assertTrue(xml.contains("introduction like concat('%', #{keyword}, '%')"));
        assertTrue(xml.contains("knowledge_topic = #{knowledgeTopic}"));
        assertTrue(xml.contains("kb_sync_status = #{kbSyncStatus}"));
        assertTrue(xml.contains("order by create_time desc, id desc"));
        assertTrue(xml.contains("biz_livestock_knowledge"));
        assertTrue(xml.contains("logicDeleteBizLivestockKnowledgeByIds"));
        assertTrue(xml.contains("del_flag = '2'"));
    }

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