@Test
  public void set_variation() {
    // Project
    SnapshotDto period1ProjectSnapshot = createForProject(PROJECT_DTO);
    dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
    dbClient
        .measureDao()
        .insert(
            session,
            newMeasureDto(
                ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 60d));

    // Directory
    ComponentDto directoryDto = ComponentTesting.newDirectory(PROJECT_DTO, "dir");
    dbClient.componentDao().insert(session, directoryDto);
    SnapshotDto period1DirectorySnapshot = createForComponent(directoryDto, period1ProjectSnapshot);
    dbClient.snapshotDao().insert(session, period1DirectorySnapshot);
    dbClient
        .measureDao()
        .insert(
            session,
            newMeasureDto(
                ISSUES_METRIC.getId(),
                directoryDto.getId(),
                period1DirectorySnapshot.getId(),
                10d));
    session.commit();

    periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot));

    Component directory =
        ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid(directoryDto.uuid()).build();
    Component project =
        ReportComponent.builder(Component.Type.PROJECT, 1)
            .setUuid(PROJECT_DTO.uuid())
            .addChildren(directory)
            .build();
    treeRootHolder.setRoot(project);

    addRawMeasure(project, ISSUES_METRIC, Measure.newMeasureBuilder().create(80, null));
    addRawMeasure(directory, ISSUES_METRIC, Measure.newMeasureBuilder().create(20, null));

    underTest.execute();

    assertThat(
            measureRepository
                .getRawMeasure(project, ISSUES_METRIC)
                .get()
                .getVariations()
                .getVariation1())
        .isEqualTo(20d);
    assertThat(
            measureRepository
                .getRawMeasure(directory, ISSUES_METRIC)
                .get()
                .getVariations()
                .getVariation1())
        .isEqualTo(10d);
  }
 @Override
 public Optional<Measure> createMeasure(FakeCounter counter, Component.Type componentType) {
   if (counter.value <= 0) {
     return Optional.absent();
   }
   return Optional.of(Measure.newMeasureBuilder().create(counter.value));
 }
Exemplo n.º 3
0
 @Override
 public Optional<Measure> createMeasure(
     DistributionCounter counter, CreateMeasureContext context) {
   Component.Type componentType = context.getComponent().getType();
   Optional<String> value = counter.getValue();
   if (value.isPresent() && CrawlerDepthLimit.LEAVES.isDeeperThan(componentType)) {
     return Optional.of(Measure.newMeasureBuilder().create(value.get()));
   }
   return Optional.absent();
 }
Exemplo n.º 4
0
  private void saveAndAggregate(Component component, Path<LastCommit> path) {
    long maxDate = path.current().getDate();
    if (maxDate > 0L) {
      measureRepository.add(
          component, lastCommitDateMetric, Measure.newMeasureBuilder().create(maxDate));

      if (!path.isRoot()) {
        path.parent().addDate(maxDate);
      }
    }
  }
  @Test
  public void set_variations_on_all_periods() {
    SnapshotDto period1ProjectSnapshot = createForProject(PROJECT_DTO).setLast(false);
    SnapshotDto period2ProjectSnapshot = createForProject(PROJECT_DTO).setLast(false);
    SnapshotDto period3ProjectSnapshot = createForProject(PROJECT_DTO).setLast(false);
    SnapshotDto period4ProjectSnapshot = createForProject(PROJECT_DTO).setLast(false);
    SnapshotDto period5ProjectSnapshot = createForProject(PROJECT_DTO).setLast(false);
    dbClient
        .snapshotDao()
        .insert(
            session,
            period1ProjectSnapshot,
            period2ProjectSnapshot,
            period3ProjectSnapshot,
            period4ProjectSnapshot,
            period5ProjectSnapshot);

    dbClient
        .measureDao()
        .insert(
            session,
            newMeasureDto(
                ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 0d),
            newMeasureDto(
                ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period2ProjectSnapshot.getId(), 20d),
            newMeasureDto(
                ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period3ProjectSnapshot.getId(), 40d),
            newMeasureDto(
                ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period4ProjectSnapshot.getId(), 80d),
            newMeasureDto(
                ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period5ProjectSnapshot.getId(), 100d));
    session.commit();

    periodsHolder.setPeriods(
        newPeriod(1, period1ProjectSnapshot),
        newPeriod(2, period2ProjectSnapshot),
        newPeriod(3, period3ProjectSnapshot),
        newPeriod(4, period4ProjectSnapshot),
        newPeriod(5, period5ProjectSnapshot));

    treeRootHolder.setRoot(PROJECT);

    addRawMeasure(PROJECT, ISSUES_METRIC, Measure.newMeasureBuilder().create(80, null));

    underTest.execute();

    assertThat(measureRepository.getRawMeasures(PROJECT).keys()).hasSize(1);

    Measure measure = measureRepository.getRawMeasure(PROJECT, ISSUES_METRIC).get();
    assertThat(measure.hasVariations()).isTrue();
    assertThat(measure.getVariations().getVariation1()).isEqualTo(80d);
    assertThat(measure.getVariations().getVariation2()).isEqualTo(60d);
    assertThat(measure.getVariations().getVariation3()).isEqualTo(40d);
    assertThat(measure.getVariations().getVariation4()).isEqualTo(0d);
    assertThat(measure.getVariations().getVariation5()).isEqualTo(-20d);
  }
Exemplo n.º 6
0
 private void assertVariation(Component component, String metricKey, int variation) {
   Measure newMeasure =
       measureRepository.getRawMeasure(component, metricRepository.getByKey(metricKey)).get();
   assertThat(newMeasure.getVariations().getVariation(PERIOD.getIndex())).isEqualTo(variation);
   assertThat(newMeasure.getVariations().hasVariation(PERIOD.getIndex() + 1)).isFalse();
 }
 public Measure createMeasure() {
   return Measure.newMeasureBuilder()
       .create(QPMeasureData.toJson(new QPMeasureData(profilesByKey.values())));
 }
 public void add(Measure measure) {
   profilesByKey.putAll(QPMeasureData.fromJson(measure.getStringValue()).getProfilesByKey());
 }
  @Test
  public void set_variation_on_all_numeric_metrics() {
    SnapshotDto period1ProjectSnapshot = createForProject(PROJECT_DTO);
    dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
    dbClient
        .measureDao()
        .insert(
            session,
            newMeasureDto(
                ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 60d),
            newMeasureDto(
                DEBT_METRIC.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 10d),
            newMeasureDto(
                FILE_COMPLEXITY_METRIC.getId(),
                PROJECT_DTO.getId(),
                period1ProjectSnapshot.getId(),
                2d),
            newMeasureDto(
                BUILD_BREAKER_METRIC.getId(),
                PROJECT_DTO.getId(),
                period1ProjectSnapshot.getId(),
                1d));
    session.commit();

    periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot));

    treeRootHolder.setRoot(PROJECT);

    addRawMeasure(PROJECT, ISSUES_METRIC, Measure.newMeasureBuilder().create(80, null));
    addRawMeasure(PROJECT, DEBT_METRIC, Measure.newMeasureBuilder().create(5L, null));
    addRawMeasure(PROJECT, FILE_COMPLEXITY_METRIC, Measure.newMeasureBuilder().create(3d, null));
    addRawMeasure(PROJECT, BUILD_BREAKER_METRIC, Measure.newMeasureBuilder().create(false, null));

    underTest.execute();

    assertThat(measureRepository.getRawMeasures(PROJECT).keys()).hasSize(4);

    assertThat(
            measureRepository
                .getRawMeasure(PROJECT, ISSUES_METRIC)
                .get()
                .getVariations()
                .getVariation1())
        .isEqualTo(20d);
    assertThat(
            measureRepository
                .getRawMeasure(PROJECT, DEBT_METRIC)
                .get()
                .getVariations()
                .getVariation1())
        .isEqualTo(-5d);
    assertThat(
            measureRepository
                .getRawMeasure(PROJECT, FILE_COMPLEXITY_METRIC)
                .get()
                .getVariations()
                .getVariation1())
        .isEqualTo(1d);
    assertThat(
            measureRepository
                .getRawMeasure(PROJECT, BUILD_BREAKER_METRIC)
                .get()
                .getVariations()
                .getVariation1())
        .isEqualTo(-1d);
  }