package com.lanyuanxiaoyao.digtal.market

import cn.hutool.json.JSONUtil
import com.lanyuanxiaoyao.digtal.market.runner.NewsRunner
import com.lanyuanxiaoyao.squirrel.core.common.Management
import jakarta.annotation.Resource
import org.junit.jupiter.api.Test
import org.slf4j.LoggerFactory
import org.springframework.boot.test.context.SpringBootTest

@SpringBootTest(
    classes = [Application::class],
    webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
)
@ExperimentalStdlibApi
class TestManagement {
    private val logger = LoggerFactory.getLogger(javaClass)

    @Resource
    private lateinit var management: Management

    @Resource
    private lateinit var newsRunner: NewsRunner

    @Test
    fun testParseList() {
        newsRunner
            .parseArticleLink(
                "1df28c35-1e9e-4d58-9595-f08029b160b4",
                "https://search.cac.gov.cn/cms/cmsadmin/infopub/gjjs.jsp?templetid=1563339473064626&pubtype=S&pubpath=portal&page=1&webappcode=A09&huopro=数据要素&mustpro=&notpro=&inpro=&startDate=\$\$\$&endDate=\$\$\$&sort=1&searchfield=\$\$\$&searchdir=A09",
                true,
            )
            .forEach { logger.info("{} {} {}", it.datetime, it.url, it.title) }
    }

    @Test
    fun testParseArticle() {
        newsRunner
            .parseArticle(
                "1df28c35-1e9e-4d58-9595-f08029b160b4",
                "https://www.cac.gov.cn/2024-10/14/c_1730595202555062.htm",
                "no title",
                "no datetime",
                "",
            )
            ?.let { logger.info("{}", JSONUtil.toJsonPrettyStr(it)) }
    }
}