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

import com.jay.monitor.data.server.SpringRunCase;
import com.jay.monitor.data.server.enums.MatchRuleEnums;
import com.jay.monitor.data.server.models.store.AlertRuleConfig;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;

import java.util.Date;

@Import(ElasticAlertRuleProcess.class)
public class ElasticAlertRuleProcessTest extends SpringRunCase {

    @Autowired
    private ElasticAlertRuleProcess elasticAlertRuleProcess;

    @Test
    public void test() {

        AlertRuleConfig alertRuleConfig = new AlertRuleConfig();
        alertRuleConfig.setStatus(1);
        alertRuleConfig.setProject("abc");
        alertRuleConfig.setCreateDate(new Date());
        alertRuleConfig.setCreator("liukx");
        alertRuleConfig.setRuleName("测试规则");
        alertRuleConfig.setTitle("测试标题");
        alertRuleConfig.setRuleType(MatchRuleEnums.eq);
        alertRuleConfig.setFieldName("status");
        alertRuleConfig.setFieldValue("-1");

        boolean save = elasticAlertRuleProcess.save(alertRuleConfig);
        Assert.assertTrue(save);
    }

    @Test
    public void testUpdate() {
        String platformId = "KFpExHsBIcT-h3qq6woY";

        AlertRuleConfig alertRuleConfig = elasticAlertRuleProcess.queryById("J1o6xHsBIcT-h3qqYQrt");
        alertRuleConfig.setCreateDate(new Date());
        alertRuleConfig.setProject("elab-marketing-notify");

        boolean update = elasticAlertRuleProcess.update(alertRuleConfig);
        Assert.assertTrue(update);
    }

}