Пример #1
0
  @Test
  public void write_component() {
    // no data yet
    assertThat(underTest.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isFalse();

    // write data
    BatchReport.Component.Builder component =
        BatchReport.Component.newBuilder()
            .setRef(1)
            .setLanguage("java")
            .setPath("src/Foo.java")
            .setType(Constants.ComponentType.FILE)
            .setIsTest(false)
            .addChildRef(5)
            .addChildRef(42);
    underTest.writeComponent(component.build());

    assertThat(underTest.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue();
    File file = underTest.getFileStructure().fileFor(FileStructure.Domain.COMPONENT, 1);
    assertThat(file).exists().isFile();
    BatchReport.Component read = Protobuf.read(file, BatchReport.Component.PARSER);
    assertThat(read.getRef()).isEqualTo(1);
    assertThat(read.getChildRefList()).containsOnly(5, 42);
    assertThat(read.hasName()).isFalse();
    assertThat(read.getIsTest()).isFalse();
  }
Пример #2
0
  @Test
  public void write_symbols() {
    // no data yet
    assertThat(underTest.hasComponentData(FileStructure.Domain.SYMBOLS, 1)).isFalse();

    // write data
    BatchReport.Symbol symbol =
        BatchReport.Symbol.newBuilder()
            .setDeclaration(
                BatchReport.Range.newBuilder()
                    .setStartLine(1)
                    .setStartOffset(3)
                    .setEndLine(1)
                    .setEndOffset(5)
                    .build())
            .addReference(
                BatchReport.Range.newBuilder()
                    .setStartLine(10)
                    .setStartOffset(15)
                    .setEndLine(11)
                    .setEndOffset(2)
                    .build())
            .build();

    underTest.writeComponentSymbols(1, Arrays.asList(symbol));

    assertThat(underTest.hasComponentData(FileStructure.Domain.SYMBOLS, 1)).isTrue();

    File file = underTest.getFileStructure().fileFor(FileStructure.Domain.SYMBOLS, 1);
    assertThat(file).exists().isFile();
    try (CloseableIterator<BatchReport.Symbol> read =
        Protobuf.readStream(file, BatchReport.Symbol.PARSER)) {
      assertThat(read).hasSize(1);
    }
  }
Пример #3
0
  @Test
  public void write_duplications() {
    assertThat(underTest.hasComponentData(FileStructure.Domain.DUPLICATIONS, 1)).isFalse();

    BatchReport.Duplication duplication =
        BatchReport.Duplication.newBuilder()
            .setOriginPosition(Range.newBuilder().setStartLine(1).setEndLine(5).build())
            .addDuplicate(
                BatchReport.Duplicate.newBuilder()
                    .setOtherFileKey("COMPONENT_A")
                    .setOtherFileRef(2)
                    .setRange(Range.newBuilder().setStartLine(6).setEndLine(10).build())
                    .build())
            .build();
    underTest.writeComponentDuplications(1, Arrays.asList(duplication));

    assertThat(underTest.hasComponentData(FileStructure.Domain.DUPLICATIONS, 1)).isTrue();
    File file = underTest.getFileStructure().fileFor(FileStructure.Domain.DUPLICATIONS, 1);
    assertThat(file).exists().isFile();
    try (CloseableIterator<BatchReport.Duplication> duplications =
        Protobuf.readStream(file, BatchReport.Duplication.PARSER)) {
      BatchReport.Duplication dup = duplications.next();
      assertThat(dup.getOriginPosition()).isNotNull();
      assertThat(dup.getDuplicateList()).hasSize(1);
    }
  }
Пример #4
0
  @Test
  public void write_scm() {
    assertThat(underTest.hasComponentData(FileStructure.Domain.CHANGESETS, 1)).isFalse();

    BatchReport.Changesets scm =
        BatchReport.Changesets.newBuilder()
            .setComponentRef(1)
            .addChangesetIndexByLine(0)
            .addChangeset(
                BatchReport.Changesets.Changeset.newBuilder()
                    .setRevision("123-456-789")
                    .setAuthor("author")
                    .setDate(123_456_789L))
            .build();

    underTest.writeComponentChangesets(scm);

    assertThat(underTest.hasComponentData(FileStructure.Domain.CHANGESETS, 1)).isTrue();
    File file = underTest.getFileStructure().fileFor(FileStructure.Domain.CHANGESETS, 1);
    assertThat(file).exists().isFile();
    BatchReport.Changesets read = Protobuf.read(file, BatchReport.Changesets.PARSER);
    assertThat(read.getComponentRef()).isEqualTo(1);
    assertThat(read.getChangesetCount()).isEqualTo(1);
    assertThat(read.getChangesetList()).hasSize(1);
    assertThat(read.getChangeset(0).getDate()).isEqualTo(123_456_789L);
  }
Пример #5
0
  @Test
  public void write_metadata() {
    BatchReport.Metadata.Builder metadata =
        BatchReport.Metadata.newBuilder()
            .setAnalysisDate(15000000L)
            .setProjectKey("PROJECT_A")
            .setRootComponentRef(1);
    underTest.writeMetadata(metadata.build());

    BatchReport.Metadata read =
        Protobuf.read(underTest.getFileStructure().metadataFile(), BatchReport.Metadata.PARSER);
    assertThat(read.getAnalysisDate()).isEqualTo(15000000L);
    assertThat(read.getProjectKey()).isEqualTo("PROJECT_A");
    assertThat(read.getRootComponentRef()).isEqualTo(1);
  }
Пример #6
0
  @Test
  public void write_issues() {
    // no data yet
    assertThat(underTest.hasComponentData(FileStructure.Domain.ISSUES, 1)).isFalse();

    // write data
    BatchReport.Issue issue =
        BatchReport.Issue.newBuilder().setLine(50).setMsg("the message").build();

    underTest.writeComponentIssues(1, Arrays.asList(issue));

    assertThat(underTest.hasComponentData(FileStructure.Domain.ISSUES, 1)).isTrue();
    File file = underTest.getFileStructure().fileFor(FileStructure.Domain.ISSUES, 1);
    assertThat(file).exists().isFile();
    try (CloseableIterator<BatchReport.Issue> read =
        Protobuf.readStream(file, BatchReport.Issue.PARSER)) {
      assertThat(Iterators.size(read)).isEqualTo(1);
    }
  }
Пример #7
0
  @Test
  public void write_measures() {
    assertThat(underTest.hasComponentData(FileStructure.Domain.MEASURES, 1)).isFalse();

    BatchReport.Measure measure =
        BatchReport.Measure.newBuilder()
            .setStringValue("text-value")
            .setDoubleValue(2.5d)
            .setValueType(Constants.MeasureValueType.DOUBLE)
            .build();

    underTest.writeComponentMeasures(1, Arrays.asList(measure));

    assertThat(underTest.hasComponentData(FileStructure.Domain.MEASURES, 1)).isTrue();
    File file = underTest.getFileStructure().fileFor(FileStructure.Domain.MEASURES, 1);
    assertThat(file).exists().isFile();
    try (CloseableIterator<BatchReport.Measure> read =
        Protobuf.readStream(file, BatchReport.Measure.PARSER)) {
      assertThat(Iterators.size(read)).isEqualTo(1);
    }
  }