Package org.sonar.api.measures

Examples of org.sonar.api.measures.Metric


    long metric2Id = 2L;
    QualityGateConditionDto cond1 = new QualityGateConditionDto().setMetricId(metric1Id);
    QualityGateConditionDto cond2 = new QualityGateConditionDto().setMetricId(metric2Id);
    Collection<QualityGateConditionDto> conditions = ImmutableList.of(cond1, cond2);
    when(conditionDao.selectForQualityGate(qGateId)).thenReturn(conditions);
    Metric metric1 = mock(Metric.class);
    when(metric1.getKey()).thenReturn(metric1Key);
    when(metricFinder.findById((int) metric1Id)).thenReturn(metric1);
    qGates.listConditions(qGateId);
  }
View Full Code Here


    verify(conditionDao, times(conditions.size())).insert(any(QualityGateConditionDto.class), eq(session));
  }

  @Test
  public void should_list_gate_metrics() {
    Metric dataMetric = mock(Metric.class);
    when(dataMetric.isDataType()).thenReturn(true);
    Metric hiddenMetric = mock(Metric.class);
    when(hiddenMetric.isHidden()).thenReturn(true);
    Metric nullHiddenMetric = mock(Metric.class);
    when(nullHiddenMetric.isHidden()).thenReturn(null);
    Metric alertMetric = CoreMetrics.ALERT_STATUS;
    Metric ratingMetric = mock(Metric.class);
    when(ratingMetric.getType()).thenReturn(ValueType.RATING);
    Metric classicMetric = mock(Metric.class);
    when(classicMetric.getType()).thenReturn(ValueType.BOOL);
    when(metricFinder.findAll()).thenReturn(ImmutableList.of(
      dataMetric, hiddenMetric, nullHiddenMetric, alertMetric, ratingMetric, classicMetric));
    assertThat(qGates.gateMetrics()).hasSize(3).containsOnly(classicMetric, hiddenMetric, nullHiddenMetric);
  }
View Full Code Here

      public String answer(InvocationOnMock invocation) throws Throwable {
        return (String) invocation.getArguments()[1];
      }
    }).when(i18n).message(any(Locale.class), any(String.class), any(String.class));

    Metric metric = mock(Metric.class);
    when(metric.getId()).thenReturn(42);
    when(metric.getKey()).thenReturn("metric");
    when(metric.getName()).thenReturn("Metric");
    when(metric.getType()).thenReturn(ValueType.BOOL);
    when(metric.getDomain()).thenReturn("General");
    when(metric.isHidden()).thenReturn(false);
    when(qGates.gateMetrics()).thenReturn(ImmutableList.of(metric));

    String json = tester.newGetRequest("api/qualitygates", "app").execute().outputAsString();

    Map responseJson = (Map) JSONValue.parse(json);
View Full Code Here

  public QualityGateConditionDto createCondition(long qGateId, String metricKey, String operator,
    @Nullable String warningThreshold, @Nullable String errorThreshold, @Nullable Integer period) {
    checkPermission(UserSession.get());
    getNonNullQgate(qGateId);
    Metric metric = getNonNullMetric(metricKey);
    validateCondition(metric, operator, warningThreshold, errorThreshold, period);
    QualityGateConditionDto newCondition = new QualityGateConditionDto().setQualityGateId(qGateId)
      .setMetricId(metric.getId()).setMetricKey(metric.getKey())
      .setOperator(operator).setWarningThreshold(warningThreshold).setErrorThreshold(errorThreshold).setPeriod(period);
    conditionDao.insert(newCondition);
    return newCondition;
  }
View Full Code Here

  public QualityGateConditionDto updateCondition(long condId, String metricKey, String operator,
    @Nullable String warningThreshold, @Nullable String errorThreshold, @Nullable Integer period) {
    checkPermission(UserSession.get());
    QualityGateConditionDto condition = getNonNullCondition(condId);
    Metric metric = getNonNullMetric(metricKey);
    validateCondition(metric, operator, warningThreshold, errorThreshold, period);
    condition.setMetricId(metric.getId()).setMetricKey(metric.getKey())
      .setOperator(operator).setWarningThreshold(warningThreshold).setErrorThreshold(errorThreshold).setPeriod(period);
    conditionDao.update(condition);
    return condition;
  }
View Full Code Here

  }

  public Collection<QualityGateConditionDto> listConditions(long qGateId) {
    Collection<QualityGateConditionDto> conditionsForGate = conditionDao.selectForQualityGate(qGateId);
    for (QualityGateConditionDto condition : conditionsForGate) {
      Metric metric = metricFinder.findById((int) condition.getMetricId());
      if (metric == null) {
        throw new IllegalStateException("Could not find metric with id " + condition.getMetricId());
      }
      condition.setMetricKey(metric.getKey());
    }
    return conditionsForGate;
  }
View Full Code Here

    }
    return qGate;
  }

  private Metric getNonNullMetric(String metricKey) {
    Metric metric = metricFinder.findByKey(metricKey);
    if (metric == null) {
      throw new NotFoundException("There is no metric with key=" + metricKey);
    }
    return metric;
  }
View Full Code Here

  @Test
  public void sort_by_ascending_alert() throws SQLException {
    db.prepareDbUnit(getClass(), "sort_by_alert.xml");

    Metric alert = new Metric.Builder(CoreMetrics.ALERT_STATUS_KEY, "Alert", Metric.ValueType.LEVEL).create().setId(5);
    MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).setSortOnMetric(alert);
    List<MeasureFilterRow> rows = executor.execute(filter, new MeasureFilterContext());

    // Php Project OK, Java Project WARN then Js Project ERROR
    assertThat(rows).hasSize(3);
View Full Code Here

  @Test
  public void sort_by_descending_alert() throws SQLException {
    db.prepareDbUnit(getClass(), "sort_by_alert.xml");

    Metric alert = new Metric.Builder(CoreMetrics.ALERT_STATUS_KEY, "Alert", Metric.ValueType.LEVEL).create().setId(5);
    MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).setSortOnMetric(alert).setSortAsc(false);
    List<MeasureFilterRow> rows = executor.execute(filter, new MeasureFilterContext());

    // Js Project ERROR, Java Project WARN, then Php Project OK
    assertThat(rows).hasSize(3);
View Full Code Here

  @Test
  public void ignore_person_measures_in_condition() throws Exception {
    db.prepareDbUnit(getClass(), "ignore_person_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

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.