コード例 #1
0
  @Test
  public void nothing_to_do_when_no_events_in_report() throws Exception {
    dbTester.prepareDbUnit(getClass(), "nothing_to_do_when_no_events_in_report.xml");

    File reportDir = temp.newFolder();
    BatchReportWriter writer = new BatchReportWriter(reportDir);
    writer.writeMetadata(
        BatchReport.Metadata.newBuilder()
            .setRootComponentRef(1)
            .setProjectKey("PROJECT_KEY")
            .setAnalysisDate(150000000L)
            .build());

    writer.writeComponent(
        BatchReport.Component.newBuilder()
            .setRef(1)
            .setType(Constants.ComponentType.PROJECT)
            .setUuid("ABCD")
            .build());

    step.execute(
        new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class)));

    dbTester.assertDbUnit(getClass(), "nothing_to_do_when_no_events_in_report.xml", "events");
  }
コード例 #2
0
  @Test
  public void keep_one_event_by_version() throws Exception {
    dbTester.prepareDbUnit(getClass(), "keep_one_event_by_version.xml");

    File reportDir = temp.newFolder();
    BatchReportWriter writer = new BatchReportWriter(reportDir);
    writer.writeMetadata(
        BatchReport.Metadata.newBuilder()
            .setRootComponentRef(1)
            .setProjectKey("PROJECT_KEY")
            .setAnalysisDate(150000000L)
            .build());

    writer.writeComponent(
        BatchReport.Component.newBuilder()
            .setRef(1)
            .setType(Constants.ComponentType.PROJECT)
            .setUuid("ABCD")
            .setSnapshotId(1001L)
            .setVersion("1.5-SNAPSHOT")
            .build());

    step.execute(
        new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class)));

    dbTester.assertDbUnit(getClass(), "keep_one_event_by_version-result.xml", "events");
  }
  private BatchReportWriter initReport() {
    BatchReportWriter writer = new BatchReportWriter(reportDir);
    writer.writeMetadata(
        BatchReport.Metadata.newBuilder()
            .setRootComponentRef(1)
            .setProjectKey("PROJECT_KEY")
            .setAnalysisDate(150000000L)
            .build());

    writer.writeComponent(
        BatchReport.Component.newBuilder()
            .setRef(1)
            .setType(Constants.ComponentType.PROJECT)
            .setUuid("PROJECT_A")
            .addChildRef(2)
            .build());
    writer.writeComponent(
        BatchReport.Component.newBuilder()
            .setRef(2)
            .setType(Constants.ComponentType.MODULE)
            .setUuid("BCDE")
            .addChildRef(FILE_REF)
            .build());
    writer.writeComponent(
        BatchReport.Component.newBuilder()
            .setRef(FILE_REF)
            .setType(Constants.ComponentType.FILE)
            .setUuid("FILE_A")
            .build());
    return writer;
  }
コード例 #4
0
  @Test
  public void readMetadata_result_is_cached() {
    BatchReport.Metadata metadata = BatchReport.Metadata.newBuilder().build();

    writer.writeMetadata(metadata);

    BatchReport.Metadata res = underTest.readMetadata();
    assertThat(res).isEqualTo(metadata);
    assertThat(underTest.readMetadata()).isSameAs(res);
  }
コード例 #5
0
  @Test
  public void persist_report_events_with_component_children() throws Exception {
    dbTester.prepareDbUnit(getClass(), "empty.xml");

    File reportDir = temp.newFolder();
    BatchReportWriter writer = new BatchReportWriter(reportDir);
    writer.writeMetadata(
        BatchReport.Metadata.newBuilder()
            .setRootComponentRef(1)
            .setProjectKey("PROJECT_KEY")
            .setAnalysisDate(150000000L)
            .build());

    writer.writeComponent(
        BatchReport.Component.newBuilder()
            .setRef(1)
            .setType(Constants.ComponentType.PROJECT)
            .setUuid("ABCD")
            .setSnapshotId(1000L)
            .addEvent(
                BatchReport.Event.newBuilder()
                    .setName("Red (was Orange)")
                    .setCategory(Constants.EventCategory.ALERT)
                    .setDescription("Open issues > 0")
                    .build())
            .addChildRef(2)
            .build());

    writer.writeComponent(
        BatchReport.Component.newBuilder()
            .setRef(2)
            .setType(Constants.ComponentType.MODULE)
            .setUuid("BCDE")
            .setSnapshotId(1001L)
            .addEvent(
                BatchReport.Event.newBuilder()
                    .setName("Red (was Orange)")
                    .setCategory(Constants.EventCategory.ALERT)
                    .setDescription("Open issues > 0")
                    .build())
            .build());

    step.execute(
        new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class)));

    dbTester.assertDbUnit(
        getClass(), "persist_report_events_with_component_children-result.xml", "events");
  }
コード例 #6
0
  @Test
  public void persist_report_events() throws Exception {
    dbTester.prepareDbUnit(getClass(), "empty.xml");

    File reportDir = temp.newFolder();
    BatchReportWriter writer = new BatchReportWriter(reportDir);
    writer.writeMetadata(
        BatchReport.Metadata.newBuilder()
            .setRootComponentRef(1)
            .setProjectKey("PROJECT_KEY")
            .setAnalysisDate(150000000L)
            .build());

    writer.writeComponent(
        BatchReport.Component.newBuilder()
            .setRef(1)
            .setType(Constants.ComponentType.PROJECT)
            .setUuid("ABCD")
            .setSnapshotId(1000L)
            .addEvent(
                BatchReport.Event.newBuilder()
                    .setName("Red (was Orange)")
                    .setCategory(Constants.EventCategory.ALERT)
                    .setDescription("Open issues > 0")
                    .build())
            .addEvent(
                BatchReport.Event.newBuilder()
                    .setName("Changes in 'Default' (Java)")
                    .setCategory(Constants.EventCategory.PROFILE)
                    .setEventData(
                        "from=2014-10-12T08:36:25+0000;key=java-default;to=2014-10-12T10:36:25+0000")
                    .build())
            .build());

    step.execute(
        new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class)));

    dbTester.assertDbUnit(getClass(), "add_events-result.xml", "events");
  }