/*
 * @Author: Kane
 * @Date: 2022-04-22 10:53:49
 * @LastEditors: Kane
 * @LastEditTime: 2022-05-10 11:33:41
 * @FilePath: \DisasterWarning\src\test\java\com\cpic\xim\wechat\officalAccount\sendMessageTest.java
 * @Description:
 *
 * Copyright (c) ${2022} by Kane, All Rights Reserved.
 */
package com.cpic.xim.wechat.officalAccount;

import com.cpic.xim.notify.disaster.QWeatherDisasterWarning;

import static org.junit.Assert.*;
import com.cpic.xim.httpUtil.*;
import java.io.IOException;

import java.util.*;

import com.fasterxml.jackson.databind.ObjectMapper;

public class sendMessageTest
{
    private static String url =
            "https://cxxmwx.cpic.com.cn/app/index.php?i=2&c=entry&do=send_group_tpl_api&m=ok_tplmessage";

    // @Test
    public void postNotifyMessageJson()
    {
        try
        {
            // sendMessage.postNotifyMessageJSON( url, "警报", "警报标题", "警报内容！" );
        }
        catch ( Exception error )
        {
            fail( "测试失败！" );
        }
    }

    // @Test
    public void postNotifyMessage()
    {
        HashMap<String, String> headers = new HashMap<String, String>();
        String param = "tplid=57&groupid=1&first=亲爱的#realname#，您好！&"
                + "keyword1=东山县气象台发布大雾黄色预警[Ⅲ级/较重]&" + "keyword1color=#ffff00&"
                + "keyword2=东山县气象台2022年04月22日06时12分发布大雾黄色预警信号：预计未来12小时内，我县、闽南渔场和台湾浅滩渔场将出现能见度小于500米的雾。请注意防范！";

        headers.put( "accept", "*/*" );
        headers.put( "Connection", "Keep-Alive" );
        headers.put( "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8" );

        try
        {
            HttpUtils.postHttpRequest( url, headers, param );
        }
        catch ( Exception error )
        {
        }

    }

    // @Test
    public void testSendWeatherDisasterWarning() throws IOException
    {
        String warningJSON =
                "{\"code\":\"200\",\"updateTime\":\"2022-04-23T23:25+08:00\",\"fxLink\":\"http://hfx.link/3645\",\"warning\":[{\"id\":\"10123060820220423203500874007118\",\"sender\":\"东山县气象台\",\"pubTime\":\"2022-04-23T20:35+08:00\",\"title\":\"东山县气象台发布大雾黄色预警[Ⅲ级/较重]\",\"status\":\"active\",\"level\":\"黄色\",\"type\":\"1017\",\"typeName\":\"大雾\",\"text\":\"东山县气象台2022年04月23日20时35分发布大雾黄色预警信号：预计未来12小时内，我县、闽南渔场和台湾浅滩渔场将出现能见度小于500米的雾。请注意防范！\",\"related\":\"\",\"urgency\":\"\",\"certainty\":\"\"}],\"refer\":{\"sources\":[\"12379\"],\"license\":[\"no commercial use\"]}}";

        try
        {
            ObjectMapper mapper = new ObjectMapper();
            QWeatherDisasterWarning warning =
                    mapper.readValue( warningJSON, QWeatherDisasterWarning.class );

            String city = "东山县";


            sendMessage.saveWeatherDisasterWarning( city, warning );
        }
        catch ( Exception error )
        {
            fail( error.getMessage() );
        }
    }

    // @Test
    public void testCheckWarningHasSended()
    {
        String warningID = "10123060820220422061200476313081";

        try
        {
            sendMessage.checkWarningHasSended( warningID );
        }
        catch ( Exception error )
        {
            error.printStackTrace();
        }
    }
}
