<commit_before>package org.gbif.crawler.pipelines.search;

import org.gbif.api.model.pipelines.PipelineProcess;
import org.gbif.api.model.pipelines.PipelineStep;
import org.gbif.api.model.pipelines.StepType;

import java.io.File;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

import com.google.common.io.Files;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/** Test class for {@link PipelinesRunningProcessSearchService}. */
public class PipelinesRunningProcessSearchServiceTest {

  private PipelinesRunningProcessSearchService searchService;

  private static PipelineProcess getTestPipelineProcess() {
    UUID datasetKey = UUID.randomUUID();
    String datasetTitle = "Pontaurus dataset";
    int attemptId = 1;
    PipelineProcess pipelineProcess = new PipelineProcess();
    pipelineProcess.setDatasetKey(datasetKey);
    pipelineProcess.setDatasetTitle(datasetTitle);
    pipelineProcess.setAttempt(attemptId);
    PipelineStep step = new PipelineStep();
    step.setType(StepType.HDFS_VIEW);
    step.setState(PipelineStep.Status.RUNNING);
    pipelineProcess.setSteps(Collections.singleton(step));
    return pipelineProcess;
  }

  /** Initializes the cache and test data. */
  @Before
  public void init() {
    File tmpDir = Files.createTempDir();
    tmpDir.deleteOnExit();
    searchService = new PipelinesRunningProcessSearchService(tmpDir.getPath());
  }

  /** Close the search service. */
  @After
  public void tearDown() {
    if (Objects.nonNull(searchService)) {
      searchService.close();
    }
  }

  /** Adds a document a search for it by dataset title. */
  @Test
  public void indexAndSearchTest() {
    // State
    PipelineProcess pipelineProcess = getTestPipelineProcess();
    searchService.index(pipelineProcess);

    // When
    List<String> hits =
        searchService.search(SearchParams.newBuilder().setDatasetTitle("ponta").build(), 0, 10);

    // Expect
    assertEquals(1, hits.size());
    assertTrue(hits.get(0).startsWith(pipelineProcess.getDatasetKey().toString()));

    // When
    hits =
        searchService.search(SearchParams.newBuilder().setDatasetTitle("onta on").build(), 0, 10);<commit_msg>fix test<commit_after>package org.gbif.crawler.pipelines.search;

import org.gbif.api.model.pipelines.PipelineProcess;
import org.gbif.api.model.pipelines.PipelineStep;
import org.gbif.api.model.pipelines.StepType;

import java.io.File;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

import com.google.common.io.Files;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/** Test class for {@link PipelinesRunningProcessSearchService}. */
public class PipelinesRunningProcessSearchServiceTest {

  private PipelinesRunningProcessSearchService searchService;

  private static PipelineProcess getTestPipelineProcess() {
    UUID datasetKey = UUID.randomUUID();
    String datasetTitle = "Pontaurus dataset";
    int attemptId = 1;
    PipelineProcess pipelineProcess = new PipelineProcess();
    pipelineProcess.setDatasetKey(datasetKey);
    pipelineProcess.setDatasetTitle(datasetTitle);
    pipelineProcess.setAttempt(attemptId);
    PipelineStep step = new PipelineStep();
    step.setType(StepType.HDFS_VIEW);
    step.setState(PipelineStep.Status.RUNNING);
    pipelineProcess.setSteps(Collections.singleton(step));
    return pipelineProcess;
  }

  /** Initializes the cache and test data. */
  @Before
  public void init() {
    File tmpDir = Files.createTempDir();
    tmpDir.deleteOnExit();
    searchService = new PipelinesRunningProcessSearchService(tmpDir.getPath());
  }

  /** Close the search service. */
  @After
  public void tearDown() {
    if (Objects.nonNull(searchService)) {
      searchService.close();
    }
  }

  /** Adds a document a search for it by dataset title. */
  @Test
  public void indexAndSearchTest() {
    // State
    PipelineProcess pipelineProcess = getTestPipelineProcess();
    searchService.index(pipelineProcess);

    // When
    List<String> hits =
        searchService.search(SearchParams.newBuilder().setDatasetTitle("ponta").build(), 0, 10);

    // Expect
    assertEquals(1, hits.size());
    assertTrue(hits.get(0).startsWith(pipelineProcess.getDatasetKey().toString()));

    // When
    hits =
        searchService.search(SearchParams.newBuilder().setDatasetTitle("onta dat").build(), 0, 10);
{'fraction_non_alphanumeric': 0.1130952380952381, 'fraction_numerical': 0.003826530612244898, 'mean_word_length': 4.371004566210046, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2150239', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1371, 'n_words': 276}