Exemplo n.º 1
0
  @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());
  }
Exemplo n.º 2
0
  @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");
  }
Exemplo n.º 3
0
  @Test
  public void list_based_on_source_file_key_and_line_number() throws Exception {
    String sourceFileUuid = "MAIN-FILE-UUID";
    String sourceFileKey = "MAIN-FILE-KEY";
    userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, TestFile1.PROJECT_UUID);
    dbClient
        .componentDao()
        .insert(
            db.getSession(),
            TestFile1.dto(),
            TestFile2.dto(),
            new ComponentDto()
                .setUuid(sourceFileUuid)
                .setUuidPath(TestFile1.PROJECT_UUID + "." + sourceFileUuid + ".")
                .setRootUuid(TestFile1.PROJECT_UUID)
                .setKey(sourceFileKey)
                .setProjectUuid(TestFile1.PROJECT_UUID));
    db.getSession().commit();

    es.putDocuments(
        TestIndexDefinition.INDEX, TestIndexDefinition.TYPE, TestFile1.doc(), TestFile2.doc());

    WsTester.TestRequest request =
        ws.newGetRequest("api/tests", "list")
            .setParam(ListAction.SOURCE_FILE_KEY, sourceFileKey)
            .setParam(ListAction.SOURCE_FILE_LINE_NUMBER, "10");

    request.execute().assertJson(getClass(), "list-main-file.json");
  }
Exemplo n.º 4
0
  @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);
  }
Exemplo n.º 5
0
  @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");
  }
Exemplo n.º 6
0
  @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());
  }
Exemplo n.º 7
0
  private void insertNewProjectInIndexes(int id) throws Exception {
    String suffix = String.valueOf(id);
    ComponentDto project =
        ComponentTesting.newProjectDto("project-uuid-" + suffix).setKey("project-key-" + suffix);
    dbClient.componentDao().insert(dbSession, project);
    dbSession.commit();

    es.putDocuments(
        IssueIndexDefinition.INDEX,
        IssueIndexDefinition.TYPE_ISSUE,
        IssueTesting.newDoc("issue-key-" + suffix, project));
    es.putDocuments(
        IssueIndexDefinition.INDEX,
        IssueIndexDefinition.TYPE_AUTHORIZATION,
        new IssueAuthorizationDoc().setProjectUuid(project.uuid()));

    TestDoc testDoc =
        new TestDoc()
            .setUuid("test-uuid-" + suffix)
            .setProjectUuid(project.uuid())
            .setFileUuid(project.uuid());
    es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE, testDoc);
  }
Exemplo n.º 8
0
  @Test
  public void list_based_on_test_file_key() throws Exception {
    userSessionRule.addComponentPermission(
        UserRole.CODEVIEWER, TestFile1.PROJECT_UUID, TestFile1.KEY);
    dbClient.componentDao().insert(db.getSession(), TestFile1.dto());
    db.getSession().commit();

    es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE, TestFile1.doc());

    WsTester.TestRequest request =
        ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_FILE_KEY, TestFile1.KEY);

    request.execute().assertJson(getClass(), "list-test-uuid.json");
  }
Exemplo n.º 9
0
  @Test
  public void find_all_view_uuids() throws Exception {
    esTester.putDocuments(
        ViewIndexDefinition.INDEX,
        ViewIndexDefinition.TYPE_VIEW,
        this.getClass(),
        "view1.json",
        "view2.json");

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

    assertThat(result)
        .containsOnly(
            "fed0a543-9d9c-4af5-a4ec-450a8fe78ce7", "8d0bc2a5-bfba-464b-92de-bb170e9d978e");
  }
Exemplo n.º 10
0
  @Test
  public void delete_views() throws Exception {
    esTester.putDocuments(
        ViewIndexDefinition.INDEX,
        ViewIndexDefinition.TYPE_VIEW,
        this.getClass(),
        "view1.json",
        "view2.json");

    index.delete(
        newArrayList(
            "fed0a543-9d9c-4af5-a4ec-450a8fe78ce7", "8d0bc2a5-bfba-464b-92de-bb170e9d978e"));

    assertThat(esTester.countDocuments(ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW))
        .isEqualTo(0L);
  }
Exemplo n.º 11
0
  @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");
  }
  @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);
  }