예제 #1
0
  @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 index_test() throws Exception {
    dbTester.prepareDbUnit(getClass(), "index_source.xml");
    TestTesting.updateDataColumn(
        dbTester.getSession(), "FILE1_UUID", TestTesting.newRandomTests(1));

    treeRootHolder.setRoot(
        DumbComponent.builder(Component.Type.PROJECT, 1)
            .setUuid("ABCD")
            .setKey("PROJECT_KEY")
            .build());

    step().execute();

    List<SearchHit> docs =
        esTester.getDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE);
    assertThat(docs).hasSize(1);
    TestDoc doc = new TestDoc(docs.get(0).sourceAsMap());
    assertThat(doc.projectUuid()).isEqualTo("ABCD");
    assertThat(doc.fileUuid()).isEqualTo("FILE1_UUID");
    assertThat(doc.coveredFiles()).isNotEmpty();
  }
예제 #3
0
 private List<SearchHit> getDocuments() {
   return es.getDocuments(INDEX, TYPE);
 }