package com.jay.monitor.data.server.store;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.cat.file.message.MessageManagerProcess;
import com.cat.file.message.config.CatFileConfiguration;
import com.cat.file.message.internal.DefaultMessageTree;
import junit.framework.TestCase;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {CatFileConfiguration.class})
public class AbstractStoreProcessTest extends TestCase {

    @Autowired
    private MessageManagerProcess messageManagerProcess = new MessageManagerProcess();

    @Test
    public void testText() throws Exception {
        JSONObject json = new JSONObject();
        json.put("id", "783098");
        DateTime dateTime = DateUtil.parseDate("2021-04-24 10:07:47");
        DefaultMessageTree defaultMessageTree =
            new DefaultMessageTree("dts-server", "172.19.189.171", 783098, dateTime, json.toString());
        messageManagerProcess.insert(defaultMessageTree);
    }

    @Test
    public void testFind() {

        DateTime parse = DateUtil.parse("2021-04-25 00:00:00");

        DefaultMessageTree defaultMessageTree =
            new DefaultMessageTree("dts-server", "172.19.189.171", 5920938, parse, null);
        String message = messageManagerProcess.getMessage(defaultMessageTree.getMessageId());
        System.out.println(message);
    }

}