Package org.sonar.api.measures

Examples of org.sonar.api.measures.Metric


  }

  @Test
  public void ignore_person_measures_in_sort() throws Exception {
    db.prepareDbUnit(getClass(), "ignore_person_measures.xml");
    MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).setSortOnMetric(new Metric("ncloc").setId(1));
    List<MeasureFilterRow> rows = executor.execute(filter, new MeasureFilterContext().setUserId(50L));

    assertThat(rows).hasSize(1);
    assertThat(rows.get(0).getSnapshotId()).isEqualTo(101L);
  }
View Full Code Here


  @Test
  public void ignore_quality_model_measures_in_condition() throws Exception {
    db.prepareDbUnit(getClass(), "ignore_quality_model_measures.xml");
    MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).addCondition(
      new MeasureFilterCondition(new Metric("ncloc").setId(1), MeasureFilterCondition.Operator.GREATER, 0.0)
    );
    List<MeasureFilterRow> rows = executor.execute(filter, new MeasureFilterContext().setUserId(50L));

    assertThat(rows).hasSize(1);
    assertThat(rows.get(0).getSnapshotId()).isEqualTo(101L);
View Full Code Here

  }

  @Test
  public void ignore_quality_model_measures_in_sort() throws Exception {
    db.prepareDbUnit(getClass(), "ignore_quality_model_measures.xml");
    MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).setSortOnMetric(new Metric("ncloc").setId(1));
    List<MeasureFilterRow> rows = executor.execute(filter, new MeasureFilterContext().setUserId(50L));

    assertThat(rows).hasSize(1);
    assertThat(rows.get(0).getSnapshotId()).isEqualTo(101L);
  }
View Full Code Here

    assertThat(MeasureFilterCondition.Operator.GREATER.getSql()).isEqualTo(">");
  }

  @Test
  public void value_condition() {
    Metric ncloc = new Metric.Builder("ncloc", "NCLOC", Metric.ValueType.INT).create();
    ncloc.setId(123);
    MeasureFilterCondition condition = new MeasureFilterCondition(ncloc, MeasureFilterCondition.Operator.GREATER, 10.0);

    assertThat(condition.metric()).isEqualTo(ncloc);
    assertThat(condition.operator()).isEqualTo(MeasureFilterCondition.Operator.GREATER);
    assertThat(condition.period()).isNull();
View Full Code Here

    assertThat(condition.appendSqlCondition(new StringBuilder(), 1).toString()).isEqualTo(" pmcond1.metric_id=123 AND pmcond1.value > 10.0 AND pmcond1.rule_id IS NULL AND pmcond1.rule_priority IS NULL AND pmcond1.characteristic_id IS NULL AND pmcond1.person_id IS NULL ");
  }

  @Test
  public void variation_condition() {
    Metric ncloc = new Metric.Builder("ncloc", "NCLOC", Metric.ValueType.INT).create();
    ncloc.setId(123);
    MeasureFilterCondition condition = new MeasureFilterCondition(ncloc, MeasureFilterCondition.Operator.LESS_OR_EQUALS, 10.0);
    condition.setPeriod(3);

    assertThat(condition.metric()).isEqualTo(ncloc);
    assertThat(condition.operator()).isEqualTo(MeasureFilterCondition.Operator.LESS_OR_EQUALS);
View Full Code Here

    assertThat(condition.appendSqlCondition(new StringBuilder(), 2).toString()).isEqualTo(" pmcond2.metric_id=123 AND pmcond2.variation_value_3 <= 10.0 AND pmcond2.rule_id IS NULL AND pmcond2.rule_priority IS NULL AND pmcond2.characteristic_id IS NULL AND pmcond2.person_id IS NULL ");
  }

  @Test
  public void text_value_condition() {
    Metric ncloc = new Metric.Builder("ncloc", "NCLOC", Metric.ValueType.INT).create();
    ncloc.setId(123);
    MeasureFilterCondition condition = new MeasureFilterCondition(ncloc, MeasureFilterCondition.Operator.EQUALS, "\"foo\"");

    assertThat(condition.metric()).isEqualTo(ncloc);
    assertThat(condition.operator()).isEqualTo(MeasureFilterCondition.Operator.EQUALS);
    assertThat(condition.period()).isNull();
View Full Code Here

  @Test
  public void shouldSaveIfNew() {
    setupData("shouldSaveIfNew");

    Metric metric1 = new Metric.Builder("new1", "short1", Metric.ValueType.FLOAT)
      .setDescription("desc1")
      .setDirection(1)
      .setQualitative(true)
      .setDomain("domain1")
      .setUserManaged(false)
      .create();
    Metric metric2 = new Metric.Builder("new2", "short2", Metric.ValueType.FLOAT)
      .setDescription("desc2")
      .setDirection(1)
      .setQualitative(true)
      .setDomain("domain2")
      .setUserManaged(false)
View Full Code Here

    String metricKey = "coverage";
    String operator = "LT";
    String warningThreshold = "90";
    when(dao.selectById(qGateId)).thenReturn(new QualityGateDto().setId(qGateId));
    Integer metricId = 10;
    Metric coverage = Mockito.spy(CoreMetrics.COVERAGE);
    when(coverage.getId()).thenReturn(metricId);
    when(metricFinder.findByKey(metricKey)).thenReturn(coverage);

    QualityGateConditionDto newCondition = qGates.createCondition(qGateId, metricKey, operator, warningThreshold, null, null);
    assertThat(newCondition.getQualityGateId()).isEqualTo(qGateId);
    assertThat(newCondition.getMetricId()).isEqualTo(metricId);
View Full Code Here

    String metricKey = "new_coverage";
    String operator = "LT";
    String errorThreshold = "80";
    when(dao.selectById(qGateId)).thenReturn(new QualityGateDto().setId(qGateId));
    Integer metricId = 10;
    Metric newCoverage = Mockito.spy(CoreMetrics.NEW_COVERAGE);
    when(newCoverage.getId()).thenReturn(metricId);
    when(metricFinder.findByKey(metricKey)).thenReturn(newCoverage);
    int period = 2;

    QualityGateConditionDto newCondition = qGates.createCondition(qGateId, metricKey, operator, null, errorThreshold, period);
    assertThat(newCondition.getQualityGateId()).isEqualTo(qGateId);
View Full Code Here

  }

  @Test(expected = BadRequestException.class)
  public void should_fail_create_condition_on_non_data_metric() {
    long qGateId = 42L;
    final Metric metric = mock(Metric.class);
    when(metric.getType()).thenReturn(ValueType.DATA);
    when(metricFinder.findByKey(anyString())).thenReturn(metric);
    when(dao.selectById(qGateId)).thenReturn(new QualityGateDto().setId(qGateId));
    qGates.createCondition(qGateId, "alert_status", "LT", null, "80", 2);
  }
View Full Code Here

TOP

Related Classes of org.sonar.api.measures.Metric

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.