<commit_before>package app.monitor.alert;

import app.monitor.AlertConfig;
import app.monitor.slack.SlackClient;
import core.framework.log.Severity;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoInteractions;

/**
 * @author ericchung
 */
class AlertServiceTest {
    private AlertService service;
    private SlackClient slackClient;

    @BeforeEach
    void createActionAlertService() {
        slackClient = mock(SlackClient.class);

        var config = new AlertConfig();
        config.ignoreWarnings = List.of(matcher(List.of("website"), List.of("PATH_NOT_FOUND")));
        config.criticalErrors = List.of(matcher(List.of(), List.of("CRITICAL_ERROR")));
        config.site = "site";
        config.timespanInHours = 4;
        config.kibanaURL = "http://kibana:5601";
        config.channel = new AlertConfig.Channel();
        config.channel.actionError = "actionErrorChannel";
        config.channel.actionWarn = "actionWarnChannel";
        config.channel.eventError = "eventErrorChannel";
        config.channel.eventWarn = "eventWarnChannel";
        service = new AlertService(config);
        service.slackClient = slackClient;
    }

    @NotNull
    private AlertConfig.Matcher matcher(List<String> apps, List<String> errorCodes) {
        var matcher = new AlertConfig.Matcher();
        matcher.apps = apps;
        matcher.errorCodes = errorCodes;
        return matcher;
    }

    @Test
    void docURL() {
        assertThat(service.docURL("test", "test-id")).isEqualTo("http://kibana:5601/app/kibana#/doc/test-pattern/test-*?id=test-id&_g=()");
    }

    @Test
    void alertChannel() {
        var alert = new Alert();
        alert.severity = Severity.ERROR;
        alert.kibanaIndex = "trace";
        assertThat(service.alertChannel(alert)).isEqualTo("actionErrorChannel");
    }

    @Test
    void alertKey() {<commit_msg>remove jetbrain annotations<commit_after>package app.monitor.alert;

import app.monitor.AlertConfig;
import app.monitor.slack.SlackClient;
import core.framework.log.Severity;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoInteractions;

/**
 * @author ericchung
 */
class AlertServiceTest {
    private AlertService service;
    private SlackClient slackClient;

    @BeforeEach
    void createActionAlertService() {
        slackClient = mock(SlackClient.class);

        var config = new AlertConfig();
        config.ignoreWarnings = List.of(matcher(List.of("website"), List.of("PATH_NOT_FOUND")));
        config.criticalErrors = List.of(matcher(List.of(), List.of("CRITICAL_ERROR")));
        config.site = "site";
        config.timespanInHours = 4;
        config.kibanaURL = "http://kibana:5601";
        config.channel = new AlertConfig.Channel();
        config.channel.actionError = "actionErrorChannel";
        config.channel.actionWarn = "actionWarnChannel";
        config.channel.eventError = "eventErrorChannel";
        config.channel.eventWarn = "eventWarnChannel";
        service = new AlertService(config);
        service.slackClient = slackClient;
    }

    private AlertConfig.Matcher matcher(List<String> apps, List<String> errorCodes) {
        var matcher = new AlertConfig.Matcher();
        matcher.apps = apps;
        matcher.errorCodes = errorCodes;
        return matcher;
    }

    @Test
    void docURL() {
        assertThat(service.docURL("test", "test-id")).isEqualTo("http://kibana:5601/app/kibana#/doc/test-pattern/test-*?id=test-id&_g=()");
    }

    @Test
    void alertChannel() {
        var alert = new Alert();
        alert.severity = Severity.ERROR;
        alert.kibanaIndex = "trace";
        assertThat(service.alertChannel(alert)).isEqualTo("actionErrorChannel");
    }

    @Test
    void alertKey() {
{'fraction_non_alphanumeric': 0.12378237110952721, 'fraction_numerical': 0.0042765502494654314, 'mean_word_length': 3.34468524251806, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3633084', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1278, 'n_words': 221}