@Test
  public void no_trace_logs() {
    logTester.setLevel(LoggerLevel.DEBUG);

    SearchResponse response =
        esTester
            .client()
            .prepareSearch(FakeIndexDefinition.INDEX)
            .setSearchType(SearchType.SCAN)
            .setScroll(TimeValue.timeValueMinutes(1))
            .get();
    logTester.clear();
    esTester.client().prepareSearchScroll(response.getScrollId()).get();
    assertThat(logTester.logs()).isEmpty();
  }
Exemplo n.º 2
0
 @Before
 public void setUp() {
   es.truncateIndices();
   db.truncateTables();
   underTest = new TestIndexer(new DbClient(db.database(), db.myBatis()), es.client());
   underTest.setEnabled(true);
 }
Exemplo n.º 3
0
 @Before
 public void before() {
   DbClient dbClient = db.getDbClient();
   ActivityIndexer indexer = new ActivityIndexer(dbClient, es.client());
   // indexers are disabled by default
   indexer.setEnabled(true);
   service = new ActivityService(dbClient, indexer, userSession);
 }
 @Test
 public void get_with_time_value_timeout_is_not_yet_implemented() {
   try {
     esTester.client().prepareSearchScroll("scrollId").get(TimeValue.timeValueMinutes(1));
     fail();
   } catch (Exception e) {
     assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
   }
 }
Exemplo n.º 5
0
 @Before
 public void setUp() {
   testIndex = new TestIndex(es.client());
   ws =
       new WsTester(
           new TestsWs(
               new ListAction(
                   dbClient, testIndex, userSessionRule, new ComponentFinder(dbClient))));
 }
 @Test
 public void get_with_string_timeout_is_not_yet_implemented() {
   try {
     esTester.client().prepareHealth().get("1");
     fail();
   } catch (Exception e) {
     assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
   }
 }
  @Test
  public void trace_logs() {
    logTester.setLevel(LoggerLevel.TRACE);

    ClusterHealthRequestBuilder requestBuilder = esTester.client().prepareHealth();
    ClusterHealthResponse state = requestBuilder.get();
    assertThat(state.getStatus()).isEqualTo(ClusterHealthStatus.GREEN);

    assertThat(logTester.logs()).hasSize(1);
  }
 @Test
 public void execute_should_throw_an_unsupported_operation_exception() {
   try {
     esTester.client().prepareSearchScroll("scrollId").execute();
     fail();
   } catch (Exception e) {
     assertThat(e)
         .isInstanceOf(UnsupportedOperationException.class)
         .hasMessage("execute() should not be called as it's used for asynchronous");
   }
 }
 @Test
 public void fail_to_search_bad_query() {
   try {
     esTester.client().prepareSearchScroll("unknown").get();
     fail();
   } catch (Exception e) {
     assertThat(e).isInstanceOf(IllegalStateException.class);
     assertThat(e.getMessage())
         .contains("Fail to execute ES search scroll request for scroll id 'null'");
   }
 }
Exemplo n.º 10
0
 private void indexTest(String projectUuid, String fileUuid, String testName, String uuid)
     throws IOException {
   es.client()
       .prepareIndex(INDEX, TYPE)
       .setId(uuid)
       .setSource(
           FileUtils.readFileToString(
               TestUtils.getResource(
                   this.getClass(), projectUuid + "_" + fileUuid + "_" + testName + ".json")))
       .setRefresh(true)
       .get();
 }
Exemplo n.º 11
0
 @Before
 public void setUp() {
   resourceType = mock(ResourceType.class);
   when(resourceType.getBooleanProperty(anyString())).thenReturn(true);
   ResourceTypes mockResourceTypes = mock(ResourceTypes.class);
   when(mockResourceTypes.get(anyString())).thenReturn(resourceType);
   ws =
       new WsTester(
           new ProjectsWs(
               new DeleteAction(
                   new ComponentCleanerService(
                       dbClient,
                       new IssueAuthorizationIndexer(dbClient, es.client()),
                       new IssueIndexer(dbClient, es.client()),
                       new TestIndexer(dbClient, es.client()),
                       mockResourceTypes,
                       new ComponentFinder(dbClient)),
                   new ComponentFinder(dbClient),
                   dbClient,
                   userSessionRule)));
   userSessionRule.login("login").setGlobalPermissions(UserRole.ADMIN);
 }
Exemplo n.º 12
0
public class ViewIndexTest {

  @Rule public EsTester esTester = new EsTester(new ViewIndexDefinition(new MapSettings()));

  ViewIndex index = new ViewIndex(esTester.client());

  @Test
  public void find_all_view_uuids() throws Exception {
    ViewDoc view1 = new ViewDoc().setUuid("UUID1").setProjects(asList("P1"));
    ViewDoc view2 = new ViewDoc().setUuid("UUID2").setProjects(asList("P2"));
    esTester.putDocuments(INDEX, TYPE_VIEW, view1);
    esTester.putDocuments(INDEX, TYPE_VIEW, view2);

    List<String> result = newArrayList(index.findAllViewUuids());

    assertThat(result).containsOnly(view1.uuid(), view2.uuid());
  }

  @Test
  public void not_find_all_view_uuids() {
    List<String> result = newArrayList(index.findAllViewUuids());

    assertThat(result).isEmpty();
  }

  @Test
  public void delete_views() throws Exception {
    ViewDoc view1 = new ViewDoc().setUuid("UUID1").setProjects(asList("P1"));
    ViewDoc view2 = new ViewDoc().setUuid("UUID2").setProjects(asList("P2", "P3", "P4"));
    ViewDoc view3 = new ViewDoc().setUuid("UUID3").setProjects(asList("P2", "P3", "P4"));
    esTester.putDocuments(INDEX, TYPE_VIEW, view1);
    esTester.putDocuments(INDEX, TYPE_VIEW, view2);
    esTester.putDocuments(INDEX, TYPE_VIEW, view3);

    index.delete(asList(view1.uuid(), view2.uuid()));

    assertThat(esTester.getDocumentFieldValues(INDEX, TYPE_VIEW, ViewIndexDefinition.FIELD_UUID))
        .containsOnly(view3.uuid());
  }
}
  @Test
  public void update_existing_document_when_indexing_one_project() throws Exception {
    String uuid = "PROJECT-UUID";
    esTester.putDocuments(
        INDEX_PROJECT_MEASURES,
        TYPE_PROJECT_MEASURES,
        new ProjectMeasuresDoc()
            .setId(uuid)
            .setKey("Old Key")
            .setName("Old Name")
            .setAnalysedAt(new Date(1_000_000L)));
    ComponentDto project = newProjectDto(uuid).setKey("New key").setName("New name");
    SnapshotDto analysis = componentDbTester.insertProjectAndSnapshot(project);

    underTest.index(project.uuid());

    assertThat(esTester.getIds(INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES)).containsOnly(uuid);
    SearchRequestBuilder request =
        esTester
            .client()
            .prepareSearch(INDEX_PROJECT_MEASURES)
            .setTypes(TYPE_PROJECT_MEASURES)
            .setQuery(
                boolQuery()
                    .must(matchAllQuery())
                    .filter(
                        boolQuery()
                            .must(termQuery("_id", uuid))
                            .must(termQuery(ProjectMeasuresIndexDefinition.FIELD_KEY, "New key"))
                            .must(termQuery(ProjectMeasuresIndexDefinition.FIELD_NAME, "New name"))
                            .must(
                                termQuery(
                                    ProjectMeasuresIndexDefinition.FIELD_ANALYSED_AT,
                                    new Date(analysis.getCreatedAt())))));
    assertThat(request.get().getHits()).hasSize(1);
  }
Exemplo n.º 14
0
public class TestIndexTest {
  @Rule public EsTester es = new EsTester(new TestIndexDefinition(new Settings()));

  TestIndex underTest = new TestIndex(es.client());

  @Test
  public void coveredFiles() throws Exception {
    es.putDocuments(
        TestIndexDefinition.INDEX,
        TestIndexDefinition.TYPE,
        newTestDoc(
            "1",
            "TESTFILE1",
            newCoveredFileDoc("3"),
            newCoveredFileDoc("4"),
            newCoveredFileDoc("5")),
        newTestDoc(
            "2",
            "TESTFILE1",
            newCoveredFileDoc("5"),
            newCoveredFileDoc("6"),
            newCoveredFileDoc("7")));

    List<CoveredFileDoc> result = underTest.coveredFiles("1");

    assertThat(result).hasSize(3);
    assertThat(result)
        .extractingResultOf("fileUuid")
        .containsOnly("main-uuid-3", "main-uuid-4", "main-uuid-5");
    assertThat(result.get(0).coveredLines()).containsOnly(25, 33, 82);
  }

  @Test
  public void searchByTestFileUuid() throws Exception {
    es.putDocuments(
        TestIndexDefinition.INDEX,
        TestIndexDefinition.TYPE,
        newTestDoc(
            "1",
            "TESTFILE1",
            newCoveredFileDoc("3"),
            newCoveredFileDoc("4"),
            newCoveredFileDoc("5")),
        newTestDoc(
            "2",
            "TESTFILE1",
            newCoveredFileDoc("5"),
            newCoveredFileDoc("6"),
            newCoveredFileDoc("7")),
        newTestDoc(
            "3",
            "TESTFILE2",
            newCoveredFileDoc("5"),
            newCoveredFileDoc("6"),
            newCoveredFileDoc("7")));

    List<TestDoc> result = underTest.searchByTestFileUuid("TESTFILE1", searchOptions()).getDocs();

    assertThat(result).hasSize(2);
    assertThat(result).extractingResultOf("name").containsOnly("name-1", "name-2");
  }

  @Test
  public void searchBySourceFileUuidAndLineNumber() throws Exception {
    es.putDocuments(
        TestIndexDefinition.INDEX,
        TestIndexDefinition.TYPE,
        newTestDoc(
            "1",
            "TESTFILE1",
            newCoveredFileDoc("10"),
            newCoveredFileDoc("11"),
            newCoveredFileDoc("12")),
        newTestDoc(
            "2",
            "TESTFILE1",
            newCoveredFileDoc("3"),
            newCoveredFileDoc("4"),
            newCoveredFileDoc("5")),
        newTestDoc(
            "3",
            "TESTFILE1",
            newCoveredFileDoc("5"),
            newCoveredFileDoc("6"),
            newCoveredFileDoc("7")));

    List<TestDoc> result =
        underTest.searchBySourceFileUuidAndLineNumber("main-uuid-5", 82, searchOptions()).getDocs();

    assertThat(result).hasSize(2);
    assertThat(result).extractingResultOf("name").containsOnly("name-2", "name-3");
  }

  @Test
  public void searchByTestUuid() throws Exception {
    es.putDocuments(
        TestIndexDefinition.INDEX,
        TestIndexDefinition.TYPE,
        newTestDoc(
            "1",
            "TESTFILE1",
            newCoveredFileDoc("3"),
            newCoveredFileDoc("4"),
            newCoveredFileDoc("5")),
        newTestDoc(
            "2",
            "TESTFILE1",
            newCoveredFileDoc("5"),
            newCoveredFileDoc("6"),
            newCoveredFileDoc("7")));

    TestDoc test = underTest.getByTestUuid("1");

    assertThat(test.testUuid()).isEqualTo("1");
    assertThat(test.fileUuid()).isEqualTo("TESTFILE1");
    assertThat(test.name()).isEqualTo("name-1");
    assertThat(test.durationInMs()).isEqualTo(1L);
    assertThat(test.status()).isEqualTo("status-1");
    assertThat(test.message()).isEqualTo("message-1");
    assertThat(test.coveredFiles()).hasSize(3);
    assertThat(test.coveredFiles())
        .extractingResultOf("fileUuid")
        .containsOnly("main-uuid-3", "main-uuid-4", "main-uuid-5");
  }

  @Test
  public void getNullableByTestUuid() throws Exception {
    es.putDocuments(
        TestIndexDefinition.INDEX,
        TestIndexDefinition.TYPE,
        newTestDoc(
            "1",
            "TESTFILE1",
            newCoveredFileDoc("3"),
            newCoveredFileDoc("4"),
            newCoveredFileDoc("5")),
        newTestDoc(
            "2",
            "TESTFILE1",
            newCoveredFileDoc("5"),
            newCoveredFileDoc("6"),
            newCoveredFileDoc("7")));

    Optional<TestDoc> result = underTest.getNullableByTestUuid("1");

    assertThat(result).isPresent();
    TestDoc test = result.get();
    assertThat(test.testUuid()).isEqualTo("1");
    assertThat(test.fileUuid()).isEqualTo("TESTFILE1");
    assertThat(test.name()).isEqualTo("name-1");
    assertThat(test.durationInMs()).isEqualTo(1L);
    assertThat(test.status()).isEqualTo("status-1");
    assertThat(test.message()).isEqualTo("message-1");
    assertThat(test.coveredFiles()).hasSize(3);
    assertThat(test.coveredFiles())
        .extractingResultOf("fileUuid")
        .containsOnly("main-uuid-3", "main-uuid-4", "main-uuid-5");
  }

  @Test
  public void getNullableByTestUuid_with_absent_value() {
    Optional<TestDoc> result = underTest.getNullableByTestUuid("unknown-uuid");

    assertThat(result).isAbsent();
  }

  @Test
  public void searchByTestUuid_with_SearchOptions() throws Exception {
    es.putDocuments(
        TestIndexDefinition.INDEX,
        TestIndexDefinition.TYPE,
        newTestDoc(
            "1",
            "TESTFILE1",
            newCoveredFileDoc("3"),
            newCoveredFileDoc("4"),
            newCoveredFileDoc("5")),
        newTestDoc(
            "2",
            "TESTFILE1",
            newCoveredFileDoc("5"),
            newCoveredFileDoc("6"),
            newCoveredFileDoc("7")));

    List<TestDoc> result = underTest.searchByTestUuid("1", searchOptions()).getDocs();

    assertThat(result).hasSize(1);
    assertThat(result.get(0).testUuid()).isEqualTo("1");
  }

  private CoveredFileDoc newCoveredFileDoc(String id) {
    return new CoveredFileDoc().setFileUuid("main-uuid-" + id).setCoveredLines(asList(25, 33, 82));
  }

  private TestDoc newTestDoc(String testUuid, String fileUuid, CoveredFileDoc... coveredFiles) {
    return new TestDoc()
        .setUuid(testUuid)
        .setProjectUuid("P1")
        .setName("name-" + testUuid)
        .setMessage("message-" + testUuid)
        .setStackTrace("stacktrace-" + testUuid)
        .setStatus("status-" + testUuid)
        .setDurationInMs(Long.valueOf(testUuid))
        .setFileUuid(fileUuid)
        .setCoveredFiles(asList(coveredFiles));
  }

  private SearchOptions searchOptions() {
    return new SearchOptions().setLimit(100).setOffset(0);
  }
}
Exemplo n.º 15
0
public class TestIndexerTest {

  @Rule public EsTester es = new EsTester(new TestIndexDefinition(new MapSettings()));

  @Rule public DbTester db = DbTester.create(System2.INSTANCE);

  private TestIndexer underTest = new TestIndexer(db.getDbClient(), es.client());

  @Test
  public void index_tests() throws Exception {
    db.prepareDbUnit(getClass(), "db.xml");
    TestTesting.updateDataColumn(db.getSession(), "FILE_UUID", TestTesting.newRandomTests(3));

    underTest.index();

    assertThat(countDocuments()).isEqualTo(3);
  }

  @Test
  public void index_tests_from_project() throws Exception {
    db.prepareDbUnit(getClass(), "db.xml");

    TestTesting.updateDataColumn(db.getSession(), "FILE_UUID", TestTesting.newRandomTests(3));

    underTest.index("PROJECT_UUID");
    assertThat(countDocuments()).isEqualTo(3);
  }

  @Test
  public void index_nothing_from_unknown_project() throws Exception {
    db.prepareDbUnit(getClass(), "db.xml");

    TestTesting.updateDataColumn(db.getSession(), "FILE_UUID", TestTesting.newRandomTests(3));

    underTest.index("UNKNOWN");
    assertThat(countDocuments()).isZero();
  }

  /**
   * File F1 in project P1 has one test -> to be updated File F2 in project P1 has one test ->
   * untouched
   */
  @Test
  public void update_already_indexed_test() throws Exception {
    indexTest("P1", "F1", "T1", "U111");
    indexTest("P1", "F2", "T1", "U121");

    FileSourcesUpdaterHelper.Row dbRow =
        TestResultSetIterator.toRow(
            "P1",
            "F1",
            new Date(),
            Arrays.asList(
                DbFileSources.Test.newBuilder()
                    .setUuid("U111")
                    .setName("NAME_1")
                    .setStatus(DbFileSources.Test.TestStatus.FAILURE)
                    .setMsg("NEW_MESSAGE_1")
                    .setStacktrace("NEW_STACKTRACE_1")
                    .setExecutionTimeMs(123_456L)
                    .addCoveredFile(
                        DbFileSources.Test.CoveredFile.newBuilder()
                            .setFileUuid("MAIN_UUID_1")
                            .addCoveredLine(42))
                    .build()));
    underTest.index(Iterators.singletonIterator(dbRow));

    assertThat(countDocuments()).isEqualTo(2L);

    SearchResponse fileSearch =
        prepareSearch().setQuery(QueryBuilders.termQuery(FIELD_FILE_UUID, "F1")).get();
    assertThat(fileSearch.getHits().getTotalHits()).isEqualTo(1L);
    Map<String, Object> fields = fileSearch.getHits().getHits()[0].sourceAsMap();
    assertThat(fields)
        .contains(
            entry(FIELD_PROJECT_UUID, "P1"),
            entry(FIELD_FILE_UUID, "F1"),
            entry(FIELD_TEST_UUID, "U111"),
            entry(FIELD_NAME, "NAME_1"),
            entry(FIELD_STATUS, "FAILURE"),
            entry(FIELD_MESSAGE, "NEW_MESSAGE_1"),
            entry(FIELD_STACKTRACE, "NEW_STACKTRACE_1"),
            entry(FIELD_DURATION_IN_MS, 123_456));
  }

  @Test
  public void delete_file_uuid() throws Exception {
    indexTest("P1", "F1", "T1", "U111");
    indexTest("P1", "F1", "T2", "U112");
    indexTest("P1", "F2", "T1", "U121");

    underTest.deleteByFile("F1");

    List<SearchHit> hits = getDocuments();
    Map<String, Object> document = hits.get(0).getSource();
    assertThat(hits).hasSize(1);
    assertThat(document.get(FIELD_NAME)).isEqualTo("NAME_1");
    assertThat(document.get(FIELD_FILE_UUID)).isEqualTo("F2");
  }

  @Test
  public void delete_by_project_uuid() throws Exception {
    indexTest("P1", "F1", "T1", "U111");
    indexTest("P1", "F1", "T2", "U112");
    indexTest("P1", "F2", "T1", "U121");
    indexTest("P2", "F3", "T1", "U231");

    underTest.deleteByProject("P1");

    List<SearchHit> hits = getDocuments();
    assertThat(hits).hasSize(1);
    Map<String, Object> document = hits.get(0).getSource();
    assertThat(hits).hasSize(1);
    assertThat(document.get(FIELD_PROJECT_UUID)).isEqualTo("P2");
  }

  private void indexTest(String projectUuid, String fileUuid, String testName, String uuid)
      throws IOException {
    es.client()
        .prepareIndex(INDEX, TYPE)
        .setId(uuid)
        .setRouting(projectUuid)
        .setSource(
            FileUtils.readFileToString(
                TestUtils.getResource(
                    this.getClass(), projectUuid + "_" + fileUuid + "_" + testName + ".json")))
        .setRefresh(true)
        .get();
  }

  private SearchRequestBuilder prepareSearch() {
    return es.client().prepareSearch(INDEX).setTypes(TYPE);
  }

  private List<SearchHit> getDocuments() {
    return es.getDocuments(INDEX, TYPE);
  }

  private long countDocuments() {
    return es.countDocuments(INDEX, TYPE);
  }
}
Exemplo n.º 16
0
 private SearchRequestBuilder prepareSearch() {
   return es.client().prepareSearch(INDEX).setTypes(TYPE);
 }
Exemplo n.º 17
0
 @Before
 public void setUp() {
   esTester.truncateIndices();
   index = new ViewIndex(esTester.client());
 }
 @Test
 public void state() {
   ClusterHealthRequestBuilder requestBuilder = esTester.client().prepareHealth();
   ClusterHealthResponse state = requestBuilder.get();
   assertThat(state.getStatus()).isEqualTo(ClusterHealthStatus.GREEN);
 }
 @Override
 protected ComputationStep step() {
   TestIndexer testIndexer = new TestIndexer(dbClient, esTester.client());
   testIndexer.setEnabled(true);
   return new IndexTestsStep(testIndexer, treeRootHolder);
 }
 @Test
 public void to_string() {
   assertThat(esTester.client().prepareHealth("rules").toString())
       .isEqualTo("ES cluster health request on indices 'rules'");
   assertThat(esTester.client().prepareHealth().toString()).isEqualTo("ES cluster health request");
 }
Exemplo n.º 21
0
 @Before
 public void setUp() {
   activeRuleIndexer = new ActiveRuleIndexer(system2, null, tester.client());
   ruleIndexer = new RuleIndexer(system2, null, tester.client());
   index = new ActiveRuleIndex(tester.client());
 }
public class ProjectMeasuresIndexerTest {

  @Rule
  public EsTester esTester = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));

  @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE);

  ComponentDbTester componentDbTester = new ComponentDbTester(dbTester);
  PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(esTester);

  ProjectMeasuresIndexer underTest =
      new ProjectMeasuresIndexer(dbTester.getDbClient(), esTester.client());

  @Test
  public void index_nothing() {
    underTest.index();

    assertThat(esTester.countDocuments(INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES)).isZero();
  }

  @Test
  public void index_all_project() {
    componentDbTester.insertProjectAndSnapshot(newProjectDto());
    componentDbTester.insertProjectAndSnapshot(newProjectDto());
    componentDbTester.insertProjectAndSnapshot(newProjectDto());

    underTest.index();

    assertThat(esTester.countDocuments(INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES)).isEqualTo(3);
  }

  @Test
  public void index_projects_even_when_no_analysis() {
    ComponentDto project = componentDbTester.insertProject();

    underTest.index();

    assertThat(esTester.getIds(INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES))
        .containsOnly(project.uuid());
  }

  @Test
  public void index_one_project() throws Exception {
    ComponentDto project = newProjectDto();
    componentDbTester.insertProjectAndSnapshot(project);
    componentDbTester.insertProjectAndSnapshot(newProjectDto());

    underTest.index(project.uuid());

    assertThat(esTester.getIds(INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES))
        .containsOnly(project.uuid());
  }

  @Test
  public void update_existing_document_when_indexing_one_project() throws Exception {
    String uuid = "PROJECT-UUID";
    esTester.putDocuments(
        INDEX_PROJECT_MEASURES,
        TYPE_PROJECT_MEASURES,
        new ProjectMeasuresDoc()
            .setId(uuid)
            .setKey("Old Key")
            .setName("Old Name")
            .setAnalysedAt(new Date(1_000_000L)));
    ComponentDto project = newProjectDto(uuid).setKey("New key").setName("New name");
    SnapshotDto analysis = componentDbTester.insertProjectAndSnapshot(project);

    underTest.index(project.uuid());

    assertThat(esTester.getIds(INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES)).containsOnly(uuid);
    SearchRequestBuilder request =
        esTester
            .client()
            .prepareSearch(INDEX_PROJECT_MEASURES)
            .setTypes(TYPE_PROJECT_MEASURES)
            .setQuery(
                boolQuery()
                    .must(matchAllQuery())
                    .filter(
                        boolQuery()
                            .must(termQuery("_id", uuid))
                            .must(termQuery(ProjectMeasuresIndexDefinition.FIELD_KEY, "New key"))
                            .must(termQuery(ProjectMeasuresIndexDefinition.FIELD_NAME, "New name"))
                            .must(
                                termQuery(
                                    ProjectMeasuresIndexDefinition.FIELD_ANALYSED_AT,
                                    new Date(analysis.getCreatedAt())))));
    assertThat(request.get().getHits()).hasSize(1);
  }

  @Test
  public void delete_project() {
    ComponentDto project1 = newProjectDto();
    componentDbTester.insertProjectAndSnapshot(project1);
    ComponentDto project2 = newProjectDto();
    componentDbTester.insertProjectAndSnapshot(project2);
    ComponentDto project3 = newProjectDto();
    componentDbTester.insertProjectAndSnapshot(project3);
    underTest.index();
    authorizationIndexerTester.indexProjectPermission(project1.uuid(), emptyList(), emptyList());
    authorizationIndexerTester.indexProjectPermission(project2.uuid(), emptyList(), emptyList());
    authorizationIndexerTester.indexProjectPermission(project3.uuid(), emptyList(), emptyList());

    underTest.deleteProject(project1.uuid());

    assertThat(esTester.getIds(INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES))
        .containsOnly(project2.uuid(), project3.uuid());
    assertThat(esTester.getIds(INDEX_PROJECT_MEASURES, TYPE_AUTHORIZATION))
        .containsOnly(project2.uuid(), project3.uuid());
  }

  @Test
  public void does_nothing_when_deleting_unknown_project() throws Exception {
    ComponentDto project = newProjectDto();
    componentDbTester.insertProjectAndSnapshot(project);
    underTest.index();
    authorizationIndexerTester.indexProjectPermission(project.uuid(), emptyList(), emptyList());

    underTest.deleteProject("UNKNOWN");

    assertThat(esTester.getIds(INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES))
        .containsOnly(project.uuid());
    assertThat(esTester.getIds(INDEX_PROJECT_MEASURES, TYPE_AUTHORIZATION))
        .containsOnly(project.uuid());
  }
}