@Test
  public void search() throws Exception {
    Activity activity1 = new Activity();
    activity1.setType(Activity.Type.ANALYSIS_REPORT);
    activity1.setAction("LOG_ANALYSIS_REPORT");
    activity1.setData("projectKey", "P1");
    activity1.setData("projectName", "POne");
    activity1.setData("projectUuid", "U1");
    activity1.setData("status", AnalysisReportDto.Status.SUCCESS);
    activity1.setData("submittedAt", new Date());
    activityService.save(activity1);

    Activity activity2 = new Activity();
    activity2.setType(Activity.Type.ANALYSIS_REPORT);
    activity2.setAction("LOG_ANALYSIS_REPORT");
    activity2.setData("projectKey", "P2");
    activity2.setData("projectName", "PTwo");
    activity2.setData("projectUuid", "U2");
    activity2.setData("status", AnalysisReportDto.Status.FAILED);
    activity2.setData("submittedAt", new Date());
    activityService.save(activity2);

    userSessionRule.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);

    WsTester.TestRequest request = tester.wsTester().newGetRequest("api/computation", "history");
    request.execute().assertJson(getClass(), "list_history_reports.json");
  }
  @Test
  public void insert_and_index() {
    when(system.now()).thenReturn(1_500_000_000_000L);

    Activity activity = new Activity();
    activity.setType(Activity.Type.ANALYSIS_REPORT);
    activity.setAction("THE_ACTION");
    activity.setMessage("THE_MSG");
    activity.setData("foo", "bar");
    activity.setProfileKey("PROFILE_KEY");
    service.save(activity);

    Map<String, Object> dbMap =
        db.selectFirst(
            "select "
                + "  log_type as \"type\", "
                + "  log_action as \"action\", "
                + "  log_message as \"msg\", "
                + "  data_field as \"data\", "
                + "  profile_key as \"profileKey\" "
                + "from activities");
    assertThat(dbMap).containsEntry("type", "ANALYSIS_REPORT");
    assertThat(dbMap).containsEntry("action", "THE_ACTION");
    assertThat(dbMap).containsEntry("msg", "THE_MSG");
    assertThat(dbMap).containsEntry("profileKey", "PROFILE_KEY");
    assertThat(dbMap.get("data")).isEqualTo("foo=bar");

    List<ActivityDoc> docs = es.getDocuments("activities", "activity", ActivityDoc.class);
    assertThat(docs).hasSize(1);
    assertThat(docs.get(0).getKey()).isNotEmpty();
    assertThat(docs.get(0).getAction()).isEqualTo("THE_ACTION");
    assertThat(docs.get(0).getMessage()).isEqualTo("THE_MSG");
    assertThat(docs.get(0).getDetails())
        .containsOnly(MapEntry.entry("foo", "bar"), MapEntry.entry("profileKey", "PROFILE_KEY"));
  }
  @Test
  public void search() throws Exception {
    Activity activity = new Activity();
    activity.setType(Activity.Type.ANALYSIS_REPORT);
    activity.setAction("THE_ACTION");
    activity.setMessage("THE_MSG");
    activity.setData("foo", "bar");
    service.save(activity);

    WsTester.TestRequest request = tester.wsTester().newGetRequest("api/activities", "search");
    WsTester.Result result = request.execute();
    assertThat(result.outputAsString()).contains("\"total\":1");
    assertThat(result.outputAsString()).contains("\"type\":\"ANALYSIS_REPORT\"");
    assertThat(result.outputAsString()).contains("\"details\":{\"foo\":\"bar\"}");
  }